motion源码分析(一)

来源:互联网 发布:中世纪2 多核优化 编辑:程序博客网 时间:2024/06/06 14:07

楔子

前几天研究了如何将ffmpeg编入motion(http://blog.csdn.net/sakaue/article/details/21394219),并实现录像功能。现在研究下motion的工作流程。


几个主要模块

motion.c主程序,视频采集编码主循环ffmpeg.c一个代理模块,封装了ffmpeg的方法,根据v4l获取的数据编码录像video.2.c提供video4linux功能video_common.c封装video.2.c中功能,为motion.c提供支持vebhttpd.c向客户端提供控制功能webcam.c向客户端提供实时图像服务(浏览器刷图片)


正文

照例从main函数进入。在这里,main起了两个线程,一个是集视频采集录像放送于一体的motion_loop:

/* Start the motion threads. First 'cnt_list' item is global if 'thread' * option is used, so start at 1 then and 0 otherwise. */for (i = cnt_list[1] != NULL ? 1 : 0; cnt_list[i]; i++) {    /* If i is 0 it means no thread files and we then set the thread number to 1 */    cnt_list[i]->threadnr = i ? i : 1;    if (strcmp(cnt_list[i]->conf_filename,"") )        motion_log(LOG_INFO, 0, "Thread %d is from %s", cnt_list[i]->threadnr, cnt_list[i]->conf_filename );        if (cnt_list[0]->conf.setup_mode) {            motion_log(-1, 0, "Thread %d is device: %s input %d", cnt_list[i]->threadnr,                       cnt_list[i]->conf.netcam_url ? cnt_list[i]->conf.netcam_url : cnt_list[i]->conf.video_device,                       cnt_list[i]->conf.netcam_url ? -1 : cnt_list[i]->conf.input                       );        }        if (cnt_list[0]->conf.setup_mode)            motion_log(LOG_ERR, 0, "Webcam port %d", cnt_list[i]->conf.webcam_port);        start_motion_thread(cnt_list[i], &thread_attr); //在这里启动线程函数motion_loop}
一个是用于web控制的motion_web_control:

/* Create a thread for the control interface if requested. Create it * detached and with 'motion_web_control' as the thread function. */if (cnt_list[0]->conf.control_port)    pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list); //启动线程函数motion_web_control

而main中的迭代主要负责一些统计任务。我们主要关心motion的核心——motion_loop。

(未完待续)

1 0