Codecpublic interface Codec implements PlugInA Codec is a media processing unit that accepts a Buffer
object as its input, performs some processing on the input data, and then puts the
result in an output Buffer object. It has one input and one output.
Typical examples of codecs include audio decoders, video encoders, and effects.
A codec usually works in one of the following modes:
- Frame based mode. In this mode, the codec accepts one frame of data from its input
and converts it to one frame of output data.
The codec must consume its input
Buffer and generate
an output Buffer .
This mode is useful when the codec can handle any size of input. A
simple gain codec fits this model: it multiplies each
sample with the gain factor and puts the product in an output Buffer .
Another scenario where this mode is useful is when the codec can only process
data that's in a fixed, pre-determined frame size
and the input Buffer is already packetized accordingly.
One example of such a codec is a GSM audio decoder, which accepts a compressed
GSM audio packet from an RTP depacketizer, decodes the packet, and then puts the result in
an output Buffer .
- Stream based mode. In this mode, the codec accepts chunks of data from its input and
might generate an output
Buffer .
The codec might consume only part of the input Buffer each time its process
method is called and might not generate an output Buffer during each round of processing.
This mode is useful in stream packetizers, which accept a stream of bytes and divide the stream
into packets (frames) that are used in the next processing phase.
Another scenario where this mode is useful is when two audio processing units that have
incompatible frame sizes need to be chained.
Some restrictions apply to the processing a Codec can perform on its input
and output Buffer objects:
- The
Codec might receive an output Buffer that is not big enough to hold its output data.
In this case, the Codec should allocate a new Buffer for its output data.
- The
Codec cannot cache references to Buffer object fields.
It must read all of the parameters from the input and output Buffer objects each time
its process method is called.
- If the
Codec needs to keep references to a Buffer object's data (for performance reasons),
the Codec must assign other data to the input Buffer object by calling setData
before returning from the process method.
The data assigned can be null, but it is better to assign
some unneeded data to the Buffer , such as input data received earlier.
Such manipulations can be used for in-place processing (where the output of the processing
is put in the same location as input data in order to enhance memory utilization) or for codecs
that need access to more than one frame of data without copying the data (for example, temporal video effects).
|
Methods Summary |
---|
public javax.media.Format[] | getSupportedInputFormats()Lists all of the input formats that this codec accepts.
| public javax.media.Format[] | getSupportedOutputFormats(javax.media.Format input)Lists the output formats that this codec can generate.
If input is non-null, this method lists the possible
output formats that can be generated from input data of the specified Format .
If input is null, this method lists
all of the output formats supported by this plug-in.
| public int | process(javax.media.Buffer input, javax.media.Buffer output)Performs the media processing defined by this codec.
| public javax.media.Format | setInputFormat(javax.media.Format format)Sets the format of the data to be input to this codec.
| public javax.media.Format | setOutputFormat(javax.media.Format format)Sets the format for the data this codec outputs.
|
|