Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.service.protocol.media
Class TransportManager<U extends MediaAwareCallPeer<?,?,?>>

java.lang.Object
  extended by net.java.sip.communicator.service.protocol.media.TransportManager<U>
Type Parameters:
U - the peer extension class like for example CallPeerSipImpl or CallPeerJabberImpl
Direct Known Subclasses:
TransportManagerGTalkImpl, TransportManagerJabberImpl, TransportManagerSipImpl

public abstract class TransportManager<U extends MediaAwareCallPeer<?,?,?>>
extends Object

TransportManagers are responsible for allocating ports, gathering local candidates and managing ICE whenever we are using it.

Author:
Emil Ivov, Lyubomir Marinov, Sebastien Vincent

Constructor Summary
protected TransportManager(U callPeer)
          Creates a new instance of this transport manager, binding it to the specified peer.
 
Method Summary
 void closeStreamConnector(MediaType mediaType)
          Closes the existing StreamConnector, if any, associated with a specific MediaType and removes its reference from this TransportManager.
protected  void closeStreamConnector(MediaType mediaType, StreamConnector streamConnector)
          Closes a specific StreamConnector associated with a specific MediaType.
protected  StreamConnector createStreamConnector(MediaType mediaType)
          Creates a media StreamConnector.
 U getCallPeer()
          Returns the MediaAwareCallPeer that this transport manager is serving.
abstract  String getICECandidateExtendedType()
          Returns the extended type of the candidate selected if this transport manager is using ICE.
static String getICECandidateExtendedType(org.ice4j.ice.Agent iceAgent)
          Returns the ICE candidate extended type selected by the given agent.
abstract  String getICEState()
          Returns the current state of ICE processing.
protected abstract  InetAddress getIntendedDestination(U peer)
          Returns the InetAddress that is most likely to be used as a next hop when contacting the specified destination.
 InetAddress getLastUsedLocalHost()
          Returns the InetAddress that we are using in one of our StreamConnectors or, in case we don't have any connectors yet the address returned by the our network address manager as the best local address to use when contacting the CallPeer associated with this MediaHandler.
protected static int getNextMediaPortToTry()
          Gets the port that we should try to bind our next media stream's RTP socket to.
 StreamConnector getStreamConnector(MediaType mediaType)
          Returns the StreamConnector instance that this media handler should use for streams of the specified mediaType.
protected static void initializePortNumbers()
          (Re)Sets the minPortNumber and maxPortNumber to their defaults or to the values specified in the ConfigurationService.
 void sendHolePunchPacket(MediaStreamTarget target, MediaType type)
          Send empty UDP packet to target destination data/control ports in order to open port on NAT or RTP proxy if any.
protected static void setNextMediaPortToTry(int nextMediaPortToTry)
          Sets the port that we should try to bind our next media stream's RTP socket to
protected  void setTrafficClass(MediaStreamTarget target, MediaType type)
          Set traffic class (QoS) for the RTP socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransportManager

protected TransportManager(U callPeer)
Creates a new instance of this transport manager, binding it to the specified peer.

Parameters:
callPeer - the MediaAwareCallPeer whose traffic we will be taking care of.
Method Detail

getStreamConnector

public StreamConnector getStreamConnector(MediaType mediaType)
                                   throws OperationFailedException
Returns the StreamConnector instance that this media handler should use for streams of the specified mediaType. The method would also create a new StreamConnector if no connector has been initialized for this mediaType yet or in case one of its underlying sockets has been closed.

Parameters:
mediaType - the MediaType that we'd like to create a connector for.
Returns:
this media handler's StreamConnector for the specified mediaType.
Throws:
OperationFailedException - in case we failed to initialize our connector.

closeStreamConnector

public void closeStreamConnector(MediaType mediaType)
Closes the existing StreamConnector, if any, associated with a specific MediaType and removes its reference from this TransportManager.

Parameters:
mediaType - the MediaType associated with the StreamConnector to close

closeStreamConnector

protected void closeStreamConnector(MediaType mediaType,
                                    StreamConnector streamConnector)
Closes a specific StreamConnector associated with a specific MediaType. If this TransportManager has a reference to the specified streamConnector, it remains. Allows extenders to override and perform additional customizations to the closing of the specified streamConnector.

Parameters:
mediaType - the MediaType associated with the specified streamConnector
streamConnector - the StreamConnector to be closed
See Also:
closeStreamConnector(MediaType)

createStreamConnector

protected StreamConnector createStreamConnector(MediaType mediaType)
                                         throws OperationFailedException
Creates a media StreamConnector. The method takes into account the minimum and maximum media port boundaries.

Parameters:
mediaType - the MediaType of the stream for which a new StreamConnector is to be created
Returns:
a new StreamConnector.
Throws:
OperationFailedException - if the binding of the sockets fails.

initializePortNumbers

protected static void initializePortNumbers()
(Re)Sets the minPortNumber and maxPortNumber to their defaults or to the values specified in the ConfigurationService.


getLastUsedLocalHost

public InetAddress getLastUsedLocalHost()
Returns the InetAddress that we are using in one of our StreamConnectors or, in case we don't have any connectors yet the address returned by the our network address manager as the best local address to use when contacting the CallPeer associated with this MediaHandler. This method is primarily meant for use with the o= and c= fields of a newly created session description. The point is that we create our StreamConnectors when constructing the media descriptions so we already have a specific local address assigned to them at the time we get ready to create the c= and o= fields. It is therefore better to try and return one of these addresses before trying the net address manager again and running the slight risk of getting a different address.

Returns:
an InetAddress that we use in one of the StreamConnectors in this class.

sendHolePunchPacket

public void sendHolePunchPacket(MediaStreamTarget target,
                                MediaType type)
Send empty UDP packet to target destination data/control ports in order to open port on NAT or RTP proxy if any.

Parameters:
target - MediaStreamTarget
type - the MediaType of the connector we'd like to send the hole punching packet through.

setTrafficClass

protected void setTrafficClass(MediaStreamTarget target,
                               MediaType type)
Set traffic class (QoS) for the RTP socket.

Parameters:
target - MediaStreamTarget
type - the MediaType of the connector we'd like to set traffic class

getIntendedDestination

protected abstract InetAddress getIntendedDestination(U peer)
Returns the InetAddress that is most likely to be used as a next hop when contacting the specified destination. This is an utility method that is used whenever we have to choose one of our local addresses to put in the Via, Contact or (in the case of no registrar accounts) From headers.

Parameters:
peer - the CallPeer that we would contact.
Returns:
the InetAddress that is most likely to be to be used as a next hop when contacting the specified destination.
Throws:
IllegalArgumentException - if destination is not a valid host/ip/fqdn

getCallPeer

public U getCallPeer()
Returns the MediaAwareCallPeer that this transport manager is serving.

Returns:
the MediaAwareCallPeer that this transport manager is serving.

getNextMediaPortToTry

protected static int getNextMediaPortToTry()
Gets the port that we should try to bind our next media stream's RTP socket to.

Returns:
the port that we should try to bind our next media stream's RTP socket to

setNextMediaPortToTry

protected static void setNextMediaPortToTry(int nextMediaPortToTry)
Sets the port that we should try to bind our next media stream's RTP socket to

Parameters:
nextMediaPortToTry - the port that we should try to bind our next media stream's RTP socket to

getICECandidateExtendedType

public abstract String getICECandidateExtendedType()
Returns the extended type of the candidate selected if this transport manager is using ICE.

Returns:
The extended type of the candidate selected if this transport manager is using ICE. Otherwise, returns null.

getICEState

public abstract String getICEState()
Returns the current state of ICE processing.

Returns:
the current state of ICE processing if this transport manager is using ICE. Otherwise, returns null.

getICECandidateExtendedType

public static String getICECandidateExtendedType(org.ice4j.ice.Agent iceAgent)
Returns the ICE candidate extended type selected by the given agent.

Parameters:
iceAgent - The ICE agent managing the ICE offer/answer exchange, collecting and selecting the candidate.
Returns:
The ICE candidate extended type selected by the given agent. null if the iceAgent is null or if there is no candidate selected or available.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.