Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia.codec
Class AbstractCodecExt

java.lang.Object
  extended by net.sf.fmj.media.AbstractControls
      extended by net.sf.fmj.media.AbstractPlugIn
          extended by net.sf.fmj.media.AbstractCodec
              extended by net.java.sip.communicator.impl.neomedia.codec.AbstractCodecExt
All Implemented Interfaces:
javax.media.Codec, javax.media.Controls, javax.media.PlugIn
Direct Known Subclasses:
DePacketizer, DePacketizer, HFlip, JavaDecoder, JavaDecoder, JavaDecoder, JavaEncoder, JavaEncoder, JavaEncoder, JavaEncoder, JNIDecoder, JNIDecoder, JNIEncoder, JNIEncoder, JNIEncoder, SpeexResampler

public abstract class AbstractCodecExt
extends net.sf.fmj.media.AbstractCodec

Extends FMJ's AbstractCodec to make it even easier to implement a Codec.

Author:
Lyubomir Marinov

Field Summary
 
Fields inherited from class net.sf.fmj.media.AbstractCodec
inputFormat, inputFormats, opened, outputFormat
 
Fields inherited from interface javax.media.PlugIn
BUFFER_PROCESSED_FAILED, BUFFER_PROCESSED_OK, INPUT_BUFFER_NOT_CONSUMED, OUTPUT_BUFFER_NOT_FILLED, PLUGIN_TERMINATED
 
Constructor Summary
protected AbstractCodecExt(String name, Class<? extends javax.media.Format> formatClass, javax.media.Format[] supportedOutputFormats)
          Initializes a new AbstractCodecExt instance with a specific PlugIn name, a specific Class of input and output Formats and a specific list of Formats supported as output.
 
Method Summary
 void close()
           
protected  void discardOutputBuffer(javax.media.Buffer outputBuffer)
           
protected abstract  void doClose()
           
protected abstract  void doOpen()
          Opens this Codec and acquires the resources that it needs to operate.
protected abstract  int doProcess(javax.media.Buffer inputBuffer, javax.media.Buffer outputBuffer)
           
protected  javax.media.Format[] getMatchingOutputFormats(javax.media.Format inputFormat)
          Get the output formats matching a specific input format.
 String getName()
           
 javax.media.Format[] getSupportedOutputFormats(javax.media.Format inputFormat)
          Implements AbstractCodec.getSupportedOutputFormats(Format).
static javax.media.Format matches(javax.media.Format in, javax.media.Format[] outs)
          Utility to perform format matching.
 void open()
          Opens this PlugIn software or hardware component and acquires the resources that it needs to operate.
 int process(javax.media.Buffer inputBuffer, javax.media.Buffer outputBuffer)
          Implements AbstractCodec#process(Buffer, Buffer).
 javax.media.Format setInputFormat(javax.media.Format format)
           
 javax.media.Format setOutputFormat(javax.media.Format format)
           
protected  void updateOutput(javax.media.Buffer outputBuffer, javax.media.Format format, int length, int offset)
          Updates the format, length and offset of a specific output Buffer to specific values.
protected  byte[] validateByteArraySize(javax.media.Buffer buffer, int newSize)
           
protected  short[] validateShortArraySize(javax.media.Buffer buffer, int newSize)
           
 
Methods inherited from class net.sf.fmj.media.AbstractCodec
checkInputBuffer, dump, getInputFormat, getOutputFormat, getSupportedInputFormats, isEOM, propagateEOM
 
Methods inherited from class net.sf.fmj.media.AbstractPlugIn
reset
 
Methods inherited from class net.sf.fmj.media.AbstractControls
addControl, getControl, getControls, removeControl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.media.PlugIn
reset
 
Methods inherited from interface javax.media.Controls
getControl, getControls
 

Constructor Detail

AbstractCodecExt

protected AbstractCodecExt(String name,
                           Class<? extends javax.media.Format> formatClass,
                           javax.media.Format[] supportedOutputFormats)
Initializes a new AbstractCodecExt instance with a specific PlugIn name, a specific Class of input and output Formats and a specific list of Formats supported as output.

Parameters:
name - the PlugIn name of the new instance
formatClass - the Class of input and output Formats supported by the new instance
supportedOutputFormats - the list of Formats supported by the new instance as output
Method Detail

close

public void close()
Specified by:
close in interface javax.media.PlugIn
Overrides:
close in class net.sf.fmj.media.AbstractPlugIn

discardOutputBuffer

protected void discardOutputBuffer(javax.media.Buffer outputBuffer)

doClose

protected abstract void doClose()

doOpen

protected abstract void doOpen()
                        throws javax.media.ResourceUnavailableException
Opens this Codec and acquires the resources that it needs to operate. A call to PlugIn.open() on this instance will result in a call to doOpen only if AbstractCodec.opened is false. All required input and/or output formats are assumed to have been set on this Codec before doOpen is called.

Throws:
javax.media.ResourceUnavailableException - if any of the resources that this Codec needs to operate cannot be acquired

doProcess

protected abstract int doProcess(javax.media.Buffer inputBuffer,
                                 javax.media.Buffer outputBuffer)

getMatchingOutputFormats

protected javax.media.Format[] getMatchingOutputFormats(javax.media.Format inputFormat)
Get the output formats matching a specific input format.

Parameters:
inputFormat - the input format to get the matching output formats of
Returns:
the output formats matching the specified input format

getName

public String getName()
Specified by:
getName in interface javax.media.PlugIn
Overrides:
getName in class net.sf.fmj.media.AbstractPlugIn

getSupportedOutputFormats

public javax.media.Format[] getSupportedOutputFormats(javax.media.Format inputFormat)
Implements AbstractCodec.getSupportedOutputFormats(Format).

Specified by:
getSupportedOutputFormats in interface javax.media.Codec
Specified by:
getSupportedOutputFormats in class net.sf.fmj.media.AbstractCodec
Parameters:
inputFormat - input format
Returns:
array of supported output format
See Also:
AbstractCodec.getSupportedOutputFormats(Format)

matches

public static javax.media.Format matches(javax.media.Format in,
                                         javax.media.Format[] outs)
Utility to perform format matching.

Parameters:
in - input format
outs - array of output formats
Returns:
the first output format that is supported

open

public void open()
          throws javax.media.ResourceUnavailableException
Opens this PlugIn software or hardware component and acquires the resources that it needs to operate. All required input and/or output formats have to be set on this PlugIn before open is called. Buffers should not be passed into this PlugIn without first calling open.

Specified by:
open in interface javax.media.PlugIn
Overrides:
open in class net.sf.fmj.media.AbstractPlugIn
Throws:
javax.media.ResourceUnavailableException - if any of the resources that this PlugIn needs to operate cannot be acquired
See Also:
AbstractPlugIn.open()

process

public int process(javax.media.Buffer inputBuffer,
                   javax.media.Buffer outputBuffer)
Implements AbstractCodec#process(Buffer, Buffer).

Specified by:
process in interface javax.media.Codec
Specified by:
process in class net.sf.fmj.media.AbstractCodec
Parameters:
inputBuffer -
outputBuffer -
Returns:
BUFFER_PROCESSED_OK if all go OK or BUFFER_PROCESSED_FAILED if problems occurred
See Also:
AbstractCodec.process(Buffer, Buffer)

setInputFormat

public javax.media.Format setInputFormat(javax.media.Format format)
Specified by:
setInputFormat in interface javax.media.Codec
Overrides:
setInputFormat in class net.sf.fmj.media.AbstractCodec

setOutputFormat

public javax.media.Format setOutputFormat(javax.media.Format format)
Specified by:
setOutputFormat in interface javax.media.Codec
Overrides:
setOutputFormat in class net.sf.fmj.media.AbstractCodec

updateOutput

protected void updateOutput(javax.media.Buffer outputBuffer,
                            javax.media.Format format,
                            int length,
                            int offset)
Updates the format, length and offset of a specific output Buffer to specific values.

Parameters:
outputBuffer - the output Buffer to update the properties of
format - the Format to set on outputBuffer
length - the length to set on outputBuffer
offset - the offset to set on outputBuffer

validateByteArraySize

protected byte[] validateByteArraySize(javax.media.Buffer buffer,
                                       int newSize)

validateShortArraySize

protected short[] validateShortArraySize(javax.media.Buffer buffer,
                                         int newSize)

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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