3

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!

J.Ney
  • 171
  • 1
  • 10

2 Answers2

4

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.

Ankit Wala
  • 59
  • 7
0

I had a similar problem to this but with a video encoder. I resolved my problem by messing around with my video's bit-rate until it worked. For now, I have settled my issue with a bit-rate of 32 * width * height * frameRate / 100. So I would recommend trying to mess with your bit-rate.

I was influenced by this answer to arrive at this solution.

Community
  • 1
  • 1
Grant
  • 373
  • 3
  • 14
  • I have tried changing `int bitrate = 450000;` to `int bitrate = 32*resultHeight*resultWidth*25 / 100;` but it still didn't work at all. I am getting [this](https://github.com/Tourenathan-G5organisation/SiliCompressor/issues/16) same error. – Narendra Singh Jul 11 '17 at 11:00