Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.MediaServiceImpl
All Implemented Interfaces:
PortAudioDeviceChangedCallback, MediaService

public class MediaServiceImpl
extends Object
implements MediaService, PortAudioDeviceChangedCallback

Implements MediaService for JMF.

Author:
Lyubomir Marinov, Dmitri Melnikov

Field Summary
static String DISABLE_VIDEO_SUPPORT_PROPERTY_NAME
          With this property video support can be disabled (enabled by default).
 
Constructor Summary
MediaServiceImpl()
           
 
Method Summary
 void addRecorderListener(Recorder.Listener listener)
          Those interested in Recorder events add listener through MediaService.
 MediaStream createMediaStream(MediaDevice device)
          Create a MediaStream which will use a specific MediaDevice for capture and playback of media.
 MediaStream createMediaStream(StreamConnector connector, MediaDevice device)
          Creates a new MediaStream instance which will use the specified MediaDevice for both capture and playback of media exchanged via the specified StreamConnector.
 MediaStream createMediaStream(StreamConnector connector, MediaDevice device, SrtpControl srtpControl)
          Creates a new MediaStream instance which will use the specified MediaDevice for both capture and playback of media exchanged via the specified StreamConnector.
 MediaDevice createMixer(MediaDevice device)
          Creates a new MediaDevice which uses a specific MediaDevice to capture and play back media and performs mixing of the captured media and the media played back by any other users of the returned MediaDevice.
 Recorder createRecorder(MediaDevice device)
          Creates a new Recorder instance that can be used to record a call which captures and plays back media using a specific MediaDevice.
 RTPTranslator createRTPTranslator()
          Initializes a new RTPTranslator which is to forward RTP and RTCP traffic between multiple MediaStreams.
 SDesControl createSDesControl()
          Creates SDesControl used to control all SDes options.
 ZrtpControl createZrtpControl()
          Creates ZrtpControl used to control all zrtp options on particular stream.
 void deviceChanged()
          Callback called from native PortAudio side that notify device changed.
 List<ScreenDevice> getAvailableScreenDevices()
          Get available screens.
 MediaDevice getDefaultDevice(MediaType mediaType, MediaUseCase useCase)
          Gets the default MediaDevice for the specified MediaType.
 ScreenDevice getDefaultScreenDevice()
          Get default screen device.
 DeviceConfiguration getDeviceConfiguration()
          Gets the CaptureDevice user choices such as the default audio and video capture devices.
 List<MediaDevice> getDevices(MediaType mediaType, MediaUseCase useCase)
          Gets a list of the MediaDevices known to this MediaService and handling the specified MediaType.
 Map<MediaFormat,Byte> getDynamicPayloadTypePreferences()
          Returns a Map that binds indicates whatever preferences this media service implementation may have for the RTP payload type numbers that get dynamically assigned to MediaFormats with no static payload type.
 EncodingConfiguration getEncodingConfiguration()
          Gets the format-related user choices such as the enabled and disabled codecs and the order of their preference.
 MediaFormatFactory getFormatFactory()
          Gets the MediaFormatFactory through which MediaFormat instances may be created for the purposes of working with the MediaStreams created by this MediaService.
 VolumeControl getInputVolumeControl()
          Gets the VolumeControl which controls the volume level of audio input/capture.
 MediaDevice getMediaDeviceForPartialDesktopStreaming(int width, int height, int x, int y)
          Get a MediaDevice for a part of desktop streaming/sharing.
 Point getOriginForDesktopStreamingDevice(MediaDevice mediaDevice)
          Gets the origin of a specific desktop streaming device.
 VolumeControl getOutputVolumeControl()
          Gets the VolumeControl which controls the volume level of audio output/playback.
 Iterator<Recorder.Listener> getRecorderListeners()
          Gives access to currently registered Recorder.Listeners.
 ScreenDevice getScreenForPoint(Point p)
          Find the screen device that contains specified point.
 Object getVideoPreviewComponent(MediaDevice device, int preferredWidth, int preferredHeight)
          Creates a preview component for the specified device(video device) used to show video preview from that device.
 boolean isPartialStreaming(MediaDevice mediaDevice)
          If the MediaDevice corresponds to partial desktop streaming device.
 void movePartialDesktopStreaming(MediaDevice mediaDevice, int x, int y)
          Move origin of a partial desktop streaming MediaDevice.
 void removeRecorderListener(Recorder.Listener listener)
          Removes an existing Recorder.Listener from the list of listeners interested in notifications from Recorders.
(package private)  void start()
          Starts this MediaService implementation and thus makes it operational.
(package private)  void stop()
          Stops this MediaService implementation and thus signals that its utilization should cease.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISABLE_VIDEO_SUPPORT_PROPERTY_NAME

public static final String DISABLE_VIDEO_SUPPORT_PROPERTY_NAME
With this property video support can be disabled (enabled by default).

See Also:
Constant Field Values
Constructor Detail

MediaServiceImpl

public MediaServiceImpl()
Method Detail

createMediaStream

public MediaStream createMediaStream(MediaDevice device)
Create a MediaStream which will use a specific MediaDevice for capture and playback of media. The new instance will not have a StreamConnector at the time of its construction and a StreamConnector will be specified later on in order to enable the new instance to send and receive media.

Specified by:
createMediaStream in interface MediaService
Parameters:
device - the MediaDevice to be used by the new instance for capture and playback of media
Returns:
a newly-created MediaStream which will use the specified device for capture and playback of media
See Also:
MediaService.createMediaStream(MediaDevice)

createMediaStream

public MediaStream createMediaStream(StreamConnector connector,
                                     MediaDevice device)
Creates a new MediaStream instance which will use the specified MediaDevice for both capture and playback of media exchanged via the specified StreamConnector.

Specified by:
createMediaStream in interface MediaService
Parameters:
connector - the StreamConnector that the new MediaStream instance is to use for sending and receiving media
device - the MediaDevice that the new MediaStream instance is to use for both capture and playback of media exchanged via the specified connector
Returns:
a new MediaStream instance
See Also:
MediaService.createMediaStream(StreamConnector, MediaDevice)

createMediaStream

public MediaStream createMediaStream(StreamConnector connector,
                                     MediaDevice device,
                                     SrtpControl srtpControl)
Creates a new MediaStream instance which will use the specified MediaDevice for both capture and playback of media exchanged via the specified StreamConnector.

Specified by:
createMediaStream in interface MediaService
Parameters:
connector - the StreamConnector that the new MediaStream instance is to use for sending and receiving media
device - the MediaDevice that the new MediaStream instance is to use for both capture and playback of media exchanged via the specified connector
srtpControl - a control which is already created, used to control the srtp operations.
Returns:
a new MediaStream instance
See Also:
MediaService.createMediaStream(StreamConnector, MediaDevice)

createMixer

public MediaDevice createMixer(MediaDevice device)
Creates a new MediaDevice which uses a specific MediaDevice to capture and play back media and performs mixing of the captured media and the media played back by any other users of the returned MediaDevice. For the AUDIO MediaType, the returned device is commonly referred to as an audio mixer. The MediaType of the returned MediaDevice is the same as the MediaType of the specified device.

Specified by:
createMixer in interface MediaService
Parameters:
device - the MediaDevice which is to be used by the returned MediaDevice to actually capture and play back media
Returns:
a new MediaDevice instance which uses device to capture and play back media and performs mixing of the captured media and the media played back by any other users of the returned MediaDevice instance
See Also:
MediaService.createMixer(MediaDevice)

getDefaultDevice

public MediaDevice getDefaultDevice(MediaType mediaType,
                                    MediaUseCase useCase)
Gets the default MediaDevice for the specified MediaType.

Specified by:
getDefaultDevice in interface MediaService
Parameters:
mediaType - a MediaType value indicating the type of media to be handled by the MediaDevice to be obtained
useCase - the MediaUseCase to obtain the MediaDevice list for
Returns:
the default MediaDevice for the specified mediaType if such a MediaDevice exists; otherwise, null
See Also:
MediaService.getDefaultDevice(MediaType, MediaUseCase)

getDeviceConfiguration

public DeviceConfiguration getDeviceConfiguration()
Gets the CaptureDevice user choices such as the default audio and video capture devices.

Returns:
the CaptureDevice user choices such as the default audio and video capture devices.

getDevices

public List<MediaDevice> getDevices(MediaType mediaType,
                                    MediaUseCase useCase)
Gets a list of the MediaDevices known to this MediaService and handling the specified MediaType.

Specified by:
getDevices in interface MediaService
Parameters:
mediaType - the MediaType to obtain the MediaDevice list for
useCase - the MediaUseCase to obtain the MediaDevice list for
Returns:
a new List of MediaDevices known to this MediaService and handling the specified MediaType. The returned List is a copy of the internal storage and, consequently, modifications to it do not affect this instance. Despite the fact that a new List instance is returned by each call to this method, the MediaDevice instances are the same if they are still known to this MediaService to be available.
See Also:
MediaService.getDevices(MediaType, MediaUseCase)

getEncodingConfiguration

public EncodingConfiguration getEncodingConfiguration()
Gets the format-related user choices such as the enabled and disabled codecs and the order of their preference.

Returns:
the format-related user choices such as the enabled and disabled codecs and the order of their preference

getFormatFactory

public MediaFormatFactory getFormatFactory()
Gets the MediaFormatFactory through which MediaFormat instances may be created for the purposes of working with the MediaStreams created by this MediaService.

Specified by:
getFormatFactory in interface MediaService
Returns:
the MediaFormatFactory through which MediaFormat instances may be created for the purposes of working with the MediaStreams created by this MediaService
See Also:
MediaService.getFormatFactory()

start

void start()
Starts this MediaService implementation and thus makes it operational.


stop

void stop()
Stops this MediaService implementation and thus signals that its utilization should cease.


createZrtpControl

public ZrtpControl createZrtpControl()
Creates ZrtpControl used to control all zrtp options on particular stream.

Specified by:
createZrtpControl in interface MediaService
Returns:
ZrtpControl instance.

createSDesControl

public SDesControl createSDesControl()
Creates SDesControl used to control all SDes options.

Specified by:
createSDesControl in interface MediaService
Returns:
SDesControl instance.

getOutputVolumeControl

public VolumeControl getOutputVolumeControl()
Gets the VolumeControl which controls the volume level of audio output/playback.

Specified by:
getOutputVolumeControl in interface MediaService
Returns:
the VolumeControl which controls the volume level of audio output/playback
See Also:
MediaService.getOutputVolumeControl()

getInputVolumeControl

public VolumeControl getInputVolumeControl()
Gets the VolumeControl which controls the volume level of audio input/capture.

Specified by:
getInputVolumeControl in interface MediaService
Returns:
the VolumeControl which controls the volume level of audio input/capture
See Also:
MediaService.getInputVolumeControl()

getAvailableScreenDevices

public List<ScreenDevice> getAvailableScreenDevices()
Get available screens.

Specified by:
getAvailableScreenDevices in interface MediaService
Returns:
screens

getDefaultScreenDevice

public ScreenDevice getDefaultScreenDevice()
Get default screen device.

Specified by:
getDefaultScreenDevice in interface MediaService
Returns:
default screen device

createRecorder

public Recorder createRecorder(MediaDevice device)
Creates a new Recorder instance that can be used to record a call which captures and plays back media using a specific MediaDevice.

Specified by:
createRecorder in interface MediaService
Parameters:
device - the MediaDevice which is used for media capture and playback by the call to be recorded
Returns:
a new Recorder instance that can be used to record a call which captures and plays back media using the specified MediaDevice
See Also:
MediaService.createRecorder(MediaDevice)

getDynamicPayloadTypePreferences

public Map<MediaFormat,Byte> getDynamicPayloadTypePreferences()
Returns a Map that binds indicates whatever preferences this media service implementation may have for the RTP payload type numbers that get dynamically assigned to MediaFormats with no static payload type. The method is useful for formats such as "telephone-event" for example that is statically assigned the 101 payload type by some legacy systems. Signaling protocol implementations such as SIP and XMPP should make sure that, whenever this is possible, they assign to formats the dynamic payload type returned in this Map.

Specified by:
getDynamicPayloadTypePreferences in interface MediaService
Returns:
a Map binding some formats to a preferred dynamic RTP payload type number.

getVideoPreviewComponent

public Object getVideoPreviewComponent(MediaDevice device,
                                       int preferredWidth,
                                       int preferredHeight)
Creates a preview component for the specified device(video device) used to show video preview from that device.

Specified by:
getVideoPreviewComponent in interface MediaService
Parameters:
device - the video device
preferredWidth - the width we prefer for the component
preferredHeight - the height we prefer for the component
Returns:
the preview component.

getMediaDeviceForPartialDesktopStreaming

public MediaDevice getMediaDeviceForPartialDesktopStreaming(int width,
                                                            int height,
                                                            int x,
                                                            int y)
Get a MediaDevice for a part of desktop streaming/sharing.

Specified by:
getMediaDeviceForPartialDesktopStreaming in interface MediaService
Parameters:
width - width of the part
height - height of the part
x - origin of the x coordinate (relative to the full desktop)
y - origin of the y coordinate (relative to the full desktop)
Returns:
MediaDevice representing the part of desktop or null if problem

movePartialDesktopStreaming

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

Specified by:
movePartialDesktopStreaming in interface MediaService
Parameters:
mediaDevice - desktop streaming MediaDevice obtained by getMediaDeviceForPartialDesktopStreaming() method.
x - new x coordinate origin
y - new y coordinate origin

isPartialStreaming

public boolean isPartialStreaming(MediaDevice mediaDevice)
If the MediaDevice corresponds to partial desktop streaming device.

Specified by:
isPartialStreaming in interface MediaService
Parameters:
mediaDevice - MediaDevice
Returns:
true if MediaDevice is a partial desktop streaming device, false otherwise

getScreenForPoint

public ScreenDevice getScreenForPoint(Point p)
Find the screen device that contains specified point.

Parameters:
p - point coordinates
Returns:
screen device that contains point

getOriginForDesktopStreamingDevice

public Point getOriginForDesktopStreamingDevice(MediaDevice mediaDevice)
Gets the origin of a specific desktop streaming device.

Specified by:
getOriginForDesktopStreamingDevice in interface MediaService
Parameters:
mediaDevice - the desktop streaming device to get the origin on
Returns:
the origin of the specified desktop streaming device

addRecorderListener

public void addRecorderListener(Recorder.Listener listener)
Those interested in Recorder events add listener through MediaService. This way they don't need to have access to the Recorder instance. Adds a new Recorder.Listener to the list of listeners interested in notifications from a Recorder.

Specified by:
addRecorderListener in interface MediaService
Parameters:
listener - the new Recorder.Listener to be added to the list of listeners interested in notifications from Recorders.

removeRecorderListener

public void removeRecorderListener(Recorder.Listener listener)
Removes an existing Recorder.Listener from the list of listeners interested in notifications from Recorders.

Specified by:
removeRecorderListener in interface MediaService
Parameters:
listener - the existing Listener to be removed from the list of listeners interested in notifications from Recorders

getRecorderListeners

public Iterator<Recorder.Listener> getRecorderListeners()
Gives access to currently registered Recorder.Listeners.

Specified by:
getRecorderListeners in interface MediaService
Returns:
currently registered Recorder.Listeners.

deviceChanged

public void deviceChanged()
Callback called from native PortAudio side that notify device changed.

Specified by:
deviceChanged in interface PortAudioDeviceChangedCallback

createRTPTranslator

public RTPTranslator createRTPTranslator()
Initializes a new RTPTranslator which is to forward RTP and RTCP traffic between multiple MediaStreams.

Specified by:
createRTPTranslator in interface MediaService
Returns:
a new RTPTranslator which is to forward RTP and RTCP traffic between multiple MediaStreams
See Also:
MediaService.createRTPTranslator()

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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