Hi All ,
I am trying to run an application tht convert Raw image to Yuv .And finally
convert it to jpg format by using jpegenc . I am using mt9t001 image sensor
type .
While running the application i got an error :-
Failed to get a pool fillting a size 3145728.
While debugging i found tht
encodedBuf = (XDAS_Int8 *)Memory_contigAlloc(encodedBufSize, BUFALIGN);
is returning Null .
I am putting my test file here .Could any one help me ?
Ashish
/* * ======== jpegenc.c ======== * * A simple
example of encoding an image using the JPEG encoder. *///typedef
int bool;#include <xdc/std.h>#include
<ti/sdo/ce/Engine.h>#include <ti/sdo/ce/osal/Memory.h>#include
<ti/sdo/ce/image1/imgenc1.h>#include <ti/sdo/ce/trace/gt.h>#include
<ti/sdo/codecs/jpegenc/dm355/ijpegenc.h>#include <stdio.h>#include
<stdlib.h>#include <string.h>#include <unistd.h>#include
<asm/types.h>#include <linux/videodev.h>#include
<media/davinci/davinci_vpfe.h>#include
<media/davinci/ccdc_dm355.h>#include
<asm/arch/dm355_ipipe.h>#include "ipipe_example.h"#include
"ipipe_config.h"#include "mt9t001_capture.h"/* * The parameters for
the encoding process. These can be changed to try * different image
sizes and JPEG features. */#define
SCANS 4#define
QVALUE 73/* this example only
supports YUV422 interleaved */#define CHROMAFORMAT
XDM_YUV_422ILE//#define CHROMAFORMAT XDM_YUV_422P/* Not a cached
system, no buffer alignment constraints */#define BUFALIGN
Memory_DEFAULTALIGNMENTstatic XDAS_Int8 *inBuf;static XDAS_Int8
*encodedBuf;static XDAS_Int32 inBufSize;static XDAS_Int32 encodedBufSize;static
String progName = "app";static String encoderName
= "jpegenc";static String engineName = "image";static String
image_base_name = "image";extern GT_Mask curMask;static Int32
encode(IMGENC1_Handle enc, XDAS_Int8 * in, XDAS_Int8 * out );void save( void *
data, int len, char * basename, char * ext );/* * ======== smain
======== */Int smain(Int argc, String argv[]){
Engine_Handle ce = NULL; IMGENC1_Handle enc =
NULL; IMGENC1_Params encParams;
IMGENC1_DynamicParams dynParams; IMGENC1_Status
imgStatus;
IJPEGENC_DynamicParams
extDynParams; char outFile[80]; int
capbuf_phyaddr; struct buffer * capbuf;
struct buffer ipipebuffer; int length; //
Setup the capture device InitCaptureDevice(CAP_FORMAT,
CAP_WIDTH, CAP_HEIGHT); // Initialize the IPIPE to just
convert from bayer to YCC InitIpipe(
RAW2YUV
,CAP_WIDTH
,CAP_HEIGHT
,CAP_WIDTH
,CAP_HEIGHT
,&ipipebuffer ); // Create a name for
the output file sprintf( outFile, "%s_%04d", image_base_name,
0 ); GT_0trace(curMask, GT_1CLASS, "Application
started.\n"); /* open the Codec Engine */
if ((ce = Engine_open(engineName, NULL, NULL)) == NULL)
{ fprintf(stderr, "ERROR: can't open
engine %s\n", engineName); goto
end; } printf("Engine Successfully Opend
:\n"); /* allocate and initialize image encoder on the engine
*/ encParams.size = sizeof(IMGENC1_Params);
encParams.maxWidth = CAP_WIDTH; encParams.maxHeight =
CAP_HEIGHT; encParams.maxScans = SCANS;
encParams.dataEndianness = XDM_DEFAULT;
encParams.forceChromaFormat = CHROMAFORMAT; enc =
IMGENC1_create(ce, encoderName, &encParams); if (enc ==
NULL) { fprintf(stderr, "%s: error:
can't open codec
%s\n",
progName, encoderName); goto
end; } printf("Codec Successfully Opend
:\n"); /* set the parameters for encoding
*/ dynParams.size =
sizeof(IMGENC1_DynamicParams); dynParams.numAU =
XDM_DEFAULT; dynParams.inputChromaFormat =
CHROMAFORMAT; dynParams.inputHeight =
CAP_HEIGHT; dynParams.inputWidth =
CAP_WIDTH; dynParams.captureWidth = 0;
dynParams.generateHeader = XDM_ENCODE_AU; dynParams.qValue =
QVALUE;#if 0 /* set the extended parameters for encoding
*/ extDynParams.imgencDynamicParams =
dynParams; extDynParams.rstInterval =
XDM_DEFAULT; extDynParams.disableEOI =
XDM_DEFAULT; extDynParams.rotation = 90;
extDynParams.customQ = NULL; imgStatus.size =
sizeof(imgStatus); if (IMGENC1_control(enc, XDM_SETPARAMS,
(IMGENC1_DynamicParams *)&extDynParams, &imgStatus)
== XDM_EFAIL)
{ fprintf(stderr, "%s: error: could
not set PARAMS: 0x%x\n",
progName,
(unsigned
int)imgStatus.extendedError); goto
end; }#else imgStatus.size =
sizeof(imgStatus); if (IMGENC1_control(enc, XDM_SETPARAMS,
&dynParams, &imgStatus) ==
XDM_EFAIL) { fprintf(stderr, "%s:
error: could not set PARAMS: 0x%x\n",
progName,
(unsigned
int)imgStatus.extendedError); goto
end; } printf("Engine PARAMS
Successfully Set :\n");#endif /* ask the codec for buffer
sizes - these are typically conservative */ if
(IMGENC1_control(enc, XDM_GETBUFINFO, &dynParams, &imgStatus)
== XDM_EFAIL)
{ fprintf(stderr, "%s: error: could
not get BUFINFO: 0x%x\n",
progName,
(unsigned
int)imgStatus.extendedError); goto
end; } printf("BUFINFO steps done
:\n"); /* allocate
input, encoded buffers based on GETBUFINFO */ inBufSize =
imgStatus.bufInfo.minInBufSize[0]; inBuf = (XDAS_Int8
*)Memory_contigAlloc(inBufSize, BUFALIGN); if
(inBuf==NULL) printf("Memory_ContigAlloc
for inbuf Not done :\n"); encodedBufSize =
imgStatus.bufInfo.minOutBufSize[0]; encodedBuf = (XDAS_Int8
*)Memory_contigAlloc(encodedBufSize, BUFALIGN); if(encodedBuf
== NULL) printf("Memory_ContigAlloc for
encodeBuf Not done :\n");
if ((inBuf == NULL) || (encodedBuf ==
NULL)) { printf("Memory_ContigAlloc Not
done :\n"); goto
end; } // Start the video
stream StartStreaming(); // Capture a
frame capbuf =
CaptureFrame(&capbuf_phyaddr); // Stop the video
stream StopStreaming();
sleep(1); // Convert the frame from bayer to
YCC DoIPIPING( RAW2YUV
,CAP_WIDTH
,CAP_HEIGHT
,CAP_WIDTH
,CAP_HEIGHT
,capbuf_phyaddr
); /* Copy the data to where the encoder can access it
*/ memcpy( inBuf, ipipebuffer.start, inBufSize
); /* use engine to encode the data */
length = encode(enc, inBuf, encodedBuf ); save(
capbuf->start, CAP_HEIGHT * CAP_WIDTH * sizeof( unsigned short ), outFile,
"raw" ); save( ipipebuffer.start, CAP_HEIGHT * CAP_WIDTH *
sizeof( unsigned short ), outFile, "ycc" ); save( encodedBuf,
length, outFile, "jpg" );end: /* free buffers
*/ if (encodedBuf)
{ Memory_contigFree(encodedBuf,
encodedBufSize); } if (inBuf)
{ Memory_contigFree(inBuf,
inBufSize); } /* teardown the codec
*/ if (enc) {
IMGENC1_delete(enc); } /* close the engine
*/ if (ce) {
Engine_close(ce); }
CloseCaptureDevice();
CloseIpipe(&ipipebuffer); return (0);}/* *
======== encode ======== */static Int32 encode(IMGENC1_Handle enc,
XDAS_Int8 * in, XDAS_Int8 * out ){ Int32
status;
IMGENC1_InArgs
encInArgs;
IMGENC1_OutArgs
encOutArgs;
IMGENC1_DynamicParams
encDynParams;
XDM1_BufDesc
inBufDesc;
XDM1_BufDesc
encodedBufDesc; /* initialize buffer descriptors that hold
input and output buffers */ inBufDesc.numBufs =
1; inBufDesc.descs[0].bufSize = inBufSize;
inBufDesc.descs[0].buf = in; encodedBufDesc.numBufs =
1; encodedBufDesc.descs[0].bufSize =
encodedBufSize; encodedBufDesc.descs[0].buf =
out; /* the size field of Args and Params structs must be
initialized */ encInArgs.size =
sizeof(encInArgs); encOutArgs.size =
sizeof(encOutArgs); encDynParams.size =
sizeof(encDynParams); /* perform the image (JPEG) encoding
*/ status = IMGENC1_process( enc
,&inBufDesc
,&encodedBufDesc
,&encInArgs
,&encOutArgs
); if (status == IMGENC1_EOK)
{ GT_2trace(curMask,
GT_2CLASS,
"Encoder process returned - 0x%x, %d bytes\n",
status,
encOutArgs.bytesGenerated
);
} else {
GT_2trace(curMask,
GT_7CLASS,
"Encoder frame processing FAILED, status = 0x%x,
"
"extendedError = 0x%x\n",
status,
encOutArgs.extendedError); } return
encOutArgs.bytesGenerated;}void save( void * data, int len, char * basename,
char * ext ){ char name[80]; FILE *
out; int ret; sprintf( name, "%s.%s",
basename, ext ); if ((out = fopen(name, "wb")) == NULL)
{ fprintf(stderr, "ERROR: can't write to
file %s\n", name); } else {
ret = fwrite(data, 1, len, out);
if ( ret != len ) {
fprintf( stderr
,"ERROR: '%s' only
wrote %d bytes, expected %d bytes\n"
,name
,ret
,len
); }
else { fclose( out
); } }}
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source