Archive for the 'RSCA' Category

Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0

Many people have been asking me how to manage publishing point programmatically on IIS Media Services 3.0 (instead of the 2.0 bits, as I explained in this post)

So, I started to dig and I came up with the following code:

// Live Streaming Section Path
const string LiveStreamingSectionPath = “system.webServer/media/liveStreaming“;
 
// Change this settings with your values
 
// Site name
string siteName = “Default Web Site“;
// Application name
string applicationName = “/SmoothStreaming“;
// Publishing point filename
string fileName = “LiveSmooth.isml“;
 
ServerManager serverManager = new ServerManager();
 
// Gets the site from IIS
Site site = serverManager.Sites[siteName];
 
// Gets the application from IIS
Application application = site.Applications[applicationName];
 
// Gets the LiveStreamingSection from the site configuration 
ConfigurationSection section = site.GetWebConfiguration().GetSection(LiveStreamingSectionPath);
 
// Gets the ConfigurationMethodInstance to get the available publishing points
ConfigurationMethodInstance instance = section.Methods["GetPublishingPoints"].CreateInstance();
 
// Sets the input parameters of the GetPublishingPoints method
instance.Input["siteName"] = site.Name;
instance.Input["virtualPath"] = applicationName;
 
// Executes the method
instance.Execute();
 
// Gets the PublishingPointCollection type.
Type type = Type.GetType("Microsoft.Web.Management.Media.LiveStreaming.PublishingPointCollection, Microsoft.Web.Management.Media.LiveStreaming“);
 
// Gets the PublishingPointCollection associated with the method output
ConfigurationElement collection = instance.Output.GetCollection(type);
 
// Gets an item from the collection using the Publishing Point fileName as parameter. 
// The item is of type PublishingPoint.
object pubPoint = collection.GetType()
                            .InvokeMember("Item“,
                                          BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance,
                                          null, collection, new object[] { fileName }, null);
 
// Invokes the desired method of the Publishing Point. 
// In this case we are calling the Start method (others supported functions are “Shutdown” and “Stop”)
pubPoint.GetType().InvokeMember("Start“,
                                BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod,
                                null, pubPoint, null);

Remember that in order to use the previous code, you must have references to the following assemblies:

  • Microsoft.Web.Administration.dll (can be found at IIS Directory %windir%\System32\inetSrv)
  • Microsoft.Web.Management.Media.LiveStreaming.dll (can be found in the GAC after installing the Live Smooth Streaming bits)

Hope this helps.

Happy streaming!

kick it on DotNetKicks.com
Shout it

Live Smooth Streaming: How-to: Retrieve the configuration settings programmatically

In my previous post, I explained how the Microsoft.Web.Administration API of IIS7 helped us to manage the Live Smooth Streaming Publishing Points programmatically. In this post I’m going to show you how, using the same API, you can retrieve the Live Smooth Streaming configuration settings.

First, let’s take a look at the Live Smooth Streaming configuration settings window

image

The main idea here is to read the Live Streaming configuration section and get the attributes values from there. The piece of code looks like:

const string LiveStreamingSectionPath = “system.webServer/media/liveStreaming”;

ServerManager serverManager = new ServerManager();

Configuration configuration = serverManager.GetApplicationHostConfiguration();
ConfigurationSection section = configuration.GetSection(LiveStreamingSectionPath);

if (section != null)
{
    foreach (ConfigurationAttribute attribute in section.Attributes)
    {
        Console.WriteLine(“{0}: {1}”, attribute.Name, attribute.Value);
    }

    Console.ReadLine();
}

Running the preceding code will output the following:

image

As you see, reading the configuration settings is easy and can enable you different scenarios, for example, deleting the archived streams of a publishing point.
If you want to take a look at the Live Smooth Streaming schema, go to %windir%\System32\inetsrv\config\schema and open the IISMedia_LiveStreaming_schema.xml file.

Happy streaming!

Live Smooth Streaming: How-to: Start, Stop & Shutdown a Publishing Point Programmatically

During the last months I have been working in a project highly related to multimedia and iis-smoothclient development technologies such as Silverlight. And in the last few weeks, I started to look to some of the new IIS Media services such as Smooth Streaming and Live Smooth Streaming in order to gather as much knowledge about them to perform some spikes for the project.

One of the things that came up while spiking was finding a way to start, stop & shutdown a publishing point via code.

Microsoft.Web.Administration to the Rescue

ServerManagerWith IIS7 a new API to administer IIS from managed code was introduced. This API is really simple to use and with a few lines of code you can manipulate the server configuration as any other information available in IIS7. (if you want to taste the power of this API, I recommend you to read this post from Carlos Aguilar Mares).

So, I used the Microsoft.Web.Administration.dll assembly, that can be found at IIS Directory (%windir%\System32\inetSrv), to perform the operations over the publishing point. But it was not so easy to do it, as there is no information available yet about what RSCA function has to be called  and which parameters need to be used in order get the desired results.

Then, I started to look at the different IIS configuration files (%windir%\System32\inetsrv\config) searching for clues and I came up with the Microsoft.Web.Management.Media.LiveStreaming.dll assembly (this assembly can be found in the GAC after installing the Live Smooth Streaming bits).

In that moment I summoned my best friend Reflector and together went to the depths of this assembly until we found some code that might be useful for our objective.

After doing some tests, I ended up with the following method:

private static void ExecuteRscaFunction(ConfigurationElement workerProcess,
                                        string siteName, string applicationPath,
                                        string fileName, string functionName)
{
    ConfigurationMethod configurationMethod = workerProcess.Methods["GetCustomData"];

    ConfigurationMethodInstance instance = configurationMethod.CreateInstance();
    instance.Input["guidIdOfFunctionCall"] = “Media_LiveStreaming_Control”;

    string currentLogicalPath = applicationPath;

    if (!currentLogicalPath.EndsWith(“/”, StringComparison.OrdinalIgnoreCase))
    {
        currentLogicalPath = currentLogicalPath + “/”;
    }

    string fullPath = string.Concat(currentLogicalPath, fileName);
    string parameters = string.Format(CultureInfo.InvariantCulture, “{0};{1};{2}”,
                                      functionName, siteName, fullPath);
    instance.Input["parametersOfFunctionCall"] = parameters;
    instance.Execute();
}

The most important thing of the method above is the functionName parameter. This parameter can be one the following values depending on what you want to accomplish:

  • StartPublishingPoint. This is used to start a publishing point.
  • StopPublishingPoint. This is used to stop the live source of the publishing point.
  • ShutdownPublishingPoint. This is used to shutdown a publishing point.

To understand where the others parameters should come from, let’s take a look at the following example: image So, if we want to the start the LiveSmoothStream publishing point associated to the SmoothStreaming application from the Default Web Site, we should call the ExecuteRscaFunction method in this way:

ExecuteRscaFunction(workerProcess,
                    “Default Web Site”, “/SmoothStreaming”,
                    “LiveSmoothStream.isml”, “StartPublishingPoint”);

The remaining parameter (workerProcess) must be retrieved from the application pool associated to the application.

Note: You can use the Microsoft.Web.Administration API to get all the values previously mentioned.

To see if the function is working you can add the following lines of code at the end of the method to parse the output and print it on the console.

string rawOutput = instance.Output["data"] as string;

byte[] bytes = Convert.FromBase64String(rawOutput);
ASCIIEncoding encoding = new ASCIIEncoding();

Console.WriteLine(encoding.GetString(bytes));

The output after executing the Stop, Shutdown and Start functions:

image

Hope this helps!. If you want to learn more about Smooth Streaming you might find useful the following links:

Happy streaming!.

kick it on DotNetKicks.com