3

I used mediacodec to play H264 stream,like this question: How do I feed H.264 NAL units to Android MediaCodec for decoding?

here is the code:

        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;
                }
        }

here is the crash log,it occurred after several times called 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)

It is a device dependent error,only happened on some devices,like note2 android4.4

Update 1: if I change the code

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

to

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

the crash log is this:

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

I don't understand why is this.Can I debug the MediaCodec C++ sourcecode?

Community
  • 1
  • 1
qqli
  • 196
  • 2
  • 6
  • Can you show the code you use to configure the decoder? Does this fail on the very first call to `dequeueInputBuffer()`, or on a later one? – fadden May 13 '15 at 16:07
  • Something isn't quite right. You're creating a decoder, which is used to convert a compressed H.264 video stream to a series of frames, but you're attempting to configure it with width/height values from the Camera. What is the source of the video? – fadden May 18 '15 at 01:50
  • @fadden,the camera is only an object that we customed,it is not the phone's Camera.The width/height is the video's width/height. I would extrated frame data from videoInputStream and then give it to the codec. – qqli May 18 '15 at 02:25
  • @fadden,I had some findings,I need to configure SPS and PPS for this H.264 video.These questions had helped me: (1)http://stackoverflow.com/questions/19742047/how-to-use-mediacodec-without-mediaextractor-for-h264; (2)http://stackoverflow.com/questions/15305241/how-do-i-feed-h-264-nal-units-to-android-mediacodec-for-decoding – qqli May 21 '15 at 02:02

0 Answers0