banner
Workin' on Windows running on Windows Azure.
Posts
 
Previous Next 

In my first post in this series I introduced the MediaPlayer class that we’ve added to the Silverlight 2 player templates in Expression Encoder 2 SP1 and highlighted some of its internals.  In this post I will explore the topic of how to debug Expression Encoder MediaPlayer projects, specifically the case where you are encoding to the IIS Smooth Streaming format.  I focus on this case because it is the most involved template debugging scenario as will become apparent.

But before we dive in I’d like to touch on IIS Smooth Streaming and also explain how Expression Encoder previews its output.

IIS Smooth Streaming falls into a class of delivery known generically as Adaptive Streaming.  With this method, the video asset is encoded at multiple bitrates in a GOP aligned fashion which allows client-side Silverlight managed code running inside of a custom MediaStreamSource class to make decisions at runtime based on network and local conditions (e.g. dropped frames) and switch to lower or higher steams as needed.

Over the wire, streams are delivered in chunks using progressive HTTP, each chunk containing a couple of seconds worth of video samples.  In classical adaptive streaming, these chunks are typically laid down on disk as many discrete files. One of the nice features of IIS Smooth Streaming is that, on disk, the chunks are all stored in a single file per stream rather than many hundreds or thousands of fragments.  The IIS Smooth Streaming Module installed on the server then translates chunk requests from the wire into file offsets and serves the chunks; effectively virtualizing the concept of a chunk.

This is a huge management win.  However, from an Expression Encoder preview point of view it complicates matters since it would suggest that you would need an IIS server running locally in order to preview the output of an encoding job.

We solved this problem by adding support for IIS Smooth Streaming to the private web server that is use to host the web preview output.

When you encode an IIS Smooth Streaming job and enable Preview in browser, we first generate the file set (which, for IIS Smooth Streaming, looks something like this):

image

And then start an in-process instance of our webserver which handles the serving up the files over HTTP and as well as the logical to physical chunk generation process where necessary.  This works great for previewing your job locally.  For deployment in the real world, both IIS7 and the IIS Smooth Streaming module are required.

Now that we understand more about IIS Smooth Streaming, we can move onto the topic of debugging Silverlight 2 Templates.  We have encoded our content into a template including the IIS Smooth Streaming client-side MSS code and we want to observe the execution as video plays back.  For example, maybe we want to debug into the heuristics module and look at the network requests for chunk retrieval.

In order to debug the client-side player code including what’s going on inside of the MediaStreamSource, we have to manually attach the debugger to the instance of IE that gets launched by Expression Encoder to ensure that the files are getting served up by our webserver.

The easiest way to illustrate this is with a worked example:

1) Import Bear.wmv

image

2) Pick the Adaptive Streaming template

image

3) Pick the default Silverlight 2 Player skin

image

4) Edit a copy in Visual Studio

image

5) Switch to VS and compile the project; open the MediaPlayer project and then open the MediaPlayer.cs source file; set a breakpoint in the constructor

image

6) Switch back to Expression Encoder and encode the job; wait until the preview launches in IE.

watch closely and see how, initially, the lowest bitrate plays and looks a little blury then after a few seconds playback seamlessly switches to a higher bitrate.  This is adaptive streaming at work.

image

7) Switch back into Visual Studio and select Attach to Process from the Debug menu (or use ctrl-alt P).  You now need to attach to the correct instance of IE.. note that if you are running IE8, this may not be the instance you expect.  The one you want to connect to is the one with Silverlight in the type column.  Sometimes it is best to close all instances of IE before you attempt to debug to make it easier to find the right one.

image

8) Switch back to Internet Explorer and hit F5 to make the browser refresh.. at this point you should hit the breakpoint you set in the constructor of MediaPlayer.

image

It is worth mentioning that, in Visual Studio, you are working with the source code of the template but are attaching the debugger to the published output of the job.

This is a subtle distinction; what it means, in practice, is that if you make changes to the source code of the template in VS, you need to republish the job by clicking encode before you’ll see the changes take effect.  This will thankfully be really fast due to the Partial Rebuild feature that only re-encodes the video if settings have been changed.  It also means that you cannot press F5 in VS and have the project launch with your encoded project.

If you are interested in a second debugging technique that enables the debugging of published output, please leave a message in the comments and I’ll do a follow up post on that topic.

In my next post I’ll focus on the internals of the AdaptiveStreaming code, talk about our default Heuristics implementation and show how you can replace it with your own.

Comments[10]
  1. 1. Made by Dongkyu on 11/28/2008 12:05:00 PM

    hi! i'm student studying silverlight media player.. 1) Import Bear.wmv 2) Pick the Adaptive Streaming template 3) Pick the default Silverlight 2 Player skin problem is (2) i can not find 'Adaptive Streaming' and Output Mode - 'IIS Smooth Streaming'. where can i find them? help :)


  2. 2. Made by Dongkyu on 11/29/2008 12:43:00 AM

    i am using Espression Encoder 2 sp1 but i can not find '2) Pick the Adaptive Streaming template' Adaptive Streaming and Iis Smooth Streaming




  3. 4. Made by James Clarke on 12/28/2008 8:01:00 PM

    Dongkyo.. Unfortunately the IIS Smooth Streaming capabilities are only available in the full commercial version of Expression Encoder, not the trial version.




  4. 6. Made by Damon Carr, Origin Digital on 4/4/2009 7:58:00 PM

    Great content. I've been making that code do backflips. Nice to see some professional coverage of the technologies involved at this level. Damon Carr, Silverlight Digital Media Lead Origin Digital


  5. 7. Made by kien nguyen on 4/6/2009 4:10:00 PM

    hi, Can you tell me how to change some button behavior in this player, i opened the template visual studio projet in VS and Blend but the page.xaml contains this code ExpressionPlayer:ExpressionPlayer... and when i open the expressionplayer project i only see cs files. I just what to change this behavior : when we click on the playlist button, the playlist appears. Now if you click again on the playlist button, the playlist disapear. I want te play list to disapear when the mouse leave the playlist area, can you tell me where can i made this modification ?


  6. 8. Made by jUna on 6/5/2009 11:24:00 PM

    Hi Clark, I have downloaded and installed the ee sp1 but I dont know how to enabling the private server to test it out the encoding video as you mention in this post. "We solved this problem by adding support for IIS Smooth Streaming to the private web server that is use to host the web preview output." Could you help me on this? TIA jUna


  7. 9. Made by jUna on 6/6/2009 1:57:00 AM

    Hi Clark, I'm using ee sp1, the full version of it. How I can enable the private web server in order to debug the SL player? I'm working with a customer and they want to show only a specific part of a smooth streaming video. eg. in a 45 minutes length video they want to play only 10 seconds starting in the 43.30 minute. best jUna


  8. 10. Made by Dugan on 8/21/2009 1:58:00 PM

    Hi Clark, I'm currently trying to figure out how to deal and modify the implementation of the smooth streaming heuristics in Silverlight. You posted that you'd post about the internals of the AdaptiveStreaming code. I couldn't find that post yet. Do you still plan to write about it or do you have any other source I could check out about this topic? Thanks and all the Best Dugan


 Name
  email (will not be shown)
 web site


Close

4/24/2014 6:55:34 PM