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.

How can I put the floating point in XDAS_Int8 with the codec engine

hello, everyone,

my development platform is Devkit8500 (DM3700), and I use the xdctools to develop my code,

it by dvsdk_dm3730-evm_4_02_00_06_setuplinux and use dvsdk's Codec Engine GenCodecPkg Wizard,

At my ARM code:

XDAS_Int8 *inPtr_lbp;
XDAS_Int8 *outPtr_lbp;

double *svm_weight;
svm_weight = (double *)malloc( 5*sizeof(double) );

/* Initialize Codec Engine runtime */
CERuntime_init();

/* Initialize Davinci Multimedia Application Interface */
Dmai_init();

/* Open the codec engine */
hEngine = Engine_open(engineName, NULL, NULL);
if (hEngine == NULL) {
     printf("Failed to open codec engine %s\n", engineName);
     exit(-1);
}

/* Create the LBP encoder */
hLBP = LBP_create(hEngine, "lbp", &LBP_params, &LBP_dynParams);
if (hLBP == NULL) {
    printf("Failed to create encoder: %s\n", "lbp");
    exit(-1);
}

/* Create an input buffer*/
bufSize = 5;
hLBP_InBuf = Buffer_create(bufSize, &lbp_bufAttrs);

/* Create an output buffer*/
bufSize = 1;
hLBP_DstBuf = Buffer_create(bufSize, &lbp_bufAttrs);

svm_weight[0] = -0.731139
svm_weight[1] = 0.8126;
svm_weight[2] = 1.2956;
svm_weight[3] = 0.1256;
svm_weight[4] = -0.513019;

inPtr_lbp[0] =  svm_weight[0];
inPtr_lbp[1] =  svm_weight[1];
inPtr_lbp[2] =  svm_weight[2];
inPtr_lbp[3] =  svm_weight[3];
inPtr_lbp[4] =  svm_weight[4];

//my question

printf("inPtr_lbp[0] = %lf \n", inPtr_lbp[0]);
printf("inPtr_lbp[1] = %lf \n", inPtr_lbp[1]);
printf("inPtr_lbp[2] = %lf \n", inPtr_lbp[2]);
printf("inPtr_lbp[3] = %lf \n", inPtr_lbp[3]);
printf("inPtr_lbp[4] = %lf \n", inPtr_lbp[4]);

/* Run LBP */
if (LBP_process(hLBP, hLBP_InBuf, hLBP_DstBuf) < 0) {
     printf("Failed to encode video buffer(lbp)\n");
     exit(-1);
}

At my DSP code:

/*
 *  ======== LBP_TI_process ========
 */
/* ARGSUSED - this line tells the TI compiler not to warn about unused args. */
XDAS_Int32 LBP_TI_process(IIMGENC1_Handle h, XDM1_BufDesc *inBufs,
    XDM1_BufDesc *outBufs, IIMGENC1_InArgs *inArgs, IIMGENC1_OutArgs *outArgs)
{
    XDAS_Int32 numInBytes;
    unsigned char * restrict lbp_inputbuffer;
    unsigned char * restrict lbp_outputbuffer;
    int size;

double *svm_weight;
svm_weight = (double *)malloc( 5*sizeof(double) ); /* validate arguments - this codec only supports "base" xDM. */ if ((inArgs->size != sizeof(*inArgs)) || (outArgs->size != sizeof(*outArgs))) { outArgs->extendedError = XDM_UNSUPPORTEDPARAM; return (IIMGENC1_EUNSUPPORTED); } /* validate that there's at least a single inBuf and outBuf */ if ((inBufs->numBufs < 1) || (outBufs->numBufs < 1)) { outArgs->extendedError = XDM_UNSUPPORTEDPARAM; return (IIMGENC1_EFAIL); } numInBytes = inBufs->descs[0].bufSize < outBufs->descs[0].bufSize ? inBufs->descs[0].bufSize : outBufs->descs[0].bufSize; /* everything looks good, do the 'encode', set outArgs and return */ //memcpy(outBufs->descs[0].buf, inBufs->descs[0].buf, numInBytes); size = inBufs->descs[0].bufSize; lbp_inputbuffer = inBufs->descs[0].buf;
lbp_outputbuffer = outBufs->descs[0].buf;
// it will show zero value , not floating point svm_weight[0] = lbp_inputbuffer[0]; svm_weight[1] = lbp_inputbuffer[1]; svm_weight[2] = lbp_inputbuffer[2]; svm_weight[3] = lbp_inputbuffer[3]; svm_weight[4] = lbp_inputbuffer[4]; /***** run my code start ********/ ……………….
/***** run my code end *********/ lbp_outputbuffer[0] = my_code_result ; /* report _how_ we accessed the 2 data buffers */ XDM_CLEARACCESSMODE_WRITE(inBufs->descs[0].accessMask); XDM_SETACCESSMODE_READ(inBufs->descs[0].accessMask); XDM_CLEARACCESSMODE_READ(outBufs->descs[0].accessMask); XDM_SETACCESSMODE_WRITE(outBufs->descs[0].accessMask); /* outArgs->bytesGenerated reports the total number of bytes encoded */ outArgs->bytesGenerated = numInBytes; /* Fill out the rest of the outArgs struct */ outArgs->extendedError = 0; outArgs->currentAU = 0; /* TODO */ return (IIMGENC1_EOK); }

My Question :

for my question, I want put the svm_weight value into inPtr_lbp (in red word) ,

because I wnat put them to DSP code and calculate,

but when I printf the value (in blue word), it will show zero, not the floating point, 

so In the DSP code, the svm_weight value will show zero, 

How should I do for this problem , or any example that I can reference, 

Thank you~

  • Hi Steven,

    I can not see memory allocation for the inPtr_lbp array in your code example. Could you try for example to define the inPtr_lbp as array:

    XDAS_Int8 inPtr_lbp[5];

    instead of

    XDAS_Int8 *inPtr_lbp;

    or to make memory allocation by malloc(...) command.

    The second issue is that the XDAS_Int8 type is integer but you try to set floating point values.

    BR

    Tsvetolin Shulev

  • Dear Tsvetolin Shulev,

    thank you for your suggest, and I follow your suggest,

    but it not matter, and I attach my integral code ,

    ARM code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <time.h>
    #include <unistd.h>

    #include <xdc/std.h>
    #include <ti/sdo/ce/Engine.h>
    #include <ti/sdo/ce/image1/imgenc1.h>

    #include <ti/sdo/dmai/Dmai.h>
    #include <ti/sdo/dmai/Buffer.h>
    #include <ti/sdo/dmai/BufferGfx.h>
    #include <ti/sdo/dmai/ce/Ienc1.h>
    #include "useLBP.h"


    static String engineName = "encode";

    int main()
    {

    LBP_Handle hLBP = NULL;
    IMGENC1_Params LBP_params = LBP_Params_DEFAULT;
    IMGENC1_DynamicParams LBP_dynParams = LBP_DynamicParams_DEFAULT;
    Engine_Handle hEngine = NULL;
    Buffer_Handle hLBP_InBuf;
    Buffer_Handle hLBP_DstBuf;
    Buffer_Attrs lbp_bufAttrs = Buffer_Attrs_DEFAULT;

    XDAS_Int8 *inPtr_lbp;
    XDAS_Int8 *outPtr_lbp;

    int bufSize;
    double *svm_weight;
    svm_weight = (double *)malloc(5*sizeof(double));

    inPtr_lbp = (XDAS_Int8 *)malloc(5*sizeof(XDAS_Int8));


    svm_weight[0] = -0.731139;
    svm_weight[1] = 0.8126;
    svm_weight[2] = 1.2956;
    svm_weight[3] = 0.1256;
    svm_weight[4] = -0.513019;

    /* Initialize Codec Engine runtime */
    CERuntime_init();


    /* Initialize Davinci Multimedia Application Interface */
    Dmai_init();

    /* Open the codec engine */
    hEngine = Engine_open(engineName, NULL, NULL);
    if (hEngine == NULL) {
    printf("Failed to open codec engine %s\n", engineName);
    exit(-1);
    }

    /* Create the LBP encoder */
    hLBP = LBP_create(hEngine, "lbp", &LBP_params, &LBP_dynParams);
    if (hLBP == NULL) {
    printf("Failed to create encoder: %s\n", "lbp");
    exit(-1);
    }

    /* Create an input buffer*/
    bufSize = 5;
    hLBP_InBuf = Buffer_create(bufSize, &lbp_bufAttrs);

    /* Create an output buffer*/
    bufSize = 1;
    hLBP_DstBuf = Buffer_create(bufSize, &lbp_bufAttrs);


    /******** Put values into input buffer start ********/

    inPtr_lbp[0] = svm_weight[0];
    inPtr_lbp[1] = svm_weight[1];
    inPtr_lbp[2] = svm_weight[2];
    inPtr_lbp[3] = svm_weight[3];
    inPtr_lbp[4] = svm_weight[4];

    /******** Put values into input buffer end ********/

    //my question
    printf("inPtr_lbp[0] = %lf \n", inPtr_lbp[0]);
    printf("inPtr_lbp[1] = %lf \n", inPtr_lbp[1]);
    printf("inPtr_lbp[2] = %lf \n", inPtr_lbp[2]);
    printf("inPtr_lbp[3] = %lf \n", inPtr_lbp[3]);
    printf("inPtr_lbp[4] = %lf \n", inPtr_lbp[4]);

    printf("start run code\n");

    /* Run LBP */
    if (LBP_process(hLBP, hLBP_InBuf, hLBP_DstBuf) < 0) {
    printf("Failed to encode video buffer(lbp)\n");
    exit(-1);
    }

    /*take out value */
    outPtr_lbp = Buffer_getUserPtr(hLBP_DstBuf);

    printf("outPtr_lbp[0] = %lf \n", outPtr_lbp[0]);

    return 0;

    }

    DSP code:

    /*
    * ======== LBP_TI_process ========
    */
    /* ARGSUSED - this line tells the TI compiler not to warn about unused args. */
    XDAS_Int32 LBP_TI_process(IIMGENC1_Handle h, XDM1_BufDesc *inBufs,
    XDM1_BufDesc *outBufs, IIMGENC1_InArgs *inArgs, IIMGENC1_OutArgs *outArgs)
    {

    XDAS_Int32 numInBytes;
    unsigned char * restrict lbp_inputbuffer;
    unsigned char * restrict lbp_outputbuffer;
    int size;
    double *svm_weight;

    svm_weight = (double *)malloc(5*sizeof(double));

    /* validate arguments - this codec only supports "base" xDM. */
    if ((inArgs->size != sizeof(*inArgs)) ||
    (outArgs->size != sizeof(*outArgs))) {
    outArgs->extendedError = XDM_UNSUPPORTEDPARAM;

    return (IIMGENC1_EUNSUPPORTED);

    }

    /* validate that there's at least a single inBuf and outBuf */
    if ((inBufs->numBufs < 1) || (outBufs->numBufs < 1)) {
    outArgs->extendedError = XDM_UNSUPPORTEDPARAM;
    return (IIMGENC1_EFAIL);
    }

    numInBytes = inBufs->descs[0].bufSize < outBufs->descs[0].bufSize ?
    inBufs->descs[0].bufSize : outBufs->descs[0].bufSize;

    /* everything looks good, do the 'encode', set outArgs and return */
    //memcpy(outBufs->descs[0].buf, inBufs->descs[0].buf, numInBytes);


    //run my code
    size = inBufs->descs[0].bufSize;
    lbp_inputbuffer = inBufs->descs[0].buf;
    lbp_outputbuffer = outBufs->descs[0].buf;

    svm_weight[0] = lbp_inputbuffer[0];
    svm_weight[1] = lbp_inputbuffer[1];
    svm_weight[2] = lbp_inputbuffer[2];
    svm_weight[3] = lbp_inputbuffer[3];
    svm_weight[4] = lbp_inputbuffer[4];


    /********** run my Algorithm start **********/

    /********** run my Algorithm end **********/

    lbp_outputbuffer[0] = svm_weight[0];

    /* report _how_ we accessed the 2 data buffers */
    XDM_CLEARACCESSMODE_WRITE(inBufs->descs[0].accessMask);
    XDM_SETACCESSMODE_READ(inBufs->descs[0].accessMask);
    XDM_CLEARACCESSMODE_READ(outBufs->descs[0].accessMask);
    XDM_SETACCESSMODE_WRITE(outBufs->descs[0].accessMask);

    /* outArgs->bytesGenerated reports the total number of bytes encoded */
    outArgs->bytesGenerated = numInBytes;

    /* Fill out the rest of the outArgs struct */
    outArgs->extendedError = 0;
    outArgs->currentAU = 0; /* TODO */

    return (IIMGENC1_EOK);

    }

    And the result:

    And for your second suggest,

    does there any type can put my floating point ?

    Or other method ?

    Thank you~

    Best regards,

    Steven 

  • Hello~

    anyone know how to solve this problem ?

    thank you~