【原创】动态图像监测开源代码 motion 学习 ----- Motion源码分析(1)
经过这两天对motion源码的分析,发现关于motion代码分析的资料很少,现在终于看出来点儿意思了。因为motion源码文件不是太多,所以直接从main函数入手。
分析工具:Source Insight。
main函数位于源码文件motion.c中。下面是main函数的源代码。
/**
* main
*
* Main entry point of Motion. Launches all the motion threads and contains
* the logic for starting up, restarting and cleaning up everything.
*
* Parameters:
*
* argc - size of argv
* argv - command-line options
*
* Returns: Motion exit status = 0 always
*/
int main (int argc, char **argv)
{
int i;
/* pthread_attr_t为线程属性结构体。 */
pthread_attr_t thread_attr;
/* pthread_t为线程id类型,打印时要用%u。 */
pthread_t thread_id;
/* Setup signals and do some initialization. 1 in the call to
* 'motion_startup' means that Motion will become a daemon if so has been
* requested, and argc and argc are necessary for reading the command
* line options.
设置信号并做一些初始化。motion_startup中的1表示Motion将以守护进程的方式
运行,前提是用户有这样的需要。另外,命令行选项需要argc。
*/
/*
sigaction为结构体,详细规定了信号处理函数和信号标志等信息。
sigaction()为信号处理函数。
*/
struct sigaction sig_handler_action;
struct sigaction sigchild_action;
setup_signals(&sig_handler_action, &sigchild_action);
motion_startup(1, argc, argv);
#ifdef HAVE_FFMPEG
/* FFMpeg initialization is only performed if FFMpeg support was found
* and not disabled during the configure phase.
*/
ffmpeg_init();
#endif /* HAVE_FFMPEG */
/* In setup mode, Motion is very communicative towards the user, which