Hi All,
I am trying to develop an application on DM365 which does Jpeg encoding successively in a loop. I am using DVSDK v2_10_01_18 and framework component v2_24.
I could able to encode one image using my application. But when I call the application in a loop I am getting the following errors,
ERROR: assertion violation: SemMP_posix.c, line 360
ERROR: assertion violation: LockMP_posix.c, line 90
ERROR: assertion violation: LockMP_posix.c, line 189
ERROR: assertion violation: LockMP_posix.c, line 190
ERROR: assertion violation: LockMP_posix.c, line 191
Could any one help me to resolve this.
Thanks in advance,
Jai,
My application is as follows,
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <strings.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <signal.h>
#include <xdc/std.h>
#include <ti/sdo/ce/Engine.h>
#include <ti/sdo/ce/trace/gt.h>
#include <ti/sdo/ce/CERuntime.h>
#include <ti/sdo/ce/video1/videnc1.h>
#include <ti/sdo/ce/image1/imgenc1.h>
#include <ti/sdo/codecs/jpegenc/ijpegenc.h>
#include <ti/sdo/fc/ires/addrspace/ires_addrspace.h>
#include <ti/sdo/fc/ires/addrspace/iresman_addrspace.h>
#include <ti/sdo/fc/ires/hdvicp/iresman_hdvicp.h>
#include <ti/sdo/fc/ires/hdvicp/ires_hdvicp.h>
#include <ti/sdo/dmai/Dmai.h>
#include <ti/sdo/dmai/BufferGfx.h>
#include <ti/sdo/fc/rman/rman.h>
#include <ti/sdo/fc/ires/iresman.h>
#include <ti/sdo/fc/ires/vicp/iresman_vicp2.h>
#include <ti/sdo/fc/ires/edma3chan/iresman_edma3Chan.h>
#include <ti/sdo/fc/ires/edma3chan/ires_edma3Chan.h>
#include <ti/sdo/fc/edma3/edma3_config.h>
#include <ti/sdo/edma3/rm/edma3_rm.h>
#include <ti/sdo/fc/ires/addrspace/ires_addrspace.h>
#include <ti/sdo/fc/ires/addrspace/iresman_addrspace.h>
#include <ti/sdo/linuxutils/cmem/include/cmem.h>
#define MAX_IMG_WIDTH 1024
#define MAX_IMG_HEIGHT 768
#define ORGBUF_OFFSET (3)
#define LUMABUF_SIZE (MAX_IMG_WIDTH * (MAX_IMG_HEIGHT+32))
#define CHROMABUF_SIZE (LUMABUF_SIZE) /* Support JPEG 4:4:4 */
#define ENCODED_DATA_BUFFER_SIZE (2 * MAX_IMG_WIDTH * MAX_IMG_HEIGHT)
static IIMGENC1_Params params;
static IIMGENC1_DynamicParams dynamicParams;
static CMEM_AllocParams memParams;
IIMGENC1_InArgs inArgs;
IIMGENC1_OutArgs outArgs;
XDM1_BufDesc inBufDesc;
XDM1_BufDesc outBufDesc;
/******************************************************************************
* main
******************************************************************************/
Int main(Int argc, Char *argv[])
{
int i;
Int status = EXIT_SUCCESS;
FILE *fp_out;
FILE *fp_in;
int bytes_read = 0;
IMGENC1_Handle/*IALG_Handle*/ handle;
char *algName = "jpegenc";
int bytesGenerated;
unsigned char* Inbuf;
unsigned char* Outbuf;
Engine_Handle hEngine = NULL;
IJPEGENC_Status encStatus;
int iresStatus;
IRESMAN_Edma3ChanParams configParams;
IRESMAN_VicpParams iresmanConfigParams;
IRESMAN_AddrSpaceParams addrspaceConfigParams;
for(i = 0; i < 2; i++) {
bytesGenerated = 0;
hEngine = NULL;
handle = NULL;
fp_in = fopen("bream2_352_288_422_UYVY.yuv", "rb");
if(fp_in == NULL)
{
printf("Input File not found \n");
return -1;
}
fp_out = fopen("bream2_352_288_422_UYVY.jpg", "wb");
if(fp_out == NULL)
{
printf("Output File not found \n");
return -1;
}
params.maxHeight = 320;
params.maxWidth = 384;
params.maxScans = 15;
params.dataEndianness = 1;
params.forceChromaFormat = 2; /* 4:2:0 SP */
params.size = sizeof(IIMGENC1_Params);
dynamicParams.inputChromaFormat = 4; /* 4:2:2 UYVY Little endian Interleaved */
dynamicParams.inputWidth = 352;
dynamicParams.inputHeight = 288;
dynamicParams.captureWidth = 352;
dynamicParams.numAU = 0;
dynamicParams.generateHeader = 0;
dynamicParams.qValue = 97;
dynamicParams.size = sizeof(IIMGENC1_DynamicParams);
/* Initialize Codec Engine runtime */
CERuntime_init();
/* Initialize Davinci Multimedia Application Interface */
Dmai_init();
memParams.type=CMEM_POOL;
memParams.flags=CMEM_NONCACHED;
memParams.alignment=256;
CMEM_init();
Inbuf = CMEM_alloc((LUMABUF_SIZE*2+ORGBUF_OFFSET), &memParams);
if(Inbuf == NULL)
{
return -1;
}
Outbuf = CMEM_alloc((ENCODED_DATA_BUFFER_SIZE), &memParams);
if(Outbuf == NULL)
{
return -1;
}
memset(Outbuf, 0xaa, ENCODED_DATA_BUFFER_SIZE);
memset(Inbuf, 0xaa, (LUMABUF_SIZE*2+ORGBUF_OFFSET));
//Read the file
bytes_read = fread(Inbuf, 1, dynamicParams.inputWidth * dynamicParams.inputHeight * 2, fp_in);
printf("Encode demo started.\n");
/* Reset, load, and start DSP Engine */
hEngine = Engine_open("encode", NULL, NULL);
if (hEngine == NULL) {
printf("Failed to open codec engine \n");
return -1;
}
if(RMAN_init() != IRES_OK)
{
printf("Cannot Init RMAN.\n");
return -1;
}
else
{
printf("RMAN initialized.\n");
}
//DM365MM_init();
printf("Registering VICP Protocols \n");
iresmanConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
iresmanConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
iresmanConfigParams.baseConfig.size = sizeof(IRESMAN_VicpParams);
if(RMAN_register(&IRESMAN_VICP2, (IRESMAN_Params *)&iresmanConfigParams) != IRES_OK)
{
printf("VICP Protocol regn failed\n");
}
else
{
printf("VICP Protocols registered.\n");
configParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
configParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
configParams.baseConfig.size = sizeof(IRESMAN_Edma3ChanParams);
if(RMAN_register(&IRESMAN_EDMA3CHAN, (IRESMAN_Params *)&configParams) != IRES_OK)
{
printf("EDMA3 Protocol regn failed\n");
}
else
{
printf("EDMA3 Protocols registered.\n");
}
}
#if 0
{
IRESMAN_HdVicpParams configParams;
configParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
configParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
configParams.baseConfig.size = sizeof(IRESMAN_HdVicpParams);
configParams.numResources = 1;
if (RMAN_register(&IRESMAN_HDVICP, (IRESMAN_Params *)&configParams) != IRES_OK) {
printf("HDVICP Protocol Registration Failed \n");
return -1;
}
}
#endif
/* ADDRSPACE registering */
/*
* * Supply initialization information for the ADDRSPACE RESMAN while
* registering
* */
addrspaceConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
addrspaceConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
addrspaceConfigParams.baseConfig.size = sizeof(IRESMAN_AddrSpaceParams);;
iresStatus = RMAN_register(&IRESMAN_ADDRSPACE, (IRESMAN_Params*)&addrspaceConfigParams);
if (IRES_OK != iresStatus) {
printf("ADDRSPACE Protocol Registration Failed \n");
return -1;
}
printf("ADDRSPACE Protocol Registration Success \n");
printf("\nhEngine = %d\n", hEngine);
handle = IMGENC1_create(hEngine, algName, ¶ms);
if (handle == NULL) {
printf("Failed to open jpeg encode algorithm: %s (0x%x)\n",
algName, Engine_getLastError(hEngine));
return -1;
}
printf("IMGENC1_create SUCCESS\n");
encStatus.imgencStatus.size = sizeof(encStatus);
status = IMGENC1_control(handle, XDM_SETPARAMS, (IIMGENC1_DynamicParams *)&dynamicParams, (IIMGENC1_Status *)&encStatus);
if (status != 0/*VIDENC1_EOK*/) {
printf("\n IMGENC1_control failed\n");
return -1;
}
printf("IMGENC1_control SUCCESS\n");
inArgs.size = sizeof(IIMGENC1_InArgs);
outArgs.size = sizeof(IIMGENC1_OutArgs);
inBufDesc.numBufs = 1;
inBufDesc.descs[0].bufSize = 288*352*2;
inBufDesc.descs[0].buf = (XDAS_Int8 *)Inbuf;
outBufDesc.numBufs = 1;
outBufDesc.descs[0].bufSize = 288*352*2;
outBufDesc.descs[0].buf = (XDAS_Int8 *)Outbuf;
/* perform the image (JPEG) encoding */
status = IMGENC1_process(handle, &inBufDesc, &outBufDesc, &inArgs, &outArgs);
if(status != 0)
{
printf("IMGENC1_process FAILS \n");
}
bytesGenerated = outArgs.bytesGenerated;
printf("IMGENC1_process SUCCESS %d\n", bytesGenerated);
fwrite(Outbuf, 1, bytesGenerated, fp_out);
fclose(fp_in);
fclose(fp_out);
if( handle){
IMGENC1_delete(handle);
}
if (hEngine) {
Engine_close(hEngine);
}
//RMAN_unregister(&IRESMAN_HDVICP);
RMAN_unregister(&IRESMAN_EDMA3CHAN);
RMAN_unregister(&IRESMAN_VICP2);
RMAN_unregister(&IRESMAN_ADDRSPACE);
RMAN_exit();
CMEM_free(Inbuf, &memParams);
CMEM_free(Outbuf, &memParams);
CMEM_exit();
//CERuntime_exit();
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------