Archive for February, 2011
OSMF getBitrateForIndex bug
Posted by Kenny Bunch in ActionScript, Flash on February 15, 2011
At Dreamsocket, we have been working on an OSMF based video player for one of our clients. An important aspect of the player is that it provides visual QOS (quality of service) information to the user about what is going on. For example, what the current stream bitrate is, the buffer length, frame rate, and other metrics are shown on screen so a user can self diagnose what is going on. If a customer is having issues and calls customer service, this information can be very helpful.
The Problem
Unfortunately, in using OSMF, we were constantly seeing incorrect bitrates being reported for the current stream. It was obvious that it was playing a 1400kbps stream when OSMF was telling us that it was a 300kbps stream. If you have ever worked with video at a low level in Flash, you will know that you can never expect events to fire exactly how you want. That turned out to be the case here. OSMF internally was looking only for NetStream.Play.TransitionComplete code being fired in for a onPlayStatus event. Well good luck with that. You can simply do a seek at the start of a video right before it does a transition, or do a few seeks while it is transitioning and you'll never see that get fired off.
The Solution
Although the onPlayStatus handler doesn't always fire, a NetStatusEvent event with a NetStream.Play.Start code does fire when a new bitrate begins. Therefore if you introspect the details property (which gives you the stream name) of the info object in that event and the stream is different than the current bitrate, you can concur that the bitrate has switched. One quirk here is that in some cases a NetStream.Play.Start can fire with event.info.details being null, so you have to watch out for that.
So how can you apply this to OSMF? Given OSMF is so black boxed, the error has to be fixed in a core class. To make it simple, we only touched a single function onNetStatus in org.osmf.net.NetStreamDynamicStreamTrait.
we added a var definition at the top of the function
-
var index:int;
we added an additional case statement
-
case NetStreamCodes.NETSTREAM_PLAY_START:
-
if(event.info.details)
-
{ // don't try to grab the index if there is no stream name
-
index = dsResource.indexFromName(event.info.details);
-
-
// if starting a stream that is not the current index, let the system know that it is transitioning
-
if(index != this.currentIndex)
-
{
-
inSetSwitching = true;
-
setSwitching(true, index);
-
inSetSwitching = false;
-
}
-
// notify the system that the stream has transitioned
-
setSwitching(false, index);
-
}
-
break;
within the transition start statement, we put a lock on the system to only indicate a stream was switching if the index was changing
-
index = dsResource.indexFromName(event.info.details);
-
if(index != this.currentIndex)
-
setSwitching(true, index);
So there you go, correct bitrate reporting with OSMF. Hopefully someone on the team will see this and they fix the issue in the core vs us having to mod their code. Hope this helps someone.
[UPDATE 2-16]
To be clear, this really is a bug with the Flash Player and FMS. The Flash Player itself is not firing the onPlayStatus event with a NetStream.Play.TransitionComplete code. This would effect any non OSMF player as well that relied only on that code to determine what stream was switched to. The bug with OSMF is that it just doesn't account for this quirk. Also, this happens in all OSMF versions that I'm aware of. We were using 1.5.

Subscribe to RSS