motion源码分析(一)

楔子

前几天研究了如何将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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值