Problem with Stream Listener

Hi !

I am creating a new Module to Wowza, and i need use Listener Stream, but by some reason the events aren’t called when start play video or stop.

I added Module in Application.xml of my Application and i debbuged my code and saw that class is being calling, but events not

Please, help me.

My Code:

package com.movile.wowza.session.user;
import com.wowza.wms.application.*;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.media.model.MediaCodecInfoAudio;
import com.wowza.wms.media.model.MediaCodecInfoVideo;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.stream.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.httpstreamer.model.*;
import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.*;
import com.wowza.wms.httpstreamer.smoothstreaming.httpstreamer.*;
public class SessionUser extends ModuleBase {
    public void doSomething(IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("doSomething");
        sendResult(client, params, "Hello Wowza");
    }
    public void onAppStart(IApplicationInstance appInstance) {
        String fullname = appInstance.getApplication().getName() + "/" + appInstance.getName();
        getLogger().info("onAppStart: " + fullname);
    }
    public void onAppStop(IApplicationInstance appInstance) {
        String fullname = appInstance.getApplication().getName() + "/" + appInstance.getName();
        getLogger().info("onAppStop: " + fullname);
    }
    public void onConnect(IClient client, RequestFunction function, AMFDataList params) {
        getLogger().info("onConnect: " + client.getClientId());
    }
    public void onConnectAccept(IClient client) {
        getLogger().info("onConnectAccept: " + client.getClientId());
    }
    public void onConnectReject(IClient client) {
        getLogger().info("onConnectReject: " + client.getClientId());
    }
    public void onDisconnect(IClient client) {
        getLogger().info("onDisconnect: " + client.getClientId());
    }
    public void onStreamCreate(IMediaStream stream) {
        getLogger().info("onStreamCreate: " + stream.getSrc());
        
        IMediaStreamActionNotify2 actionNotify = new StreamListener();
        //StreamListener actionNotify = new StreamListener();
        WMSProperties props = stream.getProperties();
        synchronized (props)
        {
                props.put("streamActionNotifier", actionNotify);
        }
        stream.addClientListener(actionNotify);
        
    }
    public void onStreamDestroy(IMediaStream stream) {
        getLogger().info("onStreamDestroy: " + stream.getSrc());
        
        
        IMediaStreamActionNotify2 actionNotify = null;
        WMSProperties props = stream.getProperties();
        synchronized (props)
        {
                actionNotify = (IMediaStreamActionNotify2) stream.getProperties().get("streamActionNotifier");
        }
        if (actionNotify != null)
        {
                stream.removeClientListener(actionNotify);
                getLogger().info("removeClientListener: " + stream.getSrc());
        }
    }
    public void onHTTPSessionCreate(IHTTPStreamerSession httpSession) {
        getLogger().info("onHTTPSessionCreate: " + httpSession.getSessionId());
        System.out.println("Query String Create " + httpSession.getQueryStr());
        //httpSession.setPlayStart(20000);
    }
    public void onHTTPSessionDestroy(IHTTPStreamerSession httpSession) {
        getLogger().info("onHTTPSessionDestroy: " + httpSession.getSessionId());
    }
    
    class StreamListener implements IMediaStreamActionNotify2
    {
        @Override
        public void onPause(IMediaStream stream, boolean isPause, double location) {
            System.out.println("onPause");
            
        }
        @Override
        public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) {
            System.out.println("onPlay");
            
        }
        @Override
        public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
            
            System.out.println("onPublish");
            
        }
        @Override
        public void onSeek(IMediaStream stream, double location) {
            
            
        }
        @Override
        public void onStop(IMediaStream stream) {
            System.out.println("onStop");
            
        }
        @Override
        public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
            // TODO Auto-generated method stub
            
        }
        @Override
        public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) {
            // TODO Auto-generated method stub
            
        }
        @Override
        public void onPauseRaw(IMediaStream stream, boolean isPause, double location) {
            // TODO Auto-generated method stub
            
        }
        
            
    }
    
    
    
}

Are you running Wowza in stand-alone (/bin/startup.bat) mode? Because that is the only way to see System.out.println() output. To see trace of these events in the logs, use getLogger():

getLogger().info("onPlay");

Richard

Just one more question please.

wowzamediaserver_access.log knows when user plays a video and stops with HSL. These points (play, stop) not is released for us developers?

Thankss!

The events that are logged are not real events. HLS does not send a notification to Wowza when the user plays or stops a stream. The logging events you see are generates at the same time the server calls onHTTPSessionCreate & onHTTPSessionDestroy

Roger.

What encoder are you using? This works with RTMP live stream from encoder like Wirecast or FMLE, or a Flash application.

Richard

No, it doesn’t work for HLS, cupertinostreaming

Richard

Yes:

package com.wowza.wms.example.module;
import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
import com.wowza.wms.module.*;
import com.wowza.wms.application.*;
public class ModuleAccessControlHTTPStreaming extends ModuleBase
{
	public void onHTTPSessionCreate(IHTTPStreamerSession httpSession)
	{
		boolean isGood = true;
		
		String ipAddressClient = httpSession.getIpAddress();
		String ipAddressServer = httpSession.getServerIp();
		String queryStr = httpSession.getQueryStr();
		String referrer = httpSession.getReferrer();
		String cookieStr = httpSession.getCookieStr();
		String userAgent = httpSession.getUserAgent();
		
		IApplicationInstance appInstance = httpSession.getAppInstance();
		String streamName = httpSession.getStreamName();
		
		// Here you can use the request and session information above to determine 
		// if you want to reject the connection
		// isGood = true/false;
		
		getLogger().info("ModuleAccessControlHTTPStreaming.onHTTPSessionCreate["+appInstance.getContextStr()+":"+streamName+"]: accept:"+isGood);
		
		if (!isGood)
			httpSession.rejectSession();
	}
public void onHTTPSessionDestroy(IHTTPStreamerSession httpSession)
	{
	}
}

Richard

For cupertinostream (HLS), IMediaStreamActionNotify.onPlay() does not run, they only work for Flash RTMP clients. You just have onHTTPSessionCreate and onHTTPSessionDestroy. and you cannot get the same accuracy and timeliness for PPM as with RTMP streaming because of the latency inherent in HTTP streaming. I would consider a log based approach instead.

Richard

Yes, best to do a controlled test with typical user actions, and look at resulting log. Look at the rows with x-event “destroy”, look at x-duration and sc-bytes.

Richard

thanks rrlanham!

I put this line in my code, but not works yet.

I put breakpoints inside events (onPlay, onStop) and when play video the event is not called. Other events like onStreamCreate works fine!

Do you know what can be?

Thanks!

Said well! If i play video using RTSP the events works! But HLS doesn’t works, this is correct?

Are there some way to listen events of play and stop using HLS?

I am using ffplay to test

RTSP: rtsp://localhost:1935/sessiontest/mp4:sample.mp4 (Ok)

HLS: http://localhost:1935/sessiontest/mp4:sample.mp4/playlist.m3u8 (not works)

Thanks Richard!

This not work with HLS?: https://www.wowza.com/docs/how-to-use-imediastreamactionnotify3-interface-to-listen-for-rtmp-stream-events-includes-codec-info

Last question Richard.

Are there some way to listen events of play and stop using HLS?

Richard,

My objetive is have the time that user watched a video.

Example: User richard watched a video during 43 seconds.

For this, i had planned create a object Date into OnPlay Event, and to create other object in OnStop Event, after, i would take the difference between.

onHTTPSessionDestroy is called some seconds after that video stop, so dont works for my problem.

Sorry my english richard.

Thanks for help.

thanks Richard!

Just one more question please.

wowzamediaserver_access.log knows when user plays a video and stops with HSL. These points (play, stop) not is released for us developers?

Thankss!

hi can you save and restart your system and you can watch these logs in server logs file for each changes done in your code it is required to restart the laptop not only wowza engine