在每个rtmp_module的postconfiguration中, 都会有
next_publish = ngx_rtmp_publish;
ngx_rtmp_publish = ngx_rtmp_access_publish;
注意到ngx_rtmp_publish是一个全部变量; next_publish是每个rtmp-module都有的一个static变量, 也就是说每个rtmp-module的next_publish保存了下一个module的publish函数。
这实际上就相当于ngx_rtmp_publish是一系列函数组成的链表, 而每执行一个postconfiguration,相当于在链表头插入了一个新的函数。
[root@nginx-1.8.1]# grep "&ngx_rtmp" ./objs/ngx_modules.c
&ngx_rtmp_module,
&ngx_rtmp_core_module,
&ngx_rtmp_cmd_module,
&ngx_rtmp_codec_module,
&ngx_rtmp_access_module,
&ngx_rtmp_record_module,
&ngx_rtmp_live_module,
&ngx_rtmp_play_module,
&ngx_rtmp_flv_module,
&ngx_rtmp_mp4_module,
&ngx_rtmp_netcall_module,
&ngx_rtmp_relay_module,
&ngx_rtmp_exec_module,
&ngx_rtmp_auto_push_module,
&ngx_rtmp_notify_module,
&ngx_rtmp_log_module,
&ngx_rtmp_limit_module,
&ngx_rtmp_hls_module,
&ngx_rtmp_dash_module,
&ngx_rtmp_stat_module,
&ngx_rtmp_control_module,
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_notify_module.c:1718: ngx_rtmp_publish = ngx_rtmp_notify_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_auto_push_module.c:122: ngx_rtmp_publish = ngx_rtmp_auto_push_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_log_module.c:1010: ngx_rtmp_publish = ngx_rtmp_log_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_record_module.c:1289: ngx_rtmp_publish = ngx_rtmp_record_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_relay_module.c:1665: ngx_rtmp_publish = ngx_rtmp_relay_publish;
./module_plugin/nginx-rtmp-module-master/dash/ngx_rtmp_dash_module.c:1516: ngx_rtmp_publish = ngx_rtmp_dash_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_access_module.c:465: ngx_rtmp_publish = ngx_rtmp_access_publish;
./module_plugin/nginx-rtmp-module-master/hls/ngx_rtmp_hls_module.c:2438: ngx_rtmp_publish = ngx_rtmp_hls_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_live_module.c:1136: ngx_rtmp_publish = ngx_rtmp_live_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_exec_module.c:1590: ngx_rtmp_publish = ngx_rtmp_exec_publish;
./module_plugin/nginx-rtmp-module-master/ngx_rtmp_cmd_module.c:921: ngx_rtmp_publish = ngx_rtmp_cmd_publish;
因此其执行ngx_rtmp_publish的过程应该是
ngx_rtmp_dash_publish-> ngx_rtmp_hls_publish --> ngx_rtmp_log_publish -->ngx_rtmp_notify_publish -->ngx_rtmp_exec_publish
-->ngx_rtmp_relay_publish --> ngx_rtmp_record_publish -->ngx_rtmp_cmd_publish