




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、 HYPERLINK /tandesir/article/details/8437272 友善之臂視頻監(jiān)控(jin kn)方案源碼學(xué)習(xí)(5) - 輸入控制【問題(wnt)描述】在 HYPERLINK /tandesir/article/details/8435162 友善之臂視頻(shpn)監(jiān)控方案源碼學(xué)習(xí)(4) - 數(shù)據(jù)流向一文中,對(duì)視頻數(shù)據(jù)流向進(jìn)行了簡(jiǎn)要闡述。本文對(duì)輸入控制進(jìn)行解析。【解析】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 輸入結(jié)構(gòu)mjpg-streamer-mini2440-read-only/plugins目錄下input.h中對(duì)input結(jié)構(gòu)描述如下: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)之臂視頻監(jiān)控方案源碼學(xué)習(xí)(1) - 架構(gòu)分析一文,指出了該方案(fng n)實(shí)質(zhì)上就是實(shí)現(xiàn)了輸入、輸出的接口。從輸入看,就是實(shí)現(xiàn)了init、stop、run、cmd函數(shù)指針。主程序中實(shí)際上,只調(diào)用了init、run接口。stop接口是在信號(hào)的回調(diào)函數(shù)void signal_handler(int sig);中調(diào)用的。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函數(shù)中,默認(rèn)的輸入為: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參數(shù)不為空,則采用下述方法更新輸入: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的參數(shù)為: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、了一系列默認(rèn)的參數(shù):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);第三,參數(shù)解析。參數(shù)解析又分為(
10、fn wi)下面幾個(gè)步驟:(a) 讀取參數(shù)(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) 將字符串形式的參數(shù)分解為字符串?dāng)?shù)組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函數(shù)解析(ji x)參數(shù)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)詳細(xì)請(qǐng)參考 HYPERLINK /tandesir/article/details/8373205 友善之臂視頻監(jiān)控方案源碼學(xué)習(xí)(xux)(2) - 主程序?qū)崿F(xiàn)細(xì)節(jié)一文描述。(d) 根據(jù)輸入的參數(shù)執(zhí)行相應(yīng)的操作: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),視頻數(shù)據(jù)信息就存儲(chǔ)在global結(jié)構(gòu)的buf變量中。第五,構(gòu)建videoIn結(jié)構(gòu)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);該結(jié)構(gòu)描述如下: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)視頻設(shè)備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)實(shí)現(xiàn)如下: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結(jié)構(gòu)(jigu)的初始化操作。第七,動(dòng)態(tài)控制初始化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);其執(zhí)行(zhxng)的命令定義在input_cmd函數(shù)中:html HYPERLINK /tandesir/article/details/8437272 o view plain view plain HYPERLINK /tandesir/article/det
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- (二模)2025年深圳市高三年級(jí)第二次調(diào)研考試地理試卷(含標(biāo)準(zhǔn)答案)
- 專業(yè)介紹課件
- 高速公路改建工程承包合同書
- 遼寧政法職業(yè)學(xué)院《生物工程導(dǎo)論》2023-2024學(xué)年第二學(xué)期期末試卷
- 洛陽(yáng)科技職業(yè)學(xué)院《西方醫(yī)學(xué)史》2023-2024學(xué)年第二學(xué)期期末試卷
- 江蘇省兩校2024-2025學(xué)年高三四模(5月)物理試題試卷含解析
- 云南省昭通市昭陽(yáng)區(qū)達(dá)標(biāo)名校2024-2025學(xué)年初三年級(jí)第一次調(diào)研考試生物試題含解析
- 蘇州工業(yè)園區(qū)職業(yè)技術(shù)學(xué)院《中國(guó)大學(xué)發(fā)展史》2023-2024學(xué)年第二學(xué)期期末試卷
- 蘇州幼兒師范高等??茖W(xué)?!洞髮W(xué)化學(xué)及實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 吉林省白城市通榆一中2024-2025學(xué)年高三期末熱身聯(lián)考英語試題含解析
- (二模)2025年深圳市高三年級(jí)第二次調(diào)研考試地理試卷(含標(biāo)準(zhǔn)答案)
- 四年級(jí)下冊(cè)《心理健康教育》全冊(cè)教案
- 自愿離婚的協(xié)議范本5篇
- 商業(yè)運(yùn)營(yíng)服務(wù)合作協(xié)議
- 員工心理健康關(guān)懷與支持措施試題及答案
- 2025書畫藝術(shù)品交易合同范本
- 兒童支氣管哮喘診斷與防治指南(2025)解讀
- 2024-2025學(xué)年人教版七年級(jí)(下)期中數(shù)學(xué)試卷(考試范圍:第7~9章) (含解析)
- 安全生產(chǎn)“反三違”學(xué)習(xí)培訓(xùn)
- 網(wǎng)球裁判考試試題及答案
- 能源儲(chǔ)備體系建設(shè)-深度研究
評(píng)論
0/150
提交評(píng)論