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.

DM3730 Application Invoke process Error

hello,

I used Codec Engine Gencodecpkg Wizard and generated a server . But it returns "IMGENC1_process() failed with error (-1 ext: 0xa000)" when I invoked IMGENC1_process api to encode yuv data by the app. Is there something not right to the server configuration or something else. How can I find out the problem and fix it.

here is my codes:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <sys/time.h>

#include <xdc/std.h>
#include <ti/sdo/ce/Engine.h>
#include <ti/sdo/ce/osal/Memory.h>
#include <ti/sdo/ce/universal/universal.h>
#include <ti/sdo/ce/image1/imgenc1.h>
#include <ti/sdo/ce/trace/gt.h>

/*
* ======== Plate recognition lib header ========
*/
#include "TH_PlateID.h"
#include "codecs.h"

XDAS_Int8 *imgBuf;
XDAS_Int8 *rstBuf;
XDAS_Int8 *outBuf;

String engine_name = "camera";
String universal_name = "plate";
String jpegenc_name = "jpegenc";

int main(int argc, char *argv[])
{
Engine_Handle ce = NULL;
/* UNIVERSAL_Handle universal = NULL;*/
IMGENC1_Handle enc = NULL;

IMGENC1_InArgs inArgs;
IMGENC1_OutArgs outArgs;
XDM1_BufDesc inBufDesc;
XDM1_BufDesc outBufDesc;
IMGENC1_Params params = Image1_Params_DEFAULT;
IMGENC1_DynamicParams dynParams = Image1_DynamicParams_DEFAULT;
IMGENC1_Status encStatus;
FILE *inFile = NULL;
FILE *outFile = NULL;
FILE *listFile = NULL;
XDAS_Int32 status = 0;
Memory_AllocParams allocParams;

CERuntime_init();
TraceUtil_start(engine_name);

/* allocate buffers */
allocParams.type = Memory_CONTIGPOOL;
allocParams.flags = Memory_NONCACHED;
allocParams.align = BUFALIGN;
allocParams.seg = 0;

imgBuf = (XDAS_Int8 *)Memory_alloc(IMAGESIZE, &allocParams);
outBuf = (XDAS_Int8 *)Memory_alloc(IMAGESIZE, &allocParams);
/*rstBuf = (XDAS_Int8 *)Memory_alloc(RESULTSIZE * 3, &allocParams);*/
if (NULL == imgBuf || NULL == outBuf) {
printf("Memory_alloc ERROR\n");
goto end;
}

printf("Engine_open ...\n");
/* Create codec engine instance */
ce = Engine_open(engine_name, NULL, NULL);
if (NULL == ce) {
printf("Engine open ERROR!\n");
goto end;
}

params.maxWidth = IMGWIDTH;
params.maxHeight = IMGHEIGHT;
params.forceChromaFormat = XDM_YUV_420P;
dynParams.inputWidth = params.maxWidth;
dynParams.inputHeight = params.maxHeight;
dynParams.captureWidth = params.maxWidth;
dynParams.inputChromaFormat = XDM_YUV_420P;

printf("IMGENC1_create ...\n");
enc = IMGENC1_create(ce, jpegenc_name, &params);
if (NULL == enc) {
printf("IMGENC1_create ERROR");
goto end;
}

encStatus.data.buf = NULL;
encStatus.size = sizeof(IMGENC1_Status);
status = IMGENC1_control(enc, XDM_SETPARAMS, &dynParams, &encStatus);
if (status != IMGENC1_EOK) {
printf("XDM_SETPARAMS failed, status=%d\n", status);
goto end;
}

/* Get buffer requirements */
status = IMGENC1_control(enc, XDM_GETBUFINFO, &dynParams, &encStatus);

if (status != IMGENC1_EOK) {
printf("XDM_GETBUFINFO failed, status=%d\n", status);
goto end;
}


inFile = fopen("YUV", "rb");
if (NULL == inFile) {
printf("Cannot open YUV file\n");
goto end;
}

outFile = fopen("yuv.jpeg", "wb");
if (NULL == outFile) {
printf("Cannot create yuv.jpeg file\n");
goto end;
}

if (0 > fread(imgBuf, IMAGESIZE, 1, inFile)) {
printf("read data failed\n");
}

inBufDesc.numBufs = 1;
inBufDesc.descs[0].buf = imgBuf;
inBufDesc.descs[0].bufSize = IMAGESIZE;

outBufDesc.numBufs = 1;
outBufDesc.descs[0].buf = outBuf;
outBufDesc.descs[0].bufSize = IMAGESIZE;

inArgs.size = sizeof(IMGENC1_InArgs);
outArgs.size = sizeof(IMGENC1_OutArgs);

Memory_cacheWbInv(inBufDesc.descs[0].buf, IMAGESIZE);
Memory_cacheInv(outBufDesc.descs[0].buf, IMAGESIZE);

status = IMGENC1_process(enc, &inBufDesc, &outBufDesc, &inArgs, &outArgs);

if (status != IMGENC1_EOK) {
printf("IMGENC1_process() failed with error (%d ext: 0x%x)\n",
(Int)status, (Uns) outArgs.extendedError);
}

Memory_cacheWb(outBufDesc.descs[0].buf, IMAGESIZE);

fwrite(outBufDesc.descs[0].buf, IMAGESIZE, 1, outFile);

end:
if (inFile) {
fclose(inFile);
}

if (outFile) {
fclose(outFile);
}

if (enc) {
IMGENC1_delete(enc);
}

/* close engine */
if (ce) {
Engine_close(ce);
}

if (imgBuf) {
Memory_free(imgBuf, IMAGESIZE, &allocParams);
}

if (rstBuf) {
Memory_free(rstBuf, RESULTSIZE * 3, &allocParams);
}
TraceUtil_stop();

printf("Leaving main ...\n");
exit(0);
}

  • Can you share the version of Codec Engine you are using ? I'll try and find out more about the error msg you are seeing.

  • hi Gunjan,

    My dvsdk version is dvsdk_dm3730-evm_4_02_00_06_setuplinux.setuplinux. 

    I didn't modify the demos.  And here is it that I have done

    1)make genServer and generate a server

    2)modify configurations:

    codecs.cfg:

    var dataSection = "DDR2";
    var udataSection = "DDR2";
    var codeSection = "DDR2";
    /*
    * "Use" the various codec modules; i.e., implementation of codecs.
    * All these "xdc.useModule" commands provide a handle to the codecs,
    * which we'll use to initialize config params and add the codecs to
    * the Server.algs array.
    */
    var PLATE = xdc.useModule('codecs.plate.PLATE');

    PLATE.serverFxns = "UNIVERSAL_SKEL";
    PLATE.stubFxns = "UNIVERSAL_STUBS";
    PLATE.useCache = false;

    var JPEGENC = xdc.useModule('ti.sdo.codecs.jpegenc.ce.JPEGENC');

    JPEGENC.serverFxns = "IMGENC1_SKEL";
    JPEGENC.useCache = false;
    JPEGENC.manageOutBufsCache = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
    JPEGENC.stubFxns = "IMGENC1_STUBS";
    JPEGENC.manageInBufsCache = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
    JPEGENC.alg.watermark = false;
    JPEGENC.alg.codeSection = codeSection;
    JPEGENC.alg.udataSection = udataSection;
    JPEGENC.alg.dataSection = dataSection;

    /*
    * The array of algorithms this server can serve up. This array also
    * configures details about the threads which will be created to run the
    * algorithms (e.g. stack sizes, priorities, etc.).
    */
    Server.algs = [
    {name: "plate", mod: PLATE , threadAttrs: {
    stackMemId: 0, priority: Server.MINPRI + 1},
    groupId : 2,
    },

    {name: "jpegenc", mod: JPEGENC , threadAttrs: {
    stackMemId: 0, priority: Server.MINPRI + 2},
    groupId : 1,
    },

    ];

    server.cfg 

    /*
    * ======== server.cfg ========
    *
    * For details about the packages and configuration parameters used throughout
    * this config script, see the Codec Engine Configuration Guide (link
    * provided in the release notes) and the Codec Engine Package Documentation at:
    * http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/ce/latest_2_x/xdoc/index.html
    * which references to Framework Components configurable modules under ti.sdo.fc.
    */

    /* scratch groups */
    var MAXGROUPS = 20;
    var GROUP_1 = 1;
    var GROUP_2 = 2;

    /*
    * Configure CE's OSAL. This codec server only builds for the BIOS-side of
    * a heterogeneous system, so use the "DSPLINK_BIOS" configuration.
    */
    var osalGlobal = xdc.useModule('ti.sdo.ce.osal.Global');
    osalGlobal.runtimeEnv = osalGlobal.DSPLINK_BIOS;

    /*
    * Uncomment and modify the following line, to change the size of the circular
    * trace buffer, if necessary.
    */
    //osalGlobal.traceBufferSize = 32 * 1024;


    /* configure default memory seg id to BIOS-defined "DDR2" */
    osalGlobal.defaultMemSegId = "DDR2";

    /* activate BIOS logging module */
    var LogServer = xdc.useModule('ti.sdo.ce.bioslog.LogServer');

    /*
    * ======== Server Configuration ========
    */
    var Server = xdc.useModule('ti.sdo.ce.Server');
    /* The server's stackSize. More than we need... but safe. */
    Server.threadAttrs.stackSize = 16384;

    /* The servers execution priority */
    Server.threadAttrs.priority = Server.MINPRI;

    /*
    * The optional stack pad to add to non-configured stacks. This is well
    * beyond most codec needs, but follows the approach of "start big and
    * safe, then optimize when things are working."
    */
    //Server.stackSizePad = 9000;

    utils.importFile("codec.cfg");

    /* to link in debug/trace FC libs, uncomment one of these */
    // xdc.useModule('ti.sdo.fc.global.Settings').profile = "debug");
    // xdc.useModule('ti.sdo.fc.global.Settings').profile = "debug_trace");
    var TRACE = xdc.useModule('ti.sdo.fc.global.Settings')
    TRACE.profile = "trace";

    /*
    * ======== DSKT2 (XDAIS Alg. memory allocation) configuration ========
    *
    * DSKT2 is the memory manager for all algorithms running in the system,
    * granting them persistent and temporary ("scratch") internal and external
    * memory. We configure it here to define its memory allocation policy.
    *
    * DSKT2 settings are critical for algorithm performance.
    *
    * First we assign various types of algorithm internal memory (DARAM0..2,
    * SARAM0..2,IPROG, which are all the same on a C64+ DSP) to "L1DHEAP"
    * defined in the .tcf file as an internal memory heap. (For instance, if
    * an algorithm asks for 5K of DARAM1 memory, DSKT2 will allocate 5K from
    * L1DHEAP, if available, and give it to the algorithm; if the 5K is not
    * available in the L1DHEAP, that algorithm's creation will fail.)
    *
    * The remaining segments we point to the "DDRALGHEAP" external memory segment
    * (also defined in the.tcf) except for DSKT2_HEAP which stores DSKT2's
    * internal dynamically allocated objects, which must be preserved even if
    * no codec instances are running, so we place them in "DDR2" memory segment
    * with the rest of system code and static data.
    */
    var DSKT2 = xdc.useModule('ti.sdo.fc.dskt2.DSKT2');
    DSKT2.DARAM0 = "L1DHEAP";
    DSKT2.DARAM1 = "L1DHEAP";
    DSKT2.DARAM2 = "L1DHEAP";
    DSKT2.SARAM0 = "L1DHEAP";
    DSKT2.SARAM1 = "L1DHEAP";
    DSKT2.SARAM2 = "L1DHEAP";
    DSKT2.ESDATA = "DDRALGHEAP";
    DSKT2.IPROG = "L1DHEAP";
    DSKT2.EPROG = "DDRALGHEAP";
    DSKT2.DSKT2_HEAP = "DDR2";


    /*
    * Next we define how to fulfill algorithms' requests for fast ("scratch")
    * internal memory allocation; "scratch" is an area an algorithm writes to
    * while it processes a frame of data and is discarded afterwards.
    *
    * First we turn off the switch that allows the DSKT2 algorithm memory manager
    * to give to an algorithm external memory for scratch if the system has run
    * out of internal memory. In that case, if an algorithm fails to get its
    * requested scratch memory, it will fail at creation rather than proceed to
    * run at poor performance. (If your algorithms fail to create, you may try
    * changing this value to "true" just to get it running and optimize other
    * scratch settings later.)
    *
    * Setting "algorithm scratch sizes", is a scheme we use to minimize internal
    * memory resources for algorithms' scratch memory allocation. Algorithms that
    * belong to the same "scratch group ID" -- field "groupId" in the algorithm's
    * Server.algs entry above, reflecting the priority of the task running the
    * algorithm -- don't run at the same time and thus can share the same
    * scratch area. When creating the first algorithm in a given "scratch group"
    * (between 0 and 19), a shared scratch area for that groupId is created with
    * a size equal to SARAM_SCRATCH_SIZES[<alg's groupId>] below -- unless the
    * algorithm requests more than that number, in which case the size will be
    * what the algorithm asks for. So SARAM_SCRATCH_SIZES[<alg's groupId>] size is
    * more of a groupId size guideline -- if the algorithm needs more it will get
    * it, but getting these size guidelines right is important for optimal use of
    * internal memory. The reason for this is that if an algorithm comes along
    * that needs more scratch memory than its groupId scratch area's size, it
    * will get that memory allocated separately, without sharing.
    *
    * This DSKT2.SARAM_SCRATCH_SIZES[<groupId>] does not mean it is a scratch size
    * that will be automatically allocated for the group <groupId> at system
    * startup, but only that is a preferred minimum scratch size to use for the
    * first algorithm that gets created in the <groupId> group, if any.
    *
    * (An example: if algorithms A and B with the same groupId = 0 require 10K and
    * 20K of scratch, and if SARAM_SCRATCH_SIZES[0] is 0, if A gets created first
    * DSKT2 allocates a shared scratch area for group 0 of size 10K, as A needs.
    * If then B gets to be created, the 20K scratch area it gets will not be
    * shared with A's -- or anyone else's; the total internal memory use will be
    * 30K. By contrast, if B gets created first, a 20K shared scratch will be
    * allocated, and when A comes along, it will get its 10K from the existing
    * group 0's 20K area. To eliminate such surprises, we set
    * SARAM_SCRATCH_SIZES[0] to 20K and always spend exactly 20K on A and B's
    * shared needs -- independent of their creation order. Not only do we save 10K
    * of precious internal memory, but we avoid the possibility that B can't be
    * created because less than 20K was available in the DSKT2 internal heaps.)
    *
    * Finally, note that if the codecs correctly implement the
    * ti.sdo.ce.ICodec.getDaramScratchSize() and .getSaramScratchSize() methods,
    * this scratch size configuration can be autogenerated by
    * configuring Server.autoGenScratchSizeArrays = true.
    */
    DSKT2.ALLOW_EXTERNAL_SCRATCH = false;
    DSKT2.SARAM_SCRATCH_SIZES[GROUP_1] = 0;
    DSKT2.SARAM_SCRATCH_SIZES[GROUP_2] = 0;
    DSKT2.DARAM_SCRATCH_SIZES[GROUP_1] = 0;
    DSKT2.DARAM_SCRATCH_SIZES[GROUP_2] = 0;

    /*
    * ======== DMAN3 (DMA manager) configuration ========
    */

    /* First we configure how DMAN3 handles memory allocations:
    *
    * Essentially the configuration below should work for most codec combinations.
    * If it doesn't work for yours -- meaning an algorithm fails to create due
    * to insufficient internal memory -- try the alternative (commented out
    * line that assigns "DDRALGHEAP" to DMAN3.heapInternal).
    *
    * What follows is an FYI -- an explanation for what the alternative would do:
    *
    * When we use an external memory segment (DDRALGHEAP) for DMAN3 internal
    * segment, we force algorithms to use external memory for what they think is
    * internal memory -- we do this in a memory-constrained environment
    * where all internal memory is used by cache and/or algorithm scratch
    * memory, pessimistically assuming that if DMAN3 uses any internal memory,
    * other components (algorithms) will not get the internal memory they need.
    *
    * This setting would affect performance very lightly.
    *
    * By setting DMAN3.heapInternal = <external-heap> DMAN3 *may not* supply
    * ACPY3_PROTOCOL IDMA3 channels the protocol required internal memory for
    * IDMA3 channel 'env' memory. To deal with this catch-22 situation we
    * configure DMAN3 with hook-functions to obtain internal-scratch memory
    * from the shared scratch pool for the associated algorithm's
    * scratch-group (i.e. it first tries to get the internal scratch memory
    * from DSKT2 shared allocation pool, hoping there is enough extra memory
    * in the shared pool, if that doesn't work it will try persistent
    * allocation from DMAN3.internalHeap).
    */

    var DMAN3 = xdc.useModule('ti.sdo.fc.dman3.DMAN3');
    DMAN3.heapInternal = "L1DHEAP"; /* L1DHEAP is an internal segment */
    DMAN3.heapExternal = "DDRALGHEAP";
    DMAN3.idma3Internal = false;
    DMAN3.scratchAllocFxn = "DSKT2_allocScratch";
    DMAN3.scratchFreeFxn = "DSKT2_freeScratch";

    /* Next, we configure all the physical resources that DMAN3 is granted
    * exclusively. These settings are optimized for the DSP on DM6446 (DaVinci).
    *
    * We assume PaRams 0..79 are taken by the Arm drivers, so we reserve
    * all the rest, up to 127 (there are 128 PaRam sets on DM6446).
    * DMAN3 takes TCC's 32 through 63 (hence the High TCC mask is 0xFFFFFFFF
    * and the Low TCC mask is 0). Of the 48 PaRams we reserved, we assign
    * all of them to scratch group 0; similarly, of the 32 TCCs we reserved,
    * we assign all of them to scratch group 0.
    *
    * If we had more scratch groups with algorithms that require EDMA, we would
    * split those 48 PaRams and 32 TCCs appropriately. For example, if we had
    * a video encoder alg. in group 0 and video decoder alg. in group 1, and they
    * both needed a number of EDMA channels, we could assing 24 PaRams and 16
    * TCCs to Groups [0] and [1] each. (Assuming both algorithms needed no more
    * than 24 channels to run properly.)
    */
    DMAN3.paRamBaseIndex = 1; // 1st EDMA3 PaRAM set available for DMAN3
    DMAN3.numQdmaChannels = 8; // number of device's QDMA channels to use
    DMAN3.qdmaChannels = [0,1,2,3,4,5,6,7]; // choice of QDMA channels to use
    DMAN3.numPaRamEntries = 127; // number of PaRAM sets exclusively used by DMAN
    DMAN3.numPaRamGroup[GROUP_1] = 0; // number of PaRAM sets for scratch group 1
    DMAN3.numPaRamGroup[GROUP_2] = 0; // number of PaRAM sets for scratch group 2
    DMAN3.numTccGroup[GROUP_1] = 0; // number of TCCs assigned to scratch group 1
    DMAN3.numTccGroup[GROUP_2] = 0; // number of TCCs assigned to scratch group 2
    DMAN3.tccAllocationMaskL = 0; // assign no TCCs 0..31 for DMAN3
    DMAN3.tccAllocationMaskH = 0xffffffff; // assign all TCCs 32..63 for DMAN3
    /*
    * ======== RMAN (IRES Resource manager) configuration ========
    */
    var RMAN = xdc.useModule('ti.sdo.fc.rman.RMAN');
    RMAN.useDSKT2 = true;
    RMAN.tableSize = 10;
    RMAN.semCreateFxn = "Sem_create";
    RMAN.semDeleteFxn = "Sem_delete";
    RMAN.semPendFxn = "Sem_pend";
    RMAN.semPostFxn = "Sem_post";
    /* The lock/unlock/set/getContext functions will default to DSKT2 */

    var EDMA3 = xdc.useModule('ti.sdo.fc.edma3.Settings');
    EDMA3.globalInit = true;
    EDMA3.maxTccs[GROUP_1] = 0;
    EDMA3.maxPaRams[GROUP_1] = 0;
    EDMA3.maxQdmaChannels[GROUP_1] = 0;
    EDMA3.maxTccs[GROUP_2] = 0;
    EDMA3.maxPaRams[GROUP_2] = 0;
    EDMA3.maxQdmaChannels[GROUP_2] = 0;

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

    /*
    * Framework Components' IRES Resman and Protocol implementation
    * for the ADDRSPACE resource.
    *
    * To use this implementation, uncomment the xdc.useModule() statement
    * assign your values to config parameters of this module.
    *
    */
    var ADDRSPACE = xdc.useModule('ti.sdo.fc.ires.addrspace.ADDRSPACE');

    /*
    * Framework Components' IRES Resman and Protocol implementation
    * for the BUFRES resource.
    *
    * To use this implementation, uncomment the xdc.useModule() statement
    * assign your values to config parameters of this module.
    *
    */
    /* var BUFRES = xdc.useModule('ti.sdo.fc.ires.bufres.BUFRES'); */

    /*
    * Framework Components' IRES Resman and Protocol implementation
    * for the NULLRES resource.
    *
    * To use this implementation, uncomment the xdc.useModule() statement
    * assign your values to config parameters of this module.
    *
    */
    /* var NULLRES = xdc.useModule('ti.sdo.fc.ires.nullresource.NULLRES'); */

    3) create app project

    *.cfg

    var Systme = xdc.useModule('xdc.runtime.System');
    var Startup = xdc.useModule('xdc.runtime.Startup');

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

    var TraceUtil = xdc.useModule('ti.sdo.ce.utils.trace.TraceUtil');
    TraceUtil.attrs = TraceUtil.DEFAULT_TRACING;
    TraceUtil.attrs.dsp0TraceMask = "*=167,server=1267";

    var Engine = xdc.useModule('ti.sdo.ce.Engine');
    var myEngine = Engine.createFromServer(
    "camera", // Engine name (as referred to in the C app)
    "bin/cs.x64P", // path to server exe, relative to its package dir
    "server.cs" // full server package name
    );

    prog.build.platform = 'ti.platforms.evm3530';

    makefile

    -include /opt/dvsdk/Rules.make

    ## -------- host-specific paths -------- ##
    XDCPATH := $(DVSDK_PACKAGES_PATH)/\;../../

    ## -------- build parameters -------- ##
    CONFIG := cfgsite
    PROGNAME := plate_rec
    TARGET := test

    ## -------- all-rule -------- ##
    all : $(TARGET)

    ## -------- compile-rule -------- ##
    %.o : %.c
    $(CC) $(shell cat $(CONFIG)/compiler.opt) -c $^

    ## -------- link-rule -------- ##
    $(TARGET) : $(PROGNAME).o 
    $(CC) $(CONFIG)/linker.cmd -lpthread -o $@ $^

    .PHONY: config config_clean clean

    ## -------- config-rule -------- ##
    config:
    @xs --xdcpath=$(XDCPATH) xdc.tools.configuro -c $(GCTOOL_DIR) -t $(XDCTARGET) -p $(XDCPLATFORM) -o $(CONFIG) -b config.bld $(PROGNAME).cfg

    config_clean:
    -rm $(CONFIG) -rf

    clean:
    -rm *.o $(TARGET) -f

  • I don't really have access to the demos, but if i look at the code generated by "gencodecpkg", the code in the process call that might generate an error is very minimal:-


    /* 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);
    }

    Any chance one of your parameters are messed up ? 

    After this, it just does a memcpy and returns without an error.