We are trying to setup a scenario where we use Wowza to stream live video to clients, but inject captioning and metadata into the stream from an external source at various points in time. As such I have implemented the following module following guides found here:
public class CaptioningInjectionModule extends HTTProvider2Base {
private IServer server;
public void onServerInit(IServer server) {
this.server = server;
}
@Override
public void onHTTPRequest(IVHost ivHost, IHTTPRequest ihttpRequest, IHTTPResponse ihttpResponse) {
String appName = ihttpRequest.getParameter("appName");
String appInstanceName = ihttpRequest.getParameter("appInstanceName");
appInstanceName = appInstanceName == null ? "_definst_" : appInstanceName;
String streamName = ihttpRequest.getParameter("streamName");
BufferedReader reader = new BufferedReader(new InputStreamReader(ihttpRequest.getInputStream()));
String text = null;
try {
text = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
String language = ihttpRequest.getParameter("language");
String trackId = ihttpRequest.getParameter("trackId");
IMediaStream stream = ivHost.getApplication(appName).getAppInstance(appInstanceName).getStreams()
.getStream(streamName);
setCaption(stream, text, language, trackId);
}
private void setCaption(final IMediaStream stream, final String text, final String language, final String trackId) {
if (stream != null) {
AMFDataObj data = new AMFDataObj();
data.put("text", new AMFDataItem(text));
data.put("language", new AMFDataItem(language));
data.put("trackid", new AMFDataItem(trackId));
stream.sendDirect("onTextData", data);
((MediaStream) stream).processSendDirectMessages();
}
}
}
and
public class MetadataInjectionModule extends HTTProvider2Base {
private IServer server;
public void onServerInit(IServer server) {
this.server = server;
}
@Override
public void onHTTPRequest(IVHost ivHost, IHTTPRequest ihttpRequest, IHTTPResponse ihttpResponse) {
String appName = ihttpRequest.getParameter("appName");
String appInstanceName = ihttpRequest.getParameter("appInstanceName");
appInstanceName = appInstanceName == null ? "_definst_" : appInstanceName;
String streamName = ihttpRequest.getParameter("streamName");
BufferedReader reader = new BufferedReader(new InputStreamReader(ihttpRequest.getInputStream()));
StringBuilder data = new StringBuilder();
try {
String line;
while((line = reader.readLine()) != null) {
data.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
IMediaStream stream = ivHost.getApplication(appName).getAppInstance(appInstanceName).getStreams()
.getStream(streamName);
injectMetadata(stream, data.toString());
}
private void injectMetadata(final IMediaStream stream, final String data) {
if (stream != null) {
AMFDataList amfList = new AMFDataList();
amfList.add(new AMFDataItem("@setDataFrame"));
amfList.add(new AMFDataItem("onMetaData"));
AMFDataMixedArray metaData = new AMFDataMixedArray();
metaData.put("param1", data);
metaData.put("param2", new AMFDataItem("data2"));
amfList.add(metaData);
synchronized (stream) {
byte[] dataData = amfList.serialize();
int size = dataData.length;
long timecode = Math.max(stream.getAudioTC(), stream.getVideoTC());
stream.setDataTC(timecode);
stream.setDataSize(size);
stream.startDataPacket();
stream.addDataData(dataData, 0, size);
}
}
}
}
and set these up in my VHost.xml file:
<HTTPProvider>
<BaseClass>gamesys.wowza.server.modules.CaptioningInjectionModule</BaseClass>
<RequestFilters>caption*</RequestFilters>
<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>
<HTTPProvider>
<BaseClass>gamesys.wowza.server.modules.MetadataInjectionModule</BaseClass>
<RequestFilters>metadata*</RequestFilters>
<AuthenticationMethod>none</AuthenticationMethod>
</HTTPProvider>
Both endpoints work and I don’t see any exceptions in the Wowza server logs. My question is how can I get hold of this data on the client. I have tried various players like flowplayer and jwplayer by binding to their onMetadata or onCuepoint etc. events but I never seem to get anything come through. Is there a stage in the middle I am missing?