SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

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

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

public class MediaServiceImpl
extends Object
implements MediaService

The service is meant to be a wrapper of media libraries such as JMF, (J)FFMPEG, JMFPAPI, and others. It takes care of all media play and capture as well as media transport (e.g. over RTP). Before being able to use this service calls would have to make sure that it is initialized (i.e. consult the isInitialized() method).

Author:
Emil Ivov, Martin Andre, Ryan Ricard, Symphorien Wanko, Ken Larson

Field Summary
 
Fields inherited from interface net.java.sip.communicator.service.media.MediaService
BIND_RETRIES_DEFAULT_VALUE, BIND_RETRIES_PROPERTY_NAME, DISABLE_VIDEO_SUPPORT_PROPERTY_NAME, MAX_PORT_NUMBER_PROPERTY_NAME, MIN_PORT_NUMBER_PROPERTY_NAME
 
Constructor Summary
MediaServiceImpl()
          Default constructor
 
Method Summary
 void addMediaListener(MediaListener listener)
          Adds a listener that will be listening for incoming media and changes in the state of the media listener.
protected  void assertStarted()
          Verifies whether the media service is started and ready for use and throws an exception otherwise.
 CallSession createCallSession(Call call)
          Creates a call session for call.
 RtpFlow createRtpFlow(String localIP, int localPort, String remoteIP, int remotePort, Map<String,List<String>> mediaEncodings)
          A RtpFlow is an object which role is to handle media data transfer, capture and playback.
 double getDataSourceDurationSeconds(Call call)
          Returns the duration (in milliseconds) of the data source being used for the given call.
 DeviceConfiguration getDeviceConfiguration()
          A valid instance of the DeviceConfiguration that a call session may use to query for supported support of audio/video capture.
 EncodingConfiguration getEncodingConfiguration()
          A valid instance of the EncodingConfiguration that a call session may use to query for encodings and their priority.
 MediaControl getMediaControl()
          A valid instance of the Media Control that the call session may use to query for supported audio video encodings.
 MediaControl getMediaControl(Call call)
          The MediaControl instance that is mapped to call.
 javax.sdp.SdpFactory getSdpFactory()
          A valid instance of an SDP factory that call session may use for manipulating sdp data.
 String[] getSupportedAudioEncodings()
          Implements getSupportedAudioEncodings from interface MediaService
 String[] getSupportedVideoEncodings()
          Implements getSupportedVideoEncodings from interface MediaService
 boolean isStarted()
          Returns true if the media service implementation is initialized and ready for use by other services, and false otherwise.
static void main(String[] args)
          This method is here most probably only temporarily for the sake of testing.
 void removeMediaListener(MediaListener listener)
          Removes a listener that was listening for incoming media and changes in the state of the media listener
 void setCallDataSink(Call call, URL dataSinkURL)
          Sets the Data Destination for call to the URL dataSinkURL instead of the default data destination.
 void setCallDataSource(Call call, URL dataSourceURL)
          Sets the data source for call to the URL dataSourceURL instead of the default data source.
 void shutdown()
          Makes the service implementation close all release any devices or other resources that it might have allocated and prepare for shutdown/garbage collection.
 void start()
          Initializes the service implementation, and puts it in a state where it could interoperate with other services.
 void stop()
          Releases all resources and prepares for shutdown.
 void unsetCallDataSink(Call call)
          Unsets the data destination for call, which will now send data to the default destination.
 void unsetCallDataSource(Call call)
          Unsets the data source for call, which will now use the default data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MediaServiceImpl

public MediaServiceImpl()
Default constructor

Method Detail

getSupportedAudioEncodings

public String[] getSupportedAudioEncodings()
Implements getSupportedAudioEncodings from interface MediaService

Specified by:
getSupportedAudioEncodings in interface MediaService
Returns:
an array of Strings containing audio formats in the order of preference.

getSupportedVideoEncodings

public String[] getSupportedVideoEncodings()
Implements getSupportedVideoEncodings from interface MediaService

Specified by:
getSupportedVideoEncodings in interface MediaService
Returns:
an array of Strings containing video formats in the order of preference.

createCallSession

public CallSession createCallSession(Call call)
                              throws MediaException
Creates a call session for call. The method allocates audio and video ports which won't be released until the corresponding call gets into a DISCONNECTED state. If a session already exists for call, it is returned and no new session is created.

Specified by:
createCallSession in interface MediaService
Parameters:
call - the Call that we'll be encapsulating in the newly created session.
Returns:
a CallSession encapsulating call.
Throws:
MediaException - with code IO_ERROR if we fail allocating ports.

createRtpFlow

public RtpFlow createRtpFlow(String localIP,
                             int localPort,
                             String remoteIP,
                             int remotePort,
                             Map<String,List<String>> mediaEncodings)
                      throws MediaException
A RtpFlow is an object which role is to handle media data transfer, capture and playback. It's build between two points, a local and a remote. The media transfered will be in a format specified by the mediaEncodings parameter.

Specified by:
createRtpFlow in interface MediaService
Parameters:
localIP - local address of this RtpFlow
localPort - local port of this RtpFlow
remoteIP - remote address of this RtpFlow
remotePort - remote port of this RtpFlow
mediaEncodings - format used to encode data on this flow
Returns:
rtpFlow the newly created RtpFlow
Throws:
MediaException - if operation fails

addMediaListener

public void addMediaListener(MediaListener listener)
Adds a listener that will be listening for incoming media and changes in the state of the media listener.

Specified by:
addMediaListener in interface MediaService
Parameters:
listener - the listener to register

removeMediaListener

public void removeMediaListener(MediaListener listener)
Removes a listener that was listening for incoming media and changes in the state of the media listener

Specified by:
removeMediaListener in interface MediaService
Parameters:
listener - the listener to remove

start

public void start()
Initializes the service implementation, and puts it in a state where it could interoperate with other services.


stop

public void stop()
Releases all resources and prepares for shutdown.


isStarted

public boolean isStarted()
Returns true if the media service implementation is initialized and ready for use by other services, and false otherwise.

Specified by:
isStarted in interface MediaService
Returns:
true if the media manager is initialized and false otherwise.

assertStarted

protected void assertStarted()
                      throws MediaException
Verifies whether the media service is started and ready for use and throws an exception otherwise.

Throws:
MediaException - if the media service is not started and ready for use.

shutdown

public void shutdown()
Makes the service implementation close all release any devices or other resources that it might have allocated and prepare for shutdown/garbage collection.


getSdpFactory

public javax.sdp.SdpFactory getSdpFactory()
A valid instance of an SDP factory that call session may use for manipulating sdp data.

Returns:
a valid instance of an SDP factory that call session may use for manipulating sdp data.

getMediaControl

public MediaControl getMediaControl()
A valid instance of the Media Control that the call session may use to query for supported audio video encodings.

Returns:
the default instance of the Media Control that the call session may use to query for supported audio video encodings.

getMediaControl

public MediaControl getMediaControl(Call call)
The MediaControl instance that is mapped to call. If call is not mapped to a particular MediaControl instance, the default instance will be returned

Parameters:
call - the call to fetch the MediaControl of
Returns:
the instance of MediaControl that is mapped to call or the defaultMediaControl if no custom one is registered for call.

getDeviceConfiguration

public DeviceConfiguration getDeviceConfiguration()
A valid instance of the DeviceConfiguration that a call session may use to query for supported support of audio/video capture.

Returns:
a valid instance of the DeviceConfiguration that a call session may use to query for supported support of audio/video capture.

getEncodingConfiguration

public EncodingConfiguration getEncodingConfiguration()
A valid instance of the EncodingConfiguration that a call session may use to query for encodings and their priority.

Returns:
a valid instance of the EncodingConfiguration

setCallDataSource

public void setCallDataSource(Call call,
                              URL dataSourceURL)
                       throws MediaException
Sets the data source for call to the URL dataSourceURL instead of the default data source. This is used (for instance) to play audio from a file instead of from a the microphone.

Specified by:
setCallDataSource in interface MediaService
Parameters:
call - the Call whose data source will be changed
dataSourceURL - the URL of the new data source
Throws:
MediaException - if we fail to initialize the data source

getDataSourceDurationSeconds

public double getDataSourceDurationSeconds(Call call)
Returns the duration (in milliseconds) of the data source being used for the given call. If the data source is not time-based, IE a microphone, or the duration cannot be determined, returns -1

Specified by:
getDataSourceDurationSeconds in interface MediaService
Parameters:
call - the call whose data source duration will be retrieved
Returns:
-1 or the duration of the data source

unsetCallDataSource

public void unsetCallDataSource(Call call)
Unsets the data source for call, which will now use the default data source.

Specified by:
unsetCallDataSource in interface MediaService
Parameters:
call - the call whose data source mapping will be released

setCallDataSink

public void setCallDataSink(Call call,
                            URL dataSinkURL)
Sets the Data Destination for call to the URL dataSinkURL instead of the default data destination. This is used (for instance) to record incoming data to a file instead of sending it to the speakers/screen.

Specified by:
setCallDataSink in interface MediaService
Parameters:
call - the call whose data destination will be changed
dataSinkURL - the URL of the new data sink.

unsetCallDataSink

public void unsetCallDataSink(Call call)
Unsets the data destination for call, which will now send data to the default destination.

Specified by:
unsetCallDataSink in interface MediaService
Parameters:
call - the call whose data destination mapping will be released

main

public static void main(String[] args)
                 throws Throwable
This method is here most probably only temporarily for the sake of testing. @todo remove main method.

Parameters:
args - String[]
Throws:
Throwable - if it doesn't feel like executing today.

SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

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