From e97e0d86bd4a0742261887ca20db9996492de837 Mon Sep 17 00:00:00 2001 From: BackT0TheFuture <10088733+BackT0TheFuture@users.noreply.github.com> Date: Fri, 5 May 2023 17:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtmp=E5=A4=9A=E5=B1=82?= =?UTF-8?q?=E7=BA=A7url=E8=A7=A3=E6=9E=90=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#2435)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解析多层级rtmp url会丢失某些层级信息: #2433 --- src/Rtmp/RtmpSession.cpp | 44 ++++++++++++++++++++-------------------- src/Rtmp/RtmpSession.h | 1 - 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 3c3f552e..15b8a89f 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -81,27 +81,23 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) { ///////////set peerBandwidth//////////////// sendPeerBandwidth(5000000); - _media_info._app = params["app"].as_string(); - _tc_url = params["tcUrl"].as_string(); - if(_tc_url.empty()){ - //defaultVhost:默认vhost - _tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info._app; + auto tc_url = params["tcUrl"].as_string(); + if (tc_url.empty()) { + // defaultVhost:默认vhost + tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info._app; } else { - auto pos = _tc_url.rfind('?'); + auto pos = tc_url.rfind('?'); if (pos != string::npos) { - //tc_url 中可能包含?以及参数,参见issue: #692 - _tc_url = _tc_url.substr(0, pos); - } - auto stream_start = _tc_url.rfind('/'); - if (stream_start != string::npos && stream_start > 1) { - auto protocol_end = _tc_url.find("://") + 2; - auto app_start = _tc_url.rfind('/', stream_start - 1); - if (app_start != protocol_end) { - // contain stream name part - _tc_url = _tc_url.substr(0, stream_start); - } + // tc_url 中可能包含?以及参数,参见issue: #692 + tc_url = tc_url.substr(0, pos); } } + // 初步解析,只用于获取vhost信息 + _media_info.parse(tc_url); + _media_info._schema = RTMP_SCHEMA; + // 赋值rtmp app + _media_info._app = params["app"].as_string(); + bool ok = true; //(app == APP_NAME); AMFValue version(AMF_OBJECT); version.set("fmsVer", "FMS/3,0,1,123"); @@ -135,8 +131,10 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { } })); dec.load();/* NULL */ - _media_info.parse(_tc_url + "/" + getStreamId(dec.load())); - _media_info._schema = RTMP_SCHEMA; + // 赋值为rtmp stream id 信息 + _media_info._streamid = getStreamId(dec.load()); + // 再解析url,切割url为app/stream_id (不一定符合rtmp url切割规范) + _media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid); auto now_stream_index = _now_stream_index; auto on_res = [this, token, now_stream_index](const string &err, const ProtocolOption &option) { @@ -433,9 +431,11 @@ string RtmpSession::getStreamId(const string &str){ } void RtmpSession::onCmd_play(AMFDecoder &dec) { - dec.load();/* NULL */ - _media_info.parse(_tc_url + "/" + getStreamId(dec.load())); - _media_info._schema = RTMP_SCHEMA; + dec.load(); /* NULL */ + // 赋值为rtmp stream id 信息 + _media_info._streamid = getStreamId(dec.load()); + // 再解析url,切割url为app/stream_id (不一定符合rtmp url切割规范) + _media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid); doPlay(dec); } diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index 243ac749..f9c2bf2a 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -92,7 +92,6 @@ private: uint32_t _continue_push_ms = 0; //消耗的总流量 uint64_t _total_bytes = 0; - std::string _tc_url; //数据接收超时计时器 toolkit::Ticker _ticker; MediaInfo _media_info;