codec engine代码阅读六---CE_DIR/examples/ti/sdo/ce/examles/apps/video_copy
2014-04-11 20:56
423 查看
这一篇来看应用,针对于dm6446的apps代码在:apps/video_copy/dualcpu/evmDM6446下面:
apps/video_copy/dualcpu/evmDM6446$ ls
app.c ceapp.c ceapp.cfg in.dat makefile package package.bld package.xdc
里面两个.c文件,一个.cfg文件,两个package.*文件是讨论的重点。
as always,let's have a look at package.xdc, whose content is as the following:
/*!
* ======== package.xdc ========
* Codec Engine build support package for the video_copy example.
*
* This package simply provides a makefile which builds each application.
*/
package ti.sdo.ce.examples.apps.video_copy.dualcpu.evmDM6446 [1, 0, 0] {
}
这里的内容也是只是声明了一个包,其他的什么也没有。然后是package.bld.这里面也没什么内容:
var Pkg = xdc.useModule('xdc.bld.PackageContents');
/* when constructing a release, release everything */
Pkg.attrs.exportAll = true;
Pkg.otherFiles = [
"makefile",
"in.dat",
];
只是提到使用了PackageContents模块,包含两个文件makefile和in.dat.
然后我们来看这里真正的主角ceapp.cfg:
/* use the tracing utility module 使用代码追踪工具模块*/
var TraceUtil = xdc.useModule('ti.sdo.ce.utils.trace.TraceUtil');
//TraceUtil.attrs = TraceUtil.SOCRATES_TRACING;
/* use and configure the osal. 使用并配置osal */
var osalGlobal = xdc.useModule('ti.sdo.ce.osal.Global');
osalGlobal.runtimeEnv = osalGlobal.DSPLINK_LINUX;
/*
* ======== Engine Configuration CE配置========
*/
var Engine = xdc.useModule('ti.sdo.ce.Engine');//使用engine模块。
var myEngine = Engine.createFromServer( //从服务器创建引擎
"video_copy", // Engine name (as referred to in the C app)//指定引擎的名字
"./video_copy.x64P", // path to server exe, relative to its package dir//服务器可执行文件的位置
"ti.sdo.ce.examples.servers.video_copy.evmDM6446" // server package服务器包名
);
有了上述内容,我们就可以使用服务器中的引擎了,然后我们看看app的代码是干什么的,ceapp.c:
int ceapp_init()
{
int status = -1; /* nonzero means failure */
/* initialize Codec Engine runtime first 初始化CE runtime*/
CERuntime_init();
/* reset, load, and start DSP Engine 复位,加载,启动DSP引擎*/
if ((ceHandle = Engine_open(engineName, NULL, NULL)) == NULL) {
printf("CEapp-> ERROR: can't open engine %s\n", engineName);
goto init_end;
}
/* activate DSP trace collection thread */
TraceUtil_start(engineName);
/* allocate and initialize video encoder on the engine在引擎上开辟并初始化视频编译器 */
encHandle = VIDENC_create(ceHandle, encoderName, NULL);
if (encHandle == NULL) {
printf("CEapp-> ERROR: can't open codec %s\n", encoderName);
goto init_end;
}
/* allocate and initialize video decoder on the engine在引擎上开辟并初始化视频解码器 */
decHandle = VIDDEC_create(ceHandle, decoderName, NULL);
if (decHandle == NULL) {
printf("CEapp-> ERROR: can't open codec %s\n", decoderName);
goto init_end;
}
status = 0; /* success */
init_end:
return status;
}
为不致于太长,楼下继续.
这里先对ceapp.c中的代码进行一下总结:
它里面的代码是为app.c调用服务的.里面的函数有这么几个:
ceapp_init()//这是使用引擎的第一步,初始化引擎
ceapp_allocContigBuf 开辟缓冲区,第二步,开辟缓冲区,然后app.c会打开文件,把文件内容一部分一部分地放入缓冲区
ceapp_validateBufSizes验证缓冲区大小时否正确
ceapp_encodeBuf 对缓冲区的内容进行编码
ceapp_decodeBuf 对缓冲区的内容进行解码
ceapp_freeContigBuf 释放缓冲区
ceapp_exit() 关闭引擎
这些函数里面的实现常常会调用IVIDENC,IVIDDEC接口的中的函数.
而这些函数的实现对应都是在codecs中实现的.
下面说app.c了:
简化后的main函数为:
int main(int argc, char *argv[])
{
char *inFileName, *outFileName;
inFileName = "in.dat";
outFileName = "out.dat";
createInFileIfMissing(inFileName);
encodeDecodeFile(inFileName, outFileName)
return 0;
}
main函数调用encodeDecodeFile来编解码,简化后的encodeDecodeFile函数为:
static int encodeDecodeFile(char *inFileName, char *outFileName)
{
inFile = fopen(inFileName, "rb")) ;
//打开两个文件,一个用于输入,一个用于输出
outFile = fopen(outFileName, "wb")) ;
ceapp_init();
//初始化引擎
inBuf = ceapp_allocContigBuf(INFRAMESIZE, "input data");
//开辟输出缓冲区
encodedBuf = ceapp_allocContigBuf(ENCODEDFRAMESIZE, "encoded data");
//开辟编解缓冲区
outBuf = ceapp_allocContigBuf(OUTFRAMESIZE, "output data");
//开辟输出缓冲区
status = ceapp_validateBufSizes(INFRAMESIZE, ENCODEDFRAMESIZE,
//验证编码缓冲区大小是否正常
for (n = 0 ;; n++) {
//for loop,不停地.....
(fread(inBuf, INFRAMESIZE, 1, inFile) == 0) {
//从输入文件读数据到输入缓冲区
status = ceapp_encodeBuf(inBuf, INFRAMESIZE,
encodedBuf, ENCODEDFRAMESIZE);
//将输入缓冲区数据编码后放入编码缓冲区
status = ceapp_decodeBuf(encodedBuf, ENCODEDFRAMESIZE,
outBuf, OUTFRAMESIZE);
//从编码缓冲区中解码,放入输出缓冲区
fwrite(outBuf, OUTFRAMESIZE, 1, outFile);
//从输出缓冲区写入输出文件
fclose(inFile);
//关闭文件
fclose(outFile);
ceapp_freeContigBuf(inBuf, INFRAMESIZE);
//释放各种缓冲区
ceapp_freeContigBuf(encodedBuf, ENCODEDFRAMESIZE);
ceapp_freeContigBuf(outBuf, OUTFRAMESIZE);
ceapp_exit();
//退出引擎
return status;
//返回
}
本篇说完总的工作流程就差不多了解了,接下来将会结合文档,说具体代码细节,并做一些示例程序.
这一篇来看应用,针对于dm6446的apps代码在:apps/video_copy/dualcpu/evmDM6446下面:
apps/video_copy/dualcpu/evmDM6446$ ls
app.c ceapp.c ceapp.cfg in.dat makefile package package.bld package.xdc
里面两个.c文件,一个.cfg文件,两个package.*文件是讨论的重点。
as always,let's have a look at package.xdc, whose content is as the following:
/*!
* ======== package.xdc ========
* Codec Engine build support package for the video_copy example.
*
* This package simply provides a makefile which builds each application.
*/
package ti.sdo.ce.examples.apps.video_copy.dualcpu.evmDM6446 [1, 0, 0] {
}
这里的内容也是只是声明了一个包,其他的什么也没有。然后是package.bld.这里面也没什么内容:
var Pkg = xdc.useModule('xdc.bld.PackageContents');
/* when constructing a release, release everything */
Pkg.attrs.exportAll = true;
Pkg.otherFiles = [
"makefile",
"in.dat",
];
只是提到使用了PackageContents模块,包含两个文件makefile和in.dat.
然后我们来看这里真正的主角ceapp.cfg:
/* use the tracing utility module 使用代码追踪工具模块*/
var TraceUtil = xdc.useModule('ti.sdo.ce.utils.trace.TraceUtil');
//TraceUtil.attrs = TraceUtil.SOCRATES_TRACING;
/* use and configure the osal. 使用并配置osal */
var osalGlobal = xdc.useModule('ti.sdo.ce.osal.Global');
osalGlobal.runtimeEnv = osalGlobal.DSPLINK_LINUX;
/*
* ======== Engine Configuration CE配置========
*/
var Engine = xdc.useModule('ti.sdo.ce.Engine');//使用engine模块。
var myEngine = Engine.createFromServer( //从服务器创建引擎
"video_copy", // Engine name (as referred to in the C app)//指定引擎的名字
"./video_copy.x64P", // path to server exe, relative to its package dir//服务器可执行文件的位置
"ti.sdo.ce.examples.servers.video_copy.evmDM6446" // server package服务器包名
);
有了上述内容,我们就可以使用服务器中的引擎了,然后我们看看app的代码是干什么的,ceapp.c:
int ceapp_init()
{
int status = -1; /* nonzero means failure */
/* initialize Codec Engine runtime first 初始化CE runtime*/
CERuntime_init();
/* reset, load, and start DSP Engine 复位,加载,启动DSP引擎*/
if ((ceHandle = Engine_open(engineName, NULL, NULL)) == NULL) {
printf("CEapp-> ERROR: can't open engine %s\n", engineName);
goto init_end;
}
/* activate DSP trace collection thread */
TraceUtil_start(engineName);
/* allocate and initialize video encoder on the engine在引擎上开辟并初始化视频编译器 */
encHandle = VIDENC_create(ceHandle, encoderName, NULL);
if (encHandle == NULL) {
printf("CEapp-> ERROR: can't open codec %s\n", encoderName);
goto init_end;
}
/* allocate and initialize video decoder on the engine在引擎上开辟并初始化视频解码器 */
decHandle = VIDDEC_create(ceHandle, decoderName, NULL);
if (decHandle == NULL) {
printf("CEapp-> ERROR: can't open codec %s\n", decoderName);
goto init_end;
}
status = 0; /* success */
init_end:
return status;
}
为不致于太长,楼下继续.
这里先对ceapp.c中的代码进行一下总结:
它里面的代码是为app.c调用服务的.里面的函数有这么几个:
ceapp_init()//这是使用引擎的第一步,初始化引擎
ceapp_allocContigBuf 开辟缓冲区,第二步,开辟缓冲区,然后app.c会打开文件,把文件内容一部分一部分地放入缓冲区
ceapp_validateBufSizes验证缓冲区大小时否正确
ceapp_encodeBuf 对缓冲区的内容进行编码
ceapp_decodeBuf 对缓冲区的内容进行解码
ceapp_freeContigBuf 释放缓冲区
ceapp_exit() 关闭引擎
这些函数里面的实现常常会调用IVIDENC,IVIDDEC接口的中的函数.
而这些函数的实现对应都是在codecs中实现的.
下面说app.c了:
简化后的main函数为:
int main(int argc, char *argv[])
{
char *inFileName, *outFileName;
inFileName = "in.dat";
outFileName = "out.dat";
createInFileIfMissing(inFileName);
encodeDecodeFile(inFileName, outFileName)
return 0;
}
main函数调用encodeDecodeFile来编解码,简化后的encodeDecodeFile函数为:
static int encodeDecodeFile(char *inFileName, char *outFileName)
{
inFile = fopen(inFileName, "rb")) ;
//打开两个文件,一个用于输入,一个用于输出
outFile = fopen(outFileName, "wb")) ;
ceapp_init();
//初始化引擎
inBuf = ceapp_allocContigBuf(INFRAMESIZE, "input data");
//开辟输出缓冲区
encodedBuf = ceapp_allocContigBuf(ENCODEDFRAMESIZE, "encoded data");
//开辟编解缓冲区
outBuf = ceapp_allocContigBuf(OUTFRAMESIZE, "output data");
//开辟输出缓冲区
status = ceapp_validateBufSizes(INFRAMESIZE, ENCODEDFRAMESIZE,
//验证编码缓冲区大小是否正常
for (n = 0 ;; n++) {
//for loop,不停地.....
(fread(inBuf, INFRAMESIZE, 1, inFile) == 0) {
//从输入文件读数据到输入缓冲区
status = ceapp_encodeBuf(inBuf, INFRAMESIZE,
encodedBuf, ENCODEDFRAMESIZE);
//将输入缓冲区数据编码后放入编码缓冲区
status = ceapp_decodeBuf(encodedBuf, ENCODEDFRAMESIZE,
outBuf, OUTFRAMESIZE);
//从编码缓冲区中解码,放入输出缓冲区
fwrite(outBuf, OUTFRAMESIZE, 1, outFile);
//从输出缓冲区写入输出文件
fclose(inFile);
//关闭文件
fclose(outFile);
ceapp_freeContigBuf(inBuf, INFRAMESIZE);
//释放各种缓冲区
ceapp_freeContigBuf(encodedBuf, ENCODEDFRAMESIZE);
ceapp_freeContigBuf(outBuf, OUTFRAMESIZE);
ceapp_exit();
//退出引擎
return status;
//返回
}
本篇说完总的工作流程就差不多了解了,接下来将会结合文档,说具体代码细节,并做一些示例程序.
相关文章推荐
- android 显示大图片
- Android RIL结构分析与移植
- cocos2d-x-3.0rc1 学习笔记3(场景切换)
- AsyncTask和Handler对比
- 【转】AndroidManifest.xml介绍
- 【Android】Fragment真正意义上的onResume和onPause
- Android LayoutInflater详解
- Smali--Dalvik虚拟机指令语言-->【android_smali语法学习一】
- cocos2dx 资料整理
- ios 内存泄露
- 安卓开发之双击返回键退出程序
- 如何制作一个横版格斗过关游戏 Cocos2d-x 2.0.4
- android 在应用中安装其他程序
- [runtime] iOS-Runtime-Headers
- 学习Android之第五个小程序新浪微博样式(Listview的使用)
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- IOS集成Alipay教程
- android之Unable to execute dex: Multiple dex files define
- Android开发系列(十七)QQ聊天之Android显示Gif ——在TextView中添加动态表情
- 关于VS2010中配置cocos2d-x ,出现OpenGL version too old 问题的解决办法