作者原創(chuàng),轉(zhuǎn)載請聯(lián)系作者
publisher通過Publish進行推送流之后愕够,客戶端可以發(fā)起Play操作过咬,本文描述客戶端經(jīng)過handshake、connection協(xié)議后的Play協(xié)議吸耿。Play協(xié)議與Publish協(xié)議非常類似祠锣,細節(jié)不同而已,本文主要講解不同之處咽安。
涉及模塊
針對推流操作伴网,NGX-RTMP處理比較復雜,涉及的模塊也比較多妆棒,先羅列如下澡腾。至于回調(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)時,將原回調(diào)ngx_rtmp_publish保存起來為next_publish红选。在ngx_rtmp_live_publish回調(diào)處理完畢后調(diào)用next_publish澜公,從而下一個模塊繼續(xù)調(diào)用。見代碼:
next_publish = ngx_rtmp_publish;
ngx_rtmp_publish = ngx_rtmp_live_publish;
- 上述那些模塊調(diào)用順序如何喇肋?
這個問題較簡單坟乾,查看我的前文《RTMP添加到NGINX》中描述,主要根據(jù)編譯時生成的 ngx_module_t *ngx_modules[] 變量在啟動的時候一次執(zhí)行 - 做什么什么工作苟蹈?
因為模塊比較多糊渊,在此挑選ngx_rtmp_live_module進行敘述,其他模塊處理細節(jié)請各位看官閱讀代碼慧脱,如有問題可以消息我渺绒,如有必要可以再撰文描述- 合法性校驗主要有:
NetStream.Play.StreamNotFound
NetStream.Publish.BadName
- 設置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回復消息NetStream.Play.Start