作者原創(chuàng),轉(zhuǎn)載請聯(lián)系作者
publisher通過Publish進(jìn)行推送流之后,客戶端可以發(fā)起Play操作,本文描述客戶端經(jīng)過handshake、connection協(xié)議后的Play協(xié)議。Play協(xié)議與Publish協(xié)議非常類似,細(xì)節(jié)不同而已,本文主要講解不同之處。
涉及模塊
針對推流操作,NGX-RTMP處理比較復(fù)雜,涉及的模塊也比較多,先羅列如下。至于回調(diào)如何注冊、如何調(diào)用請參考前文。
- 模塊名:ngx_rtmp_access_module
回 調(diào):ngx_rtmp_access_play - 模塊名:ngx_rtmp_cfms_module
回 調(diào):ngx_rtmp_cfms_play - 模塊名:ngx_rtmp_cmd_module
回 調(diào):ngx_rtmp_cmd_play - 模塊名:ngx_rtmp_exec_module
回 調(diào):ngx_rtmp_exec_play - 模塊名:ngx_rtmp_live_module
回 調(diào):ngx_rtmp_live_play - 模塊名:ngx_rtmp_log_module
回 調(diào):ngx_rtmp_log_play - 模塊名:ngx_rtmp_notify_module
回 調(diào):ngx_rtmp_notify_play - 模塊名:ngx_rtmp_play_module
回 調(diào):ngx_rtmp_play_play - 模塊名:ngx_rtmp_log_module
回 調(diào):ngx_rtmp_log_play - 模塊名:ngx_rtmp_relay_module
回 調(diào):ngx_rtmp_relay_play
具體處理
- 上述那些模塊如何順序調(diào)用?
在注冊回調(diào)時(shí),將原回調(diào)ngx_rtmp_publish保存起來為next_publish。在ngx_rtmp_live_publish回調(diào)處理完畢后調(diào)用next_publish,從而下一個(gè)模塊繼續(xù)調(diào)用。見代碼:
next_publish = ngx_rtmp_publish;
ngx_rtmp_publish = ngx_rtmp_live_publish;
- 上述那些模塊調(diào)用順序如何?
這個(gè)問題較簡單,查看我的前文《RTMP添加到NGINX》中描述,主要根據(jù)編譯時(shí)生成的 ngx_module_t *ngx_modules[] 變量在啟動的時(shí)候一次執(zhí)行 - 做什么什么工作?
因?yàn)槟K比較多,在此挑選ngx_rtmp_live_module進(jìn)行敘述,其他模塊處理細(xì)節(jié)請各位看官閱讀代碼,如有問題可以消息我,如有必要可以再撰文描述- 合法性校驗(yàn)主要有:
NetStream.Play.StreamNotFound
NetStream.Publish.BadName
- 設(shè)置ctx
```
ctx->stream = stream;
ctx->publishing = 0;
ctx->next = (stream)->ctx;
ctx->cs[0].csid = NGX_RTMP_CSID_VIDEO;
ctx->cs[1].csid = NGX_RTMP_CSID_AUDIO;
- 給pulbisher回復(fù)消息NetStream.Play.Start