Wednesday, July 10, 2013

Gotcha of the Day: FMS's "FLV segment cache is full" error stops recording, continues to broadcast video

I'm running Flash Media Server (FMS) 4.5.3 on Linux for a client and yesterday found an odd condition while doing development. The custom flash client I've written managed to fill up the FLV Segment Cache which caused the video I was publishing to stop recording. That's annoying and all, but I was even more surprised to learn that the flash playback client continued to receive the stream. In other words, I was broadcasting video I *thought* I was recording, and was being viewed in real time, but actually wasn't getting recorded.

I can't think of a more troubling scenario: to be streaming out video, assuming its getting recorded, only to find out after the fact that the recording never happened.

While I could kvetch about why FMS would allow this scenario to happen, that wouldn't do me much good. What I needed was a fix.

The first thing I did was dial down SERVER.FLVCACHE_MAXSIZE to 1 megabyte in conf/fms.ini. My logic being that I wanted to be able to recreate the scenario as easily as possible. I found that with only a couple of streams going I was now able to recreate the issue and confirm the scenario above.

I also noticed that when the FLV segment cache is full message was logged the publishing client received two events: NetStream.Record.Stop and NetStream.Record.Stop.

The fix for this, then, turned out to be just a couple of lines of code. I detect those events and close down the stream when they come in. Something like:

    ns.addEventListener(NetStatusEvent.NET_STATUS,
                          function(evt:NetStatusEvent):void {
                            if(evt.info.code == 'NetStream.Record.Stop' ||
                               evt.info.code == 'NetStream.Record.NoAccess') {
                              ns.close();
                            }
                          });
    // use the netstream as normal

I confirmed that when I encounter the FLV cache full issue, the playback client freezes as the stream is no longer published. Just like I want.

I tried an upgraded to FMS 4.5.5 but the above condition still happens.

No comments:

Post a Comment