Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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

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.AudioMediaStreamImpl
All Implemented Interfaces:
EventListener, javax.media.rtp.ReceiveStreamListener, javax.media.rtp.RemoteListener, javax.media.rtp.SendStreamListener, javax.media.rtp.SessionListener, AudioMediaStream, MediaStream

public class AudioMediaStreamImpl
extends MediaStreamImpl
implements AudioMediaStream

Extends MediaStreamImpl in order to provide an implementation of AudioMediaStream.

Author:
Lyubomir Marinov, Emil Ivov

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
AudioMediaStreamImpl(StreamConnector connector, MediaDevice device, SrtpControl srtpControl)
          Initializes a new AudioMediaStreamImpl instance which will use the specified MediaDevice for both capture and playback of audio exchanged via the specified StreamConnector.
 
Method Summary
 void addDTMFListener(DTMFListener listener)
          Adds a DTMFListener to this AudioMediaStream which is to receive notifications when the remote party starts sending DTMF tones to us.
 void addRTPExtension(byte extensionID, RTPExtension rtpExtension)
          In addition to calling MediaStreamImpl.addRTPExtension(byte, RTPExtension) this method enables sending of CSRC audio levels.
 void close()
          Releases the resources allocated by this instance in the course of its execution and prepares it to be garbage collected.
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.
protected  DtmfTransformEngine createDtmfTransformEngine()
          A stub that allows audio oriented streams to create and keep a reference to a DtmfTransformEngine.
 void fireConferenceAudioLevelEvent(long[] audioLevels)
          Delivers the audioLevels map to whoever's interested.
 void fireDTMFEvent(DTMFRtpTone tone, boolean end)
          Delivers the DTMF tones.
 AudioMediaDeviceSession getDeviceSession()
          Returns the MediaDeviceSession associated with this stream after first casting it to AudioMediaDeviceSession since this is, after all, an AudioMediaStreamImpl.
 int getLastMeasuredAudioLevel(long ssrc)
          Returns the last audio level that was measured by the underlying device session for the specified ssrc (where ssrc could also correspond to our local sync source identifier).
protected  int getPriority()
          The priority of the audio is 3, which is meant to be higher than other threads and higher than the video one.
protected  void registerCustomCodecFormats(StreamRTPManager rtpManager)
          Registers CUSTOM_CODEC_FORMATS with a specific RTPManager.
 void removeDTMFListener(DTMFListener listener)
          Removes listener from the list of DTMFListeners registered with this AudioMediaStream to receive notifications about incoming DTMF tones.
 void setCsrcAudioLevelListener(CsrcAudioLevelListener listener)
          Registers listener as the CsrcAudioLevelListener that will receive notifications for changes in the levels of conference participants that the remote party could be mixing.
 void setLocalUserAudioLevelListener(SimpleAudioLevelListener listener)
          Sets listener as the SimpleAudioLevelListener registered to receive notifications from our device session for changes in the levels of the audio that this stream is sending out.
 void setStreamAudioLevelListener(SimpleAudioLevelListener listener)
          Sets listener as the SimpleAudioLevelListener registered to receive notifications from our device session for changes in the levels of the party that's at the other end of this stream.
 void startSendingDTMF(DTMFTone tone, DTMFMethod dtmfMethod)
          Starts sending the specified DTMFTone until the stopSendingDTMF() method is called (Excepts for INBAND DTMF, which stops by itself this is why where there is no need to call the stopSendingDTMF).
 void stopSendingDTMF(DTMFMethod dtmfMethod)
          Interrupts transmission of a DTMFTone started with the startSendingDTMF() method.
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.MediaStreamImpl
addDynamicRTPPayloadType, configureDataInputStream, configureDataOutputStream, deviceSessionChanged, getActiveRTPExtensionID, getActiveRTPExtensions, getCsrcEngine, getDevice, getDirection, getDynamicRTPPayloadType, getDynamicRTPPayloadTypes, getFormat, getLocalContributingSourceIDs, getLocalControlAddress, getLocalDataAddress, getLocalSourceID, getMediaStreamStats, getRemoteContributingSourceIDs, getRemoteControlAddress, getRemoteDataAddress, getRemoteSourceID, getRTPConnector, getRTPManager, getSrtpControl, getTarget, getTransportProtocol, handleAttributes, isMute, isStarted, rtpConnectorChanged, setConnector, setDevice, setDirection, setFormat, setLocalSourceID, setMute, setRemoteSourceID, 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, 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

AudioMediaStreamImpl

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

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

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

createDtmfTransformEngine

protected DtmfTransformEngine createDtmfTransformEngine()
A stub that allows audio oriented streams to create and keep a reference to a DtmfTransformEngine.

Overrides:
createDtmfTransformEngine in class MediaStreamImpl
Returns:
a DtmfTransformEngine if this is an audio oriented stream and null otherwise.

addDTMFListener

public void addDTMFListener(DTMFListener listener)
Adds a DTMFListener to this AudioMediaStream which is to receive notifications when the remote party starts sending DTMF tones to us.

Specified by:
addDTMFListener in interface AudioMediaStream
Parameters:
listener - the DTMFListener to register for notifications about the remote party starting sending of DTM tones to this AudioMediaStream
See Also:
AudioMediaStream.addDTMFListener(DTMFListener)

setStreamAudioLevelListener

public void setStreamAudioLevelListener(SimpleAudioLevelListener listener)
Sets listener as the SimpleAudioLevelListener registered to receive notifications from our device session for changes in the levels of the party that's at the other end of this stream.

Specified by:
setStreamAudioLevelListener in interface AudioMediaStream
Parameters:
listener - the SimpleAudioLevelListener that we'd like to register or null if we want to stop stream audio level measurements.

setCsrcAudioLevelListener

public void setCsrcAudioLevelListener(CsrcAudioLevelListener listener)
Registers listener as the CsrcAudioLevelListener that will receive notifications for changes in the levels of conference participants that the remote party could be mixing.

Specified by:
setCsrcAudioLevelListener in interface AudioMediaStream
Parameters:
listener - the CsrcAudioLevelListener that we'd like to register or null if we'd like to stop receiving notifications.

registerCustomCodecFormats

protected void registerCustomCodecFormats(StreamRTPManager rtpManager)
Registers CUSTOM_CODEC_FORMATS with a specific RTPManager.

Overrides:
registerCustomCodecFormats in class MediaStreamImpl
Parameters:
rtpManager - the RTPManager to register CUSTOM_CODEC_FORMATS with
See Also:
MediaStreamImpl.registerCustomCodecFormats(StreamRTPManager)

removeDTMFListener

public void removeDTMFListener(DTMFListener listener)
Removes listener from the list of DTMFListeners registered with this AudioMediaStream to receive notifications about incoming DTMF tones.

Specified by:
removeDTMFListener in interface AudioMediaStream
Parameters:
listener - the DTMFListener to no longer be notified by this AudioMediaStream about incoming DTMF tones
See Also:
AudioMediaStream.removeDTMFListener(DTMFListener)

startSendingDTMF

public void startSendingDTMF(DTMFTone tone,
                             DTMFMethod dtmfMethod)
Starts sending the specified DTMFTone until the stopSendingDTMF() method is called (Excepts for INBAND DTMF, which stops by itself this is why where there is no need to call the stopSendingDTMF). Callers should keep in mind the fact that calling this method would most likely interrupt all audio transmission until the corresponding stop method is called. Also, calling this method successively without invoking the corresponding stop method between the calls will simply replace the DTMFTone from the first call with that from the second.

Specified by:
startSendingDTMF in interface AudioMediaStream
Parameters:
tone - the DTMFTone to start sending.
dtmfMethod - The kind of DTMF used (RTP, SIP-INOF or INBAND).
See Also:
AudioMediaStream.startSendingDTMF(DTMFTone, DTMFMethod)

stopSendingDTMF

public void stopSendingDTMF(DTMFMethod dtmfMethod)
Interrupts transmission of a DTMFTone started with the startSendingDTMF() method. Has no effect if no tone is currently being sent.

Specified by:
stopSendingDTMF in interface AudioMediaStream
Parameters:
dtmfMethod - The kind of DTMF used (RTP, SIP-INOF or INBAND).
See Also:
AudioMediaStream.stopSendingDTMF(DTMFMethod)

addRTPExtension

public void addRTPExtension(byte extensionID,
                            RTPExtension rtpExtension)
In addition to calling MediaStreamImpl.addRTPExtension(byte, RTPExtension) this method enables sending of CSRC audio levels. The reason we are doing this here rather than in the super class is that CSRC levels only make sense for audio streams so we don't want them enabled in any other kind.

Specified by:
addRTPExtension in interface MediaStream
Overrides:
addRTPExtension in class MediaStreamImpl
Parameters:
extensionID - the ID assigned to rtpExtension for the lifetime of this stream.
rtpExtension - the RTPExtension that is being added to this stream.

setLocalUserAudioLevelListener

public void setLocalUserAudioLevelListener(SimpleAudioLevelListener listener)
Sets listener as the SimpleAudioLevelListener registered to receive notifications from our device session for changes in the levels of the audio that this stream is sending out.

Specified by:
setLocalUserAudioLevelListener in interface AudioMediaStream
Parameters:
listener - the SimpleAudioLevelListener that we'd like to register or null if we want to stop local audio level measurements.

getDeviceSession

public AudioMediaDeviceSession getDeviceSession()
Returns the MediaDeviceSession associated with this stream after first casting it to AudioMediaDeviceSession since this is, after all, an AudioMediaStreamImpl.

Overrides:
getDeviceSession in class MediaStreamImpl
Returns:
the AudioMediaDeviceSession associated with this stream.

getLastMeasuredAudioLevel

public int getLastMeasuredAudioLevel(long ssrc)
Returns the last audio level that was measured by the underlying device session for the specified ssrc (where ssrc could also correspond to our local sync source identifier).

Parameters:
ssrc - the SSRC ID whose last measured audio level we'd like to retrieve.
Returns:
the audio level that was last measured for the specified ssrc or -1 if no level has been cached for that ID.

fireConferenceAudioLevelEvent

public void fireConferenceAudioLevelEvent(long[] audioLevels)
Delivers the audioLevels map to whoever's interested. This method is meant for use primarily by the transform engine handling incoming RTP packets (currently CsrcTransformEngine).

Parameters:
audioLevels - a array mapping CSRC IDs to audio levels in consecutive elements.

fireDTMFEvent

public void fireDTMFEvent(DTMFRtpTone tone,
                          boolean end)
Delivers the DTMF tones. This method is meant for use primarily by the transform engine handling incoming RTP packets (currently DtmfTransformEngine).

Parameters:
tone - the new tone
end - is end or start of tone.

close

public void close()
Releases the resources allocated by this instance in the course of its execution and prepares it to be garbage collected.

Specified by:
close in interface MediaStream
Overrides:
close in class MediaStreamImpl
See Also:
MediaStream.close()

getPriority

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

Overrides:
getPriority in class MediaStreamImpl
Returns:
audio priority.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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