From 9f1a91cda6fef7c186c37c045b0204ee153fcd14 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 6 Sep 2019 18:30:42 +0800 Subject: [PATCH] =?UTF-8?q?rtmp=E6=94=AF=E6=8C=81=E5=B8=A6=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E5=90=8D=E7=9A=84url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpSession.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/Rtmp/RtmpSession.h | 1 + 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 786c9011..b277a202 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -140,7 +140,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { } })); dec.load();/* NULL */ - _mediaInfo.parse(_strTcUrl + "/" + dec.load()); + _mediaInfo.parse(_strTcUrl + "/" + getStreamId(dec.load())); _mediaInfo._schema = RTMP_SCHEMA; auto onRes = [this,pToken](const string &err){ @@ -344,9 +344,41 @@ void RtmpSession::doPlay(AMFDecoder &dec){ void RtmpSession::onCmd_play2(AMFDecoder &dec) { doPlay(dec); } + +string RtmpSession::getStreamId(const string &str){ + string stream_id; + string params; + auto pos = str.find('?'); + if(pos != string::npos){ + //有url参数 + stream_id = str.substr(0,pos); + //获取url参数 + params = str.substr(pos + 1); + }else{ + //没有url参数 + stream_id = str; + } + + pos = stream_id.find(":"); + if(pos != string::npos){ + //vlc和ffplay在播放 rtmp://127.0.0.1/record/0.mp4时, + //传过来的url会是rtmp://127.0.0.1/record/mp4:0, + //我们在这里还原成0.mp4 + stream_id = stream_id.substr(pos + 1) + "." + stream_id.substr(0,pos); + } + + if(params.empty()){ + //没有url参数 + return stream_id; + } + + //有url参数 + return stream_id + '?' + params; +} + void RtmpSession::onCmd_play(AMFDecoder &dec) { dec.load();/* NULL */ - _mediaInfo.parse(_strTcUrl + "/" + dec.load()); + _mediaInfo.parse(_strTcUrl + "/" + getStreamId(dec.load())); _mediaInfo._schema = RTMP_SCHEMA; doPlay(dec); } diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index 452f2c95..1827c696 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -86,6 +86,7 @@ private: bool close(MediaSource &sender,bool force) override ; void onNoneReader(MediaSource &sender) override; void setSocketFlags(); + string getStreamId(const string &str); private: std::string _strTcUrl; MediaInfo _mediaInfo;