I try to decode a mp3 audio data stream with Android Media Codec. With a sample rate of 44100 the decoding works fine, but the latency is too big. So I set the sample rate to 16000, but now the decoder doesn't work anymore. I get an Illegal State Exception at dequeueOutputBuffer.
This is the part of the code where the problem might be:
bufferInfo = new MediaCodec.BufferInfo();
outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, -1);
while (outputBufferIndex >= 0) {
outputBuffer = decoder.getOutputBuffer(outputBufferIndex);
outputBuffer.position(bufferInfo.offset);
outputBuffer.limit(bufferInfo.offset + bufferInfo.size);
outData = new byte[bufferInfo.size];
outputBuffer.get(outData);
track.write(outData, 0, outData.length);
decoder.releaseOutputBuffer(outputBufferIndex, false);
outputBufferIndex = decoder.dequeueOutputBuffer(bufferInfo, -1);
}
I also tried to set the timeout of dequeueOutputBuffer to 0 but this doesn't change anything.
This is the error I receive:
E/SoftMP3: mp3 decoder returned error 1
E/ACodec: [OMX.google.mp3.decoder] ERROR(0x80001001)
E/ACodec: signalError(omxError 0x80001001, internalError -2147483648)
E/MediaCodec: Codec reported err 0x80001001, actionCode 0, while in state 6
E/AndroidRuntime: FATAL EXCEPTION: Thread-79054
Process: com.example.jonas.audio_client, PID: 26394
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:1107)
If I print the Audio Format that the Extractor gets, I see that the Sample-Rate is set to 16000.
D/Format:: {bitrate=32000, mime=audio/mpeg, durationUs=6509000, channel-count=1, sample-rate=16000, bit-rate=32000}
Thanks for any help!
If you are running this on an emulator make sure that you have selected Graphics as Hardware : GLES 2.0 in Emulator settings. There is some issue with the Software version it seems.