MediaCodec dequeueInputBuffer对sumsung s3 android4.4的IllegalStateException

时间:2015-05-13 10:02:33

标签: android mediacodec

我使用mediacodec播放H264流,就像这个问题一样: How do I feed H.264 NAL units to Android MediaCodec for decoding?

这是代码:

        videoDecoder = MediaCodec.createDecoderByType("video/avc");
        MediaFormat format = MediaFormat.createVideoFormat("video/avc", camera.getResolutionWidth(), camera.getResolutionHeight());
        videoDecoder.configure(format, surface, null, 0);
        videoDecoder.start();

        ByteBuffer[] inputBuffers = videoDecoder.getInputBuffers();
        ByteBuffer[] outputBuffers = videoDecoder.getOutputBuffers();
        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();

    while(enabled){
                int inIdx = videoDecoder.dequeueInputBuffer(10000000);
                if (inIdx >= 0) {
                    Log.d("0-0","----------inIdx = "+inIdx);
                    ...
                    videoDecoder.queueInputBuffer(inIdx, 0, mframe.getlength(), 0, 0);
                } else {
                    continue;
                }

                int outIdx = videoDecoder.dequeueOutputBuffer(info, 10000);
                Log.d("0-0","----------outIdx = "+outIdx);
                switch (outIdx) {
                    case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
                        outputBuffers = videoDecoder.getOutputBuffers();
                        break;
                    case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
                        break;
                    default:
                        ByteBuffer buffer = outputBuffers[outIdx];
                        videoDecoder.releaseOutputBuffer(outIdx, true); 
                        break;
                }
        }

这里是崩溃日志,它在多次调用dequeueInputBuffer()之后发生:

05-13 17:20:46.425    1932-5728/? E/MFC_DEC_APP﹕ SsbSipMfcDecInit] IOCTL_MFC_DEC_INIT failed
05-13 17:20:46.425    1932-5728/? E/SEC_H264_DEC﹕ SsbSipMfcDecInit() failed!
05-13 17:20:46.425    4682-5724/com.test.mytest E/ACodec﹕ [OMX.SEC.avc.dec] ERROR(0x90000004)
05-13 17:20:46.425    4682-5723/com.test.mytest E/MediaCodec﹕ Codec reported an error. (omx error 0x90000004, internalError -2147483648)
05-13 17:20:46.425    4682-5720/com.test.mytest W/dalvikvm﹕ threadid=40: thread exiting with uncaught exception (group=0x41fd5c08)
05-13 17:20:46.425    4682-5720/com.test.mytest E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-1403
Process: com.test.mytest, PID: 4682
java.lang.IllegalStateException
        at android.media.MediaCodec.dequeueInputBuffer(Native Method)

这是设备相关的错误,只发生在某些设备上,例如note2 android4.4

更新1: 如果我改变代码

  int outIdx = videoDecoder.dequeueOutputBuffer(info, 10000);

  int outIdx = videoDecoder.dequeueOutputBuffer(info, 10000000);

崩溃日志是这样的:

java.lang.IllegalStateException
        at android.media.MediaCodec.dequeueOutputBuffer(Native Method)

我不明白为什么会这样。我可以调试MediaCodec C ++源代码吗?

0 个答案:

没有答案