From ae64bc9bcbfb70757c03311f87768fcf5a867a51 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 10 Sep 2019 17:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=8C=87=E5=AE=9A=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=97=B6=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2hls=EF=BC=8Crtxp=20=E6=8F=90=E9=AB=98EasyDarwin?= =?UTF-8?q?=E7=9A=84rtsp=E6=8E=A8=E6=B5=81=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebHook.cpp | 16 ++++++++++++---- src/Rtsp/RtspSession.cpp | 13 +++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 2b338b00..e4c8945e 100644 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -211,10 +211,18 @@ void installWebHook(){ bool enableHls = true; bool enableMP4 = false; - //加try catch目的是兼容之前的hook接口,用户可以不传递enableRtxp、enableHls、enableMP4参数 - try { enableRtxp = obj["enableRtxp"].asBool(); } catch (...) {} - try { enableHls = obj["enableHls"].asBool(); } catch (...) {} - try { enableMP4 = obj["enableMP4"].asBool(); } catch (...) {} + //兼容用户不传递enableRtxp、enableHls、enableMP4参数 + if(obj.isMember("enableRtxp")){ + enableRtxp = obj["enableRtxp"].asBool(); + } + + if(obj.isMember("enableHls")){ + enableHls = obj["enableHls"].asBool(); + } + + if(obj.isMember("enableMP4")){ + enableMP4 = obj["enableMP4"].asBool(); + } invoker(err,enableRtxp,enableHls,enableMP4); }else{ diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 44586770..e933cffb 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -142,6 +142,12 @@ void RtspSession::onRecv(const Buffer::Ptr &pBuf) { } } +//字符串是否以xx结尾 +static inline bool end_of(const string &str, const string &substr){ + auto pos = str.rfind(substr); + return pos != string::npos && pos == str.size() - substr.size(); +}; + void RtspSession::onWholeRtspPacket(Parser &parser) { string strCmd = parser.Method(); //提取出请求命令字 _iCseq = atoi(parser["CSeq"].data()); @@ -241,6 +247,13 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { throw SockException(Err_shutdown,err); } + auto full_url = parser.FullUrl(); + if(end_of(full_url,".sdp")){ + //去除.sdp后缀,防止EasyDarwin推流器强制添加.sdp后缀 + full_url = full_url.substr(0,full_url.length() - 3); + _mediaInfo.parse(full_url); + } + SdpParser sdpParser(parser.Content()); _strSession = makeRandStr(12); _aTrackInfo = sdpParser.getAvailableTrack();