Smooth Streaming Cache Plugin implementation – SSME v2.0 walkthrough

If you want to know how Smooth Streaming Cache Plugin works, you could check another blog of mine. And for this blog, I will go through some improvements we made in Smooth Streaming Client SDKs v2.0.

Adding CacheRequest2

This is the public signature of CacheRequest2 and it is inherited from CacheRequest.

Now, with this new method, you could modify:

(1) Http Web Request URL for Smooth Streaming Downloader to download the data chunk

For instance, when user tries to download from certain data source, if you don’t want them to watch it, you could re-direct them to download from another data source.

(2) the tracks you want Smooth Streaming Downloader to download

For instance, if user is using a phone, no matter how fast his network speed, you may want to select a few tracks for him to choose from – it’s not so optimal to supply High resolution track to a mobile user.

And you could use CacheRequest2 in BeginRetrieve/EndRetrieve like this:

In the code above, you could see that we are requesting some video link contains BigBunkBunny and we replaced HTTP request with another link. Meanwhile, you could set a list of tracks you want Smooth Streaming downloader to download. Here I am just checking which tracks are getting downloaded. At the end, when we return null, Smooth Streaming default downloader will go ahead and download content using the CacheRequest2 you just modified.

Here is another sample for modifying CacheRequest2:

In the code above, we compose a totally new CacheRequest2 with HttpStatusCode.NotFound, so if you don’t want user to download certain content, you could use it to redirect traffic too.

I wrote a simple sample for How to utilize CacheRequest2 and you could download it here.

Adding CacheResponse2

This is the public API signature for CacheResponse2 and it is inherited from CacheResponse.

In BeginRetrieve/EndRetrieve, you could write your own downloader and download the data chunk, the result will be showed in the format of CacheResponse2. Furthermore, you could modify:

(1) PerceiveBandwidth

(2) UsedTrack: you could download multiple data track however, you may not want to cache all of them. So you could choose which bit-rate of video you want to keep.

Here is some sample code snippets on how to use CacheResponse2:

From the code above, Download is a customized download i wrote and you could get the sample code here for this customized downloader. And we could modify CacheResponse2 cacheRes’s PerceivedBandwidth and UsedTrack here.

As a summary, we add in CacheRequest2 and CacheResponse2 for ISmoothStreamingCache Interface implementation. If you are not clear with ISmoothStreamingCache implementation, you could check out a very detail MSDN documentation or my the other blog.

3 Responses to Smooth Streaming Cache Plugin implementation – SSME v2.0 walkthrough
  1. [...] Update our cache plugin properties for enabling more flexible implementation. Now if you are implementi...
  2. Gaurav Bajaj Reply

    Hi Mingfei,

    Thanks for the wonderful article!
    I have a question.
    As we know that in function call
    IAsyncResult BeginRetrieve(CacheRequest request, AsyncCallback callback, object state) {
    string uri = request.CanonicalUri.ToString()

    uri is based on current quality level and video or audio content.
    Is there any way to find out what current
    quality level asked or other parameters which are used in constructing this url. Can I fetch these fields from any component.

    I want to dump these fields while in BeginRetrieve().


  3. Gaurav Bajaj Reply

    How would I set new custom TrackInfo object in
    CacheResponse2 object.
    TrackInfo trackInfo = TrackInfo() //<<–NOT ABLE TO DO THIS

    CacheResponse2 cacheRes = new CacheResponse2(result.Stream.Length, "ContentType", null, result.Stream, System.Net.HttpStatusCode.OK, "OK", DateTime.Now);
    cacheRes.PerceivedBandwidth = 1;

    Please Help

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.