Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia.jmfext.media.protocol
Class AbstractPushBufferCaptureDevice

java.lang.Object
  extended by javax.media.protocol.DataSource
      extended by javax.media.protocol.PushBufferDataSource
          extended by net.java.sip.communicator.impl.neomedia.jmfext.media.protocol.AbstractPushBufferCaptureDevice
All Implemented Interfaces:
javax.media.Controls, javax.media.Duration, javax.media.protocol.CaptureDevice
Direct Known Subclasses:
AbstractVideoPushBufferCaptureDevice

public abstract class AbstractPushBufferCaptureDevice
extends javax.media.protocol.PushBufferDataSource
implements javax.media.protocol.CaptureDevice

Provides a base implementation of PushBufferDataSource and CaptureDevice in order to facilitate implementers by taking care of boilerplate in the most common cases.

Author:
Lyubomir Marinov

Field Summary
 
Fields inherited from interface javax.media.Duration
DURATION_UNBOUNDED, DURATION_UNKNOWN
 
Constructor Summary
protected AbstractPushBufferCaptureDevice()
          Initializes a new AbstractPushBufferCaptureDevice instance.
protected AbstractPushBufferCaptureDevice(javax.media.MediaLocator locator)
          Initializes a new AbstractPushBufferCaptureDevice instance from a specific MediaLocator.
 
Method Summary
 void connect()
          Opens a connection to the media source specified by the MediaLocator of this DataSource.
protected  javax.media.control.FrameRateControl createFrameRateControl()
          Creates a new FrameRateControl instance which is to allow the getting and setting of the frame rate of this AbstractPushBufferCaptureDevice.
protected abstract  AbstractPushBufferStream createStream(int streamIndex, javax.media.control.FormatControl formatControl)
          Create a new PushBufferStream which is to be at a specific zero-based index in the list of streams of this PushBufferDataSource.
 void disconnect()
          Closes the connection to the media source specified by the MediaLocator of this DataSource.
protected  void doConnect()
          Opens a connection to the media source specified by the MediaLocator of this DataSource.
protected  void doDisconnect()
          Closes the connection to the media source specified by the MediaLocator of this DataSource.
protected  void doStart()
          Starts the transfer of media data from this DataSource.
protected  void doStop()
          Stops the transfer of media data from this DataSource.
 javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
          Gets the CaptureDeviceInfo of this CaptureDevice which describes it.
 String getContentType()
          Gets the content type of the media represented by this instance.
 Object getControl(String controlType)
          Gets the control of the specified type available for this instance.
 Object[] getControls()
          Implements DataSource.getControls().
 javax.media.Time getDuration()
          Gets the duration of the media represented by this instance.
protected  javax.media.Format getFormat(int streamIndex, javax.media.Format oldValue)
          Gets the Format to be reported by the FormatControl of a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource.
 javax.media.control.FormatControl[] getFormatControls()
          Gets an array of FormatControl instances each one of which can be used before connect() to get and set the capture Format of each one of the capture streams.
 javax.media.protocol.PushBufferStream[] getStreams()
          Gets the PushBufferStreams through which this PushBufferDataSource gives access to its media data.
protected  Object getStreamSyncRoot()
          Gets the Object which is to synchronize the access to streams() and its return value.
protected  javax.media.Format[] getSupportedFormats(int streamIndex)
          Gets the Formats which are to be reported by a FormatControl as supported formats for a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource.
protected  javax.media.Format setFormat(int streamIndex, javax.media.Format oldValue, javax.media.Format newValue)
          Attempts to set the Format to be reported by the FormatControl of a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource.
 void start()
          Starts the transfer of media data from this DataSource.
 void stop()
          Stops the transfer of media data from this DataSource.
protected  AbstractBufferStream[] streams()
          Gets the internal array of AbstractPushBufferStreams through which this AbstractPushBufferCaptureDevice gives access to its media data.
 
Methods inherited from class javax.media.protocol.DataSource
getLocator, initCheck, setLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPushBufferCaptureDevice

protected AbstractPushBufferCaptureDevice()
Initializes a new AbstractPushBufferCaptureDevice instance.


AbstractPushBufferCaptureDevice

protected AbstractPushBufferCaptureDevice(javax.media.MediaLocator locator)
Initializes a new AbstractPushBufferCaptureDevice instance from a specific MediaLocator.

Parameters:
locator - the MediaLocator to create the new instance from
Method Detail

connect

public void connect()
             throws IOException
Opens a connection to the media source specified by the MediaLocator of this DataSource.

Specified by:
connect in interface javax.media.protocol.CaptureDevice
Specified by:
connect in class javax.media.protocol.DataSource
Throws:
IOException - if anything goes wrong while opening the connection to the media source specified by the MediaLocator of this DataSource

createFrameRateControl

protected javax.media.control.FrameRateControl createFrameRateControl()
Creates a new FrameRateControl instance which is to allow the getting and setting of the frame rate of this AbstractPushBufferCaptureDevice.

Returns:
a new FrameRateControl instance which is to allow the getting and setting of the frame rate of this AbstractPushBufferCaptureDevice

createStream

protected abstract AbstractPushBufferStream createStream(int streamIndex,
                                                         javax.media.control.FormatControl formatControl)
Create a new PushBufferStream which is to be at a specific zero-based index in the list of streams of this PushBufferDataSource. The Format-related information of the new instance is to be abstracted by a specific FormatControl.

Parameters:
streamIndex - the zero-based index of the PushBufferStream in the list of streams of this PushBufferDataSource
formatControl - the FormatControl which is to abstract the Format-related information of the new instance
Returns:
a new PushBufferStream which is to be at the specified streamIndex in the list of streams of this PushBufferDataSource and which has its Format-related information abstracted by the specified formatControl

disconnect

public void disconnect()
Closes the connection to the media source specified by the MediaLocator of this DataSource. If such a connection has not been opened, the call is ignored.

Specified by:
disconnect in interface javax.media.protocol.CaptureDevice
Specified by:
disconnect in class javax.media.protocol.DataSource

doConnect

protected void doConnect()
                  throws IOException
Opens a connection to the media source specified by the MediaLocator of this DataSource. Allows extenders to override and be sure that there will be no request to open a connection if the connection has already been opened.

Throws:
IOException - if anything goes wrong while opening the connection to the media source specified by the MediaLocator of this DataSource

doDisconnect

protected void doDisconnect()
Closes the connection to the media source specified by the MediaLocator of this DataSource. Allows extenders to override and be sure that there will be no request to close a connection if the connection has not been opened yet.


doStart

protected void doStart()
                throws IOException
Starts the transfer of media data from this DataSource. Allows extenders to override and be sure that there will be no request to start the transfer of media data if it has already been started.

Throws:
IOException - if anything goes wrong while starting the transfer of media data from this DataSource

doStop

protected void doStop()
               throws IOException
Stops the transfer of media data from this DataSource. Allows extenders to override and be sure that there will be no request to stop the transfer of media data if it has not been started yet.

Throws:
IOException - if anything goes wrong while stopping the transfer of media data from this DataSource

getCaptureDeviceInfo

public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
Gets the CaptureDeviceInfo of this CaptureDevice which describes it.

Specified by:
getCaptureDeviceInfo in interface javax.media.protocol.CaptureDevice
Returns:
the CaptureDeviceInfo of this CaptureDevice which describes it

getContentType

public String getContentType()
Gets the content type of the media represented by this instance. The AbstractPushBufferCaptureDevice implementation always returns ContentDescriptor.RAW.

Specified by:
getContentType in class javax.media.protocol.DataSource
Returns:
the content type of the media represented by this instance

getControl

public Object getControl(String controlType)
Gets the control of the specified type available for this instance.

Specified by:
getControl in interface javax.media.Controls
Specified by:
getControl in class javax.media.protocol.DataSource
Parameters:
controlType - the type of the control available for this instance to be retrieved
Returns:
an Object which represents the control of the specified type available for this instance if such a control is indeed available; otherwise, null

getControls

public Object[] getControls()
Implements DataSource.getControls(). Gets the controls available for this instance.

Specified by:
getControls in interface javax.media.Controls
Specified by:
getControls in class javax.media.protocol.DataSource
Returns:
an array of Objects which represent the controls available for this instance

getDuration

public javax.media.Time getDuration()
Gets the duration of the media represented by this instance. The AbstractPushBufferCaptureDevice always returns Duration.DURATION_UNBOUNDED.

Specified by:
getDuration in interface javax.media.Duration
Specified by:
getDuration in class javax.media.protocol.DataSource
Returns:
the duration of the media represented by this instance

getFormat

protected javax.media.Format getFormat(int streamIndex,
                                       javax.media.Format oldValue)
Gets the Format to be reported by the FormatControl of a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource. The PushBufferStream may not exist at the time of requesting its Format. Allows extenders to override the default behavior which is to report any last-known format or the first Format from the list of supported formats as defined in the JMF registration of this CaptureDevice.

Parameters:
streamIndex - the zero-based index of the PushBufferStream the Format of which is to be retrieved
oldValue - the last-known Format for the PushBufferStream at the specified streamIndex
Returns:
the Format to be reported by the FormatControl of the PushBufferStream at the specified streamIndex in the list of streams of this PushBufferDataSource.

getFormatControls

public javax.media.control.FormatControl[] getFormatControls()
Gets an array of FormatControl instances each one of which can be used before connect() to get and set the capture Format of each one of the capture streams.

Specified by:
getFormatControls in interface javax.media.protocol.CaptureDevice
Returns:
an array of FormatControl instances each one of which can be used before connect() to get and set the capture Format of each one of the capture streams

getStreamSyncRoot

protected Object getStreamSyncRoot()
Gets the Object which is to synchronize the access to streams() and its return value.

Returns:
the Object which is to synchronize the access to streams() and its return value

getStreams

public javax.media.protocol.PushBufferStream[] getStreams()
Gets the PushBufferStreams through which this PushBufferDataSource gives access to its media data.

Specified by:
getStreams in class javax.media.protocol.PushBufferDataSource
Returns:
an array of the PushBufferStreams through which this PushBufferDataSource gives access to its media data

getSupportedFormats

protected javax.media.Format[] getSupportedFormats(int streamIndex)
Gets the Formats which are to be reported by a FormatControl as supported formats for a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource.

Parameters:
streamIndex - the zero-based index of the PushBufferStream for which the specified FormatControl is to report the list of supported Formats
Returns:
an array of Formats to be reported by a FormatControl as the supported formats for the PushBufferStream at the specified streamIndex in the list of streams of this PushBufferDataSource

setFormat

protected javax.media.Format setFormat(int streamIndex,
                                       javax.media.Format oldValue,
                                       javax.media.Format newValue)
Attempts to set the Format to be reported by the FormatControl of a PushBufferStream at a specific zero-based index in the list of streams of this PushBufferDataSource. The PushBufferStream does not exist at the time of the attempt to set its Format. Allows extenders to override the default behavior which is to not attempt to set the specified Format so that they can enable setting the Format prior to creating the PushBufferStream. If setting the Format of an existing PushBufferStream is desired, AbstractPushBufferStream#doSetFormat(Format) should be overridden instead.

Parameters:
streamIndex - the zero-based index of the PushBufferStream the Format of which is to be set
oldValue - the last-known Format for the PushBufferStream at the specified streamIndex
newValue - the Format which is to be set
Returns:
the Format to be reported by the FormatControl of the PushBufferStream at the specified streamIndex in the list of streams of this PushBufferStream or null if the attempt to set the Format did not success and any last-known Format is to be left in effect

start

public void start()
           throws IOException
Starts the transfer of media data from this DataSource.

Specified by:
start in interface javax.media.protocol.CaptureDevice
Specified by:
start in class javax.media.protocol.DataSource
Throws:
IOException - if anything goes wrong while starting the transfer of media data from this DataSource

stop

public void stop()
          throws IOException
Stops the transfer of media data from this DataSource.

Specified by:
stop in interface javax.media.protocol.CaptureDevice
Specified by:
stop in class javax.media.protocol.DataSource
Throws:
IOException - if anything goes wrong while stopping the transfer of media data from this DataSource

streams

protected AbstractBufferStream[] streams()
Gets the internal array of AbstractPushBufferStreams through which this AbstractPushBufferCaptureDevice gives access to its media data.

Returns:
the internal array of AbstractPushBufferStreams through which this AbstractPushBufferCaptureDevice gives access to its media data

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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