Package org.jitsi.impl.neomedia.codec
Class AbstractCodec2
- java.lang.Object
-
- net.sf.fmj.media.AbstractControls
-
- net.sf.fmj.media.AbstractPlugIn
-
- net.sf.fmj.media.AbstractCodec
-
- org.jitsi.impl.neomedia.codec.AbstractCodec2
-
- All Implemented Interfaces:
javax.media.Codec,javax.media.Controls,javax.media.PlugIn
- Direct Known Subclasses:
AbstractFFmpegAudioCodec,DePacketizer,DePacketizer,DePacketizer,HFlip,JavaDecoder,JavaDecoder,JavaDecoder,JavaEncoder,JavaEncoder,JavaEncoder,JNIDecoder,JNIDecoder,JNIDecoderImpl,JNIEncoder,JNIEncoder,JNIEncoderImpl,Packetizer,Packetizer,SilenceEffect,SpeexResampler,VPXDecoder,VPXEncoder
public abstract class AbstractCodec2 extends net.sf.fmj.media.AbstractCodecExtends FMJ's AbstractCodec to make it even easier to implement a Codec.- Author:
- Lyubomir Marinov
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_FLAG_FECThe Buffer flag which indicates that the respective Buffer contains audio data which has been decoded as a result of the operation of FEC.static intBUFFER_FLAG_PLCThe Buffer flag which indicates that the respective Buffer contains audio data which has been decoded as a result of the operation of PLC.static javax.media.Format[]EMPTY_FORMATSAn empty array of Format element type.protected intfeaturesThe bitmap/flag mask of optional features supported by this AbstractCodec2 such asBUFFER_FLAG_FECandBUFFER_FLAG_PLC.static intMAX_AUDIO_SEQUENCE_NUMBERS_TO_PLCThe maximum number of lost sequence numbers to conceal with packet loss mitigation techniques such as Forward Error Correction (FEC) and Packet Loss Concealment (PLC) when dealing with audio.static intSEQUENCE_MAXThe maximum (RTP) sequence number value.static intSEQUENCE_MINThe minimum (RTP) sequence number value.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCodec2(String name, Class<? extends javax.media.Format> formatClass, javax.media.Format[] supportedOutputFormats)Initializes a new AbstractCodec2 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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static intcalculateLostSeqNoCount(long lastSeqNo, long seqNo)Calculates the number of sequences which have been lost i.e.voidclose()protected voiddiscardOutputBuffer(javax.media.Buffer outputBuffer)protected abstract voiddoClose()protected abstract voiddoOpen()Opens this Codec and acquires the resources that it needs to operate.protected abstract intdoProcess(javax.media.Buffer inBuf, javax.media.Buffer outBuf)protected javax.media.Format[]getMatchingOutputFormats(javax.media.Format inputFormat)Gets the Formats which are supported by this Codec as output when the input is in a specific Format.StringgetName()javax.media.Format[]getSupportedOutputFormats(javax.media.Format inputFormat)ImplementsAbstractCodec.getSupportedOutputFormats(Format).static longincrementSeqNo(long seqNo)Increments a specific sequence number and makes sure that the result stays within the range of valid RTP sequence number values.static javax.media.Formatmatches(javax.media.Format in, javax.media.Format[] outs)Utility to perform format matching.voidopen()Opens this PlugIn software or hardware component and acquires the resources that it needs to operate.intprocess(javax.media.Buffer inBuf, javax.media.Buffer outBuf)Implements AbstractCodec#process(Buffer, Buffer).javax.media.FormatsetInputFormat(javax.media.Format format)javax.media.FormatsetOutputFormat(javax.media.Format format)static javax.media.format.YUVFormatspecialize(javax.media.format.YUVFormat yuvFormat, Class<?> dataType)protected voidupdateOutput(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.static byte[]validateByteArraySize(javax.media.Buffer buffer, int newSize, boolean arraycopy)Ensures that the value of the data property of a specific Buffer is an array of bytes whose length is at least a specific number of bytes.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.AbstractControls
addControl, getControl, getControls, removeControl
-
-
-
-
Field Detail
-
BUFFER_FLAG_FEC
public static final int BUFFER_FLAG_FEC
The Buffer flag which indicates that the respective Buffer contains audio data which has been decoded as a result of the operation of FEC.- See Also:
- Constant Field Values
-
BUFFER_FLAG_PLC
public static final int BUFFER_FLAG_PLC
The Buffer flag which indicates that the respective Buffer contains audio data which has been decoded as a result of the operation of PLC.- See Also:
- Constant Field Values
-
EMPTY_FORMATS
public static final javax.media.Format[] EMPTY_FORMATS
An empty array of Format element type. Explicitly defined to reduce unnecessary allocations.
-
MAX_AUDIO_SEQUENCE_NUMBERS_TO_PLC
public static final int MAX_AUDIO_SEQUENCE_NUMBERS_TO_PLC
The maximum number of lost sequence numbers to conceal with packet loss mitigation techniques such as Forward Error Correction (FEC) and Packet Loss Concealment (PLC) when dealing with audio.- See Also:
- Constant Field Values
-
SEQUENCE_MAX
public static final int SEQUENCE_MAX
The maximum (RTP) sequence number value.- See Also:
- Constant Field Values
-
SEQUENCE_MIN
public static final int SEQUENCE_MIN
The minimum (RTP) sequence number value.- See Also:
- Constant Field Values
-
features
protected int features
The bitmap/flag mask of optional features supported by this AbstractCodec2 such asBUFFER_FLAG_FECandBUFFER_FLAG_PLC.
-
-
Constructor Detail
-
AbstractCodec2
protected AbstractCodec2(String name, Class<? extends javax.media.Format> formatClass, javax.media.Format[] supportedOutputFormats)
Initializes a new AbstractCodec2 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 instanceformatClass- the Class of input and output Formats supported by the new instancesupportedOutputFormats- the list of Formats supported by the new instance as output
-
-
Method Detail
-
calculateLostSeqNoCount
public static int calculateLostSeqNoCount(long lastSeqNo, long seqNo)Calculates the number of sequences which have been lost i.e. which have not been received.- Parameters:
lastSeqNo- the last received sequence number (prior to the current sequence number represented by seqNo.) May beBuffer.SEQUENCE_UNKNOWN. May be equal to seqNo for the purposes of Codec implementations which repeatedly process one and the same input Buffer multiple times.seqNo- the current sequence number. May be equal to lastSeqNo for the purposes of Codec implementations which repeatedly process one and the same input Buffer multiple times.- Returns:
- the number of sequences (between lastSeqNo and seqNo) which have been lost i.e. which have not been received
-
incrementSeqNo
public static long incrementSeqNo(long seqNo)
Increments a specific sequence number and makes sure that the result stays within the range of valid RTP sequence number values.- Parameters:
seqNo- the sequence number to increment- Returns:
- a sequence number which represents an increment over the specified seqNo within the range of valid RTP sequence number values
-
matches
public static javax.media.Format matches(javax.media.Format in, javax.media.Format[] outs)Utility to perform format matching.- Parameters:
in- input formatouts- array of output formats- Returns:
- the first output format that is supported
-
specialize
public static javax.media.format.YUVFormat specialize(javax.media.format.YUVFormat yuvFormat, Class<?> dataType)
-
validateByteArraySize
public static byte[] validateByteArraySize(javax.media.Buffer buffer, int newSize, boolean arraycopy)Ensures that the value of the data property of a specific Buffer is an array of bytes whose length is at least a specific number of bytes.- Parameters:
buffer- the Buffer whose data property value is to be validatednewSize- the minimum length of the array of byte which is to be the value of the data property of bufferarraycopy- true to copy the bytes which are in the value of the data property of buffer at the time of the invocation of the method if the value of the data property of buffer is an array of byte whose length is less than newSize; otherwise, false- Returns:
- an array of bytes which is the value of the data property of buffer and whose length is at least newSize number of bytes
-
close
public void close()
- Specified by:
closein interfacejavax.media.PlugIn- Overrides:
closein classnet.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.ResourceUnavailableExceptionOpens this Codec and acquires the resources that it needs to operate. A call toPlugIn.open()on this instance will result in a call to doOpen only ifAbstractCodec.openedis 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 inBuf, javax.media.Buffer outBuf)
-
getMatchingOutputFormats
protected javax.media.Format[] getMatchingOutputFormats(javax.media.Format inputFormat)
Gets the Formats which are supported by this Codec as output when the input is in a specific Format.- Parameters:
inputFormat- the Format of the input for which the supported output Formats are to be returned- Returns:
- an array of Formats supported by this Codec as output when the input is in the specified inputFormat
-
getName
public String getName()
- Specified by:
getNamein interfacejavax.media.PlugIn- Overrides:
getNamein classnet.sf.fmj.media.AbstractPlugIn
-
getSupportedOutputFormats
public javax.media.Format[] getSupportedOutputFormats(javax.media.Format inputFormat)
ImplementsAbstractCodec.getSupportedOutputFormats(Format).- Specified by:
getSupportedOutputFormatsin interfacejavax.media.Codec- Specified by:
getSupportedOutputFormatsin classnet.sf.fmj.media.AbstractCodec- Parameters:
inputFormat- input format- Returns:
- array of supported output format
- See Also:
AbstractCodec.getSupportedOutputFormats(Format)
-
open
public void open() throws javax.media.ResourceUnavailableExceptionOpens 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:
openin interfacejavax.media.PlugIn- Overrides:
openin classnet.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 inBuf, javax.media.Buffer outBuf)Implements AbstractCodec#process(Buffer, Buffer).- Specified by:
processin interfacejavax.media.Codec- Specified by:
processin classnet.sf.fmj.media.AbstractCodec- Parameters:
inBuf-outBuf-- Returns:
- BUFFER_PROCESSED_OK if the specified inBuff was successfully processed or BUFFER_PROCESSED_FAILED if the specified was not successfully processed
- See Also:
AbstractCodec.process(Buffer, Buffer)
-
setInputFormat
public javax.media.Format setInputFormat(javax.media.Format format)
- Specified by:
setInputFormatin interfacejavax.media.Codec- Overrides:
setInputFormatin classnet.sf.fmj.media.AbstractCodec
-
setOutputFormat
public javax.media.Format setOutputFormat(javax.media.Format format)
- Specified by:
setOutputFormatin interfacejavax.media.Codec- Overrides:
setOutputFormatin classnet.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 offormat- the Format to set on outputBufferlength- the length to set on outputBufferoffset- the offset to set on outputBuffer
-
validateShortArraySize
protected short[] validateShortArraySize(javax.media.Buffer buffer, int newSize)
-
-