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.

Failing to retrieve MV SAD Info on DM368 (H.264 encoder)

I am trying to get the Motion Vectors on a DM368-based platform.
I am using the H2.264 encoder.
I have followed the instructions from this document "Using MV/SAD information from DM365
encoder in application" (version 1.0).

I setup the flag mvSADoutFlag to 1.
I verified that in this case XDM_GETBUFINFO return minNumOutBufs=2
(it gives me 1 if mvSADoutFlag is set to 0).

My issue is that when I request encoding, I never get the MV buffer.
I allocated a buffer with the right size (65280 bytes for 1080P),
setup outBufDesc.numBufs=2, initialize pointer/size for ouput array[1],
but the MV buffer is not written with anything (I did a memset before the
encoder call).

Any thought what I might be missing ?
Thanks, Olivier

  • Still stuck...

    If anybody would have an idea about what I am missing...

    Encoder version:

    @(#)Id:H264VENC_TI Ver:02.20.00.01 Released by:DEV_210_V_H264_E_HP_DM365_02_20_00_01 Built:Feb 11 2011 16:43:57

    This is the function I am using to do the encoding and request the MV data:

    Int Venc1_process2( Venc1_Handle hVe, Uint32 bpp,
        Int32 width, Int32 height, Int32 lineLength,
        Int inputId,
        XDAS_Int8 *inPtr, XDAS_Int8 *outPtr,
        Int32 in_buffsize, Int32 out_buffsize,
        Int32 *frameType, Int32 *numBytes )
    {
        IVIDEO1_BufDescIn       inBufDesc;
        XDM_BufDesc             outBufDesc;
        XDAS_Int32              outBufSizeArray[3];
        XDAS_Int32              status;
        VIDENC1_InArgs          inArgs;
        VIDENC1_OutArgs         outArgs;
        XDAS_Int8   *bufs[3];
        static XDAS_Int8 *buff_addr0 = NULL;
        static Buffer_Handle buffer;

        {
            static int first = 1;
            if ( first ) {  
                first = 0;
                Buffer_Attrs  attrs = Buffer_Attrs_DEFAULT;
                buffer = Buffer_create( 65280, &attrs );
                buff_addr0 = (XDAS_Int8 *)Buffer_getUserPtr( buffer );
            }
        }

        assert(hVe);

        /* Set up the codec buffer dimensions */
        inBufDesc.frameWidth                = width;
        inBufDesc.frameHeight               = height;
        inBufDesc.framePitch                = lineLength;

        /* Point to the color planes depending on color space format */
         inBufDesc.bufDesc[0].bufSize    = hVe->minInBufSize[0];
         inBufDesc.bufDesc[1].bufSize    = hVe->minInBufSize[1];

         inBufDesc.bufDesc[0].buf        = inPtr;
         inBufDesc.bufDesc[1].buf        = inPtr + in_buffsize*2/3;
         inBufDesc.numBufs               = 2;

        outBufSizeArray[0] = out_buffsize;
        bufs[0] = outPtr;
        
        outBufSizeArray[1] = 65280;
        bufs[1] = buff_addr0;
        
        outBufDesc.numBufs                  = 2;
        outBufDesc.bufs = bufs;
        outBufDesc.bufSizes                 = outBufSizeArray;

        inArgs.size                         = sizeof(VIDENC1_InArgs);
        inArgs.inputID                      = GETID(inputId);

        /* topFieldFirstFlag is hardcoded. Used only for interlaced content */
        inArgs.topFieldFirstFlag            = 1;
        
        outArgs.size                        = sizeof(VIDENC1_OutArgs);

    memset( buff_addr0, 0x11, 65280 );

        /* Encode video buffer */
        status = VIDENC1_process( hVe->hEncode, &inBufDesc, &outBufDesc, &inArgs, &outArgs );

    //    Dmai_dbg4("VIDENC1_process() ret %d inId %d outID %d generated %d bytes\n",
    //        status, Buffer_getId(hInBuf), outArgs.outputID, outArgs.bytesGenerated);

        if (status != VIDENC1_EOK) {
            Dmai_err2("VIDENC1_process() failed with error (%d ext: 0x%x)\n",
                      (Int)status, (Uns) outArgs.extendedError);
            return Dmai_EFAIL;
        }
       
        /* if memTab was used for input buffers */
        if(hVe->hInBufTab != NULL) {
            /* One buffer is freed when output content is generated */
            if(outArgs.bytesGenerated>0) {
                /* Buffer released by the encoder */
                hVe->hFreeBuf = BufTab_getBuf(hVe->hInBufTab, GETIDX(outArgs.outputID));
            }
            else {
                hVe->hFreeBuf = NULL;
            }
        }

        /* Copy recon buffer information so we can retrieve it later */
        hVe->reconBufs = outArgs.reconBufs;

        /*
         * Setting the frame type in the input buffer even through it's a property
         * of the output buffer. This works for encoders without B-frames, but
         * when byte and display order are not the same the frame type will get
         * out of sync.
         */
        *frameType = outArgs.encodedFrameType;

        *numBytes = outArgs.bytesGenerated;

    {
        typedef struct {
            short mvx;
            short mvy;
            unsigned int sad;
        } motion_mvdata_t;
        static int cpt = 0;
        cpt++;
        if ( (cpt >= 300) && (cpt <= 310) ) {
            char fname[100];
            sprintf( fname, "/media/test_%04d", cpt );
            FILE *fp = fopen( fname, "w" );
            if ( fp ) {
              motion_mvdata_t *p = (motion_mvdata_t *)buff_addr0;
              int x, y;
              for ( x = 0; x < 120; x++ ) {
                  for ( y = 0; y < 68; y++ ) {
                      fprintf( fp, "%4d,%-4d ", p->mvx, p->mvy );
                      p++;
                  }
                  fprintf( fp, "\n" );
              }
              fclose( fp );
              if ( cpt == 300 ) {
                  FILE *fp = fopen( "/media/test.bin", "w" );
                  fwrite( buff_addr0, 120, 544, fp );
                  fclose( fp );
              }
            }
            else {
                cpt--;
            }
        }
    }

        return Dmai_EOK;
    } // Venc1_process2