Hello,
I want to add a stream listener only to the main streams that have been published using an encoder like FMLE not through smil or transcoder.
I think that creating a listener on every onStreamCreate (clients who play| clients who publish) is not practical. And it will create a load on the CPU & the memory.
I have found a way to get it working. I am not sure whether it is the best way. At least it works
public void onStreamCreate(IMediaStream stream) {
String UniqueStreamIdStr = stream.getUniqueStreamIdStr();
if (UniqueStreamIdStr.contains("_")) {
getLogger().info("onStreamCreate:.................................................... " + UniqueStreamIdStr);
IMediaStreamActionNotify3 actionNotify = new StreamListener(this.vhost, this.appInstance);
WMSProperties props = stream.getProperties();
synchronized (props) {
props.put("streamActionNotifier", actionNotify);
}
stream.addClientListener(actionNotify);
}
}
public void onStreamDestroy(IMediaStream stream) {
String UniqueStreamIdStr = stream.getUniqueStreamIdStr();
if (UniqueStreamIdStr.contains("_")) {
getLogger().info("onStreamDestroy:.................................................... " + UniqueStreamIdStr);
IMediaStreamActionNotify3 actionNotify = null;
WMSProperties props = stream.getProperties();
synchronized (props) {
actionNotify = (IMediaStreamActionNotify3) stream.getProperties().get("streamActionNotifier");
}
if (actionNotify != null) {
stream.removeClientListener(actionNotify);
}
}
}