The following LiveStreamPacketizerMpegDashDataHandler example module illustrates how to use the Wowza Streaming Engine™ Java API to access MPEG-TS SCTE-35 tags for DASH streaming for a live stream.
package com.wowza.wms.example.module; import com.wowza.util.Base64; import com.wowza.wms.amf.*; import com.wowza.wms.httpstreamer.cmafstreaming.livestreampacketizer.CmafSegment; import com.wowza.wms.httpstreamer.model.LiveStreamPacketizerPacketHolder; import com.wowza.wms.httpstreamer.mpegdashstreaming.file.*; import com.wowza.wms.httpstreamer.mpegdashstreaming.livestreampacketizer.*; import com.wowza.wms.httpstreamer.mpegdashstreaming.util.MPEGDashUtils; import com.wowza.wms.transport.mpeg2.MPEG2Section; import com.wowza.wms.transport.mpeg2.section.cue.*; import java.io.IOException; public class LiveStreamPacketizerMpegDashDataHandlerExample implements IHTTPStreamerMPEGDashLivePacketizerDataHandler { private final LiveStreamPacketizerMPEGDash liveStreamPacketizer; public LiveStreamPacketizerMpegDashDataHandlerExample(LiveStreamPacketizerMPEGDash liveStreamPacketizer) { this.liveStreamPacketizer = liveStreamPacketizer; } @Override public void onFillSegmentEnd(long startTimecode, long endTimecode, InbandEventStreams inbandEventStreams, EventStream eventStream) { // remove expired events here if necessary } @Override public void onFillSegmentDataPacket(LiveStreamPacketizerPacketHolder liveStreamPacketizerPacketHolder, AMFPacket packet, InbandEventStreams inbandEventStreams, EventStream eventStream) { try { // dataStr is some scte35 splice event that has been received in the stream. // The method for getting the data to this point isn't shown here. String dataStr = "/DAvAAAAAAAAAP/wFAUEAAAUf+/+BIcq4P4AUmXAAAAAAAAKAAhDVUVJAAAAAdY="; byte[] data = Base64.decode(dataStr); // convert the data to an MPEG2Section so the SpliceInformationTable can be extracted MPEG2Section section = new MPEG2Section(); section.write(data); SpliceInformationTable spliceInformationTable = new SpliceInformationTable(section); SpliceCommand command = spliceInformationTable.getCommand(); if (command.getType() == SpliceCommand.SPLICE_COMMAND_INSERT) { SpliceEvent spliceEvent = ((SpliceInsertCommand)command).getEvent(); SpliceTime spliceTime = spliceEvent.getSpliceTime(); long presentationTime = spliceTime.getSpliceTime(); long eventId = spliceEvent.getEventID(); long duration = -1; if (spliceEvent.isDurationFlag()) duration = spliceEvent.getBreakDuration().getDuration(); Event event = new Event(dataStr, presentationTime); event.setId(eventId); if (duration >= 0) event.setDuration(duration); eventStream.registerEvent(event); } } catch (IOException e) { throw new RuntimeException(e); } } }
To test this module, connect to a source stream. For more information on how to connect to a source stream, see the article Connect to a source stream.