Exemplo n.º 1
0
def create(cmd, client, resource_group_name, account_name, live_event_name, streaming_protocol, ips,  # pylint: disable=too-many-locals
           auto_start=False, encoding_type=None, preset_name=None, tags=None, description=None,
           key_frame_interval_duration=None, access_token=None, no_wait=False, preview_ips=None,
           preview_locator=None, streaming_policy_name=None, alternative_media_id=None,
           vanity_url=False, client_access_policy=None, cross_domain_policy=None, stream_options=None):
    from azure.mgmt.media.models import (LiveEventInputProtocol, LiveEventInput, LiveEvent,
                                         LiveEventEncoding, LiveEventInputAccessControl, IPAccessControl)
    from azure.cli.command_modules.ams._client_factory import (get_mediaservices_client)

    allowed_ips = []
    if ips[0] == 'AllowAll':
        ips = ['0.0.0.0/0']
    for ip in ips:
        allowed_ips.append(create_ip_range(live_event_name, ip))

    live_event_input_access_control = LiveEventInputAccessControl(ip=IPAccessControl(allow=allowed_ips))

    live_event_input = LiveEventInput(streaming_protocol=LiveEventInputProtocol(streaming_protocol),
                                      access_token=access_token,
                                      key_frame_interval_duration=key_frame_interval_duration,
                                      access_control=live_event_input_access_control)

    ams_client = get_mediaservices_client(cmd.cli_ctx)
    ams = ams_client.get(resource_group_name, account_name)
    location = ams.location

    live_event_preview = create_live_event_preview(preview_locator, streaming_policy_name, alternative_media_id,
                                                   preview_ips, live_event_name)

    policies = create_cross_site_access_policies(client_access_policy, cross_domain_policy)

    live_event = LiveEvent(input=live_event_input, location=location, preview=live_event_preview,
                           encoding=LiveEventEncoding(encoding_type=encoding_type, preset_name=preset_name),
                           tags=tags, vanity_url=vanity_url, stream_options=stream_options,
                           cross_site_access_policies=policies, description=description)

    return sdk_no_wait(no_wait, client.create, resource_group_name=resource_group_name, account_name=account_name,
                       live_event_name=live_event_name, parameters=live_event, auto_start=auto_start)
Exemplo n.º 2
0
# When broadcasting to a live event, please use one of the verified on-premises live streaminf encoders.
# While operating this tutorial, it is recommended to start out using OBS Studio before moving to another encoder.

# Note: When creating a LiveEvent, you can specify allowed IP addresses in one of the following formats:
#       IPV4 address with 4 numbers
#       CIDR address range

allow_all_input_range = IPRange(name="AllowAll",
                                address="0.0.0.0",
                                subnet_prefix_length=0)

# Create the LiveEvent input IP access control object
# This will control the IP that the encoder is running on and restrict access to only that encoder IP range.
# re-use the same range here for the sample, but in production, you can lock this down to the IP range for your on-premises
# live encoder, laptop, or device that is sending the live stream
live_event_input_access = LiveEventInputAccessControl(ip=IPAccessControl(
    allow=[allow_all_input_range]))

# Create the LiveEvent Preview IP access control object.
# This will restrict which clients can view the preview endpoint
# re-use the same range here for the sample, but in production, you can lock this to the IPs of your
# devices that would be monitoring the live preview.
live_event_preview = LiveEventPreview(
    access_control=LiveEventPreviewAccessControl(ip=IPAccessControl(
        allow=[allow_all_input_range])))

# To get the same ingest URL for the same LiveEvent name every single time...
# 1. Set useStaticHostname to true so you have inget like:
#       rtmps://liveevent-hevc12-eventgridmediaservice-usw22.channel.media.azure.net:2935/live/522f9b27dd2d4b26aeb9ef8ab96c5c77
# 2. Set accessToken to a desired GUID string (with or without hyphen)

# See REST API documentation for the details on each setting value