List chunks on an HLS live stream

Hey guys,

Is there a way to list chunks on a HLS/cupertino live stream?

===

I have a concrete need where my player will need to know exactly when the live stream is taking place (slide sync, of course). All of this is fairly approachable if only I can build an index up of the chunks along with a timestamp.

Obviously, I’ve been playing around in order to get there, but listening to events on the packetizer and the media list renditions isn’t really doing the trick – and at the same time the packetizer seems to be teasing me by writing the exact info that I need to the log file:

2014-06-06_19:55:13.09204 INFO server comment - LiveStreamPacketizerCupertino.endChunkTS[live/definst/dev-3753984-ab701201ab4621b3454b.mp4]: Add chunk: id:11 mode:TS[H264,AAC] a/v/k:151/306/3 duration:10566

… and I’d love to get this directly from Wowza instead of parsing log files :wink:

Sorry to push on this one, but does anyone have a good idea? Any events being fired when chunks are created, even if they are private APIs designed to be used only by DVR…?

Thanks Matt – but aren’t these events fired when the chunks are requested, not when there’s generated? If so, the timing would be off with this scheme?

Following up on this, the release notes for 4.0.4 state that:

  • Added support to Apple HLS (cupertino) live stream packetizer to provide a IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler class to control how chunks are numbered

  • LiveStreamPacketizerCupertino.setChunkIdHandler(IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHan dler chunkIdHandler)

  • Added LiveStreamPacketizers/Properties string property cupertinoChunkIdHandlerClass to specify full Java path to a class that implements IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler to control how cupertino chunks are numbered

  • Added IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler interface to control how cupertino chunks are numbered

  • void init(LiveStreamPacketizerCupertino liveStreamPacketizer);

  • long onAssignChunkId(HTTPStreamerCupertinoLiveStreamPacketizerChunkIdContext chunkIdContext);

This in turn is a way of saying that there’s now an interface to handle which number is assigned to an HLS chunk (which were previously just number sequentially). Matt notes that this can be controlled by a property in settings, but it’s also fairly easy to do programatically (and I wanted to keep my module structure).

My code to number chunks by the epoch time in milliseconds of their creation looks like this:

import com.wowza.wms.module.*;

import com.wowza.wms.application.*;

import com.wowza.wms.httpstreamer.cupertinostreaming.livestreampacketizer.*;

import com.wowza.wms.stream.livepacketizer.*;

public class MyWowzaModule extends ModuleBase {

public void onAppStart(IApplicationInstance appInstance) {

// We want to set chunk numbers for cupertino streaming; this is done first by listening to the live stream packetizers

appInstance.addLiveStreamPacketizerListener(new LiveActionNotify(appInstance));

}

/*** CHUNK NUMBER HANDLING

Set chunk numbers by the epoch time (in milliseconds) of their creation

***/

class CupertinoChunkIdHandler implements IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler {

public void init(LiveStreamPacketizerCupertino liveStreamPacketizer) {}

public long onAssignChunkId(HTTPStreamerCupertinoLiveStreamPacketizerChunkIdContext chunkIdContext) {

return System.currentTimeMillis();

}

}

class LiveActionNotify implements ILiveStreamPacketizerActionNotify {

public LiveActionNotify(IApplicationInstance appInstance) {}

public void onLiveStreamPacketizerCreate(ILiveStreamPacketizer liveStreamPacketizer, String streamName) {}

public void onLiveStreamPacketizerDestroy(ILiveStreamPacketizer liveStreamPacketizer) {}

public void onLiveStreamPacketizerInit(ILiveStreamPacketizer liveStreamPacketizer, String streamName) {

while(true) {

if (!(liveStreamPacketizer instanceof LiveStreamPacketizerCupertino)) break;

LiveStreamPacketizerCupertino cupertinoPacketizer = (LiveStreamPacketizerCupertino)liveStreamPacketizer;

cupertinoPacketizer.setChunkIdHandler(new CupertinoChunkIdHandler());

break;

}

}

}

}

This is awesome. It really is.

More wants more though: Is there any ways to do the same thing for DVR chunks?

Hi,

Even though you code will create chunks with incrementing id numbers, it may possibly cause problems on playback. THe HLS specification says that the segment ids must be sequential and increment by 1 each time. You would have to return system time / target duration to get this.

See http://tools.ietf.org/html/draft-pantos-http-live-streaming-13 for details.

Roger.

You might be able to obtain what you are looking for using IVHostHTTPStreamerRequestValidator and the validateHTTPStreamerRequest event.

In 4.0.4 (latest release) we do have IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler interface that implements the init and onAssignChunkId events which may correlate more closely to what you are looking to do. You can create a class that implements this interface then define the handler in your Application.xml within the LiveStreamPacketizers/Properties to turn it on as follows:

<Property>
                <Name>cupertinoChunkIdHandlerClass</Name>
                <Value>[Class-Path]</Value>
</Property>