com.wowza.wms.stream
Class MediaStreamMap

Object
  extended by com.wowza.wms.stream.MediaStreamMap

public class MediaStreamMap
extends Object

MediaStreamMap: collection of IMediaStream object. This collection is usually attached to an IApplicationInstance object.


Field Summary
protected  IApplicationInstance appInstance
           
protected  java.util.Map<String,ILiveStreamPacketizer> liveStreamPacketizers
           
static int MAXSTREAMINDEX
           
protected  java.util.List<IMediaStreamNotify> mediaStreamListeners
           
protected  int nameGroupId
           
protected  java.util.List<com.wowza.wms.stream.MediaStreamMapGroup> nameGroups
           
protected  java.util.concurrent.atomic.AtomicLong nextStreamId
           
protected  edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock streamLock
           
protected  java.util.Map<String,IMediaStream> streamNames
           
protected  edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock streamNamesLock
           
protected  java.util.Map<String,java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup>> streamNameToGroup
           
protected  java.util.Map<Long,IMediaStream> streams
           
 
Constructor Summary
MediaStreamMap(IApplicationInstance appInstance)
          Create empty MediaStreamMap collection
 
Method Summary
 void addMediaStreamListener(IMediaStreamNotify mediaStreamListener)
          Add a media stream listener.
 com.wowza.wms.stream.MediaStreamMapGroup addNameGroup(com.wowza.wms.stream.MediaStreamMapGroup newGroup)
           
 void broadcasePlayMessage(IMediaStream stream, long timecode, java.nio.ByteBuffer msg, int objectEncoding)
          Send a broadcast message to all play stream that are listening to this live published stream.
 int broadcastGetObjectEncoding(IMediaStream stream)
          Get the minimum object encoding level for the clients playing this stream.
 void clearStreamName(String name)
          Unregister a published live media stream name.
 void clearStreamName(String name, IMediaStream stream)
          Unregister a published live media stream name.
 IApplicationInstance getAppInstance()
          Get the parent applicationInstance.
 String getAppInstanceName()
          Get the name of the parent applicationInstance.
 String getAppName()
          Get the name of the parent application.
 int getCount()
          Get the total number of streams stored in the mediaStreamMap
 ILiveStreamPacketizer getLiveStreamPacketizer(String streamName, String packetizerName, boolean doCreate)
          Get a live stream packetizer by name and packetizer id
 Object getLiveStreamPacketizerLock()
          Get the lock to the live stream packetizer system
 java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup> getNameGroups()
           
 java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup> getNameGroups(String streamName)
           
 java.util.Set<String> getNameGroupStreamNames(String streamName)
           
 int getNextStreamIndex()
          Reserve a clientless stream id for a new media stream.
 int getNextStreamIndex(IClient client)
          Reserve a stream for a client connection.
 int getNextStreamIndex(com.wowza.wms.netconnection.INetConnection netConnection)
          Reserve a stream for a netConnection connection.
 java.util.List<String> getPublishStreamNames()
          Returns a List of published stream names
 IMediaStream getStream(IClient client, int index)
          Get a media stream reference by stream id.
 IMediaStream getStream(IClient client, int index, boolean doCreate)
          Get a media stream reference by stream id.
 IMediaStream getStream(com.wowza.wms.netconnection.INetConnection netConnection, int index)
          Get a media stream object that is owned by a server to server netConnection object (not yet implemented).
 IMediaStream getStream(com.wowza.wms.netconnection.INetConnection netConnection, int index, boolean doCreate)
          Get a media stream reference by stream id.
 IMediaStream getStream(String name)
          Get a media stream by stream name.
 IMediaStream getStreamClientless(int index, String streamTypeStr)
          Get a media stream reference by stream id.
 edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock getStreamListLock()
          Get the underlying read/write lock associated with the list of streams
 edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock getStreamNameLock()
          Get the underlying read/write lock associated with the stream names list
 java.util.List<IMediaStream> getStreams()
          Returns a list of IMediaStream objects
 IVHost getVHost()
          Get the parent vHost.
 void notifyMediaStreamCreate(IMediaStream mediaStream)
          Notify all media stream listeners that a new media stream object has been created.
 void notifyMediaStreamDestroy(IMediaStream mediaStream)
          Notify all media stream listeners that a media stream object is being destroyed.
 void notifyPlayPublish(IMediaStream stream)
          Notify all play streams that are listening to this stream that the stream is going into a state of publish (NetStream.Play.PublishNotify).
 void notifyPlayUnpublish(IMediaStream stream)
          Notify all play streams that are listening to this stream that the stream is going into a state of unpublished (NetStream.Play.UnpublishNotify).
 void notifyPlayUnpublish(String streamName)
          Notify all play streams that are listening to this stream name that the stream is going into a state of unpublished (NetStream.Play.UnpublishNotify).
 void removeLiveStreamPacketizer(String streamName)
          Remove all live stream packetizers for this stream name
 ILiveStreamPacketizer removeLiveStreamPacketizer(String streamName, String packetizerName)
          Remove live stream packetizer
 void removeMediaStreamListener(IMediaStreamNotify mediaStreamListener)
          Remove a media stream listener.
 com.wowza.wms.stream.MediaStreamMapGroup removeNameGroup(int groupId)
           
 com.wowza.wms.stream.MediaStreamMapGroup removeNameGroup(com.wowza.wms.stream.MediaStreamMapGroup nameGroup)
           
 void removeStream(IClient client, int index)
          Remove a stream associated with a client connection
 void removeStream(com.wowza.wms.netconnection.INetConnection netConnection, int index)
          Remove a stream associated with a netConnection object
 void removeStream(int index)
          Remove a clientless media stream
 void setStreamName(IMediaStream stream, String name)
          Insert live media stream into the mediaStreamMap by name.
 long streamToIndex(IMediaStream stream)
          Get the unique stream identifier for a given stream
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appInstance

protected IApplicationInstance appInstance

liveStreamPacketizers

protected java.util.Map<String,ILiveStreamPacketizer> liveStreamPacketizers

MAXSTREAMINDEX

public static final int MAXSTREAMINDEX
See Also:
Constant Field Values

mediaStreamListeners

protected java.util.List<IMediaStreamNotify> mediaStreamListeners

nameGroupId

protected int nameGroupId

nameGroups

protected java.util.List<com.wowza.wms.stream.MediaStreamMapGroup> nameGroups

nextStreamId

protected java.util.concurrent.atomic.AtomicLong nextStreamId

streamLock

protected edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock streamLock

streamNames

protected java.util.Map<String,IMediaStream> streamNames

streamNamesLock

protected edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock streamNamesLock

streamNameToGroup

protected java.util.Map<String,java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup>> streamNameToGroup

streams

protected java.util.Map<Long,IMediaStream> streams
Constructor Detail

MediaStreamMap

public MediaStreamMap(IApplicationInstance appInstance)
Create empty MediaStreamMap collection

Parameters:
appInstance - parent applicationInstance
Method Detail

addMediaStreamListener

public void addMediaStreamListener(IMediaStreamNotify mediaStreamListener)
Add a media stream listener. A media stream listener will receive the following events: onMediaStreamCreate, onMediaStreamDestroy.

Parameters:
mediaStreamListener - media stream listener

addNameGroup

public com.wowza.wms.stream.MediaStreamMapGroup addNameGroup(com.wowza.wms.stream.MediaStreamMapGroup newGroup)

broadcasePlayMessage

public void broadcasePlayMessage(IMediaStream stream,
                                 long timecode,
                                 java.nio.ByteBuffer msg,
                                 int objectEncoding)
Send a broadcast message to all play stream that are listening to this live published stream.

Parameters:
stream - media stream
timecode - timecode (milliseconds)
msg - byte[] of data that will be deserialized as an AMFData object.
objectEncoding - object encoding (AMF0 or AMF3)

broadcastGetObjectEncoding

public int broadcastGetObjectEncoding(IMediaStream stream)
Get the minimum object encoding level for the clients playing this stream.

Parameters:
stream - publish stream
Returns:
object encoding level (AMF0 or AMF3)

clearStreamName

public void clearStreamName(String name)
Unregister a published live media stream name.

Parameters:
name - stream name

clearStreamName

public void clearStreamName(String name,
                            IMediaStream stream)
Unregister a published live media stream name.

Parameters:
name - stream name
stream - stream

getAppInstance

public IApplicationInstance getAppInstance()
Get the parent applicationInstance.

Returns:
parent applicationInstance

getAppInstanceName

public String getAppInstanceName()
Get the name of the parent applicationInstance.

Returns:
parent applicationInstance name

getAppName

public String getAppName()
Get the name of the parent application.

Returns:
parent application name.

getCount

public int getCount()
Get the total number of streams stored in the mediaStreamMap

Returns:
total number of streams stored in the mediaStreamMap

getLiveStreamPacketizer

public ILiveStreamPacketizer getLiveStreamPacketizer(String streamName,
                                                     String packetizerName,
                                                     boolean doCreate)
Get a live stream packetizer by name and packetizer id

Parameters:
streamName - stream name
packetizerName - packetizer id
doCreate - create if does not exist
Returns:
live stream packetizer

getLiveStreamPacketizerLock

public Object getLiveStreamPacketizerLock()
Get the lock to the live stream packetizer system

Returns:
lock to the live stream packetizer system

getNameGroups

public java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup> getNameGroups()

getNameGroups

public java.util.Set<com.wowza.wms.stream.MediaStreamMapGroup> getNameGroups(String streamName)

getNameGroupStreamNames

public java.util.Set<String> getNameGroupStreamNames(String streamName)

getNextStreamIndex

public int getNextStreamIndex()
Reserve a clientless stream id for a new media stream. Use this method to obtain a stream id for a new media stream object that is then created with a call to getClientlessStream().

Returns:
new reserved stream id

getNextStreamIndex

public int getNextStreamIndex(IClient client)
Reserve a stream for a client connection. Use getStream(IClient, int, boolean) to create stream.

Parameters:
client - parent client
Returns:
stream index

getNextStreamIndex

public int getNextStreamIndex(com.wowza.wms.netconnection.INetConnection netConnection)
Reserve a stream for a netConnection connection. Use getStream(INetConnection, int, boolean) to create stream.

Parameters:
netConnection -
Returns:
next stream index

getPublishStreamNames

public java.util.List<String> getPublishStreamNames()
Returns a List of published stream names

Returns:
List of published stream names

getStream

public IMediaStream getStream(IClient client,
                              int index)
Get a media stream reference by stream id.

Parameters:
client - client
index - stream id
Returns:
media stream object or null if does not exist.

getStream

public IMediaStream getStream(IClient client,
                              int index,
                              boolean doCreate)
Get a media stream reference by stream id. If it does not exist, create a new one with the given id. If creating a new media stream object, its id must first be obtained by calling getNextStreamIndex(IClient) .

Parameters:
client - client
index - stream id
doCreate - true to create if it does not exist
Returns:
media stream object

getStream

public IMediaStream getStream(com.wowza.wms.netconnection.INetConnection netConnection,
                              int index)
Get a media stream object that is owned by a server to server netConnection object (not yet implemented).

Parameters:
netConnection - netConnection to remote server
index - stream id
Returns:
media stream object or null if does not exist

getStream

public IMediaStream getStream(com.wowza.wms.netconnection.INetConnection netConnection,
                              int index,
                              boolean doCreate)
Get a media stream reference by stream id. If it does not exist, create a new one with the given id. If creating a new media stream object, its id must first be obtained by calling getNextStreamIndex(INetConnection) .

Parameters:
netConnection - netConnection to remote server
index - stream id
doCreate - true to create if it does not exist
Returns:
media stream object

getStream

public IMediaStream getStream(String name)
Get a media stream by stream name. Only published live streams are stored in the mediaStreamMap by name. This method is used to lookup a published live stream by name.

Parameters:
name - stream name
Returns:
media stream object or null if does not exist

getStreamClientless

public IMediaStream getStreamClientless(int index,
                                        String streamTypeStr)
Get a media stream reference by stream id. If it does not exist, create a new one with the given id. This is a clientless stream that is served by the backend of the server. If creating a new media stream object, its id must first be obtained by calling getNextStreamIndex() .

Parameters:
index - stream id
streamTypeStr - stream type
Returns:
media stream object

getStreamListLock

public edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock getStreamListLock()
Get the underlying read/write lock associated with the list of streams

Returns:
underlying read/write lock associated with the list of streams

getStreamNameLock

public edu.emory.mathcs.backport.java.util.concurrent.locks.WMSReadWriteLock getStreamNameLock()
Get the underlying read/write lock associated with the stream names list

Returns:
underlying read/write lock associated with the stream names list

getStreams

public java.util.List<IMediaStream> getStreams()
Returns a list of IMediaStream objects

Returns:
list of IMediaStream objects

getVHost

public IVHost getVHost()
Get the parent vHost.

Returns:
parent vHost

notifyMediaStreamCreate

public void notifyMediaStreamCreate(IMediaStream mediaStream)
Notify all media stream listeners that a new media stream object has been created.

Parameters:
mediaStream - new media stream object

notifyMediaStreamDestroy

public void notifyMediaStreamDestroy(IMediaStream mediaStream)
Notify all media stream listeners that a media stream object is being destroyed.

Parameters:
mediaStream - media stream object being destroyed

notifyPlayPublish

public void notifyPlayPublish(IMediaStream stream)
Notify all play streams that are listening to this stream that the stream is going into a state of publish (NetStream.Play.PublishNotify).

Parameters:
stream - live published stream that is being published

notifyPlayUnpublish

public void notifyPlayUnpublish(IMediaStream stream)
Notify all play streams that are listening to this stream that the stream is going into a state of unpublished (NetStream.Play.UnpublishNotify).

Parameters:
stream - live published stream that is being unpublished

notifyPlayUnpublish

public void notifyPlayUnpublish(String streamName)
Notify all play streams that are listening to this stream name that the stream is going into a state of unpublished (NetStream.Play.UnpublishNotify).

Parameters:
streamName - live published stream that is being unpublished

removeLiveStreamPacketizer

public void removeLiveStreamPacketizer(String streamName)
Remove all live stream packetizers for this stream name

Parameters:
streamName - streamName

removeLiveStreamPacketizer

public ILiveStreamPacketizer removeLiveStreamPacketizer(String streamName,
                                                        String packetizerName)
Remove live stream packetizer

Parameters:
streamName - stream name
packetizerName - packetizer id
Returns:
live stream packetizer

removeMediaStreamListener

public void removeMediaStreamListener(IMediaStreamNotify mediaStreamListener)
Remove a media stream listener.

Parameters:
mediaStreamListener - media stream listener

removeNameGroup

public com.wowza.wms.stream.MediaStreamMapGroup removeNameGroup(int groupId)

removeNameGroup

public com.wowza.wms.stream.MediaStreamMapGroup removeNameGroup(com.wowza.wms.stream.MediaStreamMapGroup nameGroup)

removeStream

public void removeStream(IClient client,
                         int index)
Remove a stream associated with a client connection

Parameters:
client - client
index - stream index

removeStream

public void removeStream(com.wowza.wms.netconnection.INetConnection netConnection,
                         int index)
Remove a stream associated with a netConnection object

Parameters:
netConnection - net connection
index - stream index

removeStream

public void removeStream(int index)
Remove a clientless media stream

Parameters:
index - stream index

setStreamName

public void setStreamName(IMediaStream stream,
                          String name)
Insert live media stream into the mediaStreamMap by name.

Parameters:
stream - mediea stream object
name - media stream name

streamToIndex

public long streamToIndex(IMediaStream stream)
Get the unique stream identifier for a given stream

Parameters:
stream - stream
Returns:
unique stream identifier