tmp=0.11*inBufs[i*3]+0.59*inBufs[i*3+1]+0.3*inBufs[i*3+2];
outBufs[i*3]=tmp;
outBufs[i*3+1]=tmp;
outBufs[i*3+2]=tmp;
}
}
XDAS_Int32VIDENCCOPY_TI_process(IVIDENC_Handleh,XDM_BufDesc*inBufs,
XDM_BufDesc*outBufs,IVIDENC_InArgs*inArgs,IVIDENC_OutArgs*outArgs)
{
XDAS_Int32curBuf;
XDAS_UInt32minSamples;
#ifdefUSE_ACPY3
constUint32maxTransferChunkSize=0xffff;
Uint32thisTransferChunkSize=0x0;
Uint32remainingTransferChunkSize;
Uint32thisTransferSrcAddr,thisTransferDstAddr;
ACPY3_Paramsparams;
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);
/*validatearguments-thiscodeconlysupports"base"xDM.*/
if((inArgs->size!
=sizeof(*inArgs))||
(outArgs->size!
=sizeof(*outArgs))){
GT_2trace(curTrace,GT_ENTER,
"VIDENCCOPY_TI_process,unsupportedsize"
"(0x%x,0x%x)\n",inArgs->size,outArgs->size);
return(IVIDENC_EFAIL);
}
#ifdefUSE_ACPY3
/*
*ActivateChannelscratchDMAchannels.
*/
ACPY3_activate(videncObj->dmaHandle1D1D8B);
#endif
/*outArgs->bytesGeneratedreportsthetotalnumberofbytesgenerated*/
outArgs->bytesGenerated=0;
/*
*Acoupleconstraintsforthissimple"copy"codec:
*-Videoencodingpresumesasingleinputbuffer,soonlyoneinput
*bufferwillbeencoded,regardlessofinBufs->numBufs.
*-Givenadifferentsizeofaninputandoutputbuffers,only
*encode(i.e.,copy)thelesserofthesizes.
*/
for(curBuf=0;(curBufnumBufs)&&
(curBufnumBufs);curBuf++){
/*there'sanavailableinandoutbuffer,howmanysamples?
*/
minSamples=inBufs->bufSizes[curBuf]bufSizes[curBuf]?
inBufs->bufSizes[curBuf]:
outBufs->bufSizes[curBuf];
#if0
thisTransferSrcAddr=(Uint32)inBufs->bufs[curBuf];
thisTransferDstAddr=(Uint32)outBufs->bufs[curBuf];
remainingTransferChunkSize=minSamples;
while(remainingTransferChunkSize>0){
if(remainingTransferChunkSize>maxTransferChunkSize){
thisTransferChunkSize=maxTransferChunkSize;
}
else{
thisTransferChunkSize=remainingTransferChunkSize;
}
/*Configurethelogicalchannel*/
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;
/*Configurelogicaldmachannel*/
ACPY3_configure(videncObj->dmaHandle1D1D8B,¶ms,0);
/*UseDMAtocopydata*/
ACPY3_start(videncObj->dmaHandle1D1D8B);
/*waitfortransfertofinish*/
ACPY3_wait(videncObj->dmaHandle1D1D8B);
}
GT_1trace(curTrace,GT_2CLASS,"VIDENCCOPY_TI_process>"
"ACPY3Processed%dbytes.\n",minSamples);
#endif
GT_3trace(curTrace,GT_2CLASS,"VIDENCCOPY_TI_process>"
"memcpy(0x%x,0x%x,%d)\n",
outBufs->bufs[curBuf],inBufs->bufs[curBuf],minSamples);
/*processthedata:
readinput,produceoutput*/
//memcpy(outBufs->bufs[curBuf],inBufs->bufs[curBuf],minSamples);
//image_binarization(inBufs->bufs[curBuf],outBufs->bufs[curBuf],minSamples);
image_gray(inBufs->bufs[curBuf],outBufs->bufs[curBuf],minSamples);
outArgs->bytesGenerated+=minSamples;
}
/*FillouttherestoftheoutArgsstruct*/
outArgs->extendedError=0;
outArgs->encodedFrameType=0;/*TODO*/
outArgs->inputFrameSkip=IVIDEO_FRAME_ENCODED;
outArgs->reconBufs.numBufs=0;/*important:
indicatenoreconBufs*/
return(IVIDENC_EOK);
}
其实上面标红的部分就是我们加上的主要部分,实现了图像的二值化和灰度化。
主要的难点其实是在数据的传送部分。
bufs是一个二维指针,这个需要非常注意。
还有需要注意的是其中数据的类型,注意char*和unsignedchar*的区别。
上面程序修改之后,编译codec,没有错误的话,会生成.a64P文件,这个文件供后面Server生成调用。
2、Server集成
由于我们是在例程上修改的,所以那些配置文件基本上不用动的,如果你想修改包含的Codec也可以进行修改。
但是这里我们需要尽快跑通程序,而没有做过多的尝试。
在/home/dvsdk_1_40_02_33/codec_engine_2_10_02/examples/ti/sdo/ce/examples/servers/video_copy/evmDM6467目录下编译,生成.X64P文件。
3、应用端程序
应用端的源文件主要是app.c和ceapp.c文件。
其中app.c是主函数,以及打开文件保存文件的操作。
具体的codecengine相关调用全部放在ceapp.c中。
在/home/dvsdk_1_40_02_33/codec_engine_2_10_02/examples/ti/sdo/ce/examples/apps/video_copy/dualcpu/evmDM6467目录下,主要修改地方如下:
之前是dat文件格式的读写操作,在这里修改成的bmp文件的读写。
主要修改后文件如下所示:
/*
*Copyright2008
*TexasInstrumentsIncorporated
*
*Allrightsreserved.PropertyofTexasInstrumentsIncorporated
*Restrictedrightstouse,duplicateordisclosethiscodeare
*grantedthroughcontract.
*
*/
/*
*========app.c========
*
*Non-Codec-Engine-usingpartoftheArm-sideLinuxapplication,thatat
*certainpointstalkstotheCodec-Engine-usingpartoftheArm-side
*Linuxapplication.Thelattermoduleisinfileceapp.c.
*
*Thecallflowis:
app.cfunctions->ceapp.cfunctions->CodecEnginelibs
*/
#include
#include
/*Definitionofbuffersizesforinputdata,encodeddata,outputdata.
*
*Ourapplicationreadsarawvideofileoneblockatthetimeatthe
*inputbuffer.Itcallsceapptoencodesthatfromtheinputbufferintothe
*"encodeddata"buffer.Thenitcallsceapptodecodethevideodatafrom
*"encodeddata"bufferintotheoutputbuffer.Finallyitwritesthe
*outputblocktoanotherfile.Thisflowisillustratedhere:
*
*==(app)==>[inBuf]==>
*==(ceapp/encoder)==>[encodedBuf]==>
*==(ceapp/decoder)==>[outBuf]==>
*==(app)==>
*
*Forsimplicity,belowwedefineallblockstobe1K,butthosesizes
*couldbearbitrary(thoughtheymustmatch).
*
*Note:
ItisEXTREMELYimportantthatthebuffersthatholdthedataarenot
*simplymalloc()ed,butareactuallyphysicallycontiguous.Thisisso
*becausethebuffersarepassedontothecodecsrunningontheDSP
*verbatim(thereisnobuffercopyinginvolved).CodecEngine
*(andtheceappmodule)providesandAPIforallocatingsuchbuffers.
*/
#defineINFRAMESIZE(1024*sizeof(char))/*rawframe(input)*/
#defineENCODEDFRAMESIZE(1024*sizeof(char))/*encodedframe*/
#defineOUTFRAMESIZE(1024*sizeof(char))/*decodedframe(output)*/
//zxj
#pragmapack
(2)//两字节对齐,否则bmp_fileheader会占16Byte
typedefstructBMP
{
//14字节
unsignedshortbfType;//文件标识2字节必须为BM
unsignedintbfSize;//文件大小4字节
unsignedshortbfReserved1;//保留,每字节以"00"填写2字节
unsignedshortbfReserved2;//同上2字节
unsignedintbfOffBits;//记录图像数据区的起始位置(图象数据相对于文件头字节的偏移量)。
4字节
//40字节
unsignedintbiSize;//表示本结构的大小4字节
intbiWidth;//位图的宽度4字节
intbiHeight;//位图的高度4字节
unsignedshortbiPlanes;//永远为1,2字节
unsignedshortbiBitCount;//位图的位数分为1481624322字节
unsignedintbiCompression;//压缩说明4字节
unsignedintbiSizeImage;//表示位图数据区域的大小以字节为单位4字节
intbiXPelsPerMeter;//用象素/米表示的水平分辨率4字节
intbiYPelsPerMeter;//用象素/米表示的垂直分辨率4字节
unsignedintbiClrUsed;//位图使用的颜色索引数4字节
unsignedintbiClrImportant;//对图象显示有重要影响的颜色索引的数目4字节
}BMP;
BMPbmp;
/*prototypesoffunctionsdefinedinceapp.c:
*/
externintceapp_init();/*initializetheceappmodule*/
externchar*ceapp_allocContigBuf(/*allocatephysicallycontiguous*/
intbufSize,/*bufferofgivensize;description*/
char*bufDescription/*isusedonlyforprint*/
);
externintceapp_validateBufSizes(/*confirmthattheenc/deccodecs*/
intinBufSize,/*supportthesebuffersizes*/
intencodedBufSize,/*fortherawinputvideo,encoded*/
intoutBufSize/*videodata,anddecodedoutput*/
);
externintceapp_encodeBuf(/*encoderawvideodataininBuf*/
char*inBuf,/*andstoreresultinencodedBuf*/
intinBufSize,
char*encodedBuf,
intencodedBufSize
);
externintceapp_decodeBuf(/*decodedatafromencodedBufand*/
char*encodedBuf,/*storeresultingrawdatainoutBuf*/
intencodedBufSize,
char*outBuf,
intoutBufSize
);
externvoidceapp_freeContigBuf(/*freethecontiguousbuffer*/
char*buf,
intbufSize
);
externvoidceapp_exit();/*exittheceappmodule*/
/*
*========encodeDecodeFile========
*Thisfunctionreadsblocksoftheinputfileoneatthetime,encodes
*eachblock,decodesit,andwritestheresulttotheoutputfile.
*/
staticintencodeDecodeFile(char*inFileName,char*outFileName)
{
/*pointerstocontiguousshareddatabuffers(sharedb/wArmandDSP)*/
staticchar*inBuf=NULL;/*tocontig-allocforINFRAMESIZE*/
staticchar*encodedBuf=NULL;/*tocontig-allocforENCODEDFRAMESIZE*/
staticchar*outBuf=NULL;/*tocontig-allocforOUTFRAMESIZE*/
FILE*inFile=NULL,*outFile=NULL;
intstatus,n;
/*openfilestreamsforinputandoutput*/
if((inFile=fopen(inFileName,"rb"))