Wowza Community

Managing Announced RTSP session

I have devices that Announce RTSP streams to Wowza “live” application.

I want to track the I/O throughput, kick the devices out when they reach it and disallow reconnection for set period of time, like 24 hours.

The issue i’m having is that I can “shutdown” the RTPSession object in my module but it does not send a TEARDOWN command to the device, hence the device just keeps streaming RTP/UDP packets to Wowza.

I see that there is a com.wowza.wms.rtsp library, but I can’t find any documentation for it, nor there is any Interfaces to it, becides the IRTSPActionNotify.

I’ve also noticed that “rtspTunnelingSessionId” in my RTPSession object is always NULL. So how can I access the stream related RTSP Session?

In the future I also want to send SET_PARAMETERS RTSP messages.

Any info would be greatly appreciated.

Here is my module so far:

package com.my.wms.testing;
import java.util.*;
import com.wowza.wms.module.*;
import com.wowza.wms.stream.*;
import com.wowza.wms.util.*;
import com.wowza.util.*; 
import com.wowza.wms.application.*;
import com.wowza.wms.rtp.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.authentication.*;
import com.wowza.wms.*;
import com.wowza.wms.rtsp.*;
public class MyTesting extends ModuleBase implements IModuleOnApp, IModuleOnStream, IModuleOnRTPSession
{
	List<IMediaStream> hwstreams = new ArrayList<IMediaStream>(0);
	IApplicationInstance appInstance = null;
	
	class MyActionListener implements IMediaStreamActionNotify {
		void addStream(IMediaStream stream) {
			hwstreams.add(stream);
		}
		void removeStream(IMediaStream stream) {
			hwstreams.remove(stream);
		}
		public void onPause(IMediaStream stream, boolean isPause, double location) {}
		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) {}
		public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
			addStream(stream);
		}
		public void onSeek(IMediaStream stream, double location) {}
		public void onStop(IMediaStream stream) {} 
		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
			removeStream(stream);
		}
	}
	MyActionListener eal = new MyActionListener();
	class MyWorker extends Thread {
		public void run() {
			try {
				while( true ) {
					sleep(3000);
						getLogger().info("My MyWorker - checking active streams");
						List<IMediaStream> hwstreamsClone = new ArrayList<IMediaStream>(hwstreams);
						Iterator<IMediaStream> i = hwstreamsClone.iterator();
						while(i.hasNext()) {
							IMediaStream stream = i.next(); 
							RTPStream eStream = stream.getRTPStream();
							getLogger().info("        "+stream+" "+stream.getName());
							getLogger().info("        In/Out Bytes: "+p.getMessagesInBytes()+" "+p.getMessagesOutBytes());
							if( p.getMessagesInBytes() > 0.5*1024*1024 ) {
								bannedStreams.add(new BannedStream(stream.getName(), System.currentTimeMillis()+60*60*1000));
								eStream.shutdown(null);
								getLogger().info("My MyWorker - RTPStream shutdown ");
							}
						}
				}
			} catch (Exception e) {e.printStackTrace();}
		}
	}
	MyWorker worker = new MyWorker();
	public void onAppStart(IApplicationInstance appInstance)
	{
		getLogger().info("My onAppStart");
		this.appInstance = appInstance;
		worker.start();
	}
	public void onAppStop(IApplicationInstance appInstance) {
		getLogger().info("My onAppStop");
		worker.interrupt();
	}
	public void onStreamCreate(IMediaStream stream)
	{
		getLogger().info("My IMediaStream onStreamCreate");
		stream.addClientListener(eal);
	}
}

I’m not sure if it will work with SDP announce, but try:

eStream.getClient().setShutdownClient(true);

Richard

Try what works with pull:

rtspSession.rejectSession();

Richard

Actually, I don’t think it is possible: there is not a way in Wowza to tell an RTP encoder to stop publishing.

Richard

The rtsp clients you can stop anytime with rtspSession.rejectSession(), and not just in onRTPSessionCreate

Richard

rtspSession.rejectSession() is the right way for RTSP streams both incoming and outgoing. But it is not going to get the encoder to stop.

Richard

Richard,

Thanks for quick reply.

Both RTPStream or RTPSession don’t seem to have a method getClient().

Regardless, as far as I can understand “Client” object only created with Flash/RTMP streams and not RTSP.

Correct me if i’m wrong on that one.

I also tried a few different ways to shutdown RTPSession:

  • rtpsession.shutdown();

  • rtpsession.getRTSPStream().shutdown(new RTPRequestStatus(403, “Forbidden”));

  • rtpsession.getRTSPStream().getStream().close();

But none of them seem to work properly and they do close the RTPSession, so the stream is not published anymore.

But no TEARDOWN is ever sent to the device and seems that the network socket is still open on Wowza side, so my device just keep sending RTP.

Alternatively how can I close the socket binding, if possible. That could kill the connection I guess.

Art.

Yep, tried rtspSession.rejectSession(); but it only seems to work durint the establishment of the session.

Such as if I use it during “onRTPSessionCreate”.

Sends a 403 Forbidden to announcing client.

When session and stream are established, it doesn’t do anything.

You would think that rtpsession.shutdown() method would send a TEARDOWN, but it doesn’t.

Could it be a bug in Wowza?

Art.

Actially I was slightly incorrect.

RTPContext.shutdownRTPSession(rtpSession); closes the UDP socket that was used by the rtpStream, but not the TCP socket opened during initial RTSP negotiation.

0x000010E8 4 TCP 192.168.1.193 1935 192.168.1.223 57203 4 8 844 981 No

0x00000F48 10 UDP 0.0.0.0 6970 0 697 0 634,967 Yes

So as I understand it correctly, there is also no way to close active RTSP clients (viewers) on the fly?

Say I wanted to limit RTSP viewers by time or by I/O.

Would be the same issue, no? The stream would be broken but the player will still wait for packets to come in and depend on receive timeout to close the TCP connection.

So looks like I’m not alone.

Here is another person trying to do pretty much the same thing as myself.

I guess only Wowza developers can fix this at this point, by sending a TEARDOWN to the RTSP partner on RTPSession shutdown, which would cause the encoder to stop streaming.

but from all the class fields I’ve browsed, Wowza doesn’t track open RTSP sockets.

Would be nice to create some kind of RTSPSession and to be able to control it via some sort of interface.

There could be a lot of useful extensions possible from being able to send SET_PARAMETERS.

Art.