Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion video/live-stream/create_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_channel(
name=name,
input_attachments=[
live_stream_v1.types.InputAttachment(
key="my-input",
key=input_id,
input=input,
),
],
Expand Down
18 changes: 14 additions & 4 deletions video/live-stream/create_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"""Google Cloud Live Stream sample for creating an input endpoint. You send an
input video stream to this endpoint.
Example usage:
python create_input.py --project_id <project-id> --location <location> --input_id <input-id>
python create_input.py --project_id <project-id> --location <location> \
--input_id <input-id> [--input_type <input-type>]
"""

# [START livestream_create_input]
Expand All @@ -31,20 +32,22 @@


def create_input(
project_id: str, location: str, input_id: str
project_id: str, location: str, input_id: str, input_type: str
) -> live_stream_v1.types.Input:
"""Creates an input.
Args:
project_id: The GCP project ID.
location: The location in which to create the input.
input_id: The user-defined input ID."""
input_id: The user-defined input ID.
input_type: The input type.
"""

client = LivestreamServiceClient()

parent = f"projects/{project_id}/locations/{location}"

input = live_stream_v1.types.Input(
type_="RTMP_PUSH",
type_=input_type,
)
operation = client.create_input(parent=parent, input=input, input_id=input_id)
response = operation.result(900)
Expand All @@ -68,9 +71,16 @@ def create_input(
help="The user-defined input ID.",
required=True,
)
parser.add_argument(
"--input_type",
help="The input type.",
choices=["RTMP_PUSH", "SRT_PUSH"],
default="RTMP_PUSH",
)
args = parser.parse_args()
create_input(
args.project_id,
args.location,
args.input_id,
args.input_type,
)
26 changes: 26 additions & 0 deletions video/live-stream/get_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ def get_channel(
name = f"projects/{project_id}/locations/{location}/channels/{channel_id}"
response = client.get_channel(name=name)
print(f"Channel: {response.name}")
print(f"Creation time: {response.create_time}")
if response.labels:
print("Labels:")
for key, value in response.labels.items():
print(f" {key}: {value}")
print(f"Update time: {response.update_time}")
print(f"Streaming state: {response.streaming_state.name}")
if response.streaming_error:
print(f"Streaming error: {response.streaming_error.message}")
print(f"Active input: {response.active_input}")
for attachment in response.input_attachments:
print(f"Input attachment: {attachment.key}")
print(f"Output URI: {response.output.uri}")
print(f"Log config: {response.log_config.log_severity.name}")
if response.elementary_streams:
print("Elementary streams:")
for stream in response.elementary_streams:
print(f" {stream.key}")
if response.mux_streams:
print("Mux streams:")
for stream in response.mux_streams:
print(f" {stream.key}")
if response.manifests:
print("Manifests:")
for manifest in response.manifests:
print(f" {manifest.file_name} ({manifest.type_.name})")

return response

Expand Down
6 changes: 5 additions & 1 deletion video/live-stream/get_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def get_input(

name = f"projects/{project_id}/locations/{location}/inputs/{input_id}"
response = client.get_input(name=name)
print(f"Input: {response.name}")
print(f"Name: {response.name}")
print(f"Type: {response.type_.name}")
print(f"Tier: {response.tier.name}")
if response.uri:
print(f"URI: {response.uri}")

return response

Expand Down
6 changes: 4 additions & 2 deletions video/live-stream/list_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ def list_channels(project_id: str, location: str) -> pagers.ListChannelsPager:

parent = f"projects/{project_id}/locations/{location}"
page_result = client.list_channels(parent=parent)
print("Channels:")
print("\nThe following Channels are configured in this location:\n")

responses = []
for response in page_result:
print(response.name)
print(f"\nChannel: {response.name}")
print(f" Active input: {response.active_input}")
print(f" Output URI: {response.output.uri}")
responses.append(response)

return responses
Expand Down
28 changes: 24 additions & 4 deletions video/live-stream/update_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@


def update_channel(
project_id: str, location: str, channel_id: str, input_id: str
project_id: str,
location: str,
channel_id: str,
input_id: str,
log_config: str = None,
) -> live_stream_v1.types.Channel:
"""Updates a channel.
Args:
project_id: The GCP project ID.
location: The location of the channel.
channel_id: The user-defined channel ID.
input_id: The user-defined input ID for the new input."""
input_id: The user-defined input ID for the new input.
log_config: The log severity for the channel."""

client = LivestreamServiceClient()
input = f"projects/{project_id}/locations/{location}/inputs/{input_id}"
Expand All @@ -49,12 +54,20 @@ def update_channel(
name=name,
input_attachments=[
live_stream_v1.types.InputAttachment(
key="updated-input",
key=input_id,
input=input,
),
],
)
update_mask = field_mask.FieldMask(paths=["input_attachments"])
update_mask_paths = ["input_attachments"]

if log_config:
channel.log_config = live_stream_v1.types.LogConfig(
log_severity=live_stream_v1.types.LogConfig.LogSeverity[log_config]
)
update_mask_paths.append("log_config")

update_mask = field_mask.FieldMask(paths=update_mask_paths)

operation = client.update_channel(channel=channel, update_mask=update_mask)
response = operation.result(600)
Expand Down Expand Up @@ -83,10 +96,17 @@ def update_channel(
help="The user-defined input ID.",
required=True,
)
parser.add_argument(
"--log_config",
help="The log severity for the channel.",
choices=["OFF", "DEBUG", "INFO", "WARNING", "ERROR"],
required=False,
)
args = parser.parse_args()
update_channel(
args.project_id,
args.location,
args.channel_id,
args.input_id,
args.log_config,
)