From a391d1e2898f452a479f406a09befcffc55f5bd9 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 09:25:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtsp=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E5=B8=A6=E5=8F=82=E7=9B=B8=E5=85=B3=E7=9A=84bug:#840?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspSession.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 4c413a6b..1c2a3e37 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -213,6 +213,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { } auto full_url = parser.FullUrl(); + _content_base = full_url; if(end_with(full_url,".sdp")){ //去除.sdp后缀,防止EasyDarwin推流器强制添加.sdp后缀 full_url = full_url.substr(0,full_url.length() - 4); @@ -242,7 +243,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { _push_src = std::make_shared(_media_info._vhost, _media_info._app, _media_info._streamid); _push_src->setListener(dynamic_pointer_cast(shared_from_this())); _push_src->setSdp(sdpParser.toString()); - sendRtspResponse("200 OK",{"Content-Base", _content_base + "/"}); + sendRtspResponse("200 OK"); } void RtspSession::handleReq_RECORD(const Parser &parser){ @@ -614,7 +615,7 @@ void RtspSession::send_SessionNotFound() { void RtspSession::handleReq_Setup(const Parser &parser) { //处理setup命令,该函数可能进入多次 - int trackIdx = getTrackIndexByControlUrl(parser.Url()); + int trackIdx = getTrackIndexByControlUrl(parser.FullUrl()); SdpTrack::Ptr &trackRef = _sdp_track[trackIdx]; if (trackRef->_inited) { //已经初始化过该Track From f54e02f5118d0f6e90cc7094ef5da00c74960023 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 09:28:19 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9B=B8=E5=85=B3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpFileManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/HttpFileManager.cpp b/src/Http/HttpFileManager.cpp index 735c053c..2d156e44 100644 --- a/src/Http/HttpFileManager.cpp +++ b/src/Http/HttpFileManager.cpp @@ -577,7 +577,7 @@ void HttpResponseInvokerImp::responseFile(const StrCaseMap &requestHeader, //分节下载 code = 206; iRangeStart = atoll(FindField(strRange.data(), "bytes=", "-").data()); - iRangeEnd = atoll(FindField(strRange.data(), "-", "\r\n").data()); + iRangeEnd = atoll(FindField(strRange.data(), "-", nullptr).data()); if (iRangeEnd == 0) { iRangeEnd = fileSize - 1; } From 7641db4225bd9c1befe2369af4a9bbb4a1c47ca0 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 09:31:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?getMediaList=E7=AD=89=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=BD=95=E5=88=B6=E7=8A=B6=E6=80=81:#876?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 9160c559..5d70924c 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -261,6 +261,8 @@ Value makeMediaSourceJson(MediaSource &media){ item["originType"] = (int) media.getOriginType(); item["originTypeStr"] = getOriginTypeString(media.getOriginType()); item["originUrl"] = media.getOriginUrl(); + item["isRecordingMP4"] = media.isRecording(Recorder::type_mp4); + item["isRecordingHLS"] = media.isRecording(Recorder::type_hls); auto originSock = media.getOriginSock(); if (originSock) { item["originSock"]["local_ip"] = originSock->get_local_ip(); From b7e6bfb57441a70af7d9c59b9e37a24e2f1e0552 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 09:53:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?hook=E6=8E=A5=E5=8F=A3=E5=9C=A8http?= =?UTF-8?q?=E5=A4=B4=E4=B8=AD=E9=99=84=E5=B8=A6vhost:#872?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 2 +- server/WebHook.cpp | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 5d70924c..cbb2f6d9 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -250,7 +250,7 @@ static inline string getProxyKey(const string &vhost,const string &app,const str Value makeMediaSourceJson(MediaSource &media){ Value item; item["schema"] = media.getSchema(); - item["vhost"] = media.getVhost(); + item[VHOST_KEY] = media.getVhost(); item["app"] = media.getApp(); item["stream"] = media.getId(); item["createStamp"] = (Json::UInt64) media.getCreateStamp(); diff --git a/server/WebHook.cpp b/server/WebHook.cpp index d1df3308..18126a8e 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -113,6 +113,17 @@ const char *getContentType(const HttpArgs &value){ return "application/x-www-form-urlencoded"; } +string getVhost(const Value &value) { + const char *key = VHOST_KEY; + auto val = value.find(key, key + sizeof(VHOST_KEY) - 1); + return val ? val->asString() : ""; +} + +string getVhost(const HttpArgs &value) { + auto val = value.find(VHOST_KEY); + return val != value.end() ? val->second : ""; +} + void do_http_hook(const string &url,const ArgsType &body,const function &func){ GET_CONFIG(string, mediaServerId, General::kMediaServerId); GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec); @@ -123,6 +134,10 @@ void do_http_hook(const string &url,const ArgsType &body,const functionsetBody(bodyStr); requester->addHeader("Content-Type", getContentType(body)); + auto vhost = getVhost(body); + if (!vhost.empty()) { + requester->addHeader("X-VHOST", vhost); + } std::shared_ptr pTicker(new Ticker); requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex, const string &status, @@ -147,7 +162,7 @@ void do_http_hook(const string &url,const ArgsType &body,const function weakSrc = sender.shared_from_this(); From 7067472a18675ceed69f402dd4b81b45d4705c0e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 10:17:52 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=BD=AC=E5=8D=8F=E8=AE=AE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=85=A8=E5=B1=80=E5=85=B3=E9=97=AD=E9=9F=B3=E9=A2=91?= =?UTF-8?q?:#883?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 2 ++ src/Common/MediaSink.cpp | 5 +++++ src/Common/config.cpp | 2 ++ src/Common/config.h | 2 ++ 4 files changed, 11 insertions(+) diff --git a/conf/config.ini b/conf/config.ini index 59a7f06b..0dce3fa6 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -61,6 +61,8 @@ mergeWriteMS=0 modifyStamp=0 #服务器唯一id,用于触发hook时区别是哪台服务器 mediaServerId=your_server_id +#转协议是否全局开启或关闭音频 +enable_audio=1 ###### 以下是按需转协议的开关,在测试ZLMediaKit的接收推流性能时,请把下面开关置1 ###### 如果某种协议你用不到,你可以把以下开关置1以便节省资源(但是还是可以播放,只是第一个播放者体验稍微差点), diff --git a/src/Common/MediaSink.cpp b/src/Common/MediaSink.cpp index be887305..b372b2f2 100644 --- a/src/Common/MediaSink.cpp +++ b/src/Common/MediaSink.cpp @@ -22,6 +22,11 @@ static size_t constexpr kMaxUnreadyFrame = 100; namespace mediakit{ void MediaSink::addTrack(const Track::Ptr &track_in) { + GET_CONFIG(bool, enabel_audio, General::kEnableAudio); + if (!enabel_audio && track_in->getTrackType() == TrackAudio) { + //音频被全局忽略 + return; + } lock_guard lck(_mtx); if (_all_track_ready) { WarnL << "all track is ready, add this track too late!"; diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 47b8177a..0cd509b4 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -74,6 +74,7 @@ const string kRtspDemand = GENERAL_FIELD"rtsp_demand"; const string kRtmpDemand = GENERAL_FIELD"rtmp_demand"; const string kTSDemand = GENERAL_FIELD"ts_demand"; const string kFMP4Demand = GENERAL_FIELD"fmp4_demand"; +const string kEnableAudio = GENERAL_FIELD"enable_audio"; onceToken token([](){ mINI::Instance()[kFlowThreshold] = 1024; @@ -92,6 +93,7 @@ onceToken token([](){ mINI::Instance()[kRtmpDemand] = 0; mINI::Instance()[kTSDemand] = 0; mINI::Instance()[kFMP4Demand] = 0; + mINI::Instance()[kEnableAudio] = 1; },nullptr); diff --git a/src/Common/config.h b/src/Common/config.h index a104a789..9f21fc4a 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -187,6 +187,8 @@ extern const string kRtspDemand; extern const string kRtmpDemand; extern const string kTSDemand; extern const string kFMP4Demand; +//转协议是否全局开启或忽略音频 +extern const string kEnableAudio; }//namespace General From 975c11b74cbcfba33d80c33cbb348b8b11498e4c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 22 May 2021 10:22:56 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=94=AF=E6=8C=81http=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E6=97=A0content-length=E5=AD=97=E6=AE=B5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5:#850?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpRequester.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Http/HttpRequester.cpp b/src/Http/HttpRequester.cpp index 2ac7efe2..37ccadd5 100644 --- a/src/Http/HttpRequester.cpp +++ b/src/Http/HttpRequester.cpp @@ -21,8 +21,7 @@ HttpRequester::~HttpRequester(){ ssize_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) { _strRecvBody.clear(); - //无Content-Length字段时默认后面没有content - return 0; + return HttpClientImp::onResponseHeader(status, headers); } void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) {