net.sf.fmj.media.rtp
Class RTPSessionMgr

java.lang.Object
  extended by javax.media.rtp.RTPManager
      extended by net.sf.fmj.media.rtp.RTPSessionMgr
All Implemented Interfaces:
Controls, SessionManager

public class RTPSessionMgr
extends RTPManager
implements SessionManager

Kernel of the RTP stack. This is where almost everything is done. Instances of this class handle a single RTP session which is an association among a set of participants communicating with RTP. A participant may be involved in multiple RTP sessions at the same time. In a multimedia session, each medium is typically carried in a separate RTP session with its own RTCP packets (unless the the encoding itself multiplexes multiple media into a single data stream).

Version:
1-1-alpha3
Author:
Andrew G D Rowley, Christian Vincenot

Field Summary
protected  long ssrc
           
 
Fields inherited from interface javax.media.rtp.SessionManager
SSRC_UNSPEC
 
Constructor Summary
RTPSessionMgr()
          Creates a new RTPManager
 
Method Summary
 void addFormat(Format format, int payload)
          Add a format to the list of supported formats.
 void addPeer(SessionAddress peerAddress)
          Add a peer to send RTP data to.
 void addReceiveStreamListener(ReceiveStreamListener listener)
          Adds a listener to the list of listeners wanting to be informed when a receive stream is created.
 void addRemoteListener(RemoteListener listener)
          Adds a listener to the list of remote listeners.
 void addSendStreamListener(SendStreamListener listener)
          Add this listener to the list of listeners wanting to be informed when a send stream is created.
 void addSessionListener(SessionListener listener)
          Add this listener to the list of session listeners.
 void addTarget(SessionAddress remoteAddress)
          Add a network target to which we'll send our RTP packets.
 void closeSession(java.lang.String reason)
          Closes this RTP Session.
 SendStream createSendStream(DataSource dataSource, int streamIndex)
          Creates a send stream used to carry data from a source to some receivers over the network.
 SendStream createSendStream(int ssrc, DataSource ds, int streamindex)
          Creates a send stream used to carry data from a source to some receivers over the network.
 void dispose()
          Called when wishing to quit the RTP session.
static boolean formatSupported(Format f)
          This is a function provided by Sun's implementation, which is not in the API as AFAIK - kenlars99.
 java.lang.String generateCNAME()
          Generate a CNAME.
 long generateSSRC()
          Generates a Synchronization SouRCe (SSRC) number.
 java.util.Vector getActiveParticipants()
          Returns the list of active participants in this RTP session.
 java.util.Vector getAllParticipants()
          Returns the list of all participants in this RTP session.
 int getAverageRTCPSize()
          Returns the average RTP packet size computed until now.
 java.lang.Object getControl(java.lang.String controlClass)
          Get control for the specified type.
 java.lang.Object[] getControls()
          Get the list of all controls possible.
 long getDefaultSSRC()
          Returns the default SSRC in this RTP session.
 Format getFormat(int payload)
          Another function provided by Sun's implementation, not in the spec/API.
 GlobalReceptionStats getGlobalReceptionStats()
          Returns the global reception statistics for this RTP session.
 GlobalTransmissionStats getGlobalTransmissionStats()
          Returns the global transmission statistics for this RTP session.
 LocalParticipant getLocalParticipant()
          Returns the local participant.
 SessionAddress getLocalSessionAddress()
          Returns the local session address.
 int getMulticastScope()
          Returns the multicast scope.
 java.util.Vector getPassiveParticipants()
          Returns the list of passive participants in this RTP session.
 java.util.Vector getPeers()
          Returns all the receiver & senders peers we're sending RTP data to.
 java.util.Vector getReceiveStreams()
          Returns the list of receive streams in this RTP session.
 java.util.Vector getRemoteParticipants()
          Returns the list of remote participants in this RTP session.
 SessionAddress getRemoteSessionAddress()
          Returns the remote session address.
 java.util.Vector getSendStreams()
          Returns the list of send streams in this RTP session.
 SessionAddress getSessionAddress()
          Returns the session address.
 RTPStream getStream(long filterssrc)
          Returns the RTPStream corresponding to this SSRC.
static Format[] getSupportedFormats()
          Return the SupportedFormats via RTP
protected  void handleRTCPPacket(byte[] data, int offset, int length)
          Handles an incoming RTCP packet
protected  void handleRTPPacket(byte[] data, int offset, int length)
          Handles an incoming RTP packet
 void initialize(RTPConnector connector)
          Initializes and starts the RTP Session.
 void initialize(SessionAddress localAddress)
          Initializes and starts the RTP Session.
 void initialize(SessionAddress[] localAddresses, SourceDescription[] sourceDescription, double rtcpBandwidthFraction, double rtcpSenderBandwidthFraction, EncryptionInfo encryptionInfo)
          Initializes and starts the RTP Session.
 int initSession(SessionAddress localAddress, long defaultSSRC, SourceDescription[] defaultUserDesc, double rtcp_bw_fraction, double rtcp_sender_bw_fraction)
          Initializes and starts the session.
 int initSession(SessionAddress localAddress, SourceDescription[] defaultUserDesc, double rtcp_bw_fraction, double rtcp_sender_bw_fraction)
          Initializes and starts the session.
 void removeAllPeers()
          Removes all the peers from this RTP session.
 void removePeer(SessionAddress peerAddress)
          Removes a receiver peer from the session.
 void removeReceiveStreamListener(ReceiveStreamListener listener)
          Removes this listener from the list of listeners wanting to be be informed of the creation of new receive streams.
 void removeRemoteListener(RemoteListener listener)
          Removes this listener from the list of remote listeners.
 void removeSendStreamListener(SendStreamListener listener)
          Removes this listener from the list of listeners wanting to be informed of the creation of send streams.
 void removeSessionListener(SessionListener listener)
          Removes this listener from the list of session listeners.
 void removeTarget(SessionAddress remoteAddress, java.lang.String reason)
          Remove a network target .
 void removeTargets(java.lang.String reason)
          Remove a network target .
 void RTPPacketSent(long time, int size)
          Sort of callback method called by RTPSendStreams to inform the RTPSessionManager they're linked to that an RTP packet has been sent by the local participant.
 void sendRTCPPacket()
          Sends an RTCP packet, and schedules the next one
 void setMulticastScope(int multicastScope)
          Sets the multicast scope.
 void start()
          Starts the sending of RTCP packets
 int startSession(int mcastScope, EncryptionInfo encryptionInfo)
          Starts a session.
 int startSession(SessionAddress destAddress, int mcastScope, EncryptionInfo encryptionInfo)
          Starts a session.
 int startSession(SessionAddress localReceiverAddress, SessionAddress localSenderAddress, SessionAddress remoteReceiverAddress, EncryptionInfo encryptionInfo)
          Starts a session.
 
Methods inherited from class javax.media.rtp.RTPManager
getRTPManagerList, newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ssrc

protected long ssrc
Constructor Detail

RTPSessionMgr

public RTPSessionMgr()
Creates a new RTPManager

Method Detail

formatSupported

public static boolean formatSupported(Format f)
This is a function provided by Sun's implementation, which is not in the API as AFAIK - kenlars99. This does not include formats in the RTP bonus formats mgr. This is a somewhat dubious function, since the actual RTPSessionMgr used is determined by RTPManager.newInstance(). To the extend that Sun's code calls this function, it is assuming that its own RTPSessionMgr will be used, which may be the source of some problems.

Parameters:
f - the format which we want to test
Returns:
true if the format is supported Note: the format list in JMF is static, and in FMJ it is not. So you can add a format once with JMF, but you have to add it every time you instantiate the manager with FMJ.

getSupportedFormats

public static Format[] getSupportedFormats()
Return the SupportedFormats via RTP


getFormat

public Format getFormat(int payload)
Another function provided by Sun's implementation, not in the spec/API.


addFormat

public void addFormat(Format format,
                      int payload)
Add a format to the list of supported formats.

Specified by:
addFormat in interface SessionManager
Specified by:
addFormat in class RTPManager
Parameters:
format - format to add
payload - type of payload corresponding to this format

addReceiveStreamListener

public void addReceiveStreamListener(ReceiveStreamListener listener)
Adds a listener to the list of listeners wanting to be informed when a receive stream is created.

Specified by:
addReceiveStreamListener in interface SessionManager
Specified by:
addReceiveStreamListener in class RTPManager
Parameters:
listener - the listener to add

addRemoteListener

public void addRemoteListener(RemoteListener listener)
Adds a listener to the list of remote listeners.

Specified by:
addRemoteListener in interface SessionManager
Specified by:
addRemoteListener in class RTPManager
Parameters:
listener - listener to add

addSendStreamListener

public void addSendStreamListener(SendStreamListener listener)
Add this listener to the list of listeners wanting to be informed when a send stream is created.

Specified by:
addSendStreamListener in interface SessionManager
Specified by:
addSendStreamListener in class RTPManager
Parameters:
listener - the listener to add

addSessionListener

public void addSessionListener(SessionListener listener)
Add this listener to the list of session listeners.

Specified by:
addSessionListener in interface SessionManager
Specified by:
addSessionListener in class RTPManager
Parameters:
listener - listener to add

removeReceiveStreamListener

public void removeReceiveStreamListener(ReceiveStreamListener listener)
Removes this listener from the list of listeners wanting to be be informed of the creation of new receive streams.

Specified by:
removeReceiveStreamListener in interface SessionManager
Specified by:
removeReceiveStreamListener in class RTPManager
Parameters:
listener - listener to remove

removeRemoteListener

public void removeRemoteListener(RemoteListener listener)
Removes this listener from the list of remote listeners.

Specified by:
removeRemoteListener in interface SessionManager
Specified by:
removeRemoteListener in class RTPManager
Parameters:
listener - listener to remove

removeSendStreamListener

public void removeSendStreamListener(SendStreamListener listener)
Removes this listener from the list of listeners wanting to be informed of the creation of send streams.

Specified by:
removeSendStreamListener in interface SessionManager
Specified by:
removeSendStreamListener in class RTPManager
Parameters:
listener - listener to remove

removeSessionListener

public void removeSessionListener(SessionListener listener)
Removes this listener from the list of session listeners.

Specified by:
removeSessionListener in interface SessionManager
Specified by:
removeSessionListener in class RTPManager
Parameters:
listener - listener to remove

getActiveParticipants

public java.util.Vector getActiveParticipants()
Returns the list of active participants in this RTP session.

Specified by:
getActiveParticipants in interface SessionManager
Specified by:
getActiveParticipants in class RTPManager
Returns:
the list of active participants in this RTP session

getAllParticipants

public java.util.Vector getAllParticipants()
Returns the list of all participants in this RTP session.

Specified by:
getAllParticipants in interface SessionManager
Specified by:
getAllParticipants in class RTPManager
Returns:
the list of all participants in this RTP session

getLocalParticipant

public LocalParticipant getLocalParticipant()
Returns the local participant.

Specified by:
getLocalParticipant in interface SessionManager
Specified by:
getLocalParticipant in class RTPManager
Returns:
the local participant

getPassiveParticipants

public java.util.Vector getPassiveParticipants()
Returns the list of passive participants in this RTP session.

Specified by:
getPassiveParticipants in interface SessionManager
Specified by:
getPassiveParticipants in class RTPManager
Returns:
the list of passive participants in this RTP session

getRemoteParticipants

public java.util.Vector getRemoteParticipants()
Returns the list of remote participants in this RTP session.

Specified by:
getRemoteParticipants in interface SessionManager
Specified by:
getRemoteParticipants in class RTPManager
Returns:
the list of passive participants in this RTP session

getGlobalReceptionStats

public GlobalReceptionStats getGlobalReceptionStats()
Returns the global reception statistics for this RTP session.

Specified by:
getGlobalReceptionStats in interface SessionManager
Specified by:
getGlobalReceptionStats in class RTPManager
Returns:
the global reception stats

getGlobalTransmissionStats

public GlobalTransmissionStats getGlobalTransmissionStats()
Returns the global transmission statistics for this RTP session.

Specified by:
getGlobalTransmissionStats in interface SessionManager
Specified by:
getGlobalTransmissionStats in class RTPManager
Returns:
the global transmission statistics for this RTP session

getReceiveStreams

public java.util.Vector getReceiveStreams()
Returns the list of receive streams in this RTP session. This is the list of streams used to receive data, ie connected to senders.

Specified by:
getReceiveStreams in interface SessionManager
Specified by:
getReceiveStreams in class RTPManager
Returns:
the list of receive streams in this RTP session

getSendStreams

public java.util.Vector getSendStreams()
Returns the list of send streams in this RTP session. This is the list of streams used to send data, ie connected to receivers.

Specified by:
getSendStreams in interface SessionManager
Specified by:
getSendStreams in class RTPManager
Returns:
the list of send streams in this RTP session

initialize

public void initialize(SessionAddress localAddress)
                throws java.io.IOException
Initializes and starts the RTP Session.

Specified by:
initialize in class RTPManager
Parameters:
localAddress - the local address
Throws:
java.io.IOException - I/O Exception

initialize

public void initialize(SessionAddress[] localAddresses,
                       SourceDescription[] sourceDescription,
                       double rtcpBandwidthFraction,
                       double rtcpSenderBandwidthFraction,
                       EncryptionInfo encryptionInfo)
Initializes and starts the RTP Session.

Specified by:
initialize in class RTPManager
Parameters:
localAddresses - the local address
sourceDescription - the source description to be used when sending SDES reports
rtcpBandwidthFraction - the bandwidth fraction allocated for RTCP traffic
rtcpSenderBandwidthFraction - the RTCP bandwidth fraction allocated for senders
encryptionInfo - Encryption information - UNUSED at the moment

addTarget

public void addTarget(SessionAddress remoteAddress)
               throws java.io.IOException
Add a network target to which we'll send our RTP packets. This network target can be one receiver (unicast address) or several receivers (multicast address).

Specified by:
addTarget in class RTPManager
Parameters:
remoteAddress - remote address (unicast or multicast) to which we want to send our RTP packets
Throws:
java.io.IOException - I/O Exception

initialize

public void initialize(RTPConnector connector)
Initializes and starts the RTP Session.

Specified by:
initialize in class RTPManager
Parameters:
connector - the RTP connector used to retrieve the control & data streams

removeTarget

public void removeTarget(SessionAddress remoteAddress,
                         java.lang.String reason)
Remove a network target .

Specified by:
removeTarget in class RTPManager
Parameters:
remoteAddress - remote address (unicast or multicast) to which we want to send our RTP packets
reason - reason for which we remove this target (used in the RTCP BYE packet following this call)

removeTargets

public void removeTargets(java.lang.String reason)
Remove a network target .

Specified by:
removeTargets in class RTPManager
Parameters:
reason - reason for which we remove this target (used in the RTCP BYE packet following this call)

createSendStream

public SendStream createSendStream(DataSource dataSource,
                                   int streamIndex)
                            throws UnsupportedFormatException,
                                   java.io.IOException
Creates a send stream used to carry data from a source to some receivers over the network.

Specified by:
createSendStream in interface SessionManager
Specified by:
createSendStream in class RTPManager
Parameters:
dataSource - the datasource producing the data to send
streamIndex - the index of the stream in the datasource's streams table
Returns:
the created SendStream
Throws:
UnsupportedFormatException - thrown if the datasource's stream only outputs formats which aren't supported
java.io.IOException - I/O Exception thrown in case of problem with streams

dispose

public void dispose()
Called when wishing to quit the RTP session.

Specified by:
dispose in class RTPManager

getControl

public java.lang.Object getControl(java.lang.String controlClass)
Get control for the specified type. DUMMY.

Specified by:
getControl in interface Controls
Parameters:
controlClass - the control class
Returns:
null

getControls

public java.lang.Object[] getControls()
Get the list of all controls possible. DUMMY.

Specified by:
getControls in interface Controls
Returns:
an EMPTY ARRAY

handleRTPPacket

protected void handleRTPPacket(byte[] data,
                               int offset,
                               int length)
Handles an incoming RTP packet

Parameters:
data - The raw packet data
offset - The packet offset after which we must start investigating
length - The total packet length

handleRTCPPacket

protected void handleRTCPPacket(byte[] data,
                                int offset,
                                int length)
Handles an incoming RTCP packet

Parameters:
data - The packet data
offset - The packet offset
length - The packet length

initSession

public int initSession(SessionAddress localAddress,
                       long defaultSSRC,
                       SourceDescription[] defaultUserDesc,
                       double rtcp_bw_fraction,
                       double rtcp_sender_bw_fraction)
Initializes and starts the session. Wrapper for the "initialize" methods, needed by JMF.

Specified by:
initSession in interface SessionManager
Parameters:
localAddress - the local address
defaultSSRC - the default SSRC. UNUSED.
defaultUserDesc - the default SDES
rtcp_bw_fraction - the bandwidth fraction allocated for RTCP traffic
rtcp_sender_bw_fraction - the RTCP bandwidth fraction allocated for senders
Returns:
0

initSession

public int initSession(SessionAddress localAddress,
                       SourceDescription[] defaultUserDesc,
                       double rtcp_bw_fraction,
                       double rtcp_sender_bw_fraction)
Initializes and starts the session. Wrapper for the "initialize" methods, needed by JMF.

Specified by:
initSession in interface SessionManager
Parameters:
localAddress - the local address
defaultUserDesc - the default SDES
rtcp_bw_fraction - the bandwidth fraction allocated for RTCP traffic
rtcp_sender_bw_fraction - the RTCP bandwidth fraction allocated for senders
Returns:
0

startSession

public int startSession(SessionAddress destAddress,
                        int mcastScope,
                        EncryptionInfo encryptionInfo)
                 throws java.io.IOException
Starts a session. Wrapper for addTarget, needed by JMF.

Specified by:
startSession in interface SessionManager
Parameters:
destAddress - destination address to add as target
mcastScope - multicast scope. UNUSED.
encryptionInfo - encryption information. UNUSED.
Returns:
0
Throws:
java.io.IOException - I/O Exception

startSession

public int startSession(SessionAddress localReceiverAddress,
                        SessionAddress localSenderAddress,
                        SessionAddress remoteReceiverAddress,
                        EncryptionInfo encryptionInfo)
                 throws java.io.IOException
Starts a session. Wrapper for addTarget, needed by JMF.

Specified by:
startSession in interface SessionManager
Parameters:
localReceiverAddress - local receiver address. UNUSED.
localSenderAddress - local sender address. UNUSED.
remoteReceiverAddress - remote receiver address to add as target
encryptionInfo - encryption information. UNUSED
Returns:
0
Throws:
java.io.IOException - I/O Exception

getDefaultSSRC

public long getDefaultSSRC()
Returns the default SSRC in this RTP session.

Specified by:
getDefaultSSRC in interface SessionManager
Returns:
the current default SSRC for this RTP session

getStream

public RTPStream getStream(long filterssrc)
Returns the RTPStream corresponding to this SSRC. DUMMY. Needed by JMF.

Specified by:
getStream in interface SessionManager
Parameters:
filterssrc - SSRC. UNUSED.
Returns:
null

getMulticastScope

public int getMulticastScope()
Returns the multicast scope.

Specified by:
getMulticastScope in interface SessionManager
Returns:
127

setMulticastScope

public void setMulticastScope(int multicastScope)
Sets the multicast scope. DUMMY. Needed by JMF.

Specified by:
setMulticastScope in interface SessionManager
Parameters:
multicastScope - multicast scope. UNUSED.

closeSession

public void closeSession(java.lang.String reason)
Closes this RTP Session.

Specified by:
closeSession in interface SessionManager
Parameters:
reason - Reason why this session is closed (used in the RTCP BYE packet following this call)

generateCNAME

public java.lang.String generateCNAME()
Generate a CNAME. In our case, it just returns the CNAME generated for the local participant.

Specified by:
generateCNAME in interface SessionManager
Returns:
the CNAME generated (ie, the local participant's one)

generateSSRC

public long generateSSRC()
Generates a Synchronization SouRCe (SSRC) number.

Specified by:
generateSSRC in interface SessionManager
Returns:
the ssrc generated

getSessionAddress

public SessionAddress getSessionAddress()
Returns the session address. DUMMY. Needed by JMF.

Specified by:
getSessionAddress in interface SessionManager
Returns:
null

getRemoteSessionAddress

public SessionAddress getRemoteSessionAddress()
Returns the remote session address. DUMMY. Needed by JMF.

Returns:
null

getLocalSessionAddress

public SessionAddress getLocalSessionAddress()
Returns the local session address.

Specified by:
getLocalSessionAddress in interface SessionManager
Returns:
the local session address

createSendStream

public SendStream createSendStream(int ssrc,
                                   DataSource ds,
                                   int streamindex)
                            throws UnsupportedFormatException,
                                   java.io.IOException
Creates a send stream used to carry data from a source to some receivers over the network. Wrapper for createSendStream, needed by JMF.

Specified by:
createSendStream in interface SessionManager
Parameters:
ssrc - the stream's SSRC. UNUSED.
ds - the datasource producing the data to send
streamindex - the index of the stream in the datasource's streams table
Returns:
the created SendStream
Throws:
UnsupportedFormatException - thrown if the datasource's stream only outputs formats which aren't supported
java.io.IOException - I/O Exception thrown in case of problem with streams

startSession

public int startSession(int mcastScope,
                        EncryptionInfo encryptionInfo)
Starts a session. DUMMY. Needed by JMF.

Specified by:
startSession in interface SessionManager
Parameters:
mcastScope - multicast scope. UNUSED.
encryptionInfo - encryption information. UNUSED.
Returns:
-1

addPeer

public void addPeer(SessionAddress peerAddress)
             throws java.io.IOException
Add a peer to send RTP data to. Wrapper for addTarger, needed by JMF.

Specified by:
addPeer in interface SessionManager
Parameters:
peerAddress - the remote address used as target
Throws:
java.io.IOException - I/O Exception

removePeer

public void removePeer(SessionAddress peerAddress)
Removes a receiver peer from the session. Wrapper for removeTarget, needed by JMF.

Specified by:
removePeer in interface SessionManager
Parameters:
peerAddress - the peer's address which is used as target

removeAllPeers

public void removeAllPeers()
Removes all the peers from this RTP session. Wrapper for removeTargets, needed by JMF.

Specified by:
removeAllPeers in interface SessionManager

getPeers

public java.util.Vector getPeers()
Returns all the receiver & senders peers we're sending RTP data to. Wrapper for getAllParticipants, needed by JMF.

Specified by:
getPeers in interface SessionManager
Returns:
the list of all the peers/participants taking part in this RTP session

start

public void start()
Starts the sending of RTCP packets


sendRTCPPacket

public void sendRTCPPacket()
Sends an RTCP packet, and schedules the next one


RTPPacketSent

public void RTPPacketSent(long time,
                          int size)
Sort of callback method called by RTPSendStreams to inform the RTPSessionManager they're linked to that an RTP packet has been sent by the local participant. This is used to maintain some local variables and statistics used in several algorithms (reaper timer and RTCP delay calculation for example).

Parameters:
time - time when the packet was sent
size - size of the packet sent

getAverageRTCPSize

public int getAverageRTCPSize()
Returns the average RTP packet size computed until now.

Returns:
the average RTP packet size