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, ¶ms);
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);
}