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.

Alg_vidDec doesn't work (urgent)

Other Parts Discussed in Thread: TVP5158

Hi,

I designed our application based on MCVIP of av_capture framework. (UDWorks reference design)

Alg_vidEnc is ok and the recorded bitstream file (h264) can be decode by VLC or other player on windows without any warning.

I tried to design the decode_tsk to decode the bitstream file(h264).

There is no error message output from ALG_vidDecRun(), but Alg_vidDec doesn't work well.

The following message is one of our decoding cases. The input image is 704x480@h264 frame.

The size of first frame is "19787" bytes. After decoding by the Alg_vidDec, the runStatus.bytesUsed always is 115 bytes (if it is any Keyframe and start code is "00 00 00 01 27").

It doest not be a same small value and the decoded result is bad.

 

[output message]

Creating ALG_vidDec (codec=0, width=720, height=480)
 DECODE: 0: 4a0c8000 (0, 19787) -> 4a113000 (800x576, 0)
00 00 00 01 27 64 00 1E AD 88 0E 43 98 20 E1 0C 29 0A 44 07 21 CC 10 70 86 14 85 22 03 90 E6 08
ALG: VidDec: XDM_GETBUFINFO: min out bufs:2,size:405504 202752
 DECODE: 0:0:-1:0x0:0: 115 bytes (276, 5160941)
 DECODE: 1: 4a0c8073 (115, 19672) -> 4a1f4000 (800x576, 1)
00 00 01 25 88 85 0B FF F0 A6 7A 41 70 3F 81 E8 B7 E9 57 DD 18 76 70 80 75 B6 6E 48 1A F1 9B 05
 DECODE: 1:1:-1:0x0:0: 6 bytes (276, 5160941)
 DECODE: 2: 4a0c8079 (121, 19666) -> 4a2d5000 (800x576, 2)
0B FF F0 A6 7A 41 70 3F 81 E8 B7 E9 57 DD 18 76 70 80 75 B6 6E 48 1A F1 9B 05 88 28 5B F4 CB B3
 DECODE: 2:2:-1:0x0:0: 10372 bytes (276, 5160941)
 DECODE: 3: 4a0ca8fd (10493, 9294) -> 4a113000 (800x576, 0)
00 00 01 21 88 86 7F F4 21 DE 9B 27 8B FC 17 08 4A 95 0C 00 5C 4D 12 BC CE DC 09 01 13 74 FB 2F
 DECODE: 0:0:-1:0x0:0: 6 bytes (276, 5160941)
 DECODE: 4: 4a0ca903 (10499, 9288) -> 4a1f4000 (800x576, 1)
7F F4 21 DE 9B 27 8B FC 17 08 4A 95 0C 00 5C 4D 12 BC CE DC 09 01 13 74 FB 2F 0A 85 FC CB FB EE
 DECODE: 1:1:-1:0x0:0: 9288 bytes (276, 5160941)

[Alg_vidDec initial parameters]

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

[source]

static int DECODE_decode(int inDataSize)
{
    int status = OSA_SOK, whOffset;
    ALG_VidDecRunPrm runPrm;
    ALG_VidDecRunStatus runStatus;
    Uint8 *inAddr;

    inAddr = gDECODE_ctrl.inBufVirtAddr;

    whOffset = 0;
    if(gDECODE_ctrl.createPrm.codec == ALG_VID_CODEC_H264)
        whOffset = 96;

    gDECODE_ctrl.inDataOffset = 0;
    do { // recursive decode if there is remained data


        runPrm.inAddr         = inAddr + gDECODE_ctrl.inDataOffset;
        runPrm.outAddr        = gDECODE_ctrl.decBufVirtAddr[gDECODE_ctrl.curDecBufId];
        runPrm.inDataSize     = inDataSize - gDECODE_ctrl.inDataOffset;
        runPrm.outOffsetH     = OSA_align(gDECODE_ctrl.createPrm.maxWidth + whOffset, 32);
        runPrm.outOffsetV     = gDECODE_ctrl.createPrm.maxHeight + whOffset;
        runPrm.inputBufId     = gDECODE_ctrl.curDecBufId;
   
        OSA_prfBegin(&gDECODE_ctrl.prfDec);
   
    #define DECODE_DEBUG_RUNNING
    #ifdef DECODE_DEBUG_RUNNING
        OSA_printf(" DECODE: %d: %08x (%d, %d) -> %08x (%dx%d, %d)\n",
                   gDECODE_ctrl.frameCount,
                   (Uint32)runPrm.inAddr,
                   gDECODE_ctrl.inDataOffset,
                   runPrm.inDataSize,
                   (Uint32)runPrm.outAddr,
                   runPrm.outOffsetH,
                   runPrm.outOffsetV,
                   runPrm.inputBufId
                  );
    #endif
        int i;
        for(i=0; i<32; ++i)
            printf("%02X ", runPrm.inAddr[i]);
        printf("\n");
        status = ALG_vidDecRun(gDECODE_ctrl.algVidDecHndl, &runPrm, &runStatus);
        printf("\n");
   
        OSA_prfEnd(&gDECODE_ctrl.prfDec, 1);
   
    #ifdef DECODE_DEBUG_RUNNING
        OSA_printf(" DECODE: %d:%d:%d:%dx%d:%d: %d bytes (%d, %d)\n",
                   runStatus.freeBufId,
                   runPrm.inputBufId,
                   runStatus.outputBufId,
                   runStatus.frameWidth, runStatus.frameHeight,
                   runStatus.isKeyFrame,
                   runStatus.bytesUsed,
                   runStatus.outStartX,
                   runStatus.outStartY
                  );
    #endif
   
        gDECODE_ctrl.frameCount++;
   
        if(status == OSA_SOK)
        {
            gDECODE_ctrl.inDataOffset += runStatus.bytesUsed;
   
            if(runStatus.outputBufId >= 0 && runStatus.outputBufId < gDECODE_ctrl.decBufNum)
            {
                DECODE_displayCopy(
                    gDECODE_ctrl.decBufVirtAddr[runStatus.outputBufId],
                    gDECODE_ctrl.decBufPhysAddr[runStatus.outputBufId],
                    &runStatus
                );
            }
   
            gDECODE_ctrl.curDecBufId = (gDECODE_ctrl.curDecBufId + 1) % (gDECODE_ctrl.decBufNum);
        }
    }while( gDECODE_ctrl.inDataOffset < inDataSize);

    return status;
}

  • Hi,

    Just to confirm, what is the version of encoder and decoder that you are using? Does the regular DVR application provided in the DVR Reference Design (uimain) work well for video playback?

    Regards,

    Anshuman

  • Hi,

    We don't use the tvp5158, and I think that 'uimain' hardly runs on our EVM board without modifing.

    I tried ALG_vidDecTestMain that provides by alg_vidDec.c still get same bad result.

    I have been comparing the source code between us and udworks, but can't get any idea.

    Or I missed the configuration for dvsdk, kernel or alg library?

    Maybe I need a simple program that using the av_capture framework to decode 704x480@h264 correctly.

     

    [our system information]

    av_capture is grabbed from 1.0 udworks framework

    dvsdk_2_10_01_18

    linux-2.6.18_pro500

    [encode and decode version]

    I saw VIDENC1_xxx and VIDDEC2_xxx are used by alg_vidEnc and alg_vidDec.

    How to check right version of codec?

     

  • [alg_server.cfg]

    var osalGlobal = xdc.useModule('ti.sdo.ce.osal.Global');
    osalGlobal.runtimeEnv = osalGlobal.LINUX;

    environment['xdc.cfg.check.fatal'] = 'false';


    var RMAN = xdc.useModule('ti.sdo.fc.rman.RMAN');
    RMAN.useDSKT2 = false;
    RMAN.persistentAllocFxn = "__ALG_allocMemory";
    RMAN.persistentFreeFxn = "__ALG_freeMemory";
    RMAN.semCreateFxn = "Sem_create";
    RMAN.semDeleteFxn = "Sem_delete";
    RMAN.semPendFxn = "Sem_pend";
    RMAN.semPostFxn = "Sem_post";
    RMAN.tableSize = 10;
    RMAN.trace = true;
    RMAN.debug = true;


    var EDMA3 = xdc.useModule('ti.sdo.fc.edma3.Settings');
    EDMA3.globalInit = true;
    EDMA3.maxQdmaChannels = [10,10,10,10];
    EDMA3.trace = false;
    EDMA3.debug = false;



    var vicp = xdc.useModule('ti.sdo.linuxutils.vicp.VICP');
    vicp.debug = false;


    var HDVICP = xdc.useModule('ti.sdo.fc.ires.hdvicp.HDVICP');
    HDVICP.trace = false;
    HDVICP.debug = false;

    //Change this to VICP if the chip is not DM355
    var VICP = xdc.useModule('ti.sdo.fc.ires.vicp.VICP2');
    VICP.debug = true;

    var VICPSYNC = xdc.useModule('ti.sdo.fc.vicpsync.VICPSYNC');
    VICPSYNC.debug = false;



    var HDVICPSYNC = xdc.useModule('ti.sdo.fc.hdvicpsync.HDVICPSYNC');
    HDVICPSYNC.debug = false;
    HDVICPSYNC.trace = false;

    var VICP = xdc.useModule('ti.sdo.fc.memutils.MEMUTILS');



    DDRSPACE = xdc.useModule('ti.sdo.fc.ires.addrspace.ADDRSPACE');

    var EDMA3CHAN = xdc.useModule('ti.sdo.fc.ires.edma3chan.EDMA3CHAN');
    EDMA3CHAN.trace = false;
    EDMA3CHAN.debug = false;

    var LSP = xdc.useModule('ti.sdo.linuxutils.edma.EDMA');
    LSP.debug = false;

    var CMEM = xdc.useModule('ti.sdo.linuxutils.cmem.CMEM');

    var ALG_MEM = xdc.useModule('ti.sdo.ce.alg.Settings');
    ALG_MEM.useHeap = true;

    xdc.loadPackage("ti.sdo.ce.video2");
    xdc.loadPackage("ti.sdo.fc.hdvicpsync");

    /* This package provides mock implementation of Locks and Semaphores */
    /* var EX = xdc.useModule("ti.sdo.fc.rman.examples.EXAMPLE");*/
    /*EX.debug = false;*/
    /*
     *  ======== Engine Configuration ========
     */

    var MPEG4ENC = xdc.useModule('ti.sdo.codecs.mpeg4enc.ce.MPEG4ENC');
    var H264ENC = xdc.useModule('ti.sdo.codecs.h264enc.ce.H264ENC');
    var JPEGENC = xdc.useModule('ti.sdo.codecs.jpegenc.ce.JPEGENC');
    var G711ENC = xdc.useModule('ti.sdo.ce.examples.codecs.g711.G711ENC');

    var MPEG4DEC = xdc.useModule('ti.sdo.codecs.mpeg4dec.ce.MPEG4DEC');
    var H264DEC = xdc.useModule('ti.sdo.codecs.h264dec.ce.H264DEC');
    var JPEGDEC = xdc.useModule('ti.sdo.codecs.jpegdec.ce.JPEGDEC');
    var G711DEC = xdc.useModule('ti.sdo.ce.examples.codecs.g711.G711DEC');

    var Engine = xdc.useModule('ti.sdo.ce.Engine');
    var myEngine = Engine.create("alg_server", [

        {name: "mpeg4enc", mod: MPEG4ENC, local: true, groupId: 1},
        {name: "h264enc", mod: H264ENC, local: true, groupId: 1},
        {name: "jpegenc", mod: JPEGENC, local: true, groupId: 1},    
        {name: "g711enc", mod: G711ENC, local: true},
        {name: "mpeg4dec", mod: MPEG4DEC, local: true, groupId: 1},
        {name: "h264dec", mod: H264DEC, local: true, groupId: 1},
        {name: "jpegdec", mod: JPEGDEC, local: true, groupId: 1},    
        {name: "g711dec", mod: G711DEC, local: true},    

    ]);

    /* set the cache enabling feature of CE for ARM-side algos  - Required for audio decoder*/
    /*
    algSettings = xdc.useModule('ti.sdo.ce.alg.Settings');
    algSettings.useCache = true;
    */


    Program.main = null;

     

    it is our layout of dvsdk directory.

  • Hi,

    What is the displayDelay setting that you have done for H.264 Decoder Create time parameter?

    Regards,

    Anshuman

  • Hi,

    pObj->h264Params.displayDelay = 0;

    [It is the partial of source fromalg_vidDec.c]

    void *ALG_vidDecCreate(ALG_VidDecCreate *create)
    {
        ALG_VidDecObj *pObj;

        pObj = OSA_memAlloc(sizeof(*pObj));

        if(pObj == NULL)
            return NULL;

        memset(pObj, 0, sizeof(*pObj));

        memcpy(&pObj->createPrm, create, sizeof(pObj->createPrm));

        switch(create->codec)
        {
            case ALG_VID_CODEC_H264:
                strcpy(pObj->algName, ALG_VID_CODEC_H264_DEC_NAME);
                break;
            case ALG_VID_CODEC_MPEG4:
                strcpy(pObj->algName, ALG_VID_CODEC_MPEG4_DEC_NAME);
                break;
            case ALG_VID_CODEC_MJPEG:
            {
                ALG_JpgDecCreate jpgDecCreate;

                jpgDecCreate.dataFormat = create->dataFormat;
                jpgDecCreate.maxWidth = create->maxWidth;
                jpgDecCreate.maxHeight = create->maxHeight;

                pObj->hJpgDecode = ALG_jpgDecCreate(&jpgDecCreate);

                if(pObj->hJpgDecode == NULL)
                    return NULL;

                return pObj;
            }
            break;
            default:
                OSA_memFree(pObj);
                return NULL;
        }

        pObj->params.size               = sizeof(VIDDEC2_Params);
        pObj->params.maxHeight          = create->maxHeight;
        pObj->params.maxWidth           = create->maxWidth;
        pObj->params.maxFrameRate       = 0;
        pObj->params.maxBitRate         = ALG_VID_DEC_MAX_BITRATE;
        pObj->params.dataEndianness     = XDM_BYTE;
        pObj->params.forceChromaFormat  = 9;

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

        /* Create video decoder instance */
        pObj->hDecode = VIDDEC2_create(gALG_hEngine, pObj->algName, &pObj->h264Params);
        if (pObj->hDecode == NULL)
        {
            OSA_ERROR("Failed to open video decode algorithm (%s)\n", pObj->algName);
            OSA_memFree(pObj);
            return NULL;
        }

        return (void*)pObj;
    }

     

    Best Regards,

    Person

  • I tried to change the displayDelay to 16.

    It seems still gets same bad result. I am stuck.

  • Hi,

    I have couple of recommendations for you:

    1. Switch to ver 1.8 of DVR RDK. I have checked the alg_vidDec.c test code to ensure it works for the H.264 decoder.

    2. Refer to the attached alg_vidDec.c file and build it in your application. I just built and used it and it works reliably. You can use "moduletest.out alg_vidDec" and try decoding D1 stream. You might have to port this file for your software package.

    3. Share your stream with us and i can try decoding it in our setup, to ensure that the stream is fine.

    Regards,

    Anshuman

  • Hi,

    I will try your suggestion.

    The file is too big. How to send it for you.

    file size:2.40 MB

  • You can attach it to the forum post itself.

    Regards,

    Anshuman

  • Hi,

    I don't know how to attach the file. The image is ok, but the bistream file is not.

  • I tried the moduletest.out of DVRRDK_v1.0 and get result as following.

    [result]

    root@192.168.4.13:/dvr# ./moduletest.out alg_vidDec
    csl initialize
    vpss initialize

     CLK Hz,
     ARM   Hz =  297000000
     DDR   Hz =  243000000
     VPSS  Hz =  243000000
     IMCOP Hz =  243000000

    cmem initialize
    DavinciDisplay DavinciDisplay.1: Before finishing with S_FMT:
    layer.pix_fmt.bytesperline = 736,
     layer.pix_fmt.width = 720,
     layer.pix_fmt.height = 480,
     layer.pix_fmt.sizeimage =529920
     [OSA_FILE ] ReaDavinciDisplay DavinciDisplay.1: pixfmt->width = 720,
     layer->layer_info.config.line_length= 736
    ding file [test.264] ... Done. [2522727 bytes]
     ALG: VidDec: Opening display.
     ALG: VidDec: Decode in progress!!!
     ALG: VidDec: 0:0:-1:0x0:0: 115 bytes (436, 5147664)
     ERROR  (drv_frameCopy.c|DRV_frameCopy|59): Invalid Parameters!!!
     ERROR  (alg_vidDec.c|ALG_vidDecTestDisplayCopy|390): DRV_frameCopy(A)
     ALG: VidDec: 1:1:-1:0x0:0: 6 bytes (436, 5147664)
     ERROR  (drv_frameCopy.c|DRV_frameCopy|59): Invalid Parameters!!!
     ERROR  (alg_vidDec.c|ALG_vidDecTestDisplayCopy|390): DRV_frameCopy(A)
     ALG: VidDec: 0:0:-1:0x0:0: 10372 bytes (436, 5147664)
     ERROR  (drv_frameCopy.c|DRV_frameCopy|59): Invalid Parameters!!!
     ERROR  (alg_vidDec.c|ALG_vidDecTestDisplayCopy|390): DRV_frameCopy(A)
     ALG: VidDec: 1:1:-1:0x0:0: 6 bytes (436, 5147664)
     ERROR  (drv_frameCopy.c|DRV_frameCopy|59): Invalid Parameters!!!
     ERROR  (alg_vidDec.c|ALG_vidDecTestDisplayCopy|390): DRV_frameCopy(A)

    I get more errors with DVRRDK_v1.8, and I think that need more modifies for my enviroment.

    [result]

    root@192.168.4.13:/dvr# ./moduletest.out alg_vidDec
     CMEMK Error: Failed to find a pool which fits 28672

     CLK Hz,
     ARMCMEMK Error: get_phys: Unable to find phys addr for 0x00000000
       Hz =  2970000CMEMK Error: get_phys: get_user_pages() failed: -14
    00
     DDR   Hz = CMEMK Error: GETPHYS: Failed to convert virtual 0x0 to physical.
     243000000
     VPSCMEMK Error: get_phys: Unable to find phys addr for 0x00000000
    S  Hz =  2430000CMEMK Error: get_phys: get_user_pages() failed: -14
    00
     IMCOP Hz = CMEMK Error: FREE: Failed to convert virtual 0x0 to physical
     243000000

    CMEM Error: getPool: Failed to get a pool fitting a size 28672
    CMEM Error: getPhys: Failed to get physical address of 0
    CMEM Error: free: failed to free 0
     ERROR  (alg.c|ALG_sysInit|41): VICP Protocol regn failed

     

  • Hi,

    It works. I have a mistak.

    To change the legacy dvsdk to udworks one.

    Thank you very much!!

  • Hello, I use your attached "alg_vidDec.c"file to decode h.264 file,that recorded by dm365,it's ok. but,if I to decode other h.264 avi file ,that converted by other software ,It's only can decode 8MB,then no respone. died. why? An other question is alg_vidDec.c 's line 219 to line 232: ------------------------------ status = VIDDEC2_process(pObj->hDecode, &inBufDesc, &outBufDesc, &inArgs, &outArgs); status = VIDDEC2_control(pObj->hDecode, XDM_GETSTATUS, &pObj->dynamicParams, &pObj->decStatus); if (status != VIDDEC2_EOK) { OSA_ERROR("XDM_GETSTATUS failed, status=%ld\n", status); return OSA_EFAIL; } runStatus->bytesUsed = outArgs.bytesConsumed; if (status != VIDDEC2_EOK) { OSA_ERROR("status=%ld\n", status); return OSA_EFAIL; } ----------------------------- I think the code is error,so I modify to : ------------------- status = VIDDEC2_process(pObj->hDecode, &inBufDesc, &outBufDesc, &inArgs, &outArgs); if (status != VIDDEC2_EOK) { OSA_ERROR("status=%ld\n", status); return OSA_EFAIL; } status = VIDDEC2_control(pObj->hDecode, XDM_GETSTATUS, &pObj->dynamicParams, &pObj->decStatus); if (status != VIDDEC2_EOK) { OSA_ERROR("XDM_GETSTATUS failed, status=%ld\n", status); return OSA_EFAIL; } runStatus->bytesUsed = outArgs.bytesConsumed; -------------------- It's run error. why? Sunny