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

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

java.lang.Object
  extended by net.java.sip.communicator.util.PropertyChangeNotifier
      extended by net.java.sip.communicator.impl.media.MediaControl

public class MediaControl
extends PropertyChangeNotifier

Provides a generic way to control media package.

Author:
Martin Andre, Emil Ivov, Damian Minkov, Jean Lorchat, Ryan Ricard, Ken Larson, Lubomir Marinov

Field Summary
static String VIDEO_DATA_SOURCE
          The property which represents the current video DataSource.
 
Constructor Summary
MediaControl()
          The default constructor.
 
Method Summary
 void closeCaptureDevices()
          Closes all currently used capture devices and data sources so that they would be usable by other applications.
static javax.media.protocol.DataSource createDataSource(javax.media.MediaLocator locator)
          Returns a JMF DataSource object over the device that locator points to.
 javax.media.protocol.DataSource createDataSourceForEncodings(Map<String,List<String>> encodingSets)
          Creates a processing data source using the encodingSets map to determine the formats/encodings allowed for the various media types.
 javax.media.protocol.DataSource createLocalVideoDataSource()
          Creates a DataSource which gives access to the local video this instance captures and controls.
protected  int findFirstMatchingFormat(javax.media.Format[] availableFormats, Map<String,List<String>> requestedEncodings)
          Looks for the first encoding (among the requested encodings elements) that is also present in the availableFormats array and returns the index of the corresponding Format.
 javax.media.Time getOutputDuration()
          Returns the duration of the output data source.
 String[] getSupportedAudioEncodings()
          Returns an array of Strings containing audio formats in the order of preference.
 String[] getSupportedVideoEncodings()
          Returns an array of Strings containing video formats in the order of preference.
 void initDataSourceFromURL(URL dataSourceURL)
          Opens the source pointed to by the dataSourceURL URL and prepares to use it instead of capture devices
 void initDebugDataSource(String debugMediaSource)
          Opens the source pointed to by the debugMediaSource URL and prepares to use it instead of capture devices.
 void initialize(DeviceConfiguration deviceConfig, EncodingConfiguration encodingConfig)
          Initializes the media control.
 boolean isLocalVideoAllowed()
          Gets the indicator which determines whether the streaming of local video through this MediaControl is allowed.
 boolean isMute()
          Determines whether the audio of this instance is mute.
static Dimension selectVideoSize(javax.media.protocol.DataSource videoDS, int preferredWidth, int preferredHeight)
           
 void setLocalVideoAllowed(boolean allowed)
          Sets the indicator which determines whether the streaming of local video through this MediaControl is allowed.
 void setMute(boolean mute)
          Sets the mute state of the audio of this instance.
 void startProcessingMedia(Object reader)
          Starts reading media from the source data sources.
 void stopProcessingMedia(Object reader)
          Stops reading media from the source data sources.
 
Methods inherited from class net.java.sip.communicator.util.PropertyChangeNotifier
addPropertyChangeListener, firePropertyChange, getPropertyChangeSource, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIDEO_DATA_SOURCE

public static final String VIDEO_DATA_SOURCE
The property which represents the current video DataSource.

See Also:
Constant Field Values
Constructor Detail

MediaControl

public MediaControl()
The default constructor.

Method Detail

getOutputDuration

public javax.media.Time getOutputDuration()
Returns the duration of the output data source. Usually this will be DURATION_UNKNOWN, but if the current data source is set to an audio file, then this value will be of some use.

Returns:
the output duration

initialize

public void initialize(DeviceConfiguration deviceConfig,
                       EncodingConfiguration encodingConfig)
                throws MediaException
Initializes the media control.

Parameters:
deviceConfig - the DeviceConfiguration that we should use when retrieving device handlers.
Throws:
MediaException - if initialization fails.

initDebugDataSource

public void initDebugDataSource(String debugMediaSource)
                         throws MediaException
Opens the source pointed to by the debugMediaSource URL and prepares to use it instead of capture devices.

Parameters:
debugMediaSource - an url (e.g. file:/home/user/movie.mov) pointing to a media file to use instead of capture devices.
Throws:
MediaException - if opening the devices fails.

initDataSourceFromURL

public void initDataSourceFromURL(URL dataSourceURL)
                           throws MediaException
Opens the source pointed to by the dataSourceURL URL and prepares to use it instead of capture devices

Parameters:
dataSourceURL - an URL (e.g. file:/home/user/outgoing_message.wav) pointing to a media file to use instead of capture devices
Throws:
MediaException - if opening the devices fails

closeCaptureDevices

public void closeCaptureDevices()
                         throws MediaException
Closes all currently used capture devices and data sources so that they would be usable by other applications.

Throws:
MediaException - if closing the devices fails with an IO Exception.

createDataSource

public static javax.media.protocol.DataSource createDataSource(javax.media.MediaLocator locator)
Returns a JMF DataSource object over the device that locator points to.

Parameters:
locator - the MediaLocator of the device/movie that we'd like to transmit from.
Returns:
a connected DataSource for the media specified by the locator.

createDataSourceForEncodings

public javax.media.protocol.DataSource createDataSourceForEncodings(Map<String,List<String>> encodingSets)
                                                             throws MediaException
Creates a processing data source using the encodingSets map to determine the formats/encodings allowed for the various media types.

Parameters:
encodingSets - a hashtable mapping media types such as "audio" or "video" to Lista of encodings (ordered by preference) accepted for the corresponding type.
Returns:
a processing data source set to generate flows in the encodings specified by the encodingSets map.
Throws:
MediaException - if creating the data source fails for some reason.

findFirstMatchingFormat

protected int findFirstMatchingFormat(javax.media.Format[] availableFormats,
                                      Map<String,List<String>> requestedEncodings)
Looks for the first encoding (among the requested encodings elements) that is also present in the availableFormats array and returns the index of the corresponding Format.

Parameters:
availableFormats - an array of JMF Formats that we're currently able to transmit.
requestedEncodings - a table mapping media types (e.g. audio or video) to a list of encodings that our interlocutor has sent in order of preference.
Returns:
the index of the format corresponding to the first encoding that had a marching format in the availableFormats array.

getSupportedVideoEncodings

public String[] getSupportedVideoEncodings()
Returns an array of Strings containing video formats in the order of preference.

Returns:
an array of Strings containing video formats in the order of preference.

getSupportedAudioEncodings

public String[] getSupportedAudioEncodings()
Returns an array of Strings containing audio formats in the order of preference.

Returns:
an array of Strings containing audio formats in the order of preference.

startProcessingMedia

public void startProcessingMedia(Object reader)
Starts reading media from the source data sources. If someone is already reading, then simply add the reader to the list of readers so that we don't pull the plug from underneath their feet.

Parameters:
reader - a reference to the object calling this method, that we could use for keeping the number of simultaneous active readers.

stopProcessingMedia

public void stopProcessingMedia(Object reader)
Stops reading media from the source data sources. If there is someone else still reading, then we simply remove the local reference to the reader and wait for the last reader to call stopProcessing before we really stop the processor.

Parameters:
reader - a reference to the object calling this method, that we could use for keeping the number of simultaneous active readers.

isMute

public boolean isMute()
Determines whether the audio of this instance is mute.

Returns:
true if the audio of this instance is mute; otherwise, false

setMute

public void setMute(boolean mute)
Sets the mute state of the audio of this instance.

Parameters:
mute - true to mute the audio of this instance; false, otherwise

selectVideoSize

public static Dimension selectVideoSize(javax.media.protocol.DataSource videoDS,
                                        int preferredWidth,
                                        int preferredHeight)

createLocalVideoDataSource

public javax.media.protocol.DataSource createLocalVideoDataSource()
Creates a DataSource which gives access to the local video this instance captures and controls.

Returns:
a DataSource which gives access to the local video this instance captures and controls; null if video is not utilized by this instance

setLocalVideoAllowed

public void setLocalVideoAllowed(boolean allowed)
                          throws MediaException
Sets the indicator which determines whether the streaming of local video through this MediaControl is allowed. The setting does not reflect the availability of actual video capture devices, it just expresses the desire of the user to have the local video streamed in the case the system is actually able to do so.

Parameters:
allowed - true to allow the streaming of local video for this MediaControl; false to disallow it
Throws:
MediaException

isLocalVideoAllowed

public boolean isLocalVideoAllowed()
Gets the indicator which determines whether the streaming of local video through this MediaControl is allowed. The setting does not reflect the availability of actual video capture devices, it just expresses the desire of the user to have the local video streamed in the case the system is actually able to do so.

Returns:
true if the streaming of local video for this MediaControl is allowed; false, otherwise

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

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