diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index b678e474..b04d1321 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit b678e474f8ba8c9f3e6efd9cec6e4c517e80209d +Subproject commit b04d132139399637cbb201c2832dd98dc2786e82 diff --git a/conf/config.ini b/conf/config.ini index 35a6cc58..eb41ad2b 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/server/WebApi.cpp b/server/WebApi.cpp index b70d2d4b..1d6535a4 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -281,7 +281,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(); @@ -292,6 +292,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(); 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(); 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 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) { diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index a8d3c8ac..052fc85c 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); @@ -252,7 +253,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { _push_src->setListener(dynamic_pointer_cast(shared_from_this())); _push_src->setProtocolTranslation(enableHls, enableMP4); _push_src->setSdp(sdpParser.toString()); - sendRtspResponse("200 OK", {"Content-Base", _content_base + "/"}); + sendRtspResponse("200 OK"); }; weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); @@ -613,7 +614,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