mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-19 06:42:21 +08:00
实现rtsp/rtmp按需转协议功能
This commit is contained in:
@@ -126,7 +126,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
_media_info.parse(_tc_url + "/" + getStreamId(dec.load<std::string>()));
|
||||
_media_info._schema = RTMP_SCHEMA;
|
||||
|
||||
auto on_res = [this,pToken](const string &err, bool enableRtxp, bool enableHls, bool enableMP4){
|
||||
auto on_res = [this,pToken](const string &err, bool enableHls, bool enableMP4){
|
||||
auto src = dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTMP_SCHEMA,
|
||||
_media_info._vhost,
|
||||
_media_info._app,
|
||||
@@ -150,7 +150,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
_publisher_src.reset(new RtmpMediaSourceImp(_media_info._vhost, _media_info._app, _media_info._streamid));
|
||||
_publisher_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
||||
//设置转协议
|
||||
_publisher_src->setProtocolTranslation(enableRtxp, enableHls, enableMP4);
|
||||
_publisher_src->setProtocolTranslation(enableHls, enableMP4);
|
||||
|
||||
//如果是rtmp推流客户端,那么加大TCP接收缓存,这样能提升接收性能
|
||||
getSock()->setReadBuffer(std::make_shared<BufferRaw>(256 * 1024));
|
||||
@@ -159,30 +159,29 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
|
||||
if(_media_info._app.empty() || _media_info._streamid.empty()){
|
||||
//不允许莫名其妙的推流url
|
||||
on_res("rtmp推流url非法", false, false, false);
|
||||
on_res("rtmp推流url非法", false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
Broadcast::PublishAuthInvoker invoker = [weak_self,on_res,pToken](const string &err, bool enableRtxp, bool enableHls, bool enableMP4){
|
||||
Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, pToken](const string &err, bool enableHls, bool enableMP4) {
|
||||
auto strongSelf = weak_self.lock();
|
||||
if(!strongSelf){
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
strongSelf->async([weak_self,on_res,err,pToken,enableRtxp,enableHls,enableMP4](){
|
||||
strongSelf->async([weak_self, on_res, err, pToken, enableHls, enableMP4]() {
|
||||
auto strongSelf = weak_self.lock();
|
||||
if(!strongSelf){
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
on_res(err, enableRtxp, enableHls, enableMP4);
|
||||
on_res(err, enableHls, enableMP4);
|
||||
});
|
||||
};
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, _media_info, invoker, static_cast<SockInfo &>(*this));
|
||||
if(!flag){
|
||||
//该事件无人监听,默认鉴权成功
|
||||
GET_CONFIG(bool,to_rtxp,General::kPublishToRtxp);
|
||||
GET_CONFIG(bool,to_hls,General::kPublishToHls);
|
||||
GET_CONFIG(bool,to_mp4,General::kPublishToMP4);
|
||||
on_res("", to_rtxp, to_hls, to_mp4);
|
||||
on_res("", to_hls, to_mp4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user