I have the following function (see below) in my program and it gives me segmentation fault when calling IMGENC1_process. The function is called as follows:
MakeYUV2JPEG("/mnt/ram/image.jpeg", display_buffers[2].user_addr, 2048, 1536, 75, display_buffers[0].user_addr);
where:
display_buffers[2].user_addr is pointing to a (2048*1536*2+4096 bytes) buffer (allocated by CMEM)
display_buffers[0].user_addr is pointing to a (1056*1536*4+4096 bytes) buffer (allocated by CMEM)
What could be the cause of segmentation fault?
Thank you.
====== my function =====
int MakeYUV2JPEG(char * filename, void * ptr, int width, int height, int Q, void * tmpbuf)
{
Engine_Handle ceh;
Engine_Error cerr;
IMGENC1_Handle ieh;
IIMGENC1_Params params;
IIMGENC1_DynamicParams dynamicparams;
IMGENC1_Status status;
IIMGENC1_InArgs inargs;
IIMGENC1_OutArgs outargs;
FILE * afile;
int res, i;
params.size = sizeof(params);
// init Code Engine (run-time variables)
CERuntime_init();
// open codec engine
ceh = Engine_open("imgenc1_copy", NULL, &cerr);
if (!ceh)
{
switch(cerr)
{
case Engine_EOK: printf("Open success\n"); break;
case Engine_EEXIST: printf("Open name does not exist\n"); break;
case Engine_ENOMEM: printf("Open can't allocate memory\n"); break;
case Engine_EDSPLOAD: printf("Open can't load the DSP\n"); break;
case Engine_ENOCOMM: printf("Open can't create a comm connection to DSP\n"); break;
case Engine_ENOSERVER: printf("Open can't locate the server on the DSP\n"); break;
case Engine_ECOMALLOC: printf("Open can't allocate communication buffer\n"); break;
default: printf("Open error undefined\n");
}
CERuntime_exit();
return -1;
}
// create JPEG encoder instance
ieh = IMGENC1_create(ceh, "jpegenc", NULL);
if (!ieh)
{
printf("Failed to create jpegenc instance\n");
Engine_close(ceh);
CERuntime_exit();
return -1;
}
dynamicparams.size = sizeof(dynamicparams);
dynamicparams.numAU = XDM_DEFAULT; // number of Access units to encode.
// (if want to feed the data in chunks to save buffer space)
dynamicparams.inputChromaFormat = XDM_YUV_422P; // format of the input data. see enum XDM_ChromaFormat for all formats
dynamicparams.inputHeight = height;
dynamicparams.inputWidth = width;
dynamicparams.captureWidth = 0; // set to zero to use image width. don't know what it's for.
dynamicparams.generateHeader = XDM_ENCODE_AU; // don't knwo what it's for but this is what dvtb used.
dynamicparams.qValue = Q; // compress JPEG qith quality = 75%
memset(&status, 0, sizeof(status));
status.size = sizeof(status); // define the size of status structure
res = IMGENC1_control(ieh, XDM_SETPARAMS, &dynamicparams, &status);
if (res != IMGENC1_EOK)
{
printf("Error (%d), Extended Error (%d) in image Encoder Control:setparams\n", res, status.extendedError);
IMGENC1_delete(ieh);
Engine_close(ceh);
CERuntime_exit();
return -1;
}
printf("CE params set OK\n");
memset(&status, 0, sizeof(status));
status.size = sizeof(status); // define the size of status structure
res = IMGENC1_control(ieh, XDM_GETBUFINFO, &dynamicparams, &status);
if (res != IMGENC1_EOK)
{
printf("Error (%d), Extended Error (%d) in image Encoder Control: getbufinfo\n", res, status.extendedError);
IMGENC1_delete(ieh);
Engine_close(ceh);
CERuntime_exit();
return -1;
}
printf("Input buffers needed: %d\n",(int)status.bufInfo.minNumInBufs);
for(i=0;i<status.bufInfo.minNumInBufs;i++)
printf("Input buffer %d size: %d\n",i, (int)status.bufInfo.minInBufSize[i]);
printf("Output buffers needed: %d\n",(int)status.bufInfo.minNumOutBufs);
for(i=0;i<status.bufInfo.minNumOutBufs;i++)
printf("Output buffer %d size: %d\n",i, (int)status.bufInfo.minOutBufSize[i]);
inargs.size = sizeof(inargs);
outargs.size = sizeof(outargs);
res = IMGENC1_process(ieh, ptr, tmpbuf, &inargs, &outargs) ;
if (res != IMGENC1_EOK)
{
printf("Error encoding image\n");
IMGENC1_delete(ieh);
Engine_close(ceh);
CERuntime_exit();
return -1;
}
printf("JPEG encoded: %d bytes\n",outargs.bytesGenerated);
if ((afile = fopen(filename,"w")))
{
fwrite(tmpbuf, outargs.bytesGenerated, 1, afile);
fclose(afile);
}
IMGENC1_delete(ieh);
Engine_close(ceh);
CERuntime_exit();
return 0;
}
==================