Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia
Class VideoMediaStreamImpl

java.lang.Object
  extended by net.java.sip.communicator.service.neomedia.AbstractMediaStream
      extended by net.java.sip.communicator.impl.neomedia.MediaStreamImpl
          extended by net.java.sip.communicator.impl.neomedia.VideoMediaStreamImpl
All Implemented Interfaces:
EventListener, javax.media.rtp.ReceiveStreamListener, javax.media.rtp.RemoteListener, javax.media.rtp.SendStreamListener, javax.media.rtp.SessionListener, MediaStream, VideoMediaStream

public class VideoMediaStreamImpl
extends MediaStreamImpl
implements VideoMediaStream

Extends MediaStreamImpl in order to provide an implementation of VideoMediaStream.

Author:
Lyubomir Marinov, Sebastien Vincent

Field Summary
 
Fields inherited from class net.java.sip.communicator.impl.neomedia.MediaStreamImpl
PROPERTY_NAME_RECEIVE_BUFFER_LENGTH
 
Fields inherited from interface net.java.sip.communicator.service.neomedia.MediaStream
PNAME_LOCAL_SSRC, PNAME_REMOTE_SSRC
 
Constructor Summary
VideoMediaStreamImpl(StreamConnector connector, MediaDevice device, SrtpControl srtpControl)
          Initializes a new VideoMediaStreamImpl instance which will use the specified MediaDevice for both capture and playback of video exchanged via the specified StreamConnector.
 
Method Summary
 void addVideoListener(VideoListener listener)
          Adds a specific VideoListener to this VideoMediaStream in order to receive notifications when visual/video Components are being added and removed.
protected  void configureDataOutputStream(RTPConnectorOutputStream dataOutputStream)
          Performs any optional configuration on a specific RTPConnectorOuputStream of an RTPManager to be used by this MediaStreamImpl.
protected  void configureRTPManagerBufferControl(StreamRTPManager rtpManager, javax.media.control.BufferControl bufferControl)
          Performs any optional configuration on the BufferControl of the specified RTPManager which is to be used as the RTPManager of this MediaStreamImpl.
 Component createLocalVisualComponent()
          Creates the visual Component depicting the video being streamed from the local peer to the remote peer.
protected  void deviceSessionChanged(MediaDeviceSession oldValue, MediaDeviceSession newValue)
          Notifies this MediaStream that the MediaDevice (and respectively the MediaDeviceSession with it) which this instance uses for capture and playback of media has been changed.
 void disposeLocalVisualComponent(Component component)
          Disposes of the visual Component of the local peer.
protected  boolean fireVideoEvent(int type, Component visualComponent, int origin, boolean wait)
          Notifies the VideoListeners registered with this VideoMediaStream about a specific type of change in the availability of a specific visual Component depicting video.
protected  void fireVideoEvent(VideoEvent event, boolean wait)
          Notifies the VideoListeners registered with this instance about a specific VideoEvent.
 KeyFrameControl getKeyFrameControl()
          Implements VideoMediaStream.getKeyFrameControl().
protected  int getPriority()
          The priority of the video is 5, which is meant to be higher than other threads and lower than the audio one.
 QualityControl getQualityControl()
          Gets the QualityControl of this VideoMediaStream.
 Component getVisualComponent()
          Deprecated. 
 List<Component> getVisualComponents()
          Gets a list of the visual Components where video from the remote peer is being rendered.
protected  void handleAttributes(MediaFormat format, Map<String,String> attrs)
          Handles attributes contained in MediaFormat.
 void movePartialDesktopStreaming(int x, int y)
          Move origin of a partial desktop streaming MediaDevice.
static Dimension[] parseSendRecvResolution(String imgattr)
          Extracts and returns maximum resolution can receive from the image attribute.
 void removeVideoListener(VideoListener listener)
          Removes a specific VideoListener from this VideoMediaStream in order to have to no longer receive notifications when visual/video Components are being added and removed.
protected  void rtpConnectorChanged(AbstractRTPConnector oldValue, AbstractRTPConnector newValue)
          Notifies this MediaStream implementation that its RTPConnector instance has changed from a specific old value to a specific new value.
static Dimension selectVideoSize(javax.media.protocol.DataSource videoDS, int preferredWidth, int preferredHeight)
          Selects the VideoFormat from the list of supported formats of a specific video DataSource which has a size as close as possible to a specific size and sets it as the format of the specified video DataSource.
protected  void setLocalSourceID(long localSourceID)
          Set local SSRC.
protected  void setRemoteSourceID(long ssrc)
          Set remote SSRC.
 void updateQualityControl(Map<String,String> advancedParams)
          Updates the QualityControl of this VideoMediaStream.
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.MediaStreamImpl
addDynamicRTPPayloadType, addRTPExtension, close, configureDataInputStream, createDtmfTransformEngine, getActiveRTPExtensionID, getActiveRTPExtensions, getCsrcEngine, getDevice, getDeviceSession, getDirection, getDynamicRTPPayloadType, getDynamicRTPPayloadTypes, getFormat, getLocalContributingSourceIDs, getLocalControlAddress, getLocalDataAddress, getLocalSourceID, getMediaStreamStats, getRemoteContributingSourceIDs, getRemoteControlAddress, getRemoteDataAddress, getRemoteSourceID, getRTPConnector, getRTPManager, getSrtpControl, getTarget, getTransportProtocol, isMute, isStarted, registerCustomCodecFormats, setConnector, setDevice, setDirection, setFormat, setMute, setRTPTranslator, setTarget, start, stop, toString, update, update, update, update
 
Methods inherited from class net.java.sip.communicator.service.neomedia.AbstractMediaStream
addPropertyChangeListener, firePropertyChange, getName, matches, removePropertyChangeListener, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.java.sip.communicator.service.neomedia.MediaStream
addDynamicRTPPayloadType, addPropertyChangeListener, addRTPExtension, close, getActiveRTPExtensions, getDevice, getDirection, getDynamicRTPPayloadTypes, getFormat, getLocalSourceID, getMediaStreamStats, getName, getRemoteControlAddress, getRemoteDataAddress, getRemoteSourceID, getSrtpControl, getTarget, getTransportProtocol, isMute, isStarted, removePropertyChangeListener, setConnector, setDevice, setDirection, setFormat, setMute, setName, setRTPTranslator, setTarget, start, stop
 

Constructor Detail

VideoMediaStreamImpl

public VideoMediaStreamImpl(StreamConnector connector,
                            MediaDevice device,
                            SrtpControl srtpControl)
Initializes a new VideoMediaStreamImpl instance which will use the specified MediaDevice for both capture and playback of video exchanged via the specified StreamConnector.

Parameters:
connector - the StreamConnector the new instance is to use for sending and receiving video
device - the MediaDevice the new instance is to use for both capture and playback of video exchanged via the specified StreamConnector
srtpControl - a control which is already created, used to control the srtp operations.
Method Detail

selectVideoSize

public static Dimension selectVideoSize(javax.media.protocol.DataSource videoDS,
                                        int preferredWidth,
                                        int preferredHeight)
Selects the VideoFormat from the list of supported formats of a specific video DataSource which has a size as close as possible to a specific size and sets it as the format of the specified video DataSource.

Parameters:
videoDS - the video DataSource which is to have its supported formats examined and its format changed to the VideoFormat which is as close as possible to the specified preferredWidth and preferredHeight
preferredWidth - the width of the VideoFormat to be selected
preferredHeight - the height of the VideoFormat to be selected
Returns:
the size of the VideoFormat from the list of supported formats of videoDS which is as close as possible to preferredWidth and preferredHeight and which has been set as the format of videoDS

addVideoListener

public void addVideoListener(VideoListener listener)
Adds a specific VideoListener to this VideoMediaStream in order to receive notifications when visual/video Components are being added and removed.

Adding a listener which has already been added does nothing i.e. it is not added more than once and thus does not receive one and the same VideoEvent multiple times.

Specified by:
addVideoListener in interface VideoMediaStream
Parameters:
listener - the VideoListener to be notified when visual/video Components are being added or removed in this VideoMediaStream

configureDataOutputStream

protected void configureDataOutputStream(RTPConnectorOutputStream dataOutputStream)
Performs any optional configuration on a specific RTPConnectorOuputStream of an RTPManager to be used by this MediaStreamImpl.

Overrides:
configureDataOutputStream in class MediaStreamImpl
Parameters:
dataOutputStream - the RTPConnectorOutputStream to be used by an RTPManager of this MediaStreamImpl and to be configured

configureRTPManagerBufferControl

protected void configureRTPManagerBufferControl(StreamRTPManager rtpManager,
                                                javax.media.control.BufferControl bufferControl)
Performs any optional configuration on the BufferControl of the specified RTPManager which is to be used as the RTPManager of this MediaStreamImpl.

Overrides:
configureRTPManagerBufferControl in class MediaStreamImpl
Parameters:
rtpManager - the RTPManager which is to be used by this MediaStreamImpl
bufferControl - the BufferControl of rtpManager on which any optional configuration is to be performed

createLocalVisualComponent

public Component createLocalVisualComponent()
Creates the visual Component depicting the video being streamed from the local peer to the remote peer.

Specified by:
createLocalVisualComponent in interface VideoMediaStream
Returns:
the visual Component depicting the video being streamed from the local peer to the remote peer if it was immediately created or null if it was not immediately created and it is to be delivered to the currently registered VideoListeners in a VideoEvent with type VideoEvent.VIDEO_ADDED and origin VideoEvent.LOCAL

deviceSessionChanged

protected void deviceSessionChanged(MediaDeviceSession oldValue,
                                    MediaDeviceSession newValue)
Notifies this MediaStream that the MediaDevice (and respectively the MediaDeviceSession with it) which this instance uses for capture and playback of media has been changed. Makes sure that the VideoListeners of this instance get VideoEvents for the new/current VideoMediaDeviceSession and not for the old one.

Overrides:
deviceSessionChanged in class MediaStreamImpl
Parameters:
oldValue - the MediaDeviceSession with the MediaDevice this instance used work with
newValue - the MediaDeviceSession with the MediaDevice this instance is to work with
See Also:
MediaStreamImpl.deviceSessionChanged(MediaDeviceSession, MediaDeviceSession)

disposeLocalVisualComponent

public void disposeLocalVisualComponent(Component component)
Disposes of the visual Component of the local peer.

Specified by:
disposeLocalVisualComponent in interface VideoMediaStream
Parameters:
component - the visual Component of the local peer to dispose of

fireVideoEvent

protected boolean fireVideoEvent(int type,
                                 Component visualComponent,
                                 int origin,
                                 boolean wait)
Notifies the VideoListeners registered with this VideoMediaStream about a specific type of change in the availability of a specific visual Component depicting video.

Parameters:
type - the type of change as defined by VideoEvent in the availability of the specified visual Component depicting video
visualComponent - the visual Component depicting video which has been added or removed in this VideoMediaStream
origin - VideoEvent.LOCAL if the origin of the video is local (e.g. it is being locally captured); VideoEvent.REMOTE if the origin of the video is remote (e.g. a remote peer is streaming it)
wait - true if the call is to wait till the specified VideoEvent has been delivered to the VideoListeners; otherwise, false
Returns:
true if this event and, more specifically, the visual Component it describes have been consumed and should be considered owned, referenced (which is important because Components belong to a single Container at a time); otherwise, false

fireVideoEvent

protected void fireVideoEvent(VideoEvent event,
                              boolean wait)
Notifies the VideoListeners registered with this instance about a specific VideoEvent.

Parameters:
event - the VideoEvent to be fired to the VideoListeners registered with this instance
wait - true if the call is to wait till the specified VideoEvent has been delivered to the VideoListeners; otherwise, false

getVisualComponent

@Deprecated
public Component getVisualComponent()
Deprecated. 

Gets the visual Component where video from the remote peer is being rendered or null if no video is currently being rendered.

Specified by:
getVisualComponent in interface VideoMediaStream
Returns:
the visual Component where video from the remote peer is being rendered or null if no video is currently being rendered
See Also:
VideoMediaStream.getVisualComponent()

getVisualComponents

public List<Component> getVisualComponents()
Gets a list of the visual Components where video from the remote peer is being rendered.

Specified by:
getVisualComponents in interface VideoMediaStream
Returns:
a list of the visual Components where video from the remote peer is being rendered
See Also:
VideoMediaStream.getVisualComponents()

removeVideoListener

public void removeVideoListener(VideoListener listener)
Removes a specific VideoListener from this VideoMediaStream in order to have to no longer receive notifications when visual/video Components are being added and removed.

Specified by:
removeVideoListener in interface VideoMediaStream
Parameters:
listener - the VideoListener to no longer be notified when visual/video Components are being added or removed in this VideoMediaStream

rtpConnectorChanged

protected void rtpConnectorChanged(AbstractRTPConnector oldValue,
                                   AbstractRTPConnector newValue)
Notifies this MediaStream implementation that its RTPConnector instance has changed from a specific old value to a specific new value. Allows extenders to override and perform additional processing after this MediaStream has changed its RTPConnector instance.

Overrides:
rtpConnectorChanged in class MediaStreamImpl
Parameters:
oldValue - the RTPConnector of this MediaStream implementation before it got changed to newValue
newValue - the current RTPConnector of this MediaStream which replaced oldValue
See Also:
MediaStreamImpl.rtpConnectorChanged(AbstractRTPConnector, AbstractRTPConnector)

handleAttributes

protected void handleAttributes(MediaFormat format,
                                Map<String,String> attrs)
Handles attributes contained in MediaFormat.

Overrides:
handleAttributes in class MediaStreamImpl
Parameters:
format - the MediaFormat to handle the attributes of
attrs - the attributes Map to handle

parseSendRecvResolution

public static Dimension[] parseSendRecvResolution(String imgattr)
Extracts and returns maximum resolution can receive from the image attribute.

Parameters:
imgattr - send/recv resolution string
Returns:
maximum resolution array (first element is send, second one is recv). Elements could be null if image attribute is not present or if resolution is a wildcard.

setLocalSourceID

protected void setLocalSourceID(long localSourceID)
Set local SSRC.

Overrides:
setLocalSourceID in class MediaStreamImpl
Parameters:
localSourceID - source ID

setRemoteSourceID

protected void setRemoteSourceID(long ssrc)
Set remote SSRC.

Overrides:
setRemoteSourceID in class MediaStreamImpl
Parameters:
ssrc - remote SSRC

getPriority

protected int getPriority()
The priority of the video is 5, which is meant to be higher than other threads and lower than the audio one.

Overrides:
getPriority in class MediaStreamImpl
Returns:
video priority.

getKeyFrameControl

public KeyFrameControl getKeyFrameControl()
Implements VideoMediaStream.getKeyFrameControl(). Gets the KeyFrameControl of this VideoMediaStream.

Specified by:
getKeyFrameControl in interface VideoMediaStream
Returns:
the KeyFrameControl of this VideoMediaStream
See Also:
VideoMediaStream.getKeyFrameControl()

getQualityControl

public QualityControl getQualityControl()
Gets the QualityControl of this VideoMediaStream.

Specified by:
getQualityControl in interface VideoMediaStream
Returns:
the QualityControl of this VideoMediaStream

updateQualityControl

public void updateQualityControl(Map<String,String> advancedParams)
Updates the QualityControl of this VideoMediaStream.

Specified by:
updateQualityControl in interface VideoMediaStream
Parameters:
advancedParams - parameters of advanced attributes that may affect quality control

movePartialDesktopStreaming

public void movePartialDesktopStreaming(int x,
                                        int y)
Move origin of a partial desktop streaming MediaDevice.

Specified by:
movePartialDesktopStreaming in interface VideoMediaStream
Parameters:
x - new x coordinate origin
y - new y coordinate origin

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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