4

I am trying to play video from H264 stream coming from vlc over udp.

But not getting any success so far. I take reference from this example EncodeDecodeTest.java but still not working

http://bigflake.com/mediacodec/

Details Before Exception occured

    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

Exception

     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)

Media Codec Configuration

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

This is how I am Feeding to decoder, Adding NAL Start as mentioned in this post

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 : I tried to decode packet Online and it successfully extracted, I am removing first 28 bytes before feeding it to decoder.

Why this exception occurred and how to resolve it ?

Image At Initial phase of decoding image

Community
  • 1
  • 1
Rachit Solanki
  • 369
  • 6
  • 13
  • Does the exception happen right away or after awhile of decoding? For one thing, I don't see where you are calling [MediaCodec.start()](https://developer.android.com/reference/android/media/MediaCodec.html#start()). I think IllegalStateExceptions usually occur when the codec is stopped or improperly configured. – Grant Feb 09 '17 at 21:22
  • It happed some times after decoding, And I called MediaCodec.start in run method just above while loop, It rendered green screen for the first time then crashed – Rachit Solanki Feb 10 '17 at 18:11
  • Hey did you find any solution for this ?? – Aashit Shah Jan 07 '21 at 11:30

0 Answers0