NativeDecoderpublic class NativeDecoder extends AudioCodec
Fields Summary |
---|
public static final String | a_copyright_notice
Licensed Materials - Property of IBM
"Restricted Materials of IBM"
5746-SM2
(c) Copyright IBM Corporation 1997,1998 All Rights Reserved
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with
IBM Corporation. | static final int | MAX_MPEG_STREAM_FRAME_SIZE | static final int | MAX_PCM_FRAME_SIZE | static final int | INTERNAL_BUFFER_LEN | static final int | DECODE_ONE_FRAME_ONLY | static final int | DECODE_MANY_FRAMES | static final int | MPEG_CD_QUALITY | static final int | MPEG_HIGH_QUALITY | static final int | MPEG_MEDIUM_QUALITY | static final int | MPEG_NOERROR | static final int | MPEG_ERROR | private int | mpegAudioQuality | private int | one_frame_flag | private long[] | pdata | private int[] | samp_freq | private int[] | stereo | private int[] | in_bytes_read | private int[] | num_samples_done | private byte[] | internalBuffer | private int | internalBufferDataLen |
Constructors Summary |
---|
public NativeDecoder()
////////////////////////////////////////////////////////////////////////////
// Methods
supportedInputFormats = new AudioFormat[] { new AudioFormat(AudioFormat.MPEG) };
defaultOutputFormats = new AudioFormat[] { new AudioFormat(AudioFormat.LINEAR) };
PLUGIN_NAME="MPEG Decoder";
|
Methods Summary |
---|
public void | close()
mpeg_terminate (pdata[0]);
| protected javax.media.Format[] | getMatchingOutputFormats(javax.media.Format in)
AudioFormat af =(AudioFormat) in;
supportedOutputFormats = new AudioFormat[] {
new AudioFormat(
AudioFormat.LINEAR,
af.getSampleRate(),
16,
af.getChannels(),
AudioFormat.LITTLE_ENDIAN, //isBigEndian(),
AudioFormat.SIGNED //isSigned());
) };
return supportedOutputFormats;
| private static native int | mpeg_audio_decode(long pdata, byte[] in_buf_byte, int in_buf_offset, int in_buf_len, byte[] out_buf_byte, int out_buf_offset, int out_buf_len, int one_frame_flag, int[] num_samples_done, int[] in_bytes_read, int[] samp_freq, int[] stereo)
| private static native int | mpeg_initialization(long[] pdata, int mpeg_quality)
| private static native int | mpeg_terminate(long pdata)
| public void | open()
try {
JMFSecurityManager.loadLibrary("jmutil");
JMFSecurityManager.loadLibrary("jmmpega");
internalBufferDataLen = 0;
mpeg_initialization(pdata,mpegAudioQuality);
return;
} catch (Throwable t) {
System.out.println("Unable to load "+PLUGIN_NAME+"\n"+t);
}
throw new ResourceUnavailableException("Unable to load "+PLUGIN_NAME);
| public int | process(javax.media.Buffer inputBuffer, javax.media.Buffer outputBuffer)
if (!checkInputBuffer(inputBuffer) ) {
return BUFFER_PROCESSED_FAILED;
}
if (isEOM(inputBuffer) ) {
propagateEOM(outputBuffer);
return BUFFER_PROCESSED_OK;
}
int inpLength=inputBuffer.getLength();
int outLength=44100*40; /* default output is 1 second of 44.1Khz stereo */ // *40 is arbitray
int rc, returnResult = 0;
byte[] inpData = (byte[]) inputBuffer.getData();
byte[] outData = validateByteArraySize(outputBuffer, outLength);
/* fill input data */
if (INTERNAL_BUFFER_LEN - internalBufferDataLen > inpLength) {
System.arraycopy(inpData, inputBuffer.getOffset(),
internalBuffer, internalBufferDataLen, inpLength);
internalBufferDataLen += inpLength;
} else {
returnResult |= INPUT_BUFFER_NOT_CONSUMED;
}
/* decode */
rc = mpeg_audio_decode (pdata[0],
internalBuffer, 0, internalBufferDataLen ,
outData, 0, outData.length,
one_frame_flag, num_samples_done,
in_bytes_read, samp_freq, stereo);
if (rc != MPEG_NOERROR) {
// System.out.println("MPEG Audio decoder error");
return (returnResult | BUFFER_PROCESSED_FAILED);
}
/* if read too much, due to incomplete frame, do not crash */
if (in_bytes_read[0] > internalBufferDataLen) {
//if (in_bytes_read[0]-10 > internalBufferDataLen) { // few bytes can be over-read in the dll in end-of-stream...
// System.out.println("PROBLEM in Mpeg Audio Decoder: too many bytes have been decoded");
//}
in_bytes_read[0] = internalBufferDataLen;
}
/* meanwhile, always shift data to buf start (not so efficient...) */
System.arraycopy(internalBuffer, in_bytes_read[0],
internalBuffer, 0,
internalBufferDataLen - in_bytes_read[0]);
/* update */
internalBufferDataLen -= in_bytes_read[0];
outLength = num_samples_done[0] << 1; // number of bytes
if (outLength > 0) {
updateOutput(outputBuffer, outputFormat, outLength, 0);
} else {
returnResult |= OUTPUT_BUFFER_NOT_FILLED;
}
return (returnResult | BUFFER_PROCESSED_OK);
| public void | reset()
close();
try {
open();
} catch (Exception e) {
}
|
|