网络摄像头2 mjpg_streamer流程,编译
生活随笔
收集整理的這篇文章主要介紹了
网络摄像头2 mjpg_streamer流程,编译
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
refer to
http://www.friendlyarm.net/forum/topic/279?lang=en
http://code.google.com/p/mjpg-streamer-mini2440/
http://code.google.com/p/mjpg-streamer-mini2440/source/checkout
下載mjpg_streamer源碼并觀察源碼結構如下
[root@localhost tmp]# svn checkout http://mjpg-streamer-mini2440.googlecode.com/svn/trunk/ mjpg-streamer-mini2440-read-only [root@localhost tmp]# cd mjpg-streamer-mini2440-read-only/ [root@localhost mjpg-streamer-mini2440-read-only]# pwd /tmp/mjpg-streamer-mini2440-read-only[root@localhost mjpg-streamer-mini2440-read-only]# tree . |-- CHANGELOG |-- LICENSE |-- Makefile |-- README |-- mjpg-streamer-mini2440.kdev4 |-- mjpg_streamer.c |-- mjpg_streamer.h |-- plugins | |-- input.h | |-- input_control | | |-- Makefile | | |-- dynctrl.c | | |-- dynctrl.h | | |-- input_uvc.c | | |-- uvc_compat.h | | `-- uvcvideo.h | |-- input_file | | |-- Makefile | | `-- input_file.c | |-- input_gspcav1 | | |-- Makefile | | |-- encoder.c | | |-- encoder.h | | |-- huffman.c | | |-- huffman.h | | |-- input_gspcav1.c | | |-- jconfig.h | | |-- jdatatype.h | | |-- marker.c | | |-- marker.h | | |-- quant.c | | |-- quant.h | | |-- readme.spcacat | | |-- spcaframe.h | | |-- spcav4l.c | | |-- spcav4l.h | | |-- utils.c | | `-- utils.h | |-- input_s3c2410 | | |-- Makefile | | |-- input_s3c2410.c | | |-- readme.s3c2410 | | |-- s3c2410.c | | |-- s3c2410.h | | |-- utils.c | | `-- utils.h | |-- input_testpicture | | |-- Makefile | | |-- input_testpicture.c | | |-- pictures | | | |-- 160x120_1.jpg | | | |-- 160x120_2.jpg | | | |-- 320x240_1.jpg | | | |-- 320x240_2.jpg | | | |-- 640x480_1.jpg | | | |-- 640x480_2.jpg | | | |-- 960x720_1.jpg | | | `-- 960x720_2.jpg | | `-- testpictures.h | |-- input_uvc | | |-- Makefile | | |-- dynctrl.c | | |-- dynctrl.h | | |-- huffman.h | | |-- input_uvc.c | | |-- jpeg_utils.c | | |-- jpeg_utils.h | | |-- uvc_compat.h | | |-- uvcvideo.h | | |-- v4l2uvc.c | | `-- v4l2uvc.h | |-- output.h | |-- output_autofocus | | |-- Makefile | | |-- output_autofocus.c | | |-- processJPEG_onlyCenter.c | | `-- processJPEG_onlyCenter.h | |-- output_file | | |-- Makefile | | `-- output_file.c | `-- output_http | |-- Makefile | |-- httpd.c | |-- httpd.h | `-- output_http.c |-- simplified_jpeg_encoder.c |-- simplified_jpeg_encoder.h |-- start_s3c2410.sh |-- start_uvc.sh |-- start_uvc_yuv.sh |-- utils.c |-- utils.h `-- www|-- LICENSE.txt|-- bodybg.gif|-- cambozola.jar|-- control.htm|-- example.jpg|-- favicon.ico|-- favicon.png|-- fix.css|-- functions.js|-- index.html|-- java.html|-- java_control.html|-- java_simple.html|-- javascript.html|-- javascript_motiondetection.html|-- javascript_simple.html|-- sidebarbg.gif|-- static.html|-- static_simple.html|-- stream.html|-- stream_simple.html|-- style.css`-- videolan.html12 directories, 104 files [root@localhost mjpg-streamer-mini2440-read-only]#
其中
主目錄下
|-- start_s3c2410.sh
|-- start_uvc.sh
|-- start_uvc_yuv.sh
這幾個腳本用于執行mjpg_streamer并傳遞參數給main
|-- simplified_jpeg_encoder.c
|-- simplified_jpeg_encoder.h
用于對input模塊從驅動中取得圖像的數據進行編碼
mjpg_streamer.h,定義了一個重要的全局結構體globals
mjpg_streamer.c,main函數所在文件,此文件分析啟動命令并初始化,并定義靜態全局變量 static globals global;
plugins/目錄下是一些插件,以so文件形式提供,在裝載時動態鏈接。其中
plugins/input_file
plugins/input_gspcav1
plugins/input_s3c2410目錄,讀取cmos攝像頭驅動中的數據,保存到全局變量global
plugins/input_testpicture
plugins/input_uvc目錄,讀取usb攝像頭驅動中的數據,保存到全局變量global
plugins/output_autofocus
plugins/output_file目錄,用于將圖像數據保存到文件
plugins/output_http目錄,用于監視外部端口(默認8080)的socket請求,將圖像數據通過socket發出。即是一個小型web服務器,支持同時發起的xx個鏈接。
www目錄下是幾個網頁
**************************************************************************************************************************************************************
export LD_LIBRARY_PATH="$(pwd)" ./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d /dev/camera"再次執行./start_s3c2410.sh
結果如下
MJPG Streamer Version.: 2.0DBG(input_s3c2410.c, input_init(), 95): argv[0]=S3C2410 embedded cameraDBG(input_s3c2410.c, input_init(), 95): argv[1]=-dDBG(input_s3c2410.c, input_init(), 95): argv[2]=/dev/cameraDBG(input_s3c2410.c, input_init(), 124): case dDBG(input_s3c2410.c, input_init(), 169): initializing s3c2410 devicei: Using V4L2 device.: /dev/camerai: Desired Resolution: 640 x 512i: Grayscale mode: offDBG(s3c2410.c, init_s3c2410(), 63): Opening device Error opening device /dev/camera: unable to query device.i: init_s3c2410 failed即初始化時出現問題,不能查詢設備。
根據提示找到源碼s3c2410.c line 63附近
DBG("Opening device\n");//line 63if ((vd->fd = open( vd->videodevice, O_RDWR)) == -1)exit_fatal ("ERROR opening V4L interface");memset(&vd->cap, 0, sizeof(struct v4l2_capability));err = ioctl(vd->fd, VIDIOC_QUERYCAP, &vd->cap);if (err < 0) {fprintf(stderr, "Error opening device %s: unable to query device.\n", vd->videodevice);return err;}可知unable to query device.是由于設備不支持ioctl方法而導致的。
很奇怪哦,怎么友善給的編譯好的mjpg-streamer-mini2440-bin-r6.tar.gz放在miroc2440上就可以直接使用,而下載的源碼再編譯就不可以了呢。。。
發現友善的編譯好的是r6版本的,而用svn checkout http://mjpg-streamer-mini2440.googlecode.com/svn/trunk/ mjpg-streamer-mini2440-read-only下載到的是最新版本,而在最新版本中加入了ioctl方法對攝像頭操作。所以要下一個r6版的mjpg-streamer。不必全下,只把r6版的s3c2410.c下載下來替換掉最新版里的s3c2410.c即可。
http://code.google.com/p/mjpg-streamer-mini2440/source/browse/trunk/plugins/input_s3c2410/s3c2410.c?r=6
再次按照上面所講編譯后下到板子上,執行start_s3c2410.sh,success!如下
[root@FriendlyARM bin6]# ./start_s3c2410.sh MJPG Streamer Version.: 2.0DBG(input_s3c2410.c, input_init(), 95): argv[0]=S3C2410 embedded cameraDBG(input_s3c2410.c, input_init(), 95): argv[1]=-dDBG(input_s3c2410.c, input_init(), 95): argv[2]=/dev/cameraDBG(input_s3c2410.c, input_init(), 124): case dDBG(input_s3c2410.c, input_init(), 169): initializing s3c2410 devicei: Using V4L2 device.: /dev/camerai: Desired Resolution: 640 x 512i: Grayscale mode: offDBG(s3c2410.c, init_s3c2410(), 45): Opening deviceDBG(s3c2410.c, init_s3c2410(), 50): Allocating input buffers AllocatedDBG(output_http.c, output_init(), 85): output #00DBG(output_http.c, output_init(), 118): argv[0]=HTTP output pluginDBG(output_http.c, output_init(), 118): argv[1]=-wDBG(output_http.c, output_init(), 118): argv[2]=./wwwDBG(output_http.c, output_init(), 176): case 6,7o: www-folder-path...: ./www/o: HTTP TCP port.....: 8080o: username:password.: disabledo: commands..........: enabledDBG(mjpg_streamer.c, main(), 374): starting input pluginDBG(mjpg_streamer.c, main(), 382): starting 1 output plugin(s)DBG(output_http.c, output_run(), 229): launching server thread #00DBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 1 times 176.177002DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 2 times 178.848999DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 3 times 175.275024DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 4 times 175.626953DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 5 times 174.866089DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 6 times 175.260986DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 7 times 175.651978DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 8 times 177.951050DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 9 times 175.342041DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 10 times 175.468018DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 11 times 175.126953DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 12 times 175.375000DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 13 times 175.416992DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 14 times 175.549072DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 15 times 175.479004DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 16 times 175.432007DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 17 times 175.218994DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 18 times 175.763062DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 19 times 175.397095DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 20 times 175.398926DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 21 times 176.143921DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 22 times 175.142944DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 23 times 175.319092DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 24 times 175.833984DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 25 times 175.234985DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 26 times 174.861938DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 27 times 178.566040DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 28 times 175.076050DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 29 times 175.467041DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 30 times 174.818970DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 31 times 176.250977DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 32 times 175.798096DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 33 times 177.946045DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 34 times 175.034912DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 35 times 175.500977DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 36 times 175.244995DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 37 times 175.006104DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 38 times 175.577026DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 39 times 177.815063DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 40 times 175.934082DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 41 times 175.211914DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 42 times 175.023926DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 43 times 175.515015DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 44 times 175.171997DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "static.html"DBG(httpd.c, send_file(), 499): trying to serve file "static.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/static.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 45 times 185.374023DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 773): Request for snapshotDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 46 times 189.610962DBG(httpd.c, send_snapshot(), 310): got frame (size: 11 kB)DBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 47 times 182.471924DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 48 times 174.978027DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "stream.html"DBG(httpd.c, send_file(), 499): trying to serve file "stream.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/stream.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 777): Request for streamDBG(httpd.c, send_stream(), 340): preparing headerDBG(httpd.c, send_stream(), 353): Headers send, sending stream nowDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 49 times 200.244995DBG(httpd.c, send_stream(), 365): increasing buffer size to 11797DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): DBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "java.html"DBG(httpd.c, send_file(), 499): trying to serve file "java.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/java.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client thread waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 50 times 191.764893DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 33): "com.charliemouse.cambozola.Viewer"DBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "LICENSE.txt"DBG(httpd.c, send_file(), 499): trying to serve file "LICENSE.txt", extension: ".txt" mime: "text/plain"DBG(httpd.c, send_file(), 511): opened file: ./www/LICENSE.txtDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 51 times 183.553955DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 52 times 175.157959DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 53 times 175.160034DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "stream.html"DBG(httpd.c, send_file(), 499): trying to serve file "stream.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/stream.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 777): Request for streamDBG(httpd.c, send_stream(), 340): preparing headerDBG(httpd.c, send_stream(), 353): Headers send, sending stream nowDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 54 times 199.722046DBG(httpd.c, send_stream(), 365): increasing buffer size to 11124DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 55 times 182.822021DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 56 times 177.759033DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 57 times 175.708008DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 58 times 177.897949DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 59 times 175.118042DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 60 times 175.838989DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 61 times 175.480957DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 62 times 181.625000DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 63 times 175.881958DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 64 times 178.318970DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundary
我稍微修改過的mjpg-streamer源碼
http://download.csdn.net/detail/songqqnew/3841684
**************************************************************************************************************************************************************
先看幾個結構體
/******************************************************************mjpg-streamer.h***************************/ typedef struct _globals globals; struct _globals {int stop; //控制讀寫線程的讀寫動作進行與否/* signal fresh frames */pthread_mutex_t db; //互斥量,用于讀和寫線程的同步pthread_cond_t db_update; /* global JPG frame, this is more or less the "database" */unsigned char *buf; //全局數據區域,圖像數據int size; //圖像數據大小/* input plugin */input in; //輸入模塊/* output plugin */output out[MAX_OUTPUT_PLUGINS];//輸出模塊 #define MAX_OUTPUT_PLUGINS 10,可知最多能同時將圖像數據輸出到10個地方,比如到file,到httpint outcnt; //輸出數目,即記錄命令參數中有幾個 -o};/******************************************************************plugins/input.h***************************/ /* structure to store variables/functions for input plugin */ typedef struct _input input; struct _input {char *plugin; //so文件名,比如-i "input_s3c2410.so -d? /dev/camera -r 320x240",則plugin="input_s3c2410.so"void *handle; //so句柄input_parameter param; //參數int (*init)(input_parameter *);//初始化函數指針int (*stop)(void); //打開函數指針int (*run)(void); //執行函數指針int (*cmd)(in_cmd_type, int); //命令函數指針 };/* parameters for input plugin */ typedef struct _input_parameter input_parameter; struct _input_parameter {char *parameter_string; //比如-i "input_s3c2410.so -d? /dev/camera -r 320x240",則parameter_string="-d? /dev/camera -r 320x240"struct _globals *global; //回指全局結構體 };/******************************************************************plugins/output.h***************************/ /* structure to store variables/functions for output plugin */ typedef struct _output output; struct _output {char *plugin; //比如 -o "output_http.so -w ./www",則plugin="output_http.so"void *handle; //so句柄 output_parameter param; //參數int (*init)(output_parameter *);int (*stop)(int);int (*run)(int);int (*cmd)(int, out_cmd_type, int); };/* parameters for output plugin */ typedef struct _output_parameter output_parameter; struct _output_parameter {int id; //記錄這是第幾個輸出(-o)char *parameter_string; //比如 -o "output_http.so -w ./www",則parameter_string="-w ./www"struct _globals *global; //回指全局結構體 };
//mjpg-streamer.c /******************************************************************************* # # # MJPG-streamer allows to stream JPG frames from an input-plugin # # to several output plugins # # # # Copyright (C) 2007 Tom St枚veken # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # *******************************************************************************/#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <linux/videodev.h> #include <sys/ioctl.h> #include <errno.h> #include <signal.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/stat.h> #include <getopt.h> #include <pthread.h> #include <dlfcn.h> #include <fcntl.h> #include <syslog.h>#include "utils.h" #include "mjpg_streamer.h"/* globals */ static globals global;/****************************************************************************** Description.: Display a help message Input Value.: argv[0] is the program name and the parameter progname Return Value: - ******************************************************************************/ void help(char *progname) {fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Usage: %s\n" \" -i | --input \"<input-plugin.so> [parameters]\"\n" \" -o | --output \"<output-plugin.so> [parameters]\"\n" \" [-h | --help ]........: display this help\n" \" [-v | --version ].....: display version information\n" \" [-b | --background]...: fork to the background, daemon mode\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #1:\n" \" To open an UVC webcam \"/dev/video1\" and stream it via HTTP:\n" \" %s -i \"input_uvc.so -d /dev/video1\" -o \"output_http.so\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #2:\n" \" To open an UVC webcam and stream via HTTP port 8090:\n" \" %s -i \"input_uvc.so\" -o \"output_http.so -p 8090\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #3:\n" \" To get help for a certain input plugin:\n" \" %s -i \"input_uvc.so --help\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "In case the modules (=plugins) can not be found:\n" \" * Set the default search path for the modules with:\n" \" export LD_LIBRARY_PATH=/path/to/plugins,\n" \" * or put the plugins into the \"/lib/\" or \"/usr/lib\" folder,\n" \" * or instead of just providing the plugin file name, use a complete\n" \" path and filename:\n" \" %s -i \"/path/to/modules/input_uvc.so\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n"); }/****************************************************************************** Description.: pressing CTRL+C sends signals to this process instead of justkilling it plugins can tidily shutdown and free allocatedressources. The function prototype is defined by the system,because it is a callback function. Input Value.: sig tells us which signal was received Return Value: - ******************************************************************************/ void signal_handler(int sig) {int i;/* signal "stop" to threads */LOG("setting signal to stop\n");global.stop = 1;usleep(1000*1000);/* clean up threads */LOG("force cancelation of threads and cleanup ressources\n");global.in.stop();for(i=0; i<global.outcnt; i++) {global.out[i].stop(global.out[i].param.id);}usleep(1000*1000);/* close handles of input plugins */dlclose(&global.in.handle);for(i=0; i<global.outcnt; i++) {/* skip = 0;DBG("about to decrement usage counter for handle of %s, id #%02d, handle: %p\n", \global.out[i].plugin, global.out[i].param.id, global.out[i].handle);for(j=i+1; j<global.outcnt; j++) {if ( global.out[i].handle == global.out[j].handle ) {DBG("handles are pointing to the same destination (%p == %p)\n", global.out[i].handle, global.out[j].handle);skip = 1;}}if ( skip ) {continue;}DBG("closing handle %p\n", global.out[i].handle);*/dlclose(global.out[i].handle);}DBG("all plugin handles closed\n");pthread_cond_destroy(&global.db_update);pthread_mutex_destroy(&global.db);LOG("done\n");closelog();exit(0);return; }/****************************************************************************** Description.: Input Value.: Return Value: ******************************************************************************/ int control(int command, char *details) {switch(command) {case CONTROL_CMD_RECONFIGURE_INPUT:printf("will reload input plugin: %s\n", details);break;default:LOG("unknown control command received\n");}return 0; }/****************************************************************************** Description.: Input Value.: Return Value: ******************************************************************************/ int main(int argc, char *argv[]) {char *input = "input_uvc.so --resolution 640x480 --fps 5 --device /dev/video0";char *output[MAX_OUTPUT_PLUGINS];int daemon=0, i;size_t tmp=0;output[0] = "output_http.so --port 8080";global.outcnt = 0;global.control = control;/* parameter parsing */while(1) {int option_index = 0, c=0;static struct option long_options[] = \{{"h", no_argument, 0, 0},{"help", no_argument, 0, 0},{"i", required_argument, 0, 0},{"input", required_argument, 0, 0},{"o", required_argument, 0, 0},{"output", required_argument, 0, 0},{"v", no_argument, 0, 0},{"version", no_argument, 0, 0},{"b", no_argument, 0, 0},{"background", no_argument, 0, 0},{0, 0, 0, 0}};c = getopt_long_only(argc, argv, "", long_options, &option_index);/* no more options to parse */if (c == -1) break;/* unrecognized option */if(c=='?'){ help(argv[0]); return 0; }switch (option_index) {/* h, help */case 0:case 1:help(argv[0]);return 0;break;/* i, input */case 2:case 3:input = strdup(optarg);break;/* o, output */case 4:case 5:output[global.outcnt++] = strdup(optarg);//每遇到一個-o選項outcnt就+1,,所以outcnt代表輸出的個數break;/* v, version */case 6:case 7:printf("MJPG Streamer Version: %s\n" \"Compilation Date.....: %s\n" \"Compilation Time.....: %s\n", SOURCE_VERSION, __DATE__, __TIME__);return 0;break;/* b, background */case 8:case 9:daemon=1;break;default:help(argv[0]);return 0;}}openlog("MJPG-streamer ", LOG_PID|LOG_CONS, LOG_USER);//openlog("MJPG-streamer ", LOG_PID|LOG_CONS|LOG_PERROR, LOG_USER);syslog(LOG_INFO, "starting application");/* fork to the background */if ( daemon ) {LOG("enabling daemon mode");daemon_mode();} /*************************************************************************************初始化***************************//* initialise the global variables 初始化全局變量*/global.stop = 0;global.buf = NULL;global.size = 0;global.in.plugin = NULL;/* this mutex and the conditional variable are used to synchronize access to the global picture buffer 互斥量和條件變量 */if( pthread_mutex_init(&global.db, NULL) != 0 ) {LOG("could not initialize mutex variable\n");closelog();exit(EXIT_FAILURE);}if( pthread_cond_init(&global.db_update, NULL) != 0 ) {LOG("could not initialize condition variable\n");closelog();exit(EXIT_FAILURE);}/* ignore SIGPIPE (send by OS if transmitting to closed TCP sockets) */signal(SIGPIPE, SIG_IGN);/* register signal handler for <CTRL>+C in order to clean up */if (signal(SIGINT, signal_handler) == SIG_ERR) {LOG("could not register signal handler\n");closelog();exit(EXIT_FAILURE);}/** messages like the following will only be visible on your terminal* if not running in daemon mode*/LOG("MJPG Streamer Version.: %s\n", SOURCE_VERSION);/* check if at least one output plugin was selected */if ( global.outcnt == 0 ) {/* no? Then use the default plugin instead */global.outcnt = 1;} /*************************************************************************************global.in.init(&global.in.param)**********************//* open input plugin */tmp = (size_t)(strchr(input, ' ')-input);global.in.plugin = (tmp > 0)?strndup(input, tmp):strdup(input);//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char* input="input_s3c2410.so -d? /dev/camera -r 320x240"//則char* global.in.plugin ="input_s3c2410.so"global.in.handle = dlopen(global.in.plugin, RTLD_LAZY);//以RTLD_LAZY方式打開input_s3c2410.so,裝載進內存//RTLD_LAZY延遲綁定//可見各個so都是以插件形式裝載進內存//一般需要動態鏈接器去裝載if ( !global.in.handle ) {LOG("ERROR: could not find input plugin\n");LOG(" Perhaps you want to adjust the search path with:\n");LOG(" # export LD_LIBRARY_PATH=/path/to/plugin/folder\n");LOG(" dlopen: %s\n", dlerror() );closelog();exit(EXIT_FAILURE);}global.in.init = dlsym(global.in.handle, "input_init"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_init,其虛擬地址已經確定 //找到,返回地址,賦給結構體global的成員結構體in的成員init函數指針 //即用input_init去填充in結構體的函數指針initif ( global.in.init == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.in.stop = dlsym(global.in.handle, "input_stop"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_stop,if ( global.in.stop == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.in.run = dlsym(global.in.handle, "input_run"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_run,if ( global.in.run == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}/* try to find optional command */global.in.cmd = dlsym(global.in.handle, "input_cmd"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_cmd,global.in.param.parameter_string = strchr(input, ' ');//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d /dev/camera -r 320x240"//則char*? input="input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? global.in.plugin ="input_s3c2410.so"//則char*? global.in.param.parameter_string ="-d /dev/camera -r 320x240"global.in.param.global = &global;if ( global.in.init(&global.in.param) ) {LOG("input_init() return value signals to exit");closelog();exit(0);}/*************************************************************************************global.out[i].init(&global.out[i].param)*******************//* open output plugin */for (i=0; i<global.outcnt; i++) {tmp = (size_t)(strchr(output[i], ' ')-output[i]);global.out[i].plugin = (tmp > 0)?strndup(output[i], tmp):strdup(output[i]);global.out[i].handle = dlopen(global.out[i].plugin, RTLD_LAZY);//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? output[0]="output_http.so -w ./www"//則char*? global.out[0].plugin ="output_http.so"if ( !global.out[i].handle ) {LOG("ERROR: could not find output plugin %s\n", global.out[i].plugin);LOG(" Perhaps you want to adjust the search path with:\n");LOG(" # export LD_LIBRARY_PATH=/path/to/plugin/folder\n");LOG(" dlopen: %s\n", dlerror() );closelog();exit(EXIT_FAILURE);}global.out[i].init = dlsym(global.out[i].handle, "output_init");if ( global.out[i].init == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.out[i].stop = dlsym(global.out[i].handle, "output_stop");if ( global.out[i].stop == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.out[i].run = dlsym(global.out[i].handle, "output_run");if ( global.out[i].run == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}/* try to find optional command */global.out[i].cmd = dlsym(global.out[i].handle, "output_cmd");global.out[i].param.parameter_string = strchr(output[i], ' ');//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? output[0]="output_http.so -w ./www"//則char*? global.out[0].plugin ="output_http.so"//則char*? global.out[0].param.parameter_string ="-w ./www"global.out[i].param.global = &global;global.out[i].param.id = i; //i用于記錄-o的索引,表示第幾個輸出(-o)if ( global.out[i].init(&global.out[i].param) ) {LOG("output_init() return value signals to exit");closelog();exit(0);}} /*************************************************************************************global.in.run()***************************//* start to read the input, push pictures into global buffer */DBG("starting input plugin\n");syslog(LOG_INFO, "starting input plugin");if ( global.in.run() ) {LOG("can not run input plugin\n");closelog();return 1;} /*************************************************************************************global.out[i].run(global.out[i].param.id)************/DBG("starting %d output plugin(s)\n", global.outcnt);for(i=0; i<global.outcnt; i++) {syslog(LOG_INFO, "starting output plugin: %s (ID: %02d)", global.out[i].plugin, global.out[i].param.id);global.out[i].run(global.out[i].param.id); 傳遞的是id(表示第幾個-o)}/* wait for signals */pause();return 0; }
可知mjpg-streamer.c的作用主要是接受并分析啟動參數,然后去加載起讀寫作用的部分--插件即那幾個so.并
從輸入插件中尋找以下符號
input_init()
input_stop()
input_run()
input_cmd()
從輸出插件中尋找以下符號
output_init()
output_stop()
output_run()
output_cmd()
分別賦給globals的對應函數指針
然后執行input_init(),output_init(),input_run(),output_run(),跳到對應代碼里面。見下文。
http://www.friendlyarm.net/forum/topic/279?lang=en
http://code.google.com/p/mjpg-streamer-mini2440/
http://code.google.com/p/mjpg-streamer-mini2440/source/checkout
下載mjpg_streamer源碼并觀察源碼結構如下
[root@localhost tmp]# svn checkout http://mjpg-streamer-mini2440.googlecode.com/svn/trunk/ mjpg-streamer-mini2440-read-only [root@localhost tmp]# cd mjpg-streamer-mini2440-read-only/ [root@localhost mjpg-streamer-mini2440-read-only]# pwd /tmp/mjpg-streamer-mini2440-read-only[root@localhost mjpg-streamer-mini2440-read-only]# tree . |-- CHANGELOG |-- LICENSE |-- Makefile |-- README |-- mjpg-streamer-mini2440.kdev4 |-- mjpg_streamer.c |-- mjpg_streamer.h |-- plugins | |-- input.h | |-- input_control | | |-- Makefile | | |-- dynctrl.c | | |-- dynctrl.h | | |-- input_uvc.c | | |-- uvc_compat.h | | `-- uvcvideo.h | |-- input_file | | |-- Makefile | | `-- input_file.c | |-- input_gspcav1 | | |-- Makefile | | |-- encoder.c | | |-- encoder.h | | |-- huffman.c | | |-- huffman.h | | |-- input_gspcav1.c | | |-- jconfig.h | | |-- jdatatype.h | | |-- marker.c | | |-- marker.h | | |-- quant.c | | |-- quant.h | | |-- readme.spcacat | | |-- spcaframe.h | | |-- spcav4l.c | | |-- spcav4l.h | | |-- utils.c | | `-- utils.h | |-- input_s3c2410 | | |-- Makefile | | |-- input_s3c2410.c | | |-- readme.s3c2410 | | |-- s3c2410.c | | |-- s3c2410.h | | |-- utils.c | | `-- utils.h | |-- input_testpicture | | |-- Makefile | | |-- input_testpicture.c | | |-- pictures | | | |-- 160x120_1.jpg | | | |-- 160x120_2.jpg | | | |-- 320x240_1.jpg | | | |-- 320x240_2.jpg | | | |-- 640x480_1.jpg | | | |-- 640x480_2.jpg | | | |-- 960x720_1.jpg | | | `-- 960x720_2.jpg | | `-- testpictures.h | |-- input_uvc | | |-- Makefile | | |-- dynctrl.c | | |-- dynctrl.h | | |-- huffman.h | | |-- input_uvc.c | | |-- jpeg_utils.c | | |-- jpeg_utils.h | | |-- uvc_compat.h | | |-- uvcvideo.h | | |-- v4l2uvc.c | | `-- v4l2uvc.h | |-- output.h | |-- output_autofocus | | |-- Makefile | | |-- output_autofocus.c | | |-- processJPEG_onlyCenter.c | | `-- processJPEG_onlyCenter.h | |-- output_file | | |-- Makefile | | `-- output_file.c | `-- output_http | |-- Makefile | |-- httpd.c | |-- httpd.h | `-- output_http.c |-- simplified_jpeg_encoder.c |-- simplified_jpeg_encoder.h |-- start_s3c2410.sh |-- start_uvc.sh |-- start_uvc_yuv.sh |-- utils.c |-- utils.h `-- www|-- LICENSE.txt|-- bodybg.gif|-- cambozola.jar|-- control.htm|-- example.jpg|-- favicon.ico|-- favicon.png|-- fix.css|-- functions.js|-- index.html|-- java.html|-- java_control.html|-- java_simple.html|-- javascript.html|-- javascript_motiondetection.html|-- javascript_simple.html|-- sidebarbg.gif|-- static.html|-- static_simple.html|-- stream.html|-- stream_simple.html|-- style.css`-- videolan.html12 directories, 104 files [root@localhost mjpg-streamer-mini2440-read-only]#
其中
主目錄下
|-- start_s3c2410.sh
|-- start_uvc.sh
|-- start_uvc_yuv.sh
這幾個腳本用于執行mjpg_streamer并傳遞參數給main
|-- simplified_jpeg_encoder.c
|-- simplified_jpeg_encoder.h
用于對input模塊從驅動中取得圖像的數據進行編碼
mjpg_streamer.h,定義了一個重要的全局結構體globals
mjpg_streamer.c,main函數所在文件,此文件分析啟動命令并初始化,并定義靜態全局變量 static globals global;
plugins/目錄下是一些插件,以so文件形式提供,在裝載時動態鏈接。其中
plugins/input_file
plugins/input_gspcav1
plugins/input_s3c2410目錄,讀取cmos攝像頭驅動中的數據,保存到全局變量global
plugins/input_testpicture
plugins/input_uvc目錄,讀取usb攝像頭驅動中的數據,保存到全局變量global
plugins/output_autofocus
plugins/output_file目錄,用于將圖像數據保存到文件
plugins/output_http目錄,用于監視外部端口(默認8080)的socket請求,將圖像數據通過socket發出。即是一個小型web服務器,支持同時發起的xx個鏈接。
www目錄下是幾個網頁
**************************************************************************************************************************************************************
對源碼試著編譯一下---在板子上先插入cmos攝像頭,型號0v9650
先修改mjpg_streamer.h,添加DEBUG宏,以便出錯時可以知道錯在哪里
#define DEBUG
再修改Makefile,指定編譯器,并指定生成input_s3c2410.so插件
CC = arm-linux-gcc
PLUGINS += input_s3c2410.so
執行
make
make package
此時會生成mjpg-streamer-mini2440-bin.tar.gz,考到板子上解壓后進入它的目錄
執行
./start_s3c2410.sh
結果如下
export LD_LIBRARY_PATH="$(pwd)" ./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d /dev/camera"再次執行./start_s3c2410.sh
結果如下
MJPG Streamer Version.: 2.0DBG(input_s3c2410.c, input_init(), 95): argv[0]=S3C2410 embedded cameraDBG(input_s3c2410.c, input_init(), 95): argv[1]=-dDBG(input_s3c2410.c, input_init(), 95): argv[2]=/dev/cameraDBG(input_s3c2410.c, input_init(), 124): case dDBG(input_s3c2410.c, input_init(), 169): initializing s3c2410 devicei: Using V4L2 device.: /dev/camerai: Desired Resolution: 640 x 512i: Grayscale mode: offDBG(s3c2410.c, init_s3c2410(), 63): Opening device Error opening device /dev/camera: unable to query device.i: init_s3c2410 failed即初始化時出現問題,不能查詢設備。
根據提示找到源碼s3c2410.c line 63附近
DBG("Opening device\n");//line 63if ((vd->fd = open( vd->videodevice, O_RDWR)) == -1)exit_fatal ("ERROR opening V4L interface");memset(&vd->cap, 0, sizeof(struct v4l2_capability));err = ioctl(vd->fd, VIDIOC_QUERYCAP, &vd->cap);if (err < 0) {fprintf(stderr, "Error opening device %s: unable to query device.\n", vd->videodevice);return err;}可知unable to query device.是由于設備不支持ioctl方法而導致的。
很奇怪哦,怎么友善給的編譯好的mjpg-streamer-mini2440-bin-r6.tar.gz放在miroc2440上就可以直接使用,而下載的源碼再編譯就不可以了呢。。。
發現友善的編譯好的是r6版本的,而用svn checkout http://mjpg-streamer-mini2440.googlecode.com/svn/trunk/ mjpg-streamer-mini2440-read-only下載到的是最新版本,而在最新版本中加入了ioctl方法對攝像頭操作。所以要下一個r6版的mjpg-streamer。不必全下,只把r6版的s3c2410.c下載下來替換掉最新版里的s3c2410.c即可。
http://code.google.com/p/mjpg-streamer-mini2440/source/browse/trunk/plugins/input_s3c2410/s3c2410.c?r=6
再次按照上面所講編譯后下到板子上,執行start_s3c2410.sh,success!如下
[root@FriendlyARM bin6]# ./start_s3c2410.sh MJPG Streamer Version.: 2.0DBG(input_s3c2410.c, input_init(), 95): argv[0]=S3C2410 embedded cameraDBG(input_s3c2410.c, input_init(), 95): argv[1]=-dDBG(input_s3c2410.c, input_init(), 95): argv[2]=/dev/cameraDBG(input_s3c2410.c, input_init(), 124): case dDBG(input_s3c2410.c, input_init(), 169): initializing s3c2410 devicei: Using V4L2 device.: /dev/camerai: Desired Resolution: 640 x 512i: Grayscale mode: offDBG(s3c2410.c, init_s3c2410(), 45): Opening deviceDBG(s3c2410.c, init_s3c2410(), 50): Allocating input buffers AllocatedDBG(output_http.c, output_init(), 85): output #00DBG(output_http.c, output_init(), 118): argv[0]=HTTP output pluginDBG(output_http.c, output_init(), 118): argv[1]=-wDBG(output_http.c, output_init(), 118): argv[2]=./wwwDBG(output_http.c, output_init(), 176): case 6,7o: www-folder-path...: ./www/o: HTTP TCP port.....: 8080o: username:password.: disabledo: commands..........: enabledDBG(mjpg_streamer.c, main(), 374): starting input pluginDBG(mjpg_streamer.c, main(), 382): starting 1 output plugin(s)DBG(output_http.c, output_run(), 229): launching server thread #00DBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 1 times 176.177002DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 2 times 178.848999DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 3 times 175.275024DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 4 times 175.626953DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 5 times 174.866089DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 6 times 175.260986DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 7 times 175.651978DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 8 times 177.951050DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 9 times 175.342041DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 10 times 175.468018DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 11 times 175.126953DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 12 times 175.375000DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 13 times 175.416992DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 14 times 175.549072DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 15 times 175.479004DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 16 times 175.432007DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 17 times 175.218994DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 18 times 175.763062DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 19 times 175.397095DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 20 times 175.398926DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 21 times 176.143921DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 22 times 175.142944DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 23 times 175.319092DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 24 times 175.833984DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 25 times 175.234985DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 26 times 174.861938DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 27 times 178.566040DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 28 times 175.076050DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 29 times 175.467041DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 30 times 174.818970DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 31 times 176.250977DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 32 times 175.798096DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 33 times 177.946045DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 34 times 175.034912DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 35 times 175.500977DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 36 times 175.244995DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 37 times 175.006104DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 38 times 175.577026DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 39 times 177.815063DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 40 times 175.934082DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 41 times 175.211914DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 42 times 175.023926DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 43 times 175.515015DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 44 times 175.171997DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "static.html"DBG(httpd.c, send_file(), 499): trying to serve file "static.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/static.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 45 times 185.374023DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 773): Request for snapshotDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 46 times 189.610962DBG(httpd.c, send_snapshot(), 310): got frame (size: 11 kB)DBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 47 times 182.471924DBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 48 times 174.978027DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "stream.html"DBG(httpd.c, send_file(), 499): trying to serve file "stream.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/stream.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 777): Request for streamDBG(httpd.c, send_stream(), 340): preparing headerDBG(httpd.c, send_stream(), 353): Headers send, sending stream nowDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 49 times 200.244995DBG(httpd.c, send_stream(), 365): increasing buffer size to 11797DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): DBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "java.html"DBG(httpd.c, send_file(), 499): trying to serve file "java.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/java.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client thread waiting for clients to connectDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 50 times 191.764893DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 33): "com.charliemouse.cambozola.Viewer"DBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "LICENSE.txt"DBG(httpd.c, send_file(), 499): trying to serve file "LICENSE.txt", extension: ".txt" mime: "text/plain"DBG(httpd.c, send_file(), 511): opened file: ./www/LICENSE.txtDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 51 times 183.553955DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 52 times 175.157959DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 53 times 175.160034DBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "stream.html"DBG(httpd.c, send_file(), 499): trying to serve file "stream.html", extension: ".html" mime: "text/html"DBG(httpd.c, send_file(), 511): opened file: ./www/stream.htmlDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 777): Request for streamDBG(httpd.c, send_stream(), 340): preparing headerDBG(httpd.c, send_stream(), 353): Headers send, sending stream nowDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 9): "style.css"DBG(httpd.c, send_file(), 499): trying to serve file "style.css", extension: ".css" mime: "text/css"DBG(httpd.c, send_file(), 511): opened file: ./www/style.cssDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 13): "sidebarbg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "sidebarbg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/sidebarbg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 10): "bodybg.gif"DBG(httpd.c, send_file(), 499): trying to serve file "bodybg.gif", extension: ".gif" mime: "image/gif"DBG(httpd.c, send_file(), 511): opened file: ./www/bodybg.gifDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 54 times 199.722046DBG(httpd.c, send_stream(), 365): increasing buffer size to 11124DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(httpd.c, server_thread(), 947): create thread to handle client that just established a connectionDBG(httpd.c, server_thread(), 919): waiting for clients to connectDBG(httpd.c, client_thread(), 710): try to serve a fileDBG(httpd.c, client_thread(), 729): parameter (len: 11): "favicon.ico"DBG(httpd.c, send_file(), 499): trying to serve file "favicon.ico", extension: ".ico" mime: "image/x-icon"DBG(httpd.c, send_file(), 511): opened file: ./www/favicon.icoDBG(httpd.c, client_thread(), 800): leaving HTTP client threadDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 55 times 182.822021DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 56 times 177.759033DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 57 times 175.708008DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 58 times 177.897949DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 59 times 175.118042DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 60 times 175.838989DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 61 times 175.480957DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 62 times 181.625000DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 63 times 175.881958DBG(httpd.c, send_stream(), 379): got frame (size: 10 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundaryDBG(s3c2410.c, s3c2410_Grab(), 172): compress frame 64 times 178.318970DBG(httpd.c, send_stream(), 379): got frame (size: 11 kB)DBG(httpd.c, send_stream(), 391): sending intemdiate headerDBG(httpd.c, send_stream(), 394): sending frameDBG(httpd.c, send_stream(), 397): sending boundary
我稍微修改過的mjpg-streamer源碼
http://download.csdn.net/detail/songqqnew/3841684
**************************************************************************************************************************************************************
先看幾個結構體
/******************************************************************mjpg-streamer.h***************************/ typedef struct _globals globals; struct _globals {int stop; //控制讀寫線程的讀寫動作進行與否/* signal fresh frames */pthread_mutex_t db; //互斥量,用于讀和寫線程的同步pthread_cond_t db_update; /* global JPG frame, this is more or less the "database" */unsigned char *buf; //全局數據區域,圖像數據int size; //圖像數據大小/* input plugin */input in; //輸入模塊/* output plugin */output out[MAX_OUTPUT_PLUGINS];//輸出模塊 #define MAX_OUTPUT_PLUGINS 10,可知最多能同時將圖像數據輸出到10個地方,比如到file,到httpint outcnt; //輸出數目,即記錄命令參數中有幾個 -o};/******************************************************************plugins/input.h***************************/ /* structure to store variables/functions for input plugin */ typedef struct _input input; struct _input {char *plugin; //so文件名,比如-i "input_s3c2410.so -d? /dev/camera -r 320x240",則plugin="input_s3c2410.so"void *handle; //so句柄input_parameter param; //參數int (*init)(input_parameter *);//初始化函數指針int (*stop)(void); //打開函數指針int (*run)(void); //執行函數指針int (*cmd)(in_cmd_type, int); //命令函數指針 };/* parameters for input plugin */ typedef struct _input_parameter input_parameter; struct _input_parameter {char *parameter_string; //比如-i "input_s3c2410.so -d? /dev/camera -r 320x240",則parameter_string="-d? /dev/camera -r 320x240"struct _globals *global; //回指全局結構體 };/******************************************************************plugins/output.h***************************/ /* structure to store variables/functions for output plugin */ typedef struct _output output; struct _output {char *plugin; //比如 -o "output_http.so -w ./www",則plugin="output_http.so"void *handle; //so句柄 output_parameter param; //參數int (*init)(output_parameter *);int (*stop)(int);int (*run)(int);int (*cmd)(int, out_cmd_type, int); };/* parameters for output plugin */ typedef struct _output_parameter output_parameter; struct _output_parameter {int id; //記錄這是第幾個輸出(-o)char *parameter_string; //比如 -o "output_http.so -w ./www",則parameter_string="-w ./www"struct _globals *global; //回指全局結構體 };
//mjpg-streamer.c /******************************************************************************* # # # MJPG-streamer allows to stream JPG frames from an input-plugin # # to several output plugins # # # # Copyright (C) 2007 Tom St枚veken # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # *******************************************************************************/#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <linux/videodev.h> #include <sys/ioctl.h> #include <errno.h> #include <signal.h> #include <sys/socket.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/stat.h> #include <getopt.h> #include <pthread.h> #include <dlfcn.h> #include <fcntl.h> #include <syslog.h>#include "utils.h" #include "mjpg_streamer.h"/* globals */ static globals global;/****************************************************************************** Description.: Display a help message Input Value.: argv[0] is the program name and the parameter progname Return Value: - ******************************************************************************/ void help(char *progname) {fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Usage: %s\n" \" -i | --input \"<input-plugin.so> [parameters]\"\n" \" -o | --output \"<output-plugin.so> [parameters]\"\n" \" [-h | --help ]........: display this help\n" \" [-v | --version ].....: display version information\n" \" [-b | --background]...: fork to the background, daemon mode\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #1:\n" \" To open an UVC webcam \"/dev/video1\" and stream it via HTTP:\n" \" %s -i \"input_uvc.so -d /dev/video1\" -o \"output_http.so\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #2:\n" \" To open an UVC webcam and stream via HTTP port 8090:\n" \" %s -i \"input_uvc.so\" -o \"output_http.so -p 8090\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "Example #3:\n" \" To get help for a certain input plugin:\n" \" %s -i \"input_uvc.so --help\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n");fprintf(stderr, "In case the modules (=plugins) can not be found:\n" \" * Set the default search path for the modules with:\n" \" export LD_LIBRARY_PATH=/path/to/plugins,\n" \" * or put the plugins into the \"/lib/\" or \"/usr/lib\" folder,\n" \" * or instead of just providing the plugin file name, use a complete\n" \" path and filename:\n" \" %s -i \"/path/to/modules/input_uvc.so\"\n", progname);fprintf(stderr, "-----------------------------------------------------------------------\n"); }/****************************************************************************** Description.: pressing CTRL+C sends signals to this process instead of justkilling it plugins can tidily shutdown and free allocatedressources. The function prototype is defined by the system,because it is a callback function. Input Value.: sig tells us which signal was received Return Value: - ******************************************************************************/ void signal_handler(int sig) {int i;/* signal "stop" to threads */LOG("setting signal to stop\n");global.stop = 1;usleep(1000*1000);/* clean up threads */LOG("force cancelation of threads and cleanup ressources\n");global.in.stop();for(i=0; i<global.outcnt; i++) {global.out[i].stop(global.out[i].param.id);}usleep(1000*1000);/* close handles of input plugins */dlclose(&global.in.handle);for(i=0; i<global.outcnt; i++) {/* skip = 0;DBG("about to decrement usage counter for handle of %s, id #%02d, handle: %p\n", \global.out[i].plugin, global.out[i].param.id, global.out[i].handle);for(j=i+1; j<global.outcnt; j++) {if ( global.out[i].handle == global.out[j].handle ) {DBG("handles are pointing to the same destination (%p == %p)\n", global.out[i].handle, global.out[j].handle);skip = 1;}}if ( skip ) {continue;}DBG("closing handle %p\n", global.out[i].handle);*/dlclose(global.out[i].handle);}DBG("all plugin handles closed\n");pthread_cond_destroy(&global.db_update);pthread_mutex_destroy(&global.db);LOG("done\n");closelog();exit(0);return; }/****************************************************************************** Description.: Input Value.: Return Value: ******************************************************************************/ int control(int command, char *details) {switch(command) {case CONTROL_CMD_RECONFIGURE_INPUT:printf("will reload input plugin: %s\n", details);break;default:LOG("unknown control command received\n");}return 0; }/****************************************************************************** Description.: Input Value.: Return Value: ******************************************************************************/ int main(int argc, char *argv[]) {char *input = "input_uvc.so --resolution 640x480 --fps 5 --device /dev/video0";char *output[MAX_OUTPUT_PLUGINS];int daemon=0, i;size_t tmp=0;output[0] = "output_http.so --port 8080";global.outcnt = 0;global.control = control;/* parameter parsing */while(1) {int option_index = 0, c=0;static struct option long_options[] = \{{"h", no_argument, 0, 0},{"help", no_argument, 0, 0},{"i", required_argument, 0, 0},{"input", required_argument, 0, 0},{"o", required_argument, 0, 0},{"output", required_argument, 0, 0},{"v", no_argument, 0, 0},{"version", no_argument, 0, 0},{"b", no_argument, 0, 0},{"background", no_argument, 0, 0},{0, 0, 0, 0}};c = getopt_long_only(argc, argv, "", long_options, &option_index);/* no more options to parse */if (c == -1) break;/* unrecognized option */if(c=='?'){ help(argv[0]); return 0; }switch (option_index) {/* h, help */case 0:case 1:help(argv[0]);return 0;break;/* i, input */case 2:case 3:input = strdup(optarg);break;/* o, output */case 4:case 5:output[global.outcnt++] = strdup(optarg);//每遇到一個-o選項outcnt就+1,,所以outcnt代表輸出的個數break;/* v, version */case 6:case 7:printf("MJPG Streamer Version: %s\n" \"Compilation Date.....: %s\n" \"Compilation Time.....: %s\n", SOURCE_VERSION, __DATE__, __TIME__);return 0;break;/* b, background */case 8:case 9:daemon=1;break;default:help(argv[0]);return 0;}}openlog("MJPG-streamer ", LOG_PID|LOG_CONS, LOG_USER);//openlog("MJPG-streamer ", LOG_PID|LOG_CONS|LOG_PERROR, LOG_USER);syslog(LOG_INFO, "starting application");/* fork to the background */if ( daemon ) {LOG("enabling daemon mode");daemon_mode();} /*************************************************************************************初始化***************************//* initialise the global variables 初始化全局變量*/global.stop = 0;global.buf = NULL;global.size = 0;global.in.plugin = NULL;/* this mutex and the conditional variable are used to synchronize access to the global picture buffer 互斥量和條件變量 */if( pthread_mutex_init(&global.db, NULL) != 0 ) {LOG("could not initialize mutex variable\n");closelog();exit(EXIT_FAILURE);}if( pthread_cond_init(&global.db_update, NULL) != 0 ) {LOG("could not initialize condition variable\n");closelog();exit(EXIT_FAILURE);}/* ignore SIGPIPE (send by OS if transmitting to closed TCP sockets) */signal(SIGPIPE, SIG_IGN);/* register signal handler for <CTRL>+C in order to clean up */if (signal(SIGINT, signal_handler) == SIG_ERR) {LOG("could not register signal handler\n");closelog();exit(EXIT_FAILURE);}/** messages like the following will only be visible on your terminal* if not running in daemon mode*/LOG("MJPG Streamer Version.: %s\n", SOURCE_VERSION);/* check if at least one output plugin was selected */if ( global.outcnt == 0 ) {/* no? Then use the default plugin instead */global.outcnt = 1;} /*************************************************************************************global.in.init(&global.in.param)**********************//* open input plugin */tmp = (size_t)(strchr(input, ' ')-input);global.in.plugin = (tmp > 0)?strndup(input, tmp):strdup(input);//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char* input="input_s3c2410.so -d? /dev/camera -r 320x240"//則char* global.in.plugin ="input_s3c2410.so"global.in.handle = dlopen(global.in.plugin, RTLD_LAZY);//以RTLD_LAZY方式打開input_s3c2410.so,裝載進內存//RTLD_LAZY延遲綁定//可見各個so都是以插件形式裝載進內存//一般需要動態鏈接器去裝載if ( !global.in.handle ) {LOG("ERROR: could not find input plugin\n");LOG(" Perhaps you want to adjust the search path with:\n");LOG(" # export LD_LIBRARY_PATH=/path/to/plugin/folder\n");LOG(" dlopen: %s\n", dlerror() );closelog();exit(EXIT_FAILURE);}global.in.init = dlsym(global.in.handle, "input_init"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_init,其虛擬地址已經確定 //找到,返回地址,賦給結構體global的成員結構體in的成員init函數指針 //即用input_init去填充in結構體的函數指針initif ( global.in.init == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.in.stop = dlsym(global.in.handle, "input_stop"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_stop,if ( global.in.stop == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.in.run = dlsym(global.in.handle, "input_run"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_run,if ( global.in.run == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}/* try to find optional command */global.in.cmd = dlsym(global.in.handle, "input_cmd"); //查找符號,在剛裝載的模塊比如input_s3c2410.so內存單元范圍內中查找符號input_cmd,global.in.param.parameter_string = strchr(input, ' ');//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d /dev/camera -r 320x240"//則char*? input="input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? global.in.plugin ="input_s3c2410.so"//則char*? global.in.param.parameter_string ="-d /dev/camera -r 320x240"global.in.param.global = &global;if ( global.in.init(&global.in.param) ) {LOG("input_init() return value signals to exit");closelog();exit(0);}/*************************************************************************************global.out[i].init(&global.out[i].param)*******************//* open output plugin */for (i=0; i<global.outcnt; i++) {tmp = (size_t)(strchr(output[i], ' ')-output[i]);global.out[i].plugin = (tmp > 0)?strndup(output[i], tmp):strdup(output[i]);global.out[i].handle = dlopen(global.out[i].plugin, RTLD_LAZY);//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? output[0]="output_http.so -w ./www"//則char*? global.out[0].plugin ="output_http.so"if ( !global.out[i].handle ) {LOG("ERROR: could not find output plugin %s\n", global.out[i].plugin);LOG(" Perhaps you want to adjust the search path with:\n");LOG(" # export LD_LIBRARY_PATH=/path/to/plugin/folder\n");LOG(" dlopen: %s\n", dlerror() );closelog();exit(EXIT_FAILURE);}global.out[i].init = dlsym(global.out[i].handle, "output_init");if ( global.out[i].init == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.out[i].stop = dlsym(global.out[i].handle, "output_stop");if ( global.out[i].stop == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}global.out[i].run = dlsym(global.out[i].handle, "output_run");if ( global.out[i].run == NULL ) {LOG("%s\n", dlerror());exit(EXIT_FAILURE);}/* try to find optional command */global.out[i].cmd = dlsym(global.out[i].handle, "output_cmd");global.out[i].param.parameter_string = strchr(output[i], ' ');//比如./mjpg_streamer -o "output_http.so -w ./www" -i "input_s3c2410.so -d? /dev/camera -r 320x240"//則char*? output[0]="output_http.so -w ./www"//則char*? global.out[0].plugin ="output_http.so"//則char*? global.out[0].param.parameter_string ="-w ./www"global.out[i].param.global = &global;global.out[i].param.id = i; //i用于記錄-o的索引,表示第幾個輸出(-o)if ( global.out[i].init(&global.out[i].param) ) {LOG("output_init() return value signals to exit");closelog();exit(0);}} /*************************************************************************************global.in.run()***************************//* start to read the input, push pictures into global buffer */DBG("starting input plugin\n");syslog(LOG_INFO, "starting input plugin");if ( global.in.run() ) {LOG("can not run input plugin\n");closelog();return 1;} /*************************************************************************************global.out[i].run(global.out[i].param.id)************/DBG("starting %d output plugin(s)\n", global.outcnt);for(i=0; i<global.outcnt; i++) {syslog(LOG_INFO, "starting output plugin: %s (ID: %02d)", global.out[i].plugin, global.out[i].param.id);global.out[i].run(global.out[i].param.id); 傳遞的是id(表示第幾個-o)}/* wait for signals */pause();return 0; }
可知mjpg-streamer.c的作用主要是接受并分析啟動參數,然后去加載起讀寫作用的部分--插件即那幾個so.并
從輸入插件中尋找以下符號
input_init()
input_stop()
input_run()
input_cmd()
從輸出插件中尋找以下符號
output_init()
output_stop()
output_run()
output_cmd()
分別賦給globals的對應函數指針
然后執行input_init(),output_init(),input_run(),output_run(),跳到對應代碼里面。見下文。
轉載于:https://www.cnblogs.com/-song/archive/2011/11/23/3331931.html
總結
以上是生活随笔為你收集整理的网络摄像头2 mjpg_streamer流程,编译的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络摄像头1 mjpg-streamer
- 下一篇: 2011年度最佳 jQuery 插件发布