




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 友善之臂視頻監控方案源碼學習(5) - 輸入控制【問題描述】在友善之臂視頻監控方案源碼學習(4) - 數據流向一文中,對視頻數據流向進行了簡要闡述。本文對輸入控制進行解析?!窘馕觥? 涉及到的文件和目錄mjpg-streamer-mini2440-read-only/start_uvc.shmjpg-streamer-mini2440-read-only/mjpg_streamer.cmjpg-streamer-mini2440-read-only/mjpg_streamer.hmjpg-streamer-mini2440-read-only/plugins/input.hmjpg
2、-streamer-mini2440-read-only/plugins/input_uvc 2 輸入結構mjpg-streamer-mini2440-read-only/plugins目錄下input.h中對input結構描述如下:html view plaincopy1. /* structure to store variables/functions for input plugin */ 2. typedef struct _input
3、0;input; 3. struct _input 4. char *plugin; 5. void *handle; 6. input_parameter param; 7. 8. int (*init)(input_parameter *); 9.
4、;int (*stop)(void); 10. int (*run)(void); 11. int (*cmd)(in_cmd_type, int); 12. ; 友善之臂視頻監控方案源碼學習(1) - 架構分析一文,指出了該方案實質上就是實現了輸入、輸出的接口。從輸入看,就是實現了init、stop、run、cmd函數指針。主程序中實際上,只調用了init、run接口。stop接口是在信號的回調函數void signa
5、l_handler(int sig);中調用的。 3 input_init分析(1) 定義在mjpg-streamer-mini2440-read-only/plugins/input_uvc/Input_uvc.c文件中(2) 在mjpg-streamer-mini2440-read-only/mjpg_streamer.c 的main函數中,默認的輸入為:html view plaincopy1. char *input = "input_uvc.so -resolution 6
6、40x480 -fps 5 -device /dev/video0" 若-i參數不為空,則采用下述方法更新輸入:html view plaincopy1. /* i, input */ 2. case 2: 3. case 3: 4.
7、; input = strdup(optarg); 5. break; 傳送給Input_uvc.c中input_init的參數為:html view plaincopy1. global.in.param.parameter_string = strchr(input, ' ');
8、0;下面分析mjpg-streamer-mini2440-read-only/plugins/input_uvc/input_uvc.c中的input_init接口。接口定義如下:html view plaincopy1. int input_init(input_parameter *param); 首先,定義了一系列默認的參數:html view plaincopy1. char *argvMAX_ARGUMENTS=NULL, *dev = "/dev/video0"
9、, *s; 2. int argc=1, width=640, height=480, fps=5, format=V4L2_PIX_FMT_MJPEG, i; 3. in_cmd_type led = IN_CMD_LED_AUTO; 4. char fourcc5=0,0,0,0,0; 第二,初始化互斥鎖:html view plaincopy1. /* initialize
10、 the mutes variable */ 2. if( pthread_mutex_init(&controls_mutex, NULL) != 0 ) 3. IPRINT("could not initialize mutex variablen"); 4. exit(EX
11、IT_FAILURE); 5. 第三,參數解析。參數解析又分為下面幾個步驟:(a) 讀取參數html view plaincopy1. argv0 = INPUT_PLUGIN_NAME; 2. if ( param->parameter_string != NULL && strlen(param->parameter_string) != 0
12、;) 3. char *arg=NULL, *saveptr=NULL, *token=NULL; 4. 5. arg=(char *)strdup(param->parameter_string); (b) 將字符串形式的參數分解為字符串數組html view plaincopy1. if ( strchr(arg,
13、60;' ') != NULL ) 2. token=strtok_r(arg, " ", &saveptr); 3. if ( token != NULL ) 4.
14、; argvargc = strdup(token); 5. argc+; 6. while ( (token=strtok_r(NULL, " ", &saveptr) != NULL&
15、#160;) 7. argvargc = strdup(token); 8. argc+; 9. if (argc >
16、;= MAX_ARGUMENTS) 10. IPRINT("ERROR: too many arguments to input pluginn"); 11. ret
17、urn 1; 12. 13. 14. 15. 16. (c) 利用getopt函數解析參
18、數html view plaincopy1. reset_getopt(); 2. while(1) 3. int option_index = 0, c=0; 4. static struct option long_options = 5.
19、0; 6. "h", no_argument, 0, 0, 7. "help", no_argument, 0, 0, 8. "d", required_argument,
20、160;0, 0, 9. "device", required_argument, 0, 0, 10. "r", required_argument, 0, 0, 11. "resolution&q
21、uot;, required_argument, 0, 0, 12. "f", required_argument, 0, 0, 13. "fps", required_argument, 0, 0, 14. &
22、#160; "y", no_argument, 0, 0, 15. "yuv", no_argument, 0, 0, 16. "q", required_argument, 0, 0, 17.
23、; "quality", required_argument, 0, 0, 18. "m", required_argument, 0, 0, 19. "minimum_size", required_argument, 0,
24、0, 20. "n", no_argument, 0, 0, 21. "no_dynctrl", no_argument, 0, 0, 22. "l", required_argument
25、, 0, 0, 23. "led", required_argument, 0, 0, 24. 0, 0, 0, 0 25. 26. 27. /*
26、 parsing all parameters according to the list above is sufficent */ 28. c = getopt_long_only(argc, argv, "", long_options, &option_index); 該過程詳細請參考友善之臂視頻監控
27、方案源碼學習(2) - 主程序實現細節一文描述。(d) 根據輸入的參數執行相應的操作:html view plaincopy1. /* no more options to parse */ 2. if (c = -1) break; 3. 4. /* unrecognized option *
28、/ 5. if (c = '?') 6. help(); 7. return 1; 8. 9. 10. /*
29、dispatch the given options */ 11. switch (option_index) 12. /* h, help */ 13. case 0: 14. &
30、#160; case 1: 15. DBG("case 0,1n"); 16. help(); 17. return 1; 18.
31、0; break; 19. 20. /* d, device */ 21. case 2: 22. case 3: 23.
32、160; DBG("case 2,3n"); 24. dev = strdup(optarg); 25. break; 26. 27. /
33、* r, resolution */ 28. case 4: 29. case 5: 30. DBG("case 4,5n"); 31.
34、60; width = -1; 32. height = -1; 33. 34. /* try to find the resolution in lookup table &
35、quot;resolutions" */ 35. for ( i=0; i < LENGTH_OF(resolutions); i+ ) 36. if ( strcmp(resolutionsi.string,&
36、#160;optarg) = 0 ) 37. width = resolutionsi.width; 38. height = resolutionsi.height;
37、60; 39. 40. 41. /* done if width and height were set */ 42.
38、0; if(width != -1 && height != -1) 43. break; 44. /* parse value as dec
39、imal value */ 45. width = strtol(optarg, &s, 10); 46. height = strtol(s+1, NULL, 10); 47.
40、60; break; 48. 49. /* f, fps */ 50. case 6: 51. case 7: 52.
41、0; DBG("case 6,7n"); 53. fps=atoi(optarg); 54. break; 55. 56. /* y, yuv */
42、160; 57. case 8: 58. case 9: 59. DBG("case 8,9n"); 60. format =&
43、#160;V4L2_PIX_FMT_YUYV; 61. break; 62. 63. /* q, quality */ 64. case 10: 65.
44、60; case 11: 66. DBG("case 10,11n"); 67. format = V4L2_PIX_FMT_YUYV; 68. gquality =
45、 MIN(MAX(atoi(optarg), 0), 100); 69. break; 70. 71. /* m, minimum_size */ 72. case 12: 73
46、. case 13: 74. DBG("case 12,13n"); 75. minimum_size = MAX(atoi(optarg), 0); 76.
47、160; break; 77. 78. /* n, no_dynctrl */ 79. case 14: 80. case 15: 81.
48、 DBG("case 14,15n"); 82. dynctrls = 0; 83. break; 84. 85. /* l,&
49、#160;led */ 86. case 16: 87. case 17: 88. DBG("case 16,17n"); 89.
50、0; if ( strcmp("on", optarg) = 0 ) 90. led = IN_CMD_LED_ON; 91. else if ( strcmp("o
51、ff", optarg) = 0 ) 92. led = IN_CMD_LED_OFF; 93. else if ( strcmp("auto", optarg) =
52、;0 ) 94. led = IN_CMD_LED_AUTO; 95. else if ( strcmp("blink", optarg) = 0 ) 96. &
53、#160; led = IN_CMD_LED_BLINK; 97. 98. break; 99. 100. defau
54、lt: 101. DBG("default casen"); 102. help(); 103. return 1; 104.
55、0; 注:步驟(c)和(d)是在while(1)循環內檢測的。第四,使全局指針指向param->param->globalhtml view plaincopy1. /* keep a pointer to the global variables */ 2. pglobal = param->global; 這一步非常重要,視頻數據信息就存儲在global結構的buf變量中。第五,構建vi
56、deoIn結構html view plaincopy1. videoIn = malloc(sizeof(struct vdIn); 2. if ( videoIn = NULL ) 3. IPRINT("not enough memory for videoInn"); 4.
57、0; exit(EXIT_FAILURE); 5. 6. memset(videoIn, 0, sizeof(struct vdIn); 該結構描述如下:html view plaincopy1. struct vdIn 2. int fd; 3.
58、char *videodevice 4. unsigned char *pFramebuffer; 5. unsigned char *ptframeOUTFRMNUMB; 6. unsigned char *memNB_BUFFER; 7.
59、60;8. int framelockOUTFRMNUMB; 9. pthread_mutex_t grabmutex; 10. int framesizeIn 11. volatile
60、60;int frame_cour; 12. int bppIn; 13. int hdrwidth; 14. int hdrheight; 15. int formatIn; 16. &
61、#160; int signalquit; 17. struct v4l2_capability cap; 18. struct v4l2_format fmt; 19. struct v4l2_buffer buf;
62、0;20. struct v4l2_requestbuffers rb; 21. 22. int grayscale; 23. uint32_t quality; 24. 25. &
63、#160; 主要定義了視頻輸入控制變量。第六,打開視頻設備html view plaincopy1. /* open video device and prepare data structure */ 2. if (init_videoIn(videoIn, dev, width, height, fps, format, 1) < 0)
64、160; 3. IPRINT("init_VideoIn failedn"); 4. closelog(); 5. exit(EXIT_FAILURE); 6. init_videoIn具體實現如下:html view plaincopy1. int init_vide
65、oIn(struct vdIn *vd, char *device, int width, int height, int fps, int format, int grabmethod) 2. 3. if (vd = NULL | device = NULL) 4.
66、160; return -1; 5. if (width = 0 | height = 0) 6. return -1; 7. if (grabmethod < 0 | grabmethod > 1) 8. &
67、#160; grabmethod = 1; /mmap by default; 9. vd->videodevice = NULL; 10. vd->status = NULL; 11. vd->pictName = NULL; 12.
68、160;vd->videodevice = (char *) calloc (1, 16 * sizeof (char); 13. vd->status = (char *) calloc (1, 100 * sizeof (char); 14. vd->pictName = (char&
69、#160;*) calloc (1, 80 * sizeof (char); 15. snprintf (vd->videodevice, 12, "%s", device); 16. vd->toggleAvi = 0; 17. vd->getPict = 0;
70、0;18. vd->signalquit = 1; 19. vd->width = width; 20. vd->height = height; 21. vd->fps = fps; 22. vd->formatIn = format;
71、23. vd->grabmethod = grabmethod; 24. if (init_v4l2 (vd) < 0) 25. fprintf (stderr, " Init v4L2 failed ! exit fatal n"); 26.
72、 goto error; 27. 28. /* alloc a temp buffer to reconstruct the pict */ 29. vd->framesizeIn = (vd->width * vd->height <&
73、lt; 1); 30. switch (vd->formatIn) 31. case V4L2_PIX_FMT_MJPEG: 32. vd->tmpbuffer = (unsigned char *) calloc(1, (size_t) vd->framesizeIn); 33. &
74、#160; if (!vd->tmpbuffer) 34. goto error; 35. vd->framebuffer = 36. (unsigned char *) calloc(1, (size
75、_t) vd->width * (vd->height + 8) * 2); 37. break; 38. case V4L2_PIX_FMT_YUYV: 39. default: 40. vd->framebuffer = 41. (unsigned char *) calloc(1, (size_t) vd->framesizeIn); 42. break; 43. /fprintf(stderr, " should never arrive
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 城鎮污水管網建設項目安全管理方案(參考模板)
- xx河流排水防澇設施建設項目數字化方案(范文)
- 城鎮污水管網建設項目申請報告(模板范文)
- 鄉村振興戰略下能源電力行業面臨的挑戰及對策
- 物流與供應鏈管理教案
- 五年級學期學習計劃(34篇)
- 2025年光學纖維面板系列項目發展計劃
- 五年級科學上冊教案 - 5《身體的“聯絡員”》 教科版
- 中暑現場應急處置方案
- 2025年大流量羅茨鼓風機項目發展計劃
- 典型振動頻譜圖范例
- 石化質檢員試題
- GB/T 6417.1-2005金屬熔化焊接頭缺欠分類及說明
- GB/T 32350.2-2015軌道交通絕緣配合第2部分:過電壓及相關防護
- GB/T 19520.16-2015電子設備機械結構482.6 mm(19 in)系列機械結構尺寸第3-100部分:面板、插箱、機箱、機架和機柜的基本尺寸
- (約克)機組熱回收技術
- (完整版)常見腫瘤AJCC分期手冊第八版(中文版)
- 托瑪琳養生碗gg課件
- 水產養殖示范基地建設項目實施方案
- 行政后勤人員 三級安全教育培訓記錄卡
- DB52∕T 1480-2019 GLW-8430連棟塑料薄膜溫室通用技術規范
評論
0/150
提交評論