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.

problem customizing DMAI Venc1_process to get h.264 motion vectors

I'm trying to customized the DMAI Ven1_process to get bot encoded data and the motion vector field.

The error I get is

VIDENC1_process() failed with error (-1 ext: 0x0)

so I don't understand what's wrong with the function. I post the code, do you have an idea why it does not work?

 

Int Venc1_process_with_mv_data(Venc1_Handle hVe, Buffer_Handle hInBuf, Buffer_Handle hOutBuf, XDAS_Int8 * mvData, XDAS_Int32 mvDataSize)
{
    IVIDEO1_BufDescIn       inBufDesc;
    XDM_BufDesc             outBufDesc;
    XDAS_Int32              outBufSizeArray[1];
    XDAS_Int32              status;
    VIDENC1_InArgs          inArgs;
    VIDENC1_OutArgs         outArgs;
    XDAS_Int8              *inPtr;
    XDAS_Int8              *outPtr;
    BufferGfx_Dimensions    dim;
    UInt32                  offset = 0;
    Uint32                  bpp;

    XDAS_Int32 bufSizes[2];
    XDAS_Int8  *bufs[2];

    assert(hVe);
    assert(hInBuf);
    assert(hOutBuf);
    assert(Buffer_getUserPtr(hInBuf));
    assert(Buffer_getUserPtr(hOutBuf));
    assert(Buffer_getSize(hInBuf));
    assert(Buffer_getSize(hOutBuf));
    assert(Buffer_getType(hInBuf) == Buffer_Type_GRAPHICS);

    bpp = ColorSpace_getBpp(BufferGfx_getColorSpace(hInBuf));

    BufferGfx_getDimensions(hInBuf, &dim);

    offset = (dim.y * dim.lineLength) + (dim.x * (bpp >> 3));
    assert(offset < Buffer_getSize(hInBuf));

    inPtr  = Buffer_getUserPtr(hInBuf)  + offset;
    outPtr = Buffer_getUserPtr(hOutBuf);

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

    /* Point to the color planes depending on color space format */
    if (BufferGfx_getColorSpace(hInBuf) == ColorSpace_YUV420PSEMI) {
        inBufDesc.bufDesc[0].bufSize    = hVe->minInBufSize[0];
        inBufDesc.bufDesc[1].bufSize    = hVe->minInBufSize[1];

        inBufDesc.bufDesc[0].buf        = inPtr;
        inBufDesc.bufDesc[1].buf        = inPtr + Buffer_getSize(hInBuf) * 2/3;
        inBufDesc.numBufs               = 2;
    }
    else if (BufferGfx_getColorSpace(hInBuf) == ColorSpace_UYVY) {
        inBufDesc.bufDesc[0].bufSize    = Buffer_getSize(hInBuf);
        inBufDesc.bufDesc[0].buf        = inPtr;
        inBufDesc.numBufs               = 1;
    }
    else {
        fprintf (stderr, "Unsupported color format of input buffer\n");
        return Dmai_EINVAL;
    }

    outBufSizeArray[0]                  = Buffer_getSize(hOutBuf);

    outBufDesc.bufs = bufs;
    outBufDesc.bufSizes= bufSizes;

    outBufDesc.numBufs                  = 2;
    outBufDesc.bufs[0]                  = outPtr;
    outBufDesc.bufSizes[0]              = outBufSizeArray[0];
    outBufDesc.bufs[1]                  = mvData;
    outBufDesc.bufSizes[1]              = mvDataSize;

    inArgs.size                         = sizeof(VIDENC1_InArgs);
    outArgs.size                        = sizeof(VIDENC1_OutArgs);

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

    if (status != VIDENC1_EOK) {
        fprintf (stderr, "VIDENC1_process() failed with error (%d ext: 0x%x)\n",
                  (Int)status, (Uns) outArgs.extendedError);
        return Dmai_EFAIL;
    }

    /* 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.
     */
    BufferGfx_setFrameType(hInBuf, outArgs.encodedFrameType);

    Buffer_setNumBytesUsed(hOutBuf, outArgs.bytesGenerated);

    return Dmai_EOK;
}