友善之臂视频监控方案源码学习(5) - 输入控制(共12页)_第1页
友善之臂视频监控方案源码学习(5) - 输入控制(共12页)_第2页
友善之臂视频监控方案源码学习(5) - 输入控制(共12页)_第3页
友善之臂视频监控方案源码学习(5) - 输入控制(共12页)_第4页
友善之臂视频监控方案源码学习(5) - 输入控制(共12页)_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 HYPERLINK /tandesir/article/details/8437272 友善之臂视频监控(jin kn)方案源码学习(5) - 输入控制【问题(wnt)描述】在 HYPERLINK /tandesir/article/details/8435162 友善之臂视频(shpn)监控方案源码学习(4) - 数据流向一文中,对视频数据流向进行了简要阐述。本文对输入控制进行解析。【解析】1 涉及到的文件和目录mjpg-streamer-mini2440-read-only/start_uvc.shmjpg-streamer-mini2440-read-only/mjpg_streame

2、r.cmjpg-streamer-mini2440-read-only/mjpg_streamer.hmjpg-streamer-mini2440-read-only/plugins/input.hmjpg-streamer-mini2440-read-only/plugins/input_uvc2 输入结构mjpg-streamer-mini2440-read-only/plugins目录下input.h中对input结构描述如下:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLIN

3、K /tandesir/article/details/8437272 o copy copy/*structuretostorevariables/functionsforinputplugin*/typedefstruct_inputinput;struct_inputchar*plugin;void*handle;input_parameterparam;int(*init)(input_parameter*);int(*stop)(void);int(*run)(void);int(*cmd)(in_cmd_type,int); HYPERLINK /tandesir/article/

4、details/8373013 友善(yushn)之臂视频监控方案源码学习(1) - 架构分析一文,指出了该方案(fng n)实质上就是实现了输入、输出的接口。从输入看,就是实现了init、stop、run、cmd函数指针。主程序中实际上,只调用了init、run接口。stop接口是在信号的回调函数void signal_handler(int sig);中调用的。3input_init分析(fnx)(1)定义在mjpg-streamer-mini2440-read-only/plugins/input_uvc/Input_uvc.c文件中(2) 在mjpg-streamer-mini2440

5、-read-only/mjpg_streamer.c 的main函数中,默认的输入为:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copychar*input=input_uvc.so-resolution640 x480-fps5-device/dev/video0;若-i参数不为空,则采用下述方法更新输入:html HYPERLINK /tandesir/article/details/8

6、437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copy/*i,input*/case2:case3:input=strdup(optarg);break;传送给Input_uvc.c中input_init的参数为:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyglobal

7、.in.param.parameter_string=strchr(input,);下面分析mjpg-streamer-mini2440-read-only/plugins/input_uvc/input_uvc.c中的input_init接口。接口定义如下:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyintinput_init(input_parameter*param);首先,定义

8、了一系列默认的参数:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copychar*argvMAX_ARGUMENTS=NULL,*dev=/dev/video0,*s;intargc=1,width=640,height=480,fps=5,format=V4L2_PIX_FMT_MJPEG,i;in_cmd_typeled=IN_CMD_LED_AUTO;charfourcc5=0,0,0,

9、0,0;第二(d r),初始化互斥锁:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copy/*initializethemutesvariable*/if(pthread_mutex_init(&controls_mutex,NULL)!=0)IPRINT(couldnotinitializemutexvariablen);exit(EXIT_FAILURE);第三,参数解析。参数解析又分为(

10、fn wi)下面几个步骤:(a) 读取参数(cnsh)html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyargv0=INPUT_PLUGIN_NAME;if(param-parameter_string!=NULL&strlen(param-parameter_string)!=0)char*arg=NULL,*saveptr=NULL,*token=NULL;arg=(char*)strd

11、up(param-parameter_string);(b) 将字符串形式的参数分解为字符串数组html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyif(strchr(arg,)!=NULL)token=strtok_r(arg,&saveptr);if(token!=NULL)argvargc=strdup(token);argc+;while(token=strtok_r(NULL,&sa

12、veptr)!=NULL)argvargc=strdup(token);argc+;if(argc=MAX_ARGUMENTS)IPRINT(ERROR:toomanyargumentstoinputpluginn);return1;(c) 利用getopt函数解析(ji x)参数html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyreset_getopt();while(1)intoptio

13、n_index=0,c=0;staticstructoptionlong_options=h,no_argument,0,0,help,no_argument,0,0,d,required_argument,0,0,device,required_argument,0,0,r,required_argument,0,0,resolution,required_argument,0,0,f,required_argument,0,0,fps,required_argument,0,0,y,no_argument,0,0,yuv,no_argument,0,0,q,required_argumen

14、t,0,0,quality,required_argument,0,0,m,required_argument,0,0,minimum_size,required_argument,0,0,n,no_argument,0,0,no_dynctrl,no_argument,0,0,l,required_argument,0,0,led,required_argument,0,0,0,0,0,0;/*parsingallparametersaccordingtothelistaboveissufficent*/c=getopt_long_only(argc,argv,long_options,&o

15、ption_index);该过程(guchng)详细请参考 HYPERLINK /tandesir/article/details/8373205 友善之臂视频监控方案源码学习(xux)(2) - 主程序实现细节一文描述。(d) 根据输入的参数执行相应的操作:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copy/*nomoreoptionstoparse*/if(c=-1)break;/*un

16、recognizedoption*/if(c=?)help();return1;/*dispatchthegivenoptions*/switch(option_index)/*h,help*/case0:case1:DBG(case0,1n);help();return1;break;/*d,device*/case2:case3:DBG(case2,3n);dev=strdup(optarg);break;/*r,resolution*/case4:case5:DBG(case4,5n);width=-1;height=-1;/*trytofindtheresolutioninlookup

17、tableresolutions*/for(i=0;iparam-globalhtml HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copy/*keepapointertotheglobalvariables*/pglobal=param-global;这一步非常重要(zhngyo),视频数据信息就存储在global结构的buf变量中。第五,构建videoIn结构html HYPERLINK /tand

18、esir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyvideoIn=malloc(sizeof(structvdIn);if(videoIn=NULL)IPRINT(notenoughmemoryforvideoInn);exit(EXIT_FAILURE);memset(videoIn,0,sizeof(structvdIn);该结构描述如下:html HYPERLINK /tandesir/article/details/843

19、7272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copystructvdInintfd;char*videodevice;unsignedchar*pFramebuffer;unsignedchar*ptframeOUTFRMNUMB;unsignedchar*memNB_BUFFER;intframelockOUTFRMNUMB;pthread_mutex_tgrabmutex;intframesizeIn;volatileintframe_cour;intbppIn;inthdr

20、width;inthdrheight;intformatIn;intsignalquit;structv4l2_capabilitycap;structv4l2_formatfmt;structv4l2_bufferbuf;structv4l2_requestbuffersrb;intgrayscale;uint32_tquality;主要定义了视频(shpn)输入控制变量。第六,打开(d ki)视频设备html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/art

21、icle/details/8437272 o copy copy/*openvideodeviceandpreparedatastructure*/if(init_videoIn(videoIn,dev,width,height,fps,format,1)0)IPRINT(init_VideoInfailedn);closelog();exit(EXIT_FAILURE);init_videoIn具体(jt)实现如下:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tande

22、sir/article/details/8437272 o copy copyintinit_videoIn(structvdIn*vd,char*device,intwidth,intheight,intfps,intformat,intgrabmethod)if(vd=NULL|device=NULL)return-1;if(width=0|height=0)return-1;if(grabmethod1)grabmethod=1;/mmapbydefault;vd-videodevice=NULL;vd-status=NULL;vd-pictName=NULL;vd-videodevic

23、e=(char*)calloc(1,16*sizeof(char);vd-status=(char*)calloc(1,100*sizeof(char);vd-pictName=(char*)calloc(1,80*sizeof(char);snprintf(vd-videodevice,12,%s,device);vd-toggleAvi=0;vd-getPict=0;vd-signalquit=1;vd-width=width;vd-height=height;vd-fps=fps;vd-formatIn=format;vd-grabmethod=grabmethod;if(init_v4

24、l2(vd)framesizeIn=(vd-width*vd-heightformatIn)caseV4L2_PIX_FMT_MJPEG:vd-tmpbuffer=(unsignedchar*)calloc(1,(size_t)vd-framesizeIn);if(!vd-tmpbuffer)gotoerror;vd-framebuffer=(unsignedchar*)calloc(1,(size_t)vd-width*(vd-height+8)*2);break;caseV4L2_PIX_FMT_YUYV:default:vd-framebuffer=(unsignedchar*)call

25、oc(1,(size_t)vd-framesizeIn);break;/fprintf(stderr,shouldneverarriveexitfatal!n);/gotoerror;/break;if(!vd-framebuffer)gotoerror;return0;error:free(vd-videodevice);free(vd-status);free(vd-pictName);close(vd-fd);return-1;主要是完成了vdIn结构(jigu)的初始化操作。第七,动态控制初始化html HYPERLINK /tandesir/article/details/84372

26、72 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyif(dynctrls)initDynCtrls(videoIn-fd);第八(d b),LED初始化html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/details/8437272 o copy copyin_cmd_typeled=IN_CMD_LED_AUTO;./*switchtheLEDaccordingtothecommandlineparameters(ifany)*/input_cmd(led,0);其执行(zhxng)的命令定义在input_cmd函数中:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/det

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论