Hello everybody
Since a few Days i am trying to implement the jpeg encoder into the encode/decode demo...
at first i hope this is possible but i couldn't imagine why it shouldn't be possible....
the first step i made was to add the jpeg encoder engine to the encodedecode.cfg
/* ============================================================================* Copyright (c) Texas Instruments Incorporated 2007
* Use of this software is controlled by the terms and conditions found in the
* license agreement under which this software has been supplied or provided.
* ============================================================================*/
var osalGlobal = xdc.useModule( 'ti.sdo.ce.osal.Global' );
osalGlobal.runtimeEnv = osalGlobal.LINUX;
var MPEG4ENC = xdc.useModule('ti.sdo.codecs.mpeg4enc.dm355.ce.MPEG4ENC');
var MPEG4DEC = xdc.useModule('ti.sdo.codecs.mpeg4dec.dm355.ce.MPEG4DEC');
var JPEGENC = xdc.useModule('ti.sdo.codecs.jpegenc.dm355.ce.JPEGENC');
/*======== Engine Configuration ========*/
var Engine = xdc.useModule('ti.sdo.ce.Engine');
var demoEngine = Engine.create("encodedecode", [
{name: "mpeg4enc", mod: MPEG4ENC, local: true, groupId: 1},
{name: "mpeg4dec", mod: MPEG4DEC, local: true, groupId: 1},
{name: "jpegenc", mod: JPEGENC, local: true, groupId: 1},
]);
Next step i made was to start the engine inside the video1.c, this was already there, only thing i made was to took it out of the if clause to start it also if passthrough is active.
After this i allocated and initialized the jpeg encoder (mpeg4 encoder/decoder stays off, cause of passthrough)
Therefor i used a copy of the funktion to start the mpeg4 encoder (videoEncodeAlgCreate) and renamed the copy into "jpgEncodeAlgCreate"
/******************************************************************************* jpgEncodeAlgCreate
******************************************************************************/
static int jpgEncodeAlgCreate(Engine_Handle hEngine, IMGENC1_Handle *hImgencPtr, int width, int height)
{
IMGENC1_DynamicParams dynParams;
IMGENC1_Status encStatus;
IMGENC1_Params encParams;
IMGENC1_Handle hImgenc;
XDAS_Int32 status;
/* allocate and initialize image encoder on the engine */
encParams.size = sizeof(IMGENC1_Params);
encParams.maxWidth = width;
encParams.maxHeight = height;
encParams.maxScans = 4;
encParams.dataEndianness = XDM_DEFAULT;
encParams.forceChromaFormat = XDM_YUV_422ILE;
/* Create JPEG encoder instance */
hImgenc = IMGENC1_create(hEngine, "jpegenc", &encParams);
if (hImgenc == NULL) {
printf("Failed to open jpg encode algorithm: %s (0x%x)\n", "jpegenc", Engine_getLastError(hEngine));
return FAILURE;
}
/* set the parameters for encoding */
dynParams.size = sizeof(IMGENC1_DynamicParams);
dynParams.numAU = XDM_DEFAULT;
dynParams.inputChromaFormat = XDM_YUV_422ILE;
dynParams.inputHeight = height;
dynParams.inputWidth = width;
dynParams.captureWidth = 0;
dynParams.generateHeader = XDM_ENCODE_AU;
dynParams.qValue = 73;
/* Set video encoder dynamic parameters */
encStatus.size = sizeof(IMGENC1_Status);
encStatus.data.buf = NULL;
status = IMGENC1_control(hImgenc, XDM_SETPARAMS, &dynParams, &encStatus);
if (status != VIDENC1_EOK) {
printf("XDM_SETPARAMS failed, status=%ld\n", status);
return FAILURE;
}
*hImgencPtr = hImgenc;
return SUCCESS;
}
This function stops executing the programm with these errors.
starting the programm with ./encodedecode -r 720x576 -x -p
Encodedecode Demo started.Codec Engines opend in video thread (<-- this is a line in the videoThrFxn after starting the Engine, after this my jpgencodeAlgCreate is called)
CMEMK Error: GETPHYS: Failed to convert virtual 0x4001dac0 to physical.
CMEM Error: getPhys: Failed to get physical address of 0x4001dac0
Failed to open jpg encode algorithm: jpegenc (0x0)
Capturing 720x576 video (cropped to 720x576)
Encodedecode Error: Failed FBIO_WAITFORVSYNC (Connection timed out)
I also added imgenc1.h gt.h and stdlib.h cause they were included in the jpgenc example...
I commented the video Main Loop out, cause i want only one frame as picture. I tested these befor and i saw only one picture on the tv after that.
So now i have no idea why it wont start the jpeg encoder ... i hope you can help me... i simply want to build some jpegs out of the video stream befor encoding to mpeg4.
p.s. the jpegenc example is no futher help, i looked at it already... or do you have some more guides about that?
p.p.s here is also the jpeg encode function but the programm quits befor its execution and the other function calls
jpegEncodeAlgCreate call/* Reset, load, and start DSP Engine */
hEngine = Engine_open(ENGINE_NAME, NULL, NULL);
if (hEngine == NULL) {
printf("Failed to open codec engine %s\n", ENGINE_NAME);
cleanup(THREAD_FAILURE);
} else {
printf("Codec Engines opened in video thread\n");
}
/* Allocate and initialize jpeg encoder on the engine */
if (jpgEncodeAlgCreate(hEngine, &hImgenc, envp->imageWidth, envp->imageHeight) == FAILURE) {
cleanup(THREAD_FAILURE);
}
encodejpg call
if (encodeJpeg(hImgenc, ce.virtBuf, ce.bufSize, encBuf, encBufSize, &frameSize) == FAILURE) {
breakLoop(THREAD_FAILURE);
}
/******************************************************************************* encodeJpeg
******************************************************************************/
static int encodeJpeg(IMGENC1_Handle hImgenc, char *inBuf, int inBufSize,
char *outBuf, int outBufMaxSize, int *outBufSize)
{
IVIDEO1_BufDescIn inBufDesc;
XDM_BufDesc outBufDesc;
XDAS_Int32 outBufSizeArray[1];
XDAS_Int32 status;
VIDENC1_InArgs inArgs;
VIDENC1_OutArgs outArgs;
outBufSizeArray[0] = outBufMaxSize;
inBufDesc.numBufs = 1;
inBufDesc.frameWidth = 720;
inBufDesc.frameHeight = 576;
inBufDesc.bufDesc[0].bufSize = inBufSize;
inBufDesc.bufDesc[0].buf = inBuf;
outBufDesc.numBufs = 1;
outBufDesc.bufSizes = outBufSizeArray;
outBufDesc.bufs = (XDAS_Int8 **) &outBuf;
inArgs.size = sizeof(VIDENC1_InArgs);
outArgs.size = sizeof(VIDENC1_OutArgs);
/* Encode Jpeg/video buffer */
status = IMGENC1_process(hImgenc, &inBufDesc, &outBufDesc, &inArgs, &outArgs);
if (status != IMGENC1_EOK) {
printf("VIDENC1_process() failed with a fatal error (%ld ext: %#lx\n",
status, outArgs.extendedError);
return FAILURE;
}
*outBufSize = outArgs.bytesGenerated;
return SUCCESS;
}
