Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class CallPeerMediaHandlerJabberImpl

java.lang.Object
  extended by net.java.sip.communicator.util.event.PropertyChangeNotifier
      extended by net.java.sip.communicator.service.protocol.media.CallPeerMediaHandler<CallPeerJabberImpl>
          extended by net.java.sip.communicator.impl.protocol.jabber.CallPeerMediaHandlerJabberImpl

public class CallPeerMediaHandlerJabberImpl
extends CallPeerMediaHandler<CallPeerJabberImpl>

An XMPP specific extension of the generic media handler.

Author:
Emil Ivov, Lyubomir Marinov

Field Summary
 
Fields inherited from class net.java.sip.communicator.service.protocol.media.CallPeerMediaHandler
AUDIO_LOCAL_SSRC, AUDIO_REMOTE_SSRC, SSRC_UNKNOWN, VIDEO_LOCAL_SSRC, VIDEO_REMOTE_SSRC
 
Constructor Summary
CallPeerMediaHandlerJabberImpl(CallPeerJabberImpl peer)
          Creates a new handler that will be managing media streams for peer.
 
Method Summary
 void close()
          Closes the CallPeerMediaHandler.
 ContentPacketExtension createContentForMedia(MediaType mediaType)
          Creates a ContentPacketExtension for a particular stream.
 List<ContentPacketExtension> createContentList()
          Creates a List containing the ContentPacketExtensions of the streams that this handler is prepared to initiate depending on available MediaDevices and local on-hold and video transmission preferences.
 List<ContentPacketExtension> createContentList(MediaType mediaType)
          Creates a List containing the ContentPacketExtensions of the streams of a specific MediaType that this handler is prepared to initiate depending on available MediaDevices and local on-hold and video transmission preferences.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Overrides to give access to the transport manager to send events about ICE state changes.
 Iterable<ContentPacketExtension> generateSessionAccept()
          Wraps up any ongoing candidate harvests and returns our response to the last offer we've received, so that the peer could use it to send a session-accept.
 ContentPacketExtension getLocalContent(String contentType)
          Get the local content of a specific content type (like audio or video).
 QualityControl getQualityControl()
          Returns the quality control for video calls if any.
 ContentPacketExtension getRemoteContent(String contentType)
          Get the remote content of a specific content type (like audio or video).
protected  TransportManagerJabberImpl getTransportManager()
          Gets the TransportManager implementation handling our address management.
protected  MediaStream initStream(String streamName, StreamConnector connector, MediaDevice device, MediaFormat format, MediaStreamTarget target, MediaDirection direction, List<RTPExtension> rtpExtensions, boolean masterStream)
          Creates if necessary, and configures the stream that this MediaHandler is using for the MediaType matching the one of the MediaDevice.
 void processAnswer(List<ContentPacketExtension> answer)
          Handles the specified answer by creating and initializing the corresponding MediaStreams.
 void processOffer(List<ContentPacketExtension> offer)
          Parses and handles the specified offer and returns a content extension representing the current state of this media handler.
 void processTransportInfo(Iterable<ContentPacketExtension> contents)
          Processes the transport-related information provided by the remote peer in a specific set of ContentPacketExtensions.
 void reinitAllContents()
          Reinitialize all media contents.
 void reinitContent(String name, ContentPacketExtension content, boolean modify)
          Reinitialize a media content such as video.
 void removeContent(String name)
          Removes a media content with a specific name from the session represented by this CallPeerMediaHandlerJabberImpl and closes its associated media stream.
 void setLocalInputEvtAware(boolean enable)
          Enable or disable inputevt support (remote-control).
 void setRemotelyOnHold(boolean onHold)
          Acts upon a notification received from the remote party indicating that they've put us on/off hold.
 void setSupportQualityControls(boolean value)
          Sometimes as initing a call with custom preset can set and we force that quality controls is supported.
 void start()
          Waits for the associated TransportManagerJabberImpl to conclude any started connectivity establishment and then starts this CallPeerMediaHandler.
protected  void throwOperationFailedException(String message, int errorCode, Throwable cause)
          Lets the underlying implementation take note of this error and only then throws it to the using bundles.
 
Methods inherited from class net.java.sip.communicator.service.protocol.media.CallPeerMediaHandler
addAdvertisedEncryptionMethod, addVideoListener, closeStream, createLocalVisualComponent, disposeLocalVisualComponent, findMediaFormat, fireVideoEvent, fireVideoEvent, getAdvertisedEncryptionMethods, getAudioRemoteSSRC, getDefaultDevice, getDirectionUserPreference, getDynamicPayloadTypes, getEncryptionMethod, getExtensionsForType, getICECandidateExtendedType, getICEState, getMediaHandler, getPeer, getRtpExtensionsRegistry, getSrtpControls, getStream, getVisualComponent, getVisualComponents, initStream, intersectFormats, intersectRTPExtensions, isLocalAudioTransmissionEnabled, isLocallyOnHold, isLocalVideoTransmissionEnabled, isMute, isRemotelyOnHold, isSecure, processKeyFrameRequest, removeVideoListener, requestKeyFrame, sendHolePunchPacket, setCsrcAudioLevelListener, setLocalAudioTransmissionEnabled, setLocallyOnHold, setLocalUserAudioLevelListener, setLocalVideoTransmissionEnabled, setMediaHandler, setMute, setStreamAudioLevelListener, startSrtpMultistream
 
Methods inherited from class net.java.sip.communicator.util.event.PropertyChangeNotifier
addPropertyChangeListener, getPropertyChangeSource, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CallPeerMediaHandlerJabberImpl

public CallPeerMediaHandlerJabberImpl(CallPeerJabberImpl peer)
Creates a new handler that will be managing media streams for peer.

Parameters:
peer - that CallPeerJabberImpl instance that we will be managing media for.
Method Detail

throwOperationFailedException

protected void throwOperationFailedException(String message,
                                             int errorCode,
                                             Throwable cause)
                                      throws OperationFailedException
Lets the underlying implementation take note of this error and only then throws it to the using bundles.

Specified by:
throwOperationFailedException in class CallPeerMediaHandler<CallPeerJabberImpl>
Parameters:
message - the message to be logged and then wrapped in a new OperationFailedException
errorCode - the error code to be assigned to the new OperationFailedException
cause - the Throwable that has caused the necessity to log an error and have a new OperationFailedException thrown
Throws:
OperationFailedException - the exception that we wanted this method to throw.

setLocalInputEvtAware

public void setLocalInputEvtAware(boolean enable)
Enable or disable inputevt support (remote-control).

Parameters:
enable - new state of inputevt support

getRemoteContent

public ContentPacketExtension getRemoteContent(String contentType)
Get the remote content of a specific content type (like audio or video).

Parameters:
contentType - content type name
Returns:
remote ContentPacketExtension or null if not found

getLocalContent

public ContentPacketExtension getLocalContent(String contentType)
Get the local content of a specific content type (like audio or video).

Parameters:
contentType - content type name
Returns:
remote ContentPacketExtension or null if not found

initStream

protected MediaStream initStream(String streamName,
                                 StreamConnector connector,
                                 MediaDevice device,
                                 MediaFormat format,
                                 MediaStreamTarget target,
                                 MediaDirection direction,
                                 List<RTPExtension> rtpExtensions,
                                 boolean masterStream)
                          throws OperationFailedException
Creates if necessary, and configures the stream that this MediaHandler is using for the MediaType matching the one of the MediaDevice. This method extends the one already available by adding a stream name, corresponding to a stream's content name.

Parameters:
streamName - the name of the stream as indicated in the XMPP content element.
connector - the MediaConnector that we'd like to bind the newly created stream to.
device - the MediaDevice that we'd like to attach the newly created MediaStream to.
format - the MediaFormat that we'd like the new MediaStream to be set to transmit in.
target - the MediaStreamTarget containing the RTP and RTCP address:port couples that the new stream would be sending packets to.
direction - the MediaDirection that we'd like the new stream to use (i.e. sendonly, sendrecv, recvonly, or inactive).
rtpExtensions - the list of RTPExtensions that should be enabled for this stream.
masterStream - whether the stream to be used as master if secured
Returns:
the newly created MediaStream.
Throws:
OperationFailedException - if creating the stream fails for any reason (like for example accessing the device or setting the format).

processOffer

public void processOffer(List<ContentPacketExtension> offer)
                  throws OperationFailedException,
                         IllegalArgumentException
Parses and handles the specified offer and returns a content extension representing the current state of this media handler. This method MUST only be called when offer is the first session description that this MediaHandler is seeing.

Parameters:
offer - the offer that we'd like to parse, handle and get an answer for.
Throws:
OperationFailedException - if we have a problem satisfying the description received in offer (e.g. failed to open a device or initialize a stream ...).
IllegalArgumentException - if there's a problem with offer's format or semantics.

generateSessionAccept

public Iterable<ContentPacketExtension> generateSessionAccept()
                                                       throws OperationFailedException
Wraps up any ongoing candidate harvests and returns our response to the last offer we've received, so that the peer could use it to send a session-accept.

Returns:
the last generated list of ContentPacketExtensions that the call peer could use to send a session-accept.
Throws:
OperationFailedException - if we fail to configure the media stream

createContentForMedia

public ContentPacketExtension createContentForMedia(MediaType mediaType)
                                             throws OperationFailedException
Creates a ContentPacketExtension for a particular stream.

Parameters:
mediaType - MediaType of the content
Returns:
a ContentPacketExtension
Throws:
OperationFailedException - if we fail to create the descriptions for reasons like - problems with device interaction, allocating ports, etc.

createContentList

public List<ContentPacketExtension> createContentList(MediaType mediaType)
                                               throws OperationFailedException
Creates a List containing the ContentPacketExtensions of the streams of a specific MediaType that this handler is prepared to initiate depending on available MediaDevices and local on-hold and video transmission preferences.

Parameters:
mediaType - MediaType of the content
Returns:
a List containing the ContentPacketExtensions of streams that this handler is prepared to initiate.
Throws:
OperationFailedException - if we fail to create the descriptions for reasons like - problems with device interaction, allocating ports, etc.

createContentList

public List<ContentPacketExtension> createContentList()
                                               throws OperationFailedException
Creates a List containing the ContentPacketExtensions of the streams that this handler is prepared to initiate depending on available MediaDevices and local on-hold and video transmission preferences.

Returns:
a List containing the ContentPacketExtensions of streams that this handler is prepared to initiate.
Throws:
OperationFailedException - if we fail to create the descriptions for reasons like problems with device interaction, allocating ports, etc.

reinitAllContents

public void reinitAllContents()
                       throws OperationFailedException,
                              IllegalArgumentException
Reinitialize all media contents.

Throws:
OperationFailedException - if we fail to handle content for reasons like failing to initialize media devices or streams.
IllegalArgumentException - if there's a problem with the syntax or the semantics of content. Method is synchronized in order to avoid closing mediaHandler when we are currently in process of initializing, configuring and starting streams and anybody interested in this operation can synchronize to the mediaHandler instance to wait processing to stop (method setState in CallPeer).

reinitContent

public void reinitContent(String name,
                          ContentPacketExtension content,
                          boolean modify)
                   throws OperationFailedException,
                          IllegalArgumentException
Reinitialize a media content such as video.

Parameters:
name - name of the Jingle content
content - media content
modify - if it correspond to a content-modify for resolution change
Throws:
OperationFailedException - if we fail to handle content for reasons like failing to initialize media devices or streams.
IllegalArgumentException - if there's a problem with the syntax or the semantics of content. Method is synchronized in order to avoid closing mediaHandler when we are currently in process of initializing, configuring and starting streams and anybody interested in this operation can synchronize to the mediaHandler instance to wait processing to stop (method setState in CallPeer).

removeContent

public void removeContent(String name)
Removes a media content with a specific name from the session represented by this CallPeerMediaHandlerJabberImpl and closes its associated media stream.

Parameters:
name - the name of the media content to be removed from this session

processAnswer

public void processAnswer(List<ContentPacketExtension> answer)
                   throws OperationFailedException,
                          IllegalArgumentException
Handles the specified answer by creating and initializing the corresponding MediaStreams.

Parameters:
answer - the Jingle answer
Throws:
OperationFailedException - if we fail to handle answer for reasons like failing to initialize media devices or streams.
IllegalArgumentException - if there's a problem with the syntax or the semantics of answer. Method is synchronized in order to avoid closing mediaHandler when we are currently in process of initializing, configuring and starting streams and anybody interested in this operation can synchronize to the mediaHandler instance to wait processing to stop (method setState in CallPeer).

getTransportManager

protected TransportManagerJabberImpl getTransportManager()
Gets the TransportManager implementation handling our address management.

Specified by:
getTransportManager in class CallPeerMediaHandler<CallPeerJabberImpl>
Returns:
the TransportManager implementation handling our address management
See Also:
CallPeerMediaHandler.getTransportManager()

setRemotelyOnHold

public void setRemotelyOnHold(boolean onHold)
Acts upon a notification received from the remote party indicating that they've put us on/off hold.

Parameters:
onHold - true if the remote party has put us on hold and false if they've just put us off hold.

processTransportInfo

public void processTransportInfo(Iterable<ContentPacketExtension> contents)
                          throws OperationFailedException
Processes the transport-related information provided by the remote peer in a specific set of ContentPacketExtensions.

Parameters:
contents - the ContentPacketExtenions provided by the remote peer and containing the transport-related information to be processed
Throws:
OperationFailedException - if anything goes wrong while processing the transport-related information provided by the remote peer in the specified set of ContentPacketExtensions

start

public void start()
           throws IllegalStateException
Waits for the associated TransportManagerJabberImpl to conclude any started connectivity establishment and then starts this CallPeerMediaHandler.

Overrides:
start in class CallPeerMediaHandler<CallPeerJabberImpl>
Throws:
IllegalStateException - if no offer or answer has been provided or generated earlier

getQualityControl

public QualityControl getQualityControl()
Returns the quality control for video calls if any.

Returns:
the implemented quality control.

setSupportQualityControls

public void setSupportQualityControls(boolean value)
Sometimes as initing a call with custom preset can set and we force that quality controls is supported.

Parameters:
value - whether quality controls is supported..

close

public void close()
Closes the CallPeerMediaHandler.

Overrides:
close in class CallPeerMediaHandler<CallPeerJabberImpl>

firePropertyChange

protected void firePropertyChange(String property,
                                  Object oldValue,
                                  Object newValue)
Overrides to give access to the transport manager to send events about ICE state changes.

Overrides:
firePropertyChange in class PropertyChangeNotifier
Parameters:
property - the name of the property of this PropertyChangeNotifier which had its value changed
oldValue - the value of the property with the specified name before the change
newValue - the value of the property with the specified name after

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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