Partilhar via


Live Smooth Streaming Using IIS Media Services: Overview and Automation

Introduction

In this post I will give detailed overview of the following:

  • What is Live Smooth streaming?
  • IIS Media Services as an Integrated media platform for IIS
  • Using IIS Media Services for Live Smooth Streaming Broadcast over HTTP
  • Creating Live Smooth Streaming Publishing Points in IIS using IIS Media Services
  • Programmatically creation of Publishing Points for automation
  • Network Architecture for Live Smooth Streaming Implementation Using IIS Media Services

Live Smooth Streaming

•       Enables adaptive streaming of live events to Smooth Streaming clients

•       IIS Media Services extension

•       Uses HTTP to deliver live events

•       Existing HTTP networks and keeps content close to your viewers

•       Makes True HD(720+) a realistic option

•       Existing HTTP infrastructure also drastically increases live event availability

•       For most popular live web broadcasts, CDNs and content providers can take advantage of their network resources using HTTP

•       Adaptation based on user’s network bandwidth

•       Support Typical PVR(Personal Video Recorder) style interaction

•       World’s First IIS Based Live Streaming: French Open 2009

IIS Media Service: An IIS Integrated Media Platform

  • An integrated HTTP-based media delivery package for IIS
  • Supported with IIS 7 on Windows Server 2008, Windows Server 2008 R2, Windows Vista with SP1, Windows 7

Key Features:

  •     Smooth Streaming : adaptive streaming of on-demand media over HTTP
  •     Live Smooth Streaming : live adaptive streaming for broadcast events
  •     Bit Rate Throttling : meters the speed at which content is delivered to a player
  •     Web Playlists : secure sequencing and server-side control of media content
  •     Advanced Logging : rich, real-time client- and server-side logging
  •     Application Request Routing (ARR) : intelligent HTTP proxying and caching
  •     Smooth Streaming Player Development Kit : for creating customized players

 

Live Smooth Streaming Using IIS Media Services

  • Publishing Points: These are IIS Based URLs which will point to specific Live smooth streaming provider encoder.
  • There are two source types:-

                  • Push – This will push live content to the client or another publishing point of PULL type.

                  • Pull- This will pull live content from another PUSH type publishing point or encoder.

        •       ISML files: These are xml based files which are generated when a publishing point is created.

        •       Features:

         – Broadcasting live streams

        • IIS Media Services Enables broadcasting live streams over HTTP by the concept of publishing points

        • This gets the live stream from the encoder and broadcasts over HTTP.

        – Distributing live streams

        • IIS Media Services enables distributing live streams to various sources

        • This basically enables user to point to publishing point URLs where the live streams has to be pushed.

        – Archiving live streams

        •  IIS media services enabled archiving of live streams for a specific period of time which can be configured.

        •  This archived stream can be used in future by provider as Video On Demand

        •  This also enables digital video recording which will enable user to rewind back when live stream is in progress

        •  Default archived stream is stored in %SystemDrive%\inetpub\media\archives\SiteName\PublishingPointFileName-isml

 

Creating Live Smooth Streaming Publishing Point in IIS

  • Check if IIS Media Services 4.1 is Installed or not. IIS Media Services can be installed from Here

  • Click on Live Smooth Streaming Publishing Point 

  • Now Click on Add which is there in the right hand pane

  • Once you click on add the “Add Publishing Point” window will open from where you can add publishing point.

 

Description of Each Input Element for Creating Live Smooth Streaming Publishing Point:-

a. Basic Settings

  • File Name:- Name of the ISML file which will created
  • Title:- Title of the publishing point
  • Estimated Duration: If you know the length of your live stream then this will create a progress bar on the client setting an end time like in case of normal videos
  •  Live Source Type:- This has been described in earlier section
    • Push
    • Pull

b.       Advanced Settings

  • Archive Media: If you enable this then Archiving of the live stream will be enabled and this will be storing the Live Stream in the default location (%SystemDrive%\inetpub\media\archives\SiteName\PublishingPointFileName-isml)

              Archive as single Presentation: This will archive the live stream as single smooth streaming file

              Archive as Segmented Presentation: This will archive the live stream in chunks based on the time given in Segment Length(in Minutes) specified.

  •  Allow Client Connections: This will enable the client to send request to the server to rewind back and will also enable digital view recording

             Enable DVR for the entire event: This will enable Digital video recording for the live stream i.e. client can rewind back to start from the current state

             Enable DVR for recent content: This will enable client to rewind back only to specified amount of time based on DVR Window Length(in minutes) specified

  • Allow Server Connections: This will allow a publishing point to push or pull live content to/from another publishing point
  • Start Publishing point automatically upon fir request: This will start the publishing as soon as it gets request first live streaming request
  • Number of lookahead fragments: Enter the number of fragments that will be buffered by the server. Clients use the information about the buffered fragments, which is stored in the current response, to optimize requests for the subsequent buffered fragments in a stream. This enables smoother playback of video.

c.        Mobile Devices

  • Enable output to Apple mobile digital devices : enable the Live Smooth Streaming publishing point to convert live Smooth Streaming MPEG-4 (MP4) fragments to MPEG-2 Transport Stream (MPEG-2 TS) segments, and to create an Apple HTTP Live Streaming (.m3u8) playlist file that describes the MPEG-2 TS presentation for the mobile device.
  • Segment length: duration of each MPEG-2 TS segment, in seconds. The default value is 10 seconds, which is recommended for most Apple mobile digital devices.
  • Maximum bit rate: maximum bit rate, in kilobits per second (Kbps), to be created for the MPEG-2 TS segments. Some bit rates in a Live Smooth Streaming presentation are too high to be played by an Apple device after they are converted to MPEG-2 TS container format. Most Apple devices can play media encoded at bit rates up to 1,600 Kbps.
  • Enable iOS 3.0 compatibility: enable the MPEG-2 TS segments to be played on Apple devices that use the iOS 3.0 mobile operating system, such as the iPhone 3GS and iPod Touch® devices.
  • Apple AES-128 encryption: Live Smooth Streams for Apple devices can be encrypted so that they can only be viewed by devices that obtain a file that contains the content key to decrypt the streaming content. Live Smooth Streaming encrypts content by using the Advanced Encryption Standard (AES) with a 128-bit key. It can also provide the content key file to clients, or you can specify that the content key be provided from an alternate location, such as a custom ASP.NET Web page.

Creating Live Smooth Streaming Publishing Point Programmatically

As mentioned above when you create a publishing point in the IIS using IIS Media Services then it will create a file with .isml extension which contains data in xml format with UTF-8 encoding.

NOTE:-

1) The web application which will host these publishing points should be kept in a separate application pool as this is supposed to be running all the time.

2)  This application pool should be enabled to server live content which can be done by going to the Live Smooth Streaming of the IIS media services in the web application and on the right hand side it will ask to enable application pool. See the screenshot below.

 

Step1:     Create a class which will have the publishing point data to be set as input

 public enum SourceType
 {
 Push,
 Pull
 }
 /// <summary>
 /// Class to provide data for creating publishing point URL.
 /// </summary>
 public class PublishingPointParams
 {
 public PublishingPointParams()
 {
 ToolAction = true;
 FileName = string.Empty;
 Title = string.Empty;
 Module = string.Empty;
 SourceType = IISMediaServicesHelper.SourceType.Push;
 EstimatedTime = "0";
 LookaheadChunks = 0;
 ManifestWindowLength = "0";
 StartOnFirstRequest = false;
 PublishPointUrls = new List<string>();
 WebSiteName = WebSiteConstants.WebSiteName;
 ArchiveSegmentLength = string.Empty;
 WebApplicationTargetName = string.Empty;
 IsArchive = true;
 AllowClientConnections = true;
 Publishing = string.Empty;
 AppPoolName = string.Empty;
 WebApplicationDefaultPath = WebSiteConstants.WebApplicationPhysicalPath;
 }
 
 public bool ToolAction { get; set; }
 public string FileName { get; set; }
 public string Title { get; set; }
 public string Module { get; set; }
 public SourceType SourceType { get; set; }
 public string Publishing { get; set; }
 public string EstimatedTime { get; set; }
 public uint LookaheadChunks { get; set; }
 public string ManifestWindowLength { get; set; }
 public bool StartOnFirstRequest { get; set; }
 public string ArchiveSegmentLength { get; set; }
 public List<string> PublishPointUrls { get; set; }
 public string WebSiteName { get; set; }
 public string WebApplicationTargetName { get; set; }
 public bool IsArchive { get; set; }
 public bool AllowClientConnections { get; set; }
 public string AppPoolName { get; set; }
 public string WebApplicationDefaultPath { get; set; }
 }

Step 2:  Generate the xml data to be stored

 /// <summary>
 /// Function to generate the publish point XML for creating ISML file.
 /// </summary>
 /// <param name="pubPoint"></param>
 /// <returns></returns>
 private XDocument GeneratePubPointXMLData(PublishingPointParams pubPoint)
 {
 XNamespace ns = "https://www.w3.org/2001/SMIL20/Language";
 XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", ""));
 XElement eleHead = new XElement(ns + "head",
 new XElement(ns + "meta", new XAttribute("name", "title"), new XAttribute("content", pubPoint.Title)),
 new XElement(ns + "meta", new XAttribute("name", "module"), new XAttribute("content", pubPoint.Module)),
 new XElement(ns + "meta", new XAttribute("name", "sourceType"), new XAttribute("content", pubPoint.SourceType)),
 new XElement(ns + "meta", new XAttribute("name", "publishing"), new XAttribute("content", pubPoint.Publishing)),
 new XElement(ns + "meta", new XAttribute("name", "estimatedTime"), new XAttribute("content", pubPoint.EstimatedTime)),
 new XElement(ns + "meta", new XAttribute("name", "lookaheadChunks"), new XAttribute("content", pubPoint.LookaheadChunks)),
 new XElement(ns + "meta", new XAttribute("name", "manifestWindowLength"), new XAttribute("content", pubPoint.ManifestWindowLength)),
 new XElement(ns + "meta", new XAttribute("name", "startOnFirstRequest"), new XAttribute("content", pubPoint.StartOnFirstRequest)),
 new XElement(ns + "meta", new XAttribute("name", "archiveSegmentLength"), new XAttribute("content", pubPoint.ArchiveSegmentLength)),
 new XElement(ns + "meta", new XAttribute("name", "formats"), new XAttribute("content", "")),
 new XElement(ns + "meta", new XAttribute("name", "filters"), new XAttribute("content", "")));
 XElement eleBody = new XElement(ns + "body");
 XElement eleUrl;
 
 if (pubPoint.SourceType == SourceType.Push)
 eleUrl = new XElement(ns + "par");
 else
 eleUrl = new XElement(ns + "switch");
 foreach (string pubLishUrl in pubPoint.PublishPointUrls)
 {
 eleUrl.Add(new XElement(ns + "ref", new XAttribute("src", pubLishUrl)));
 }
 eleBody.Add(eleUrl);
 XElement eleIsml = new XElement(ns + "smil", new XElement(eleHead), new XElement(eleBody));
 doc.Add(eleIsml);
 return doc;
 
 }

Step 3:  Get the data stored in a file and save the file into the web application path using “Microsostf.Web.Administration dll” which can be found in the inetsrv folder of System32. This is a managed API of IIS.

 

 /// <summary>
 /// Function to create live publishing point url.
 /// </summary>
 /// <param name="pubPoint">Publish point param class object with input parameters to create publishing point.</param>
 /// <param name="logger"></param>
 /// <returns></returns>
 public bool CreatePublishingPointUrl(PublishingPointParams pubPoint, ILogger logger)
 {
 bool retVal = false;
 try
 {
 using (var manager = new ServerManager())
 {
 Site site = manager.Sites[pubPoint.WebSiteName];
 Application application = site.Applications["/" + pubPoint.WebApplicationTargetName];
 string livePubPointData = string.Empty;
 
 if (application == null)
 {
 if (!(CreateWebApplication(pubPoint, manager, site)))
 {
 logger.Write("Unable to create web application. Publish point URL can not be created.");
 return false;
 }
 }
 
 XDocument doc = GeneratePubPointXMLData(pubPoint);
 StringWriter streamWriter = new StringWriterWithEncoding(Encoding.UTF8);(This is a custom class which will return UTF8 enecoded object of string writer class)
 doc.Save(streamWriter, SaveOptions.None);
 livePubPointData = streamWriter.ToString();
 
 string path = (application == null) ? string.Format(@"{0}\{1}", pubPoint.WebApplicationDefaultPath, pubPoint.FileName + ".isml") : 
 string.Format(@"{0}\{1}", application.VirtualDirectories[0].PhysicalPath, pubPoint.FileName + ".isml");
 
 if (!File.Exists(path))
 {
 File.WriteAllText(path, livePubPointData);
 retVal = true;
 }
 else
 {
 logger.Write("Publishing point " + pubPoint.Title + " already exists. Please try again with some other name.");
 }
 }
 }
 catch (Exception ex)
 {
 logger.Write("Cannot create Publishing Point error ar CreatePubPoinUtl():" + ex);
 return false;
 }
 return retVal;
 } 

Architecture followed to provide Live Smooth Streaming Using IIS Media Services