How to use IRTSPActionNotify interface to listen for RTSP stream events

package com.wowza.wms.example.module;

import com.wowza.wms.application.WMSProperties;
import com.wowza.wms.module.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.rtsp.RTSPRequestMessage;
import com.wowza.wms.rtsp.RTSPResponseMessages;

public class ModuleRTSPActionNotifyExample extends ModuleBase {

	public void onRTPSessionCreate(RTPSession rtpSession) {
		IRTSPActionNotify sessionListener = new RTPSessionListenter();
		rtpSession.getAppInstance().getProperties().put(rtpSession.getSessionId(), sessionListener);
		rtpSession.addActionListener(sessionListener);
	}

	public void onRTPSessionDestroy(RTPSession rtpSession) {
		IRTSPActionNotify sessionListener = null;
		WMSProperties props = rtpSession.getAppInstance().getProperties();

		synchronized(props)
		{
			sessionListener = (IRTSPActionNotify)props.get(rtpSession.getSessionId());
		}
		if (sessionListener != null)
		{
			rtpSession.removeActionListener(sessionListener);
			getLogger().info("removeClientListener: "+ rtpSession.getSessionId());
		}
	}

	class RTPSessionListenter implements IRTSPActionNotify
	{
		public void onTeardown(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onAnnounce(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onDescribe(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onGetParameter(RTPSession rtspSession,
				RTSPRequestMessage req, RTSPResponseMessages resp) {
		}

		public void onOptions(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onPause(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onPlay(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onRecord(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onRedirect(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}

		public void onSetParameter(RTPSession rtspSession,
				RTSPRequestMessage req, RTSPResponseMessages resp) {
		}

		public void onSetup(RTPSession rtspSession, RTSPRequestMessage req,
				RTSPResponseMessages resp) {
		}
	}
}

Originally Published: 10-03-2010.

If you're having problems or want to discuss this article, post in our forum.