Mjpg-streamer Camera Remote Transmission UVC
1 Download Source code
Mjpg-streamer's source code address Https://github.com/codewithpassion/mjpg-streamer
Embedded mini2440 version Https://github.com/vfonov/mjpg-streamer
2 compiling
Mjpg-streamermake
Perform
Export Ld_library_path= "$ (PWD)"
./mjpg_streamer-i "./input_uvc.so-y"-o "./output_ http.so-w./www"
PC-side input with Firefox browser
Http://192.168.1.17:8080/?
Action=stream
Among them 192.168.1.17 according to the actual situation input
2 Source Code Analysis
Start
from main in mjpg_streamer.c
getopt_long_only: Parsing input parametersGlobal.in.init = Dlsym (Global.in.handle, "input_init"); Let Global.in.init = Input_init Dlsym Take the dynamic object address
Input_init ( input_uvc.c)- if (Init_videoin (Videoin, dev, width, height, fps, format, 1) < 0)Init_videoin (V4L2UVC.C (PLUGINS\INPUT_UVC) init_v4l2
Global.in.run = Dlsym (Global.in.handle, "Input_run");
Input_run ( input_uvc.c)
-->pthread_create (&cam, 0, Cam_thread, NULL);
void *cam_thread (void *arg)
Uvcgrab (Videoin)
if (Videoin->formatin = = v4l2_pix_fmt_yuyv)
pglobal->size = Compress_yuyv_to_jpeg (Videoin, Pglobal->buf, Videoin->framesizein, gquality );
Else
{
pglobal->size = Memcpy_picture (Pglobal->buf, Videoin->tmpbuffer, videoin->buf.bytesused);
}
global.out[i].init = Dlsym (Global.out[i].handle, "Output_init"); Output_init (OUTPUT_HTTP.C)
Servers[param->id].id = param->id; Servers[param->id].pglobal = param->global; Servers[param->id].conf.port = port; Servers[param->id].conf.credentials = credentials; Servers[param->id].conf.www_folder = Www_folder; Servers[param->id].conf.nocommands = Nocommands;
global.out[i].stop = Dlsym (Global.out[i].handle, "output_stop");
Blockquote style= "Background-color:inherit; margin:0px 0px 0px 40px; Border:none; padding:0px "> output_stop
Pthread_cancel (Servers[id].threadid);
Global.out[i].run = Dlsym (Global.out[i].handle, "Output_run");
Output_run ( output_http.c )Pthread_create (& (Servers[id].threadid), NULL, Server_thread, & (Servers[id])); Create a thread Server_thread Pthread_detach (Servers[id].threadid); Wait for thread to end to recycle
Server_thread (httpd.c\plugins\output_http) Client_thread if (strstr (buffer, "GET/?action=snapshot")! = NULL)
{
req.type = a_snapshot;
}
Else if (strstr (buffer, "GET/?action=stream")! = NULL)
{
req.type = A_stream;
}
Else if (strstr (buffer, "GET/?action=command")! = NULL)
{
req.type = A_command; }
switch (req.type) {
Case
A_snapshot:
DBG ("Request for snapshot\n");
Send_snapshot (LCFD.FD);
Break
;
Case
A_stream:
DBG ("Request for stream\n");
Send_stream (LCFD.FD);
Break
;
}
Mjpg-streamer Camera Remote Transmission UVC