Wowza Community

Why onStreamDestroy(IMediaStream stream) being called automatically?

Hi

I have a server code to listen flash media encoder.

public void onStreamDestroy(IMediaStream stream) {
		IMediaStreamActionNotify actionNotify = null;
		WMSProperties props = stream.getProperties();
		synchronized(props)
		{
			actionNotify = (IMediaStreamActionNotify)stream.getProperties().get("streamActionNotifier");
		}
		if (actionNotify != null)
		{
			stream.removeClientListener(actionNotify);
			getLogger().info("removeClientListener: "+stream.getSrc());
		}
	}
	class StreamListener implements IMediaStreamActionNotify2 
	{
		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) 
		{			
		}
		public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) 
		{			
		}		
		public void onPauseRaw(IMediaStream stream, boolean isPause, double location) 
		{			
		}
		public void onSeek(IMediaStream stream, double location)
		{
			getLogger().info("onSeek");
		}		
		public void onStop(IMediaStream stream)
		{
			getLogger().info("onStop By: " + stream.getClientId());
		}		
		public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
		{
			getLogger().info("onPublish");
		}		
		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
		{
			getLogger().info("onUNPublish");
		}		
		public void onPause(IMediaStream stream, boolean isPause, double location)
		{
			getLogger().info("onPause");
		}
	}

INFO stream stop 2009-07-29 15:28:27 1680587985 202.64.190.66 - 3992 9807454 192.172 mystream1 3 9767079 0 - - mystream1 -

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - onStop By: 1680587985

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - onStreamDestroy Source: 3

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - onStreamDestroy ClientID 1: 1680587985

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - IMediaStream Destroy 4: com.wowza.wms.stream.live.MediaStreamLive@7881db

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - IMediaStream Destroy 6: mystream1

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - removeClientListener: 3

INFO server comment 2009-07-29 15:28:27 - - - - - 501.172 - - - - - - - onStreamDestroy: 3

INFO stream destroy 2009-07-29 15:28:27 1680587985 202.64.190.66 - 3992 9807454 192.172 mystream1 3 9767079 0 - - mystream1 -

INFO session disconnect 2009-07-29 15:28:27 1680587985 202.64.190.66 - 3992 9807454 192.328 - - - - - - 1680587985 -

INFO server comment 2009-07-29 15:28:28 - - - - - 501.188 - - - - - - - onDisconnect: 1680587985

INFO server comment 2009-07-29 15:28:28 - - - - - 501.203 - - - - - - - checkLogin roletype: 2

INFO server comment 2009-07-29 15:28:28 - - - - - 501.234 - - - - - - - onDisconnect: 1680587985

INFO server comment 2009-07-29 15:28:28 - - - - - 501.234 - - - - - - - onDisconnect: 1680587985

There are 2 players to play the stream published by FME. However, after certain minutes (no fixed time), server side calls onStop and onDisconnect automatically to disconnect those 2 players.

FME is still connected and started.

What cause that problem and how should I fix it?

as it is impossible to stop players to play video.

I can’t see the reason why that would happen. Is that the whole module? Is there onStreamCreate method?

Richard

I’m not sure I understand.

Try giving the shared object a different name then the stream name.

If you are using FMLE to publish, how is the publisher entering text?

Also, in that code snip, are calling onStop in your code?

Richard

It sounds like two client apps are publishing a stream with the same name.

Richard

The code preceding onStop is in the client. Because the events of the IMediaStreamActionNotify2 interface are stream events triggered in the client. For example, doing netstream.seek in the Flash client will trigger the onSeek.

So you need to put your breakpoints in the Actionscript code and the Wowza IDE to step through it.

Richard

Is some client subscribing to the stream like this?

netstream.play("YourLiveStream");

Whoever is doing that is triggering most of those events server-side.

Richard

Publishing a stream and Subscribing to a stream both triggger onStreamCreate. Each client that subscribes to a stream triggers onStreamCreate for their stream. Different instances of the ServerListener handle each stream.

The methods onPublish and onUnPublish are triggered by the client that is publishing the stream.

onPlay, onPause, onPauseRaw, onSeek and onStop are triggered by clients that subscribe to a stream.

Richard

These events are triggered by the stream and do no require any explicit client-side code, necessarily.

Removing the mechanism to listen for Stream events in your module doesn’t effect the Stream events, you are just not handling them in anyway.

Richard

Yes, there is onStreamCreate Method:

public void onStreamCreate(IMediaStream stream) {
IMediaStreamActionNotify actionNotify = new StreamListener();
WMSProperties props = stream.getProperties();
synchronized(props)
{
props.put("streamActionNotifier", actionNotify);
}
stream.addClientListener(actionNotify);
}

Hi

I use text chat example code with chat shared object ‘mystream’ to let publisher to input text.

In FME 3, I set the stream name to be ‘mystream’ to let publisher to publish video.

In client player side, it has a video player and text chat box to see cam video and text chat with publisher, the stream name and chat shared object name are the same ‘mystream’.

I found that it is the following situations and will make client stop.

When publisher input text for a couple of minutes, one of the client player would stop.

When 2 client players input text for a couple of minutes, either his player stops or other player stops.

But, publisher nevers stop by server.

I am not sure how and when the client player would be stopped by server.

IMediaStreamActionNotify actionNotify  = new StreamListener();		
stream.addClientListener(actionNotify);
onStop(IMediaStream stream)

I think it should relate to the above code.

Hi

I tried many ways but still not fix it.

  1. There is one application name ‘videochat’ with Application.xml
<Streams>
<StreamType>live-lowlatency</StreamType>			<StorageDir>${com.wowza.wms.AppHome}/content</StorageDir>
			<Properties>
			</Properties>
		</Streams>
		<SharedObjects>
			<StorageDir></StorageDir>
		</SharedObjects>
		<Client>
			<IdleFrequency>-1</IdleFrequency>
			<Access>				<StreamReadAccess>*</StreamReadAccess>				<StreamWriteAccess>*</StreamWriteAccess>				<StreamAudioSampleAccess></StreamAudioSampleAccess>		<StreamVideoSampleAccess></StreamVideoSampleAccess>		<SharedObjectReadAccess>*</SharedObjectReadAccess>		<SharedObjectWriteAccess>*</SharedObjectWriteAccess>
			</Access>
		</Client>
		<RTP>
			<Authentication>
				<Method>digest</Method>
			</Authentication>
			<AVSyncMethod>senderreport</AVSyncMethod>
			<MaxRTCPWaitTime>12000</MaxRTCPWaitTime>
			<Properties>							</Properties>
		</RTP>
		<Application>
			<ValidationFrequency>0</ValidationFrequency>
		</Application>

  1. I separated the text chat shared object and stream.

textchat sharedobject name: textchat

It is in the fla.

stream name: video

It is in Flash media encoder 3

  1. On publisher side:

I built a fla with textchat example.

var rtmp:String = “rtmp://[publicIP]/videochat”;

var chatSharedObjectName:String = “textchat”;

The publisher fla does not concern publishing video.

In FME 3, I set

rtmp://[publicIP]/videochat

stream: video

So, both textchat flash client and video broadcast in FME3 points to the same rtmp with the same application name.

The publisher can input textchat on swf and publishing video on FME as I need to publish H.264.

  1. On client side:

I built a flash client which has textchat and play video.

I set

var rtmp:String = “rtmp://[publicIP]/videochat”;

var chatSharedObjectName:String = “textchat”;

//textchat sharedobject

function initSharedObject() {

nc.call(“initSharedObject”, new Responder(connectSharedObjectRes), “textchat”);

}

//video

nsPlay = new NetStream(nc);

nsPlay.play(“video”);

So, the client can input textchat while viewing video.

------------- Problem on server side java code --------------

Problem in case:

I play videochat in one client, it is no problem to input text and view video, publisher side also can see text input from client.

When I play videochat on other machines, e.g. I open 2 or more videochat clients, it will destroy the stream and disconnect the client.

Sometimes, it disconnect the client himself and disconnect other client sessions. It is by random to disconnect client in times and client sessions.

I tried to connect max 3 players for an hour under the same subnet. If other machines in other subnet, they will be disconnected or kick out other clients connection.

onStop By ClientId: 177299858

onStop By streamName: video

onStreamDestroy ClientID: 177299858

IMediaStream onStreamDestroy: video

onStreamDestroy: 3

onDisconnect: 177299858

I double check the AS3 code, there is no code to trigger the OnStop stream method.


Question:


How can I trace which segment of code to cause the OnStop event?

OR, FME stops client?

I did not encounter this problem before, until changing to use FME as video broadcasting and that problem occurs.

public void onStreamCreate(IMediaStream stream) {
		IMediaStreamActionNotify actionNotify  = new StreamListener();				
		stream.addClientListener(actionNotify);
}
	
public void onStreamDestroy(IMediaStream stream) {
		IMediaStreamActionNotify actionNotify = null;
		if (actionNotify != null)
		{
			stream.removeClientListener(actionNotify);
		}
}
	
class StreamListener implements IMediaStreamActionNotify2 
{
		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) 
		{			
		}
		
		public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) 
		{			
		}
		
		public void onPauseRaw(IMediaStream stream, boolean isPause, double location) 
		{			
		}
		public void onSeek(IMediaStream stream, double location)
		{
			getLogger().info("onSeek");
		}
		
		public void onStop(IMediaStream stream)
		{
			getLogger().info("onStop By ClientId: " + stream.getClientId());
			getLogger().info("onStop By streamName: " + stream.getName());
		}
		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend)
		{
			getLogger().info("onStreamUNPublish ClientID 1: " + stream.getClientId());
		}
		
		public void onPause(IMediaStream stream, boolean isPause, double location)
		{
			getLogger().info("onPause");
		}
}	

By the way, the main reason to use StreamListener is that I need to get the clientid of FME which it publishes the video.

The clientid of FME will be used in private session not being disconnected.

And, the publisher client session has not been disconnected so far. It happened just on the player client side.

I am not sure.

Because textchat flash client:

var chatSharedObjectName:String = “textchat”;

It is the textchat sharedObject which does NOT publish as a stream.

FME client:

stream: video which publishes as a stream.

So, the stream name and sharedOject name are 2 different names.

Any idea how to trace which segment of code to execute the OnStop()?

“IMediaStreamActionNotify2 interface are stream events triggered in the client”

Since textchat sharedObject does not publish stream, it does not has any AS3 code involve in stream or onStop.

On publisher side, there are only

  1. nc = new NetConnection(); and

  2. initSharedObject(chatSharedObjectName);

On client side, there is nsPlay:NetStream

but it is for

nsPlay = new NetStream(nc);

nsPlay.play(streamName);

So, there is not calling OnStop()

And only FME publishes stream, do you know will FME 3 has the limitation to view the stream published by it?

As FME 3 license agreement said it only used for FMS but not other media server.

On player client side, the only flash client code for netstream is :

function subscribe() 
{
	if (connectButton.label == 'Stop')
	{		
	    nsPlay = new NetStream(nc);			
		nsPlay.addEventListener(NetStatusEvent.NET_STATUS, nsPlayOnStatus);		
		var nsPlayClientObj:Object = new Object();
		nsPlay.client = nsPlayClientObj;
		nsPlayClientObj.onMetaData = function(infoObject:Object) 
		{
			trace("onMetaData");			
			for (var propName:String in infoObject)
			{
				trace("  "+propName + " = " + infoObject[propName]);
			}
		};		
		nsPlay.bufferTime = 1;		
		nsPlay.play(streamName);	//where streamName = "textchat"	
		videoRemote.attachNetStream(nsPlay);	
	}
}

It did not has any closing netstream code like below:

nsPlay.close();

nsPlay.play(null);

nsPlay = null;

videoRemote.attachNetStream(null);

videoRemote.clear();

nc.close();

nc = null;

Today, I did a lot of checking but the problem still cannot be traced.

There is a VideoChatModule on server side.

I removed all onAppStop, onDisconnect, onStreamCreate, onStreamDestroy, class StreamListener implements IMediaStreamActionNotify2 methods and class in that customized java module.

They are other modules for this application:

<Module>
<Name>base</Name>
<Description>Base</Description>
<Class>com.wowza.wms.module.ModuleCore</Class>
</Module>
<Module>
<Name>properties</Name>
<Description>Properties</Description>
<Class>com.wowza.wms.module.ModuleProperties</Class>
</Module>
<Module>
<Name>logging</Name>
<Description>Client Logging</Description>
<Class>com.wowza.wms.module.ModuleClientLogging</Class>
</Module>
<Module>
<Name>flvplayback</Name>
<Description>FLVPlayback</Description>
<Class>com.wowza.wms.module.ModuleFLVPlayback</Class>
</Module>

So, I give up to get the FME clientID, just make a simple publish and play testing.

Publisher side is ok. I open 5 players on 5 machines, used firefox and IE7.

Theoretically, both client and server sides do not have any code about Disconnect, OnStop, OnAppStop, nsPlay.close(), nc.close(). But, the stream still be stop, destroy and disconnect client session.

I did not google about FME would destroy stream automatically. Or, the browser or network in client side have problem? But, when I use those computers to view other video cam web sites, they did not have that problem and able to play the video without disconnect.

I keep on ping the server which run wowza and there is no packet lost.

Here is the log:

INFO	stream	stop	2009-08-04	16:23:41	1908680512	video
INFO	stream	destroy	2009-08-04	16:23:41	1908680512	video
INFO	session	disconnect	2009-08-04	16:23:41	1908680512	
INFO	stream	stop	2009-08-04	16:25:38	1565497498	video
INFO	stream	destroy	2009-08-04	16:25:38	1565497498	video
INFO	session	disconnect	2009-08-04	16:25:38	1565497498	
INFO	stream	stop	2009-08-04	16:25:51	694391715	video
INFO	stream	stop	2009-08-04	16:25:51	694391715	video
INFO	stream	unpublish	2009-08-04	16:25:51	694391715	video
INFO	stream	destroy	2009-08-04	16:25:51	694391715	video
INFO	session	disconnect	2009-08-04	16:25:51	694391715	
INFO	session	disconnect	2009-08-04	16:26:41	813651732	
INFO	stream	destroy	2009-08-04	16:31:49	720493492	video
INFO	session	disconnect	2009-08-04	16:31:49	720493492	
INFO	stream	destroy	2009-08-04	16:41:43	1645166618	video
INFO	session	disconnect	2009-08-04	16:41:43	1645166618	
INFO	application	app-stop	2009-08-04	16:42:43

What do you suggest me to fix it?

Yes, so I deleted all the code regarding onStreamCreate, onStreamDestroy, class StreamListener on server side custom module.

And there is no client side code about nsPlay.close(); and nsPlay.play(null);

Once the client code nsPlay.play(streamName) execute, why server still destroy stream and disconnect client session?

Because I deleted all the code regarding Destroy Stream and Disconnect client.

I still do not know how the server destroy stream just viewing the log.

Should I contact wowza technical support? as we are going to buy the server license soon.

We approached wowza support this morning and they suggest we use the example flash client to test. The same problem occurs.

However, after changing to use local IP and the problem seems to be fixed. So, it should be the network problem.

Thanks for your kind help.