This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Input data of DM368 h.264 decoder

Hi all:

    I can use cmd "./moduletest.out alg_vidDec"  to decode a h.264 file well,

now I modify the ALG_vidDecTestMain function to build my own h.264 decoder function for real time stream,

but the output video is not good, it will have some Remnant shade and wrongcolor when video is moving,

it only look better in static video, so I guess, it maybe get wrong input data for decoder,

 

 

Now, I can get h.264 data from openRTSP,

step 1- 00 00 00 01 67 ...

step 2- 00 00 00 01 68 ...

step 3- 00 00 00 01 65 ...

step 4 - 00 00 00 01 61 ...

step 5- 00 00 00 01 61 ... 

I will get 00 00 00 01 61 (like step  4 and 5) about 29 times and then return to step 1 for a cycle.

 

My input data is as follow

step 1 input data - 00 00 00 01 67 ... 00 00 00 01 68 ... 00 00 00 01 65 at first time (size about 5xxxx )

step 2. input data - 00 00 00 01 61 ... (size about 1xxxx)

step 3 input data - 00 00 00 01 61 ... (size about 1xxxx)

the data of 00 00 00 01 61 will be 29 times and then return step 1 for a cycle

can I input the above data style to decoder?

 

 

My function code is as follow

////////////////////////////////////////////////////

totalDecSize = 0;
  bufId=0;
  count=0;

   whOffset = 96;
  decodeId=0;


 //while(totalDecSize < fbuff_size) {                                               //  I mask the while loop and every data input to decoder only one time

          decPrm.inAddr         = curInAddr;
            decPrm.outAddr        = outVirtAddr[bufId];
            decPrm.inDataSize     = 100*KB;
            decPrm.outOffsetH     = OSA_align(720+whOffset, 32);                     //My resolution is D1
            decPrm.outOffsetV     = 480+whOffset;                                                //My resolution is D1
            decPrm.inputBufId     = bufId;
         OSA_prfBegin(&gAVSERVER_ctrl.decodePrf[decodeId]);

        status = ALG_vidDecRun(gVIDEO_ctrl.decodeStream[decodeId].algDecHndl, &decPrm, &decStatus);
        OSA_prfEnd(&gAVSERVER_ctrl.decodePrf[decodeId], 1);
       

    if(status==OSA_SOK) {
        / /OSA_printf(" ALG: VidDec: ALG_vidDecRun() : OK  \n");
    //  curInAddr += decStatus.bytesUsed;
    //  totalDecSize += decStatus.bytesUsed;

     
    } else {
   
      OSA_printf(" ALG: VidDec: ALG_vidDecRun() ERROR !!!\n");
    //  break;
    }
   

/*   bufId ^= 1;
    count++;
    if(count>10000)

      break;*/

         ALG_vidDecDisplayCopy(
            outVirtAddr[decStatus.outputBufId],
            outPhysAddr[decStatus.outputBufId],
            &decStatus);

///////////////////////////////////////////////////////////////////////////////////////////

Can anyone give me some advise?  Thanks a lot.

  • Hi,

    This issue is because of not having sufficient buffers in DPB(used for output and reference buffer). can you try by increasing dbp size allocation?

  •  

    Hi Veeranna Hanchinal:

        Thanks for your reply, I try to modify the buff size, but it still don't work well.

    I modify the buff size in alg_vidDec.c->Alg_vidDecRun()

    ////////////////////////////////////

    outArgs.decodedBufs.bufDesc[0].bufSize = 1000000;                 //modfiy buff size
    outArgs.decodedBufs.bufDesc[1].bufSize = 500000;                   //modfiy buff size

      status = VIDDEC2_process(pObj->hDecode, &inBufDesc, &outBufDesc, &inArgs, &outArgs);

    ///////////////////////////////////

    Is it correct? My input resolution is 720x480(D1) and the original buff size are 589824(buff 0) and 294912(buff1).

     

    By the way, I find one situation, when I move direction from top to bottom, the video will bad.

    but if I move direction from bottom to top, it looks like good.

    If I don't move anything, the video is very well.

    Do you have any idea for this situation?

    Pic1: Direction: Top->Bottom

     

    Pic2: Directioon: Bottom->Top

     

    Pic3: Don't move

     

     

    Pic4: Diection: Left->Right

     

  • HI hirain hsieh,

    You needs to increase number of buffers in dpb, not the buffer size. Normally application has to initialize required number of buffs(used for reference buff and output buffers)or with respect to supported level limit of the decoder. Please see the testapp provided with decoder package, how buffers initialized  and assigned to decoder.

     

  • Hi Veeranna Hanchinal:

        Thanks for your reply, I try to modify alg_vidDec.c->ALG_vidDecRun()

    ///////////////////////////////////////

    XDAS_Int32      outBufSizeArray[4];    //from  2->4

    XDAS_Int8            *outBufPtrs[4];        //from  2->4

    outBufSizeArray[0] = (prm->outOffsetH)*(prm->outOffsetV);
      outBufSizeArray[1] = outBufSizeArray[0]/2;
      outBufSizeArray[2] = outBufSizeArray[0]/2;                      //  I increase this buff
      outBufSizeArray[3] = outBufSizeArray[0]/2;                      //  I increase this buff

     

    outBufPtrs[0] = (XDAS_Int8 *)prm->outAddr;         
      outBufPtrs[1] = (XDAS_Int8 *)(prm->outAddr + outBufSizeArray[0]) ;          
      outBufPtrs[2] = (XDAS_Int8 *)(prm->outAddr + outBufSizeArray[0]*2) ;           //  I increase this buff
      outBufPtrs[3] = (XDAS_Int8 *)(prm->outAddr + outBufSizeArray[0]*3) ;           //  I increase this buff

     

    outBufDesc.numBufs      = 4;                //from 2->4

    /////////////////////////

    but it will show "ALG: VidDec: ALG_vidDecRun() ERROR !!!"

    Is my step right?

    This is my first time to use decoder on DM368 ipnc, Very sorry about this.

  • Hi,

    I wanted say number of buffers in DBP, these buffers will be used for reference buffer and output buffers.  Your modifications are not correct, the function 'ALG_vidDecTestMain' meant for file based test application, it doesn't  have buffer management to handle buffers. You can refer encoder '/av_server/src/video/videoEncodeThr.c' file to create decoder thread and buffer management.

    BTW which encoder's stream you are using? Are you using TI's encoder? please share all parameters of encoder and decoder?

  • Hi Veeranna Hanchinal:

        Thanks for your reply.  I am using TI's decoder but my input stream which is getting by openRTSP.

    Decoder version is H264DEC.version.02.00.00.05.wizardversion.0.5.3

    According to your advise, I try to find the buff management and find something strange.

    When I use test function for a file decoder, the runStatus.outputBufId will be 0 or 1 in "ALG_vidDecRun(algVidDecHndl, &runPrm, &runStatus);" return value.

    but if I use my own real time stream, the runStatus.outputBufId will be 0 and -1(if using buff 2)

    I have already try to increase output buff from 2 to 4, but the runStatus.outputBufId will be 0, -1, -1 -1 and not 0, 1, 2 , 3.

    They are using the same ALG_vidDecRun function, so I think it maybe something wrong with my setting,

    Can you help me to check?

    My input and output stream are D1.

    ///////////////////////////////////////////

    1.allocate when thread create

    Uint8 * curInAddr,*outVirtAddr[4], *outPhysAddr[4],*inPhysAddr;     //global var


    int VIDEO_decodeTskCreate()
    {
      int i, captureStreamId;
      ALG_VidDecCreate createPrm;

     Uint32 size=1*MB, fileSize, totalDecSize;
     

     V_addr.inVirtAddr0     =OSA_cmemAlloc(size, 32);


      outVirtAddr[0] = OSA_cmemAlloc(2*MB, 32);
      outVirtAddr[1] = OSA_cmemAlloc(2*MB, 32);
      outVirtAddr[2] = OSA_cmemAlloc(2*MB, 32);
      outVirtAddr[3] = OSA_cmemAlloc(2*MB, 32);
     

      outPhysAddr[0] = OSA_cmemGetPhysAddr(outVirtAddr[0]);
      outPhysAddr[1] = OSA_cmemGetPhysAddr(outVirtAddr[1]);
      outPhysAddr[2] = OSA_cmemGetPhysAddr(outVirtAddr[2]);
      outPhysAddr[3] = OSA_cmemGetPhysAddr(outVirtAddr[3]);

     

      memset(outVirtAddr[0], 0xFF, 2*MB);
      memset(outVirtAddr[1], 0xFF, 2*MB);
     memset(outVirtAddr[2], 0xFF, 2*MB);
      memset(outVirtAddr[3], 0xFF, 2*MB);
     
      OSA_prfReset(&gAVSERVER_ctrl.decodePrf[0]);

     
      createPrm.codec           = ALG_VID_CODEC_H264;
      createPrm.dataFormat      = DRV_DATA_FORMAT_YUV420;
      createPrm.maxWidth        = 720;
      createPrm.maxHeight       = 480;

     
      gVIDEO_ctrl.decodeStream[0].algDecHndl  = ALG_vidDecCreate(&createPrm);
      
      return OSA_SOK;
    }

     

     

    2. run decoder function in real time

          curInAddr = V_addr.inVirtAddr0;
      
          totalDecSize = 0;
          bufId=0;
          count=0;

           whOffset = 96;
     
         
     while(totalDecSize < fbuff_size) {

              decPrm.inAddr         = curInAddr;
                decPrm.outAddr        = outVirtAddr[bufId];
                decPrm.inDataSize     = 100*KB;
                decPrm.outOffsetH     = OSA_align(720+whOffset, 32);
                decPrm.outOffsetV     = 480+whOffset;
                decPrm.inputBufId     = bufId;
             OSA_prfBegin(&gAVSERVER_ctrl.decodePrf[0]);

            status = ALG_vidDecRun(gVIDEO_ctrl.decodeStream[0].algDecHndl, &decPrm, &decStatus);      //decStatus.outputBufId is very strange
            OSA_prfEnd(&gAVSERVER_ctrl.decodePrf[0], 1);
          

        if(status==OSA_SOK) {

          curInAddr += decStatus.bytesUsed;
          totalDecSize += decStatus.bytesUsed;
       
        } else {
       
          OSA_printf(" ALG: VidDec: ALG_vidDecRun() ERROR !!!\n");
          break;
        }

     
        //bufId ^= 1;                 //using for 2 buff
        bufId += 1;                 //using for 4 buff
        if(bufId>3)
        bufId=0;
        count++;
        if(count>10000)
          break;
         
             ALG_vidDecDisplayCopy(
                outVirtAddr[decStatus.outputBufId],
                outPhysAddr[decStatus.outputBufId],
                &decStatus);

     }

    //////////////////////////////////////

    Do you have any advise for me? Thanks a lot.

  • Hi 

    Can you please share your complete createtime and dynamic parameters of decoder? Are you using Closedloop decoder? and what is the value of displayDelay, Are you using base param mode? if yes value of displayDelay parameter will be 16, after encoding 16 frames your outputID will get set to valid buffer ID.

    When you use file based decoder are you seeing valid outputID just after first frame process call? Please share both streams(one used for file based decoder and other is openRTSP stream) . And also check is decoder returning any errors and outArgs.viddecOutArgs.bytesConsumed

     

  • Hi Veeranna Hanchinal:

       Thanks for your reply.  My setting parameters are as follow

    ///////////////////

    1. create

      pObj->params.size               = sizeof(VIDDEC2_Params);
      pObj->params.maxHeight          = 720;
      pObj->params.maxWidth           = 480;
      pObj->params.maxFrameRate       = 0;
      pObj->params.maxBitRate         = ALG_VID_DEC_MAX_BITRATE;      // 4*1024*1024
      pObj->params.dataEndianness     = XDM_BYTE;
      pObj->params.forceChromaFormat  = XDM_YUV_420SP;

      pObj->h264Params.displayDelay = 0;
      pObj->h264Params.hdvicpHandle = NULL;
    //  pObj->h264Params.resetHDVICPeveryFrame = TRUE;
      pObj->h264Params.disableHDVICPeveryFrame = 0;
      pObj->h264Params.frame_closedloop_flag = 1;
      pObj->h264Params.inputDataMode = 1;
      pObj->h264Params.sliceFormat = 1;
      pObj->h264Params.viddecParams = pObj->params;
      pObj->h264Params.viddecParams.size = sizeof(pObj->h264Params);

    2. run time parameter setting at first

        pObj->dynamicParams.size          = sizeof(VIDDEC2_DynamicParams);
        pObj->dynamicParams.decodeHeader  = XDM_DECODE_AU;
        pObj->dynamicParams.displayWidth  = prm->outOffsetH;                             //OSA_align(720+whOffset, 32);
        pObj->dynamicParams.frameSkipMode = IVIDEO_NO_SKIP;
        pObj->dynamicParams.frameOrder    = IVIDDEC2_DECODE_ORDER;

        pObj->decStatus.size     = sizeof(VIDDEC2_Status);
        pObj->decStatus.data.buf = NULL;
        h264DynParams.viddecDynamicParams = pObj->dynamicParams;
        h264DynParams.viddecDynamicParams.size = sizeof(h264DynParams);
        h264DynParams.resetHDVICPeveryFrame = 1;
        h264DynParams.dataSyncHandle = NULL;
        h264DynParams.getDataFxn = NULL;   

    //////////////////////////////////////////////////////

    I think I can get valid in file based decoder

    //for file based decoder

    I can get output ID 0  ->freeID 1

                    output ID 1  ->freeID 0  ....for the cycle until the file finish.

    //for real time streaming

    but I can only get the ouputID 0  -> freeID  0

                                       outputID -1  ->freeID 1  (if necessary) usually it only use buff 1

     

    I have an idea, will it possible I input wrong data,

    In file based decoder, it only input data at once and do while loop until the file finish

    the data is continual.

     

    In real time streaming based decoder,

    My step is as follow

    1. using openRTSP to save 30 frame for a cycle

          frame 1 data is include 00 00 00 01 67...00 00 00 01 68...00 00 00 01 65 .......(data size about 5xxxx)

          frame 2~30 data is include 00 00 00 01 61 ...(data size about 2xxxx)

       I use "fwrite" to write bin file in /tmp

    2. get data in deocder

        I use "fread" to read bin file when openRTSP have already saved  3frame data.

        And input read data in alg_vidDec();

    The data is non-continual.

    Is it the key point?

  • Hi hirain hsieh,

    You are using closedloop decoder mode(pObj->h264Params.frame_closedloop_flag = 1), you can't use this decoder for all streams. This decoder mode can only decode streams generated from TI's DM365/DM368 H264 encoder. So I guess decoder is returning error, please set pObj->h264Params.frame_closedloop_flag = 0 and try.

  • Hi Veeranna Hanchinal:

        Thanks for your reply,

    I get the file and real time streaming from another DM368 ipnc, so the encoder is using DM368

    and I don't see any error return.

    but I try to change closeloop flag from 1 to 0, it still work bad.

    Do you have another advise?

  • Hi Veeranna Hanchnal:

        I have already solve this problem,

    It's really DPB buff problem.

    In file based, the inputBufId will 0->1->0->1.. change

    so the freeBufId will 1->0->1->0..to show current free DPB ID,

    But in my real time streaming based,

    I will make the inputBufId become 0 every time,

    So it will unstable because it using the same buff.

    I modify the inputBufId and it work will.

    Thank you very much for your kindly help.

     

    BTW, I have another issue, It will hang up sometime and show "Bus error"

    I will try to fix it,

  • Hi,

    Its nice to know you video curruption issue is solved. And you are using little old version of decoder (02.00.00.05), Can you please use latest version available at below link.

     http://software-dl.ti.com/dsps/dsps_public_sw/codecs/DM36x/index_FDS.html

     

    Thanks,

    Veeranna