Control MPEG-DASH fragment IDs and timecodes with the Wowza Streaming Engine Java API

You can use the Wowza Streaming Engine™ Java API to adjust the chunk IDs and timecodes of live MPEG-DASH streams as they're packetized by Wowza Streaming Engine media server software. This can be useful for synchronizing streams between servers for redundancy.

Note: Wowza Streaming Engine™ 4.5.0 or later is required.

To implement, create a class that implements the IHTTPStreamerMPEGDashLiveStreamPacketizerChunkIdHandler interface and add the mpegdashChunkIdHandlerClass property to the <LiveStreamPacketizer>/<Properties> section of [install-dir]/conf/[application-name][/Application.xml. A new instance of your class will be created each time an MPEG-DASH packetizer is created. The init method will be called for each new instance. The onAssignChunkId method will be called at the start of each new fragment. In the onAssignChunkId, return either a new HTTPStreamerMPEGDashLiveStreamPacketizerChunkIdContext object with your adjusted timecode and chunk ID info or null to use the information that was passed into the call.

The following is an example implementation that offsets a stream by 1000000000L milliseconds:

package com.wowza.wms.plugin.test2.mpegdashchunkid;

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

public class MPEGDashLiveStreamPacketizerChunkIdHandlerTest implements IHTTPStreamerMPEGDashLiveStreamPacketizerChunkIdHandler
{
	LiveStreamPacketizerMPEGDash liveStreamPacketizer = null;

	@Override
	public void init(LiveStreamPacketizerMPEGDash liveStreamPacketizer)
	{
		this.liveStreamPacketizer = liveStreamPacketizer;
	}

	@Override
	public HTTPStreamerMPEGDashLiveStreamPacketizerChunkIdContext onAssignChunkId(HTTPStreamerMPEGDashLiveStreamPacketizerChunkIdContext chunkIdContext)
	{
		long timecode = chunkIdContext.getTimecode();
		long chunkIndex = chunkIdContext.getChunkIndex();

		int chunkDurationTarget = liveStreamPacketizer.getSegmentDurationTarget();

		long timecodeNew = timecode + 1000000000L;
		long chunkIndexNew = 1 + (timecodeNew/chunkDurationTarget);

		System.out.println("onAssignChunkId: tc:"+timecodeNew+"/"+timecode+" index:"+chunkIndexNew+"/"+chunkIndex);

		return new HTTPStreamerMPEGDashLiveStreamPacketizerChunkIdContext(chunkIndexNew, timecodeNew);
	}
}
 
Note: In Wowza Streaming Engine versions 4.7.7 and earlier, the getChunkDurationTarget method is used to get the duration target instead of getSegmentDurationTarget.

It's important that the chunk ID is calculated as specified above. It should be:

chunkIndexNew = 1 + (timecodeNew/chunkDurationTarget);

This is required for many MPEG-DASH players to work properly since they use the chunk ID and availability start time to determine the next chunk ID to request.

Set the <LiveStreamPacketizer>/<Properties> property in [install-dir]/conf/[application-name]/Application.xml for the above class as follows:

<Property>
	<Name>mpegdashChunkIdHandlerClass</Name>
	<Value>com.wowza.wms.plugin.test2.mpegdashchunkid.MPEGDashLiveStreamPacketizerChunkIdHandlerTest</Value>
</Property>