Skip to content

Commit

Permalink
added REST topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliako committed Feb 18, 2015
1 parent e21a2f9 commit 521811c
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 47 deletions.
147 changes: 100 additions & 47 deletions articles/media-services-deliver-streaming-content.md
@@ -1,6 +1,6 @@
<properties
pageTitle="How to Deliver Streaming Content from Media Services – Azure"
description="Learn how to deliver streaming content from Media Services using a direct URL. Code samples are written in C# and use the Media Services SDK for .NET."
description="Learn how to create a locator that is used to build a streaming URL. Code samples are written in C# and use the Media Services SDK for .NET."
authors="juliako"
manager="dwrede"
editor=""
Expand All @@ -13,7 +13,7 @@
ms.tgt_pltfrm="na"
ms.devlang="na"
ms.topic="article"
ms.date="02/15/2015"
ms.date="02/17/2015"
ms.author="juliako"/>


Expand All @@ -24,76 +24,129 @@ This article is part of the [Media Services Video on Demand workflow](../media-s

##Overview

You can use adaptive bitrate streaming to deliver content by creating a streaming locator. Before you create a locator you should configure asset delivery policy as described in [this](../media-services-dotnet-configure-asset-delivery-policy) topic.
You can stream an adaptive bitrate MP4 set by creating an OnDemand streaming locator and building a streaming URL. The [encoding an asset](../media-services-encode-asset) topic shows how to encode into an adaptive bitrate MP4 set. Before you create a locator you should configure asset delivery policy as described in [this](../media-services-dotnet-configure-asset-delivery-policy) topic.

The following example shows how to create an origin locator for an output asset produced by a job. The example assumes that you have already obtained a reference to an asset that contains smooth streaming files, and the variable named **assetToStream** is referenced in the code.
You can also use an OnDemand streaming locator to build URLs that point to MP4 files that can be progressively downloaded.

To create an origin locator to streaming content:
This topic shows how to create an OnDemand streaming locator in order to publish your asset and build a Smooth, MPEG DASH, and HLS streaming URLs. It also shows hot to build progressive download URLs.

##Create an OnDemand streaming locator

1. Get a reference to the streaming manifest file (.ism) in the asset
2. Define an access policy
3. Create the origin locator by calling the CreateLocator method
4. Build a URL to the manifest file
To create the OnDemand streaming locator and get URLs you need to do the following:

##Use Media Services .NET SDK

private static ILocator GetStreamingOriginLocator( string targetAssetID)
1. Define an access policy.
2. Create an OnDemand streaming locator.
3. If you plan to stream, get the streaming manifest file (.ism) in the asset.

If you plan to progressively download, get the names of MP4 files in the asset.
4. Build URLs to the manifest file or MP4 files.


###Use Media Services .NET SDK

Build Streaming URLs

private static void BuildStreamingURLs(IAsset asset)
{
// Get a reference to the asset you want to stream.
IAsset assetToStream = GetAsset(targetAssetID);

// Get a reference to the streaming manifest file from the
// collection of files in the asset.
var theManifest =
from f in assetToStream.AssetFiles
where f.Name.EndsWith(".ism")
select f;

// Cast the reference to a true IAssetFile type.
IAssetFile manifestFile = theManifest.First();
IAccessPolicy policy = null;
ILocator originLocator = null;
// Create a 30-day readonly access policy.
policy = _context.AccessPolicies.Create("Streaming policy",
IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy",
TimeSpan.FromDays(30),
AccessPermissions.Read);

// Create an OnDemandOrigin locator to the asset.
originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, assetToStream,
// Create a locator to the streaming content on an origin.
ILocator originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset,
policy,
DateTime.UtcNow.AddMinutes(-5));

// Display some useful values based on the locator.
Console.WriteLine("Streaming asset base path on origin: ");
Console.WriteLine(originLocator.Path);
Console.WriteLine();

// Get a reference to the streaming manifest file from the
// collection of files in the asset.
var manifestFile = asset.AssetFiles.Where(f => f.Name.ToLower().
EndsWith(".ism")).
FirstOrDefault();
// Create a full URL to the manifest file. Use this for playback
// in streaming media clients.
string urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";
Console.WriteLine("URL to manifest for client streaming: ");
Console.WriteLine("URL to manifest for client streaming using Smooth Streaming protocol: ");
Console.WriteLine(urlForClientStreaming);
Console.WriteLine("URL to manifest for client streaming using HLS protocol: ");
Console.WriteLine(urlForClientStreaming + "(format=m3u8-aapl)");
Console.WriteLine("URL to manifest for client streaming using MPEG DASH protocol: ");
Console.WriteLine(urlForClientStreaming + "(format=mpd-time-csf)");
Console.WriteLine();
// Display the ID of the origin locator, the access policy, and the asset.
Console.WriteLine("Origin locator Id: " + originLocator.Id);
Console.WriteLine("Access policy Id: " + policy.Id);
Console.WriteLine("Streaming asset Id: " + assetToStream.Id);
}

The code outputs:

URL to manifest for client streaming using Smooth Streaming protocol:
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest
URL to manifest for client streaming using HLS protocol:
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=m3u8-aapl)
URL to manifest for client streaming using MPEG DASH protocol:
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=mpd-time-csf)


Build progressive download URLs

private static void BuildProgressiveDownloadURLs(IAsset asset)
{
// Create a 30-day readonly access policy.
IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy",
TimeSpan.FromDays(30),
AccessPermissions.Read);

// Return the locator.
return originLocator;
// Create an OnDemandOrigin locator to the asset.
ILocator originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset,
policy,
DateTime.UtcNow.AddMinutes(-5));

// Display some useful values based on the locator.
Console.WriteLine("Streaming asset base path on origin: ");
Console.WriteLine(originLocator.Path);
Console.WriteLine();

// Get MP4 files.
IEnumerable<IAssetFile> mp4AssetFiles = asset
.AssetFiles
.ToList()
.Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));
// Create a full URL to the MP4 files. Use this to progressively download files.
foreach (var pd in mp4AssetFiles)
Console.WriteLine(originLocator.Path + pd.Name);
}

##Use Media Services .NET SDK Extensions
The code outputs:

http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_650kbps_AAC_und_ch2_96kbps.mp4
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_400kbps_AAC_und_ch2_96kbps.mp4
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_3400kbps_AAC_und_ch2_96kbps.mp4
http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_2250kbps_AAC_und_ch2_96kbps.mp4

. . .

The following code calls methods that generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming.
###Use Media Services .NET SDK Extensions

// and the Progressive Download URL.
Uri smoothStreamingUri = outputAsset.GetSmoothStreamingUri();
Uri hlsUri = outputAsset.GetHlsUri();
Uri mpegDashUri = outputAsset.GetMpegDashUri();
The following code calls .NET SDK extensions methods that create a locator and generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming.

Console.WriteLine(smoothStreamingUri);
Console.WriteLine(hlsUri);
Console.WriteLine(mpegDashUri);
// Create a loctor.
_context.Locators.Create(
LocatorType.OnDemandOrigin,
inputAsset,
AccessPermissions.Read,
TimeSpan.FromDays(30));

// Get the streaming URLs.
Uri smoothStreamingUri = inputAsset.GetSmoothStreamingUri();
Uri hlsUri = inputAsset.GetHlsUri();
Uri mpegDashUri = inputAsset.GetMpegDashUri();

Console.WriteLine(smoothStreamingUri);
Console.WriteLine(hlsUri);
Console.WriteLine(mpegDashUri);
176 changes: 176 additions & 0 deletions articles/media-services-rest-deliver-streaming-content.md
@@ -0,0 +1,176 @@
<properties
pageTitle="How to Deliver Streaming Content from Media Services"
description="Learn how to create a locator that is used to build a streaming URL. The code uses REST API."
authors="juliako"
manager="dwrede"
editor=""
services="media-services"
documentationCenter=""/>

<tags
ms.service="media-services"
ms.workload="media"
ms.tgt_pltfrm="na"
ms.devlang="na"
ms.topic="article"
ms.date="02/17/2015"
ms.author="juliako"/>


#How to: Deliver streaming content

This article is part of the [Media Services Video on Demand workflow](../media-services-video-on-demand-workflow) and [Media Services Live Streaming workflow](../media-services-live-streaming-workflow) series.

##Overview


You can stream an adaptive bitrate MP4 set by creating an OnDemand streaming locator and building a streaming URL. The [encoding an asset](../media-services-rest-encode-asset) topic shows how to encode into an adaptive bitrate MP4 set. Before you create a locator you should configure asset delivery policy as described in [this](../media-services-rest-configure-asset-delivery-policy) topic.

You can also use an OnDemand streaming locator to build URLs that point to MP4 files that can be progressively downloaded.

This topic shows how to create an OnDemand streaming locator in order to publish your asset and build a Smooth, MPEG DASH, and HLS streaming URLs. It also shows hot to build progressive download URLs.

The [following](#types) section shows the enum types whose values are used in the REST calls.

##Create an OnDemand streaming locator

To create the OnDemand streaming locator and get URLs you need to do the following:


1. Define an access policy.
2. Create an OnDemand streaming locator.
3. If you plan to stream, get the streaming manifest file (.ism) in the asset.

If you plan to progressively download, get the names of MP4 files in the asset.
4. Build URLs to the manifest file or MP4 files.


###Create an access policy

Request:

POST https://media.windows.net/api/AccessPolicies HTTP/1.1
Content-Type: application/json
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json
Accept-Charset: UTF-8
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=amstest1&urn%3aSubscriptionId=bbbef702-e769-477b-9f16-bc4d3aa97387&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1424263184&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=NWE%2f986Hr5lZTzVGKtC%2ftzHm9n6U%2fxpTFULItxKUGC4%3d
x-ms-version: 2.8
x-ms-client-request-id: 6bcfd511-a561-448d-a022-a319a89ecffa
Host: media.windows.net
Content-Length: 68

{"Name":"access policy","DurationInMinutes":43200.0,"Permissions":1}

Response:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 311
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Location: https:/media.windows.net/api/AccessPolicies('nb%3Apid%3AUUID%3A69c80d98-7830-407f-a9af-e25f4b0d3e5f')
Server: Microsoft-IIS/8.5
request-id: a877528a-bdb4-4414-9862-273f8e64f882
x-ms-request-id: a877528a-bdb4-4414-9862-273f8e64f882
x-ms-client-request-id: 6bcfd511-a561-448d-a022-a319a89ecffa
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Wed, 18 Feb 2015 06:52:09 GMT

{"odata.metadata":"https://media.windows.net/api/$metadata#AccessPolicies/@Element","Id":"nb:pid:UUID:69c80d98-7830-407f-a9af-e25f4b0d3e5f","Created":"2015-02-18T06:52:09.8862191Z","LastModified":"2015-02-18T06:52:09.8862191Z","Name":"access policy","DurationInMinutes":43200.0,"Permissions":1}

###Create an OnDemand streaming locator

Create the locator for the specified asset and asset policy.

Request:

POST https://media.windows.net/api/Locators HTTP/1.1
Content-Type: application/json
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json
Accept-Charset: UTF-8
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=amstest1&urn%3aSubscriptionId=bbbef702-e769-477b-9f16-bc4d3aa97387&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1424263184&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=NWE%2f986Hr5lZTzVGKtC%2ftzHm9n6U%2fxpTFULItxKUGC4%3d
x-ms-version: 2.8
x-ms-client-request-id: ac159492-9a0c-40c3-aacc-551b1b4c5f62
Host: media.windows.net
Content-Length: 181

{"AccessPolicyId":"nb:pid:UUID:1480030d-c481-430a-9687-535c6a5cb272","AssetId":"nb:cid:UUID:cc1e445d-1500-80bd-538e-f1e4b71b465e","StartTime":"2015-02-18T06:34:47.267872Z","Type":2}

Response:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 637
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Location: https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3Abe245661-2bbd-4fc6-b14f-9cf9a1492e5e')
Server: Microsoft-IIS/8.5
request-id: 5bd5864a-0afd-44c0-a67a-4044a2c9043b
x-ms-request-id: 5bd5864a-0afd-44c0-a67a-4044a2c9043b
x-ms-client-request-id: ac159492-9a0c-40c3-aacc-551b1b4c5f62
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Wed, 18 Feb 2015 06:58:37 GMT

{"odata.metadata":"https://media.windows.net/api/$metadata#Locators/@Element","Id":"nb:lid:UUID:be245661-2bbd-4fc6-b14f-9cf9a1492e5e","ExpirationDateTime":"2015-03-20T06:34:47.267872+00:00","Type":2,"Path":"http://amstest1.streaming.mediaservices.windows.net/be245661-2bbd-4fc6-b14f-9cf9a1492e5e/","BaseUri":"http://amstest1.streaming.mediaservices.windows.net","ContentAccessComponent":"be245661-2bbd-4fc6-b14f-9cf9a1492e5e","AccessPolicyId":"nb:pid:UUID:1480030d-c481-430a-9687-535c6a5cb272","AssetId":"nb:cid:UUID:cc1e445d-1500-80bd-538e-f1e4b71b465e","StartTime":"2015-02-18T06:34:47.267872+00:00","Name":null}

###Build streaming URLs

Use the **Path** value returned after the creation of the locator to build the Smooth, HLS, and MPEG DASH URLs.

Smooth Streaming: **Path** + manifest file name + "/manifest"

example:

http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest

HLS: **Path** + manifest file name + "/manifest(format=m3u8-aapl)"

example:

http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=m3u8-aapl)


DASH: **Path** + manifest file name + "/manifest(format=mpd-time-csf)"


example:

http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=mpd-time-csf)


###Build progressive download URLs

Use the **Path** value returned after the creation of the locator to build the progressive download URL.

URL: **Path** + asset file mp4 name

example:

http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_650kbps_AAC_und_ch2_96kbps.mp4

##<a id="types"></a>Enum types

[Flags]
public enum AccessPermissions
{
None = 0,
Read = 1,
Write = 2,
Delete = 4,
List = 8,
}

public enum LocatorType
{
None = 0,
Sas = 1,
OnDemandOrigin = 2,
}
1 change: 1 addition & 0 deletions includes/media-services-selector-publish.md
@@ -1,3 +1,4 @@
> [AZURE.SELECTOR]
- [Portal](/en-us/documentation/articles/media-services-manage-content#publish/)
- [.NET SDK](/en-us/documentation/articles/media-services-deliver-streaming-content/)
- [REST API](/en-us/documentation/articles/media-services-rest-deliver-streaming-content)

0 comments on commit 521811c

Please sign in to comment.