Hi,I add some code to videnc_copy.c under example/codec/videnc directory.Here is my code:
/*
* ======== VIDENCCOPY_TI_process ========
*/
XDAS_Int32 VIDENCCOPY_TI_process(IVIDENC_Handle h, XDM_BufDesc *inBufs,
XDM_BufDesc *outBufs, IVIDENC_InArgs *inArgs, IVIDENC_OutArgs *outArgs)
{
XDAS_Int32 curBuf;
XDAS_UInt32 minSamples;
int i;
int j;
unsigned char *m_Temp;
int height=inArgs->height;
int length =inArgs->length;
#ifdef USE_ACPY3
const Uint32 maxTransferChunkSize = 0xffff;
Uint32 thisTransferChunkSize = 0x0;
Uint32 remainingTransferChunkSize;
Uint32 thisTransferSrcAddr, thisTransferDstAddr;
ACPY3_Params params;
VIDENCCOPY_TI_Obj *videncObj = (VIDENCCOPY_TI_Obj *)h;
#endif
GT_5trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_process(0x%x, 0x%x, 0x%x, "
"0x%x, 0x%x)\n", h, inBufs, outBufs, inArgs, outArgs);
/* validate arguments - this codec only supports "base" xDM. */
if ((inArgs->size != sizeof(*inArgs)) ||
(outArgs->size != sizeof(*outArgs))) {
GT_2trace(curTrace, GT_ENTER,
"VIDENCCOPY_TI_process, unsupported size "
"(0x%x, 0x%x)\n", inArgs->size, outArgs->size);
return (IVIDENC_EFAIL);
}
#ifdef USE_ACPY3
/*
* Activate Channel scratch DMA channels.
*/
ACPY3_activate(videncObj->dmaHandle1D1D8B);
#endif
/* outArgs->bytesGenerated reports the total number of bytes generated */
outArgs->bytesGenerated = 0;
/*
* A couple constraints for this simple "copy" codec:
* - Video encoding presumes a single input buffer, so only one input
* buffer will be encoded, regardless of inBufs->numBufs.
* - Given a different size of an input and output buffers, only
* encode (i.e., histogram) the lesser of the sizes.
*/
for (curBuf = 0; (curBuf < inBufs->numBufs) &&
(curBuf < outBufs->numBufs); curBuf++) {
/* there's an available in and out buffer, how many samples? */
minSamples = inBufs->bufSizes[curBuf] < outBufs->bufSizes[curBuf] ?
inBufs->bufSizes[curBuf] : outBufs->bufSizes[curBuf];
m_Temp = (unsigned char *)malloc(height*length);
if(m_Temp==NULL) {
GT_1trace(curTrace, GT_ENTER,"Fail to malloc memory (0x%x)\n",m_Temp);
return (IVIDENC_EFAIL);}
memcpy(m_Temp,inBufs->bufs[curBuf],inBufs->bufSizes[curBuf]);
/* Change to grey image. */
for(i=0;i< height;i++)
for(j=0;j< length;j+=2)
{
m_Temp[i*length+j]=0x80;
}
memcpy(inBufs->bufs[curBuf],m_Temp,inBufs->bufSizes[curBuf]);
free(m_Temp);
#ifdef USE_ACPY3
thisTransferSrcAddr = (Uint32)inBufs->bufs[curBuf];
thisTransferDstAddr = (Uint32)outBufs->bufs[curBuf];
remainingTransferChunkSize = minSamples;
while (remainingTransferChunkSize > 0) {
if (remainingTransferChunkSize > maxTransferChunkSize) {
thisTransferChunkSize = maxTransferChunkSize;
}
else {
thisTransferChunkSize = remainingTransferChunkSize;
}
/* Configure the logical channel */
params.transferType = ACPY3_1D1D;
params.srcAddr = (void *)thisTransferSrcAddr;
params.dstAddr = (void *)thisTransferDstAddr;
params.elementSize = thisTransferChunkSize;
params.numElements = 1;
params.waitId = 0;
params.numFrames = 1;
remainingTransferChunkSize -= thisTransferChunkSize;
thisTransferSrcAddr += thisTransferChunkSize;
thisTransferDstAddr += thisTransferChunkSize;
/* Configure logical dma channel */
ACPY3_configure(videncObj->dmaHandle1D1D8B, ¶ms, 0);
/* Use DMA to histogram data */
ACPY3_start(videncObj->dmaHandle1D1D8B);
/* wait for transfer to finish */
ACPY3_wait(videncObj->dmaHandle1D1D8B);
}
GT_1trace(curTrace, GT_2CLASS, "VIDENCHISTOGRAM_TI_process> "
"ACPY3 Processed %d bytes.\n", minSamples);
#else
GT_3trace(curTrace, GT_2CLASS, "VIDENCHISTOGRAM_TI_process> "
"memcpy (0x%x, 0x%x, %d)\n",
outBufs->bufs[curBuf], inBufs->bufs[curBuf], minSamples);
/* process the data: read input, produce output */
memcpy(outBufs->bufs[curBuf], inBufs->bufs[curBuf], minSamples);
#endif
outArgs->bytesGenerated += minSamples;
}
/* Fill out the rest of the outArgs struct */
outArgs->extendedError = 0;
outArgs->encodedFrameType = 0; /* TODO */
outArgs->inputFrameSkip = IVIDEO_FRAME_ENCODED;
outArgs->reconBufs.numBufs = 0; /* important: indicate no reconBufs */
return (IVIDENC_EOK);
}
When I run my application,I got the error message below:
[DSP] @0x0040468f:[T:0x8fa215e4] codecs.videnc_histogram - Fail to malloc memory
(0x0)
Why did I fail to malloc some memory in the codec? I know that when I use malloc to request memory ,the system will distribute it at DDRALGHEAP section,and my DDRALGHEAP's size is 128M bytes.It's big enough. So please ,I want somebody to tell me where is my fault,and how to correct it .Thanks a lot.