I am using the TI evaluation JPEG codec and experiencing a problem with
trying to encode and store multiple JPEG files.
The app code is below. It is modified from code that I have been using
successfully with an mpeg4 codec.
The result is that I get one encoded frame back which is stored in a file
1.jpg. The rest of the files 2.jpg , 3.jpg etc are only 14 bytes in size.
It appears that the encodeVideoBuffer() will only encode the first frame
that is sent to it.
Any ideas?
Thanks,
Lee.
/***************************************************************************
***
* videoEncodeAlgCreate
****************************************************************************
**/
static int videoEncodeAlgCreate(Engine_Handle hEngine, IMGENC_Handle
*hEncodePtr, VideoEncoder videoEncoder, int width, int height, int bitrate)
{
/* JPEG Enc and Dec params */
IMGENC_Params encParams;
IMGENC_Handle encHandle;
IMGENC_DynamicParams dynamicEncParams;
IMGENC_Status encStatus;
XDAS_Int32 ret;
/*Jpeg Encoder Base params init */
encParams.size = sizeof
(IMGENC_Params);
encParams.maxWidth = 640;
encParams.maxHeight = 480;
encParams.dataEndianness = XDM_LE_32;
encParams.forceChromaFormat = XDM_YUV_422P;
encParams.maxScans = 3;
encHandle = IMGENC_create(hEngine, "jpegenc", &encParams);
if(encHandle == NULL)
{
printf("JPEG Encoder algorithm creation failed\n");
exit(1);
}
/*Jpeg Encoder Dynamic params init */
dynamicEncParams.size =
sizeof(IIMGENC_DynamicParams);
dynamicEncParams.numAU =
0;//XDM_DECODE_AU ;
dynamicEncParams.inputChromaFormat = XDM_YUV_422ILE;
dynamicEncParams.inputWidth =
640;//ncHandle->captureWidth;
dynamicEncParams.inputHeight =
480;//ncHandle->captureHeight;
dynamicEncParams.captureWidth =
0;//ncHandle->captureWidth;
dynamicEncParams.generateHeader =
XDM_ENCODE_AU;
dynamicEncParams.qValue = 50;
encStatus.size
= sizeof(IIMGENC_Status);
ret =
IMGENC_control(encHandle,XDM_SETPARAMS,&dynamicEncParams,&encStatus);
if (ret != IMGENC_EOK)
{
printf("JPEG Encode XDM_SETPARAMS Control error ;ret
= %d\n",(int)ret);
exit(1);
}
else
{
printf("JPEG Encode XDM_SETPARAMS Control Done\n");
}
*hEncodePtr = encHandle;
return SUCCESS;
}
/***************************************************************************
***
* encodeVideoBuffer
****************************************************************************
**/
static int encodeVideoBuffer(IMGENC_Handle hEncode, char *inBuf, int
inBufSize,
char *outBuf, int *outBufSize)
{
XDM_BufDesc inBufDesc;
XDM_BufDesc outBufDesc;
XDAS_Int32 inBufSizeArray[0];
XDAS_Int32 outBufSizeArray[0];
XDAS_Int32 status;
IIMGENC_InArgs inArgs;
IIMGENC_OutArgs outArgs;
inBufSizeArray[0] = 640 * (SCREEN_BPP/8) * 480;//inBufSize;
outBufSizeArray[0] = 640 * (SCREEN_BPP/8) * 480;
inBufDesc.numBufs = 1;
inBufDesc.bufSizes = inBufSizeArray;
inBufDesc.bufs = (XDAS_Int8 **) &inBuf;
outBufDesc.numBufs = 1;
outBufDesc.bufSizes = outBufSizeArray;
outBufDesc.bufs = (XDAS_Int8 **) &outBuf;
inArgs.size = sizeof(IIMGENC_InArgs);
outArgs.size = sizeof(IIMGENC_OutArgs);
/* Encode video buffer */
status = IMGENC_process(hEncode, &inBufDesc, &outBufDesc, &inArgs,
&outArgs);
if (status != IMGENC_EOK) {
ERR("VIDENC_process() failed with a fatal error (%ld ext: %#lx\n",
status, outArgs.extendedError);
return FAILURE;
}
*outBufSize = outArgs.bytesGenerated;
return SUCCESS;
}
/***************************************************************************
***
* from writer.c
****************************************************************************
**/
while (1)
{
/* Get an encoded buffer from the video thread */
FifoUtil_get(&envp->outFifo, &oe);
if (oe.id != WRITER_PRIME)
{
sprintf(str, "%d" , envp->imageCount);
strncat(str, ".jpg", 100);
printf("image count is :%s\n", str);
printf("framesize is:%d\n", oe.frameSize);
envp->imageCount += 1;
outputFp = fopen(str, "wb");
fwrite(oe.encodedBuffer, oe.frameSize, 1, outputFp);
fclose(outputFp);
}
/***************************************************************************
***
* from video.c
****************************************************************************
**/
while (1)
{
CLEAR(v4l2buf);
v4l2buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
v4l2buf.memory = V4L2_MEMORY_MMAP;
/* Get a frame buffer with captured data */
ioctl(inputFd, VIDIOC_DQBUF, &v4l2buf);
e.frameBuffer = vidBufs[v4l2buf.index].start;
e.width = envp->imageWidth ;
e.height = envp->imageHeight ;
/* Display raw frame while encoding it */
FifoUtil_put(&displayEnv.outFifo, &e);
/* Get a buffer back from the writer thread */
FifoUtil_get(&writerEnv.inFifo, &oe);
/* Encode the captured video frame */
encodeVideoBuffer(hEncode, vidBufs[v4l2buf.index].start,
imageSize, oe.encodedBuffer, &oe.frameSize);
/* Send the encoded buffer to be written to the filesystem */
FifoUtil_put(&writerEnv.outFifo, &oe);
/* Receive a buffer with a displayed frame from the display thread
*/
FifoUtil_get(&displayEnv.inFifo, &e);
/* Issue captured frame buffer back to device driver */
ioctl(inputFd, VIDIOC_QBUF, &v4l2buf); == -1)
}
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source