videocopy例程修改.docx

上传人:b****4 文档编号:12095933 上传时间:2023-04-17 格式:DOCX 页数:27 大小:23.53KB
下载 相关 举报
videocopy例程修改.docx_第1页
第1页 / 共27页
videocopy例程修改.docx_第2页
第2页 / 共27页
videocopy例程修改.docx_第3页
第3页 / 共27页
videocopy例程修改.docx_第4页
第4页 / 共27页
videocopy例程修改.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

videocopy例程修改.docx

《videocopy例程修改.docx》由会员分享,可在线阅读,更多相关《videocopy例程修改.docx(27页珍藏版)》请在冰豆网上搜索。

videocopy例程修改.docx

videocopy例程修改

Video_copy例程修改

本实验只要目的:

实现在codecenginevideo_copy例程上的修改,加入简单的图像处理。

通过对例程的修改,掌握整个工程所需要的文件,以及文件中的相互关系和开发流程。

但是请注意,这里只是开发方式中的一种,也是最简便的一种,所以实现相对而言比较简便,如果想要自己创建工程,还需对其中的文件进一步的理解以及熟悉。

1、codecs修改

在/home/dvsdk_1_40_02_33/codec_engine_2_10_02/examples/ti/sdo/ce/examples/codecs中,有两个文件夹,分别为viddec_copy和videnc_copy文件夹,这两个文件名分别表示视频的解码和编码。

表面上是这样的意思,其实打开里面的源文件,发现只是实现了拷贝的一个动作,并没有涉及到编解码的相关知识。

这两个文件夹就是两个codec,我们只需要对其中一个进行修改就可以了。

其实在第二步中我们所讲的Server构建的时候,其中有配置文件提到了,这边是调用了两个codec,我们完全可以只调用其中一个。

这里为了不带来不必要的麻烦,就没有删除。

我们主要在videnc_copy中进行修改,主要修改process函数,其他的都没有改动。

主要把其中DMA部分去掉,然后添加我们自己写的算法,如下所示:

*========VIDENCCOPY_TI_process========

*/

//zxj二值化

voidimage_binarization(char*inBufs,char*outBufs,intsize)

{

inti;

for(i=0;i

{

if(inBufs[i]<0)

{

outBufs[i]=0xFF;

}

else

{

outBufs[i]=0x0;

}

}

}

//zxj灰度化

voidimage_gray(unsignedchar*inBufs,unsignedchar*outBufs,intsize)

{

inti;

unsignedchartmp;

for(i=0;i

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"))

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 表格类模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1