MediaCodec在解码期间崩溃

时间:2017-01-31 14:24:27

标签: android udp android-mediaplayer h.264 mediacodec

我正在尝试通过udp播放来自vlc的H264流的视频。

但到目前为止还没有取得任何成功。 我从这个例子EncodeDecodeTest.java中引用但仍然无法正常工作

http://bigflake.com/mediacodec/

在发生异常之前的详细信息

    E/VDO_LOG: [Vdec_Drv_H264_open] VAL_CHIP_NAME_MT6752, VAL_CHIP_NAME_MT6582, VAL_CHIP_NAME_MT8135, VAL_CHIP_NAME_MT6592, VAL_CHIP_NAME_MT8127, VAL_CHIP_NAME_ROME
    E/VDO_LOG: [Err] invalid NALU - 1 18 47 170 90!!
     E/VDO_LOG: [Err] invalid NALU - 1 224 2 10 128!!
     E/VDO_LOG: [Err] invalid NALU - 1 234 107 24 1!!
     E/VDO_LOG: [Err, h264_dec_init] Fail to open Vdec Drv H264 instance! -11
     E/VDO_LOG: [Err] Error code -10
     E/MtkOmxVdec: [0xb7a47e38] Error!! Cannot init driver
     E/VDO_LOG: [Err, h264_dec_deInit] Invalid input argument
     E/M4U_L: ~MTKM4UDrv 66.
     E/VDO_LOG: [eHalEMICtrl]Profile_Change(BWCPT_VIDEO_PLAYBACK, false)
    [BWC INFO](29451): get_bwc_mm_property success
    [BWC INFO](29451): BWC_SETTING::DumpInfo-------
     [BWC INFO](29451):          sensor_size =      0 x      0
     [BWC INFO](29451):              vr_size =    320 x    560
    [BWC INFO](29451):            disp_size =      0 x      0
     [BWC INFO](29451):              tv_size =      0 x      0
    [BWC INFO](29451):                  fps =      0
    [BWC INFO](29451):      venc_codec_type =      0
   [BWC INFO](29451):      vdec_codec_type =      2
     [BWC INFO](29451): ----------------------------
    [BWC INFO](29451): Read DDR type string:LPDDR3
   [BWC INFO](29451): DDR Type = 2
     [BWC INFO](29451): smi_bw_ctrl_set: scen 2, turn off
     [BWC INFO](29451): emi_bw_ctrl_set: CON_SCE_VP OFF
    [BWC INFO](29451): set_bwc_mm_property: propterty_id=0, value1=0, value2=0
     [BWC INFO](29451): Profile_Change:[BWCPT_VIDEO_PLAYBACK]:OFF,current concurrency is 0x0

异常

     E/VDO_LOG: [eValDeInit] close VCodec_ValFd, VCodec_ValFd = -1
     E/VDO_LOG: [ERROR] fail to open mcdi_file
     E/MtkOmxVdec: [0xb7a47e38] InitVideoDecodeHW failed
     E/MtkOmxVdec: [0xb7a47e38] something wrong when decoding....
     E/ACodec: [OMX.MTK.VIDEO.DECODER.AVC] ERROR(0x80001005)
     E/ACodec: signalError(omxError 0x80001005, internalError -2147483648)
     E/MediaCodec: Codec reported err 0xfffffbb1, actionCode 0, while in state 6
     E/AndroidRuntime: FATAL EXCEPTION: Thread-2966
    Process: com.rvale.videocodec, PID: 29410
    java.lang.IllegalStateException
         at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
         at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:1041)
         at com.rvale.videocodec.VideoPlayer$MediaCodecThread.run(VideoPlayer.java:432)

媒体编解码器配置

try {
            mediaCodec = MediaCodec.createDecoderByType("video/avc");
        } catch (IOException e) {
            e.printStackTrace();
        }

        mediaFormat=MediaFormat.createVideoFormat("video/avc", 464,290);//new MediaFormat();


         mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE,23);
        MediaCodecInfo mediaCodecInfo=selectCodec(MediaFormat.MIMETYPE_VIDEO_AVC);
        int colorFormat = selectColorFormat(mediaCodecInfo, MediaFormat.MIMETYPE_VIDEO_AVC);
       //mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,colorFormat);
        info = new MediaCodec.BufferInfo();
        assert mediaCodec != null;
        mediaCodec.configure(mediaFormat,getHolder().getSurface(),null,0);

这就是我如何提供解码器,添加NAL Start,如本文所述

How to process raw UDP packets so that they can be decoded by a decoder filter in a directshow source filter

public void feedToDecoder(byte[] buffer)
    {

        byte[] combined=new byte[NAL_START.length+buffer.length];
         System.arraycopy(NAL_START,0,combined,0,NAL_START.length);
         System.arraycopy(buffer,0,combined,NAL_START.length,buffer.length);
         int inputBufferId = mediaCodec.dequeueInputBuffer(-1);
        if (inputBufferId >= 0) {
            ByteBuffer inputBuffer = mediaCodec.getInputBuffer(inputBufferId);
            // fill inputBuffer with valid data
             inputBuffer.put(ByteBuffer.wrap(combined));
            mediaCodec.queueInputBuffer(inputBufferId, 0,buffer.length,info.presentationTimeUs,0);
        }
        info.presentationTimeUs+=1;
    } 

Deqeue Buffer

MediaCodec.BufferInfo bufferInfo=new MediaCodec.BufferInfo();
        while(decoding)
        {
            bufferInfo.presentationTimeUs+=1;
            int outputBufferId = mediaCodec.dequeueOutputBuffer(bufferInfo,-1);
            if (outputBufferId >= 0) {
                ByteBuffer outputBuffer = mediaCodec.getOutputBuffer(outputBufferId);
                 mediaCodec.releaseOutputBuffer(outputBufferId, true);

            } else if (outputBufferId == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
                // Subsequent data will conform to new format.
                // Can ignore if using getOutputFormat(outputBufferId)
            }
        }

PS:我尝试解码在线数据包并成功提取,我在将其提供给解码器之前删除了前28个字节。

为什么发生此异常以及如何解决?

图像在解码的初始阶段 image

0 个答案:

没有答案