From 4aa330ab822d6b8d46d4de58c201432eb5591554 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Tue, 16 Apr 2024 22:34:54 +0800 Subject: [PATCH 1/6] rtp g711 encoder rtp not key pos avoid gop cache useless (#3476) g711 rtp encoder input packet not key pos , avoid gop cache useless, fix the bug --- ext-codec/G711Rtp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext-codec/G711Rtp.cpp b/ext-codec/G711Rtp.cpp index 16a9c5c2..766d600f 100644 --- a/ext-codec/G711Rtp.cpp +++ b/ext-codec/G711Rtp.cpp @@ -46,7 +46,7 @@ bool G711RtpEncoder::inputFrame(const Frame::Ptr &frame) { const size_t rtp_size = max_size; n++; stamp += _pkt_dur_ms; - RtpCodec::inputRtp(getRtpInfo().makeRtp(TrackAudio, ptr, rtp_size, mark, stamp), true); + RtpCodec::inputRtp(getRtpInfo().makeRtp(TrackAudio, ptr, rtp_size, mark, stamp), false); ptr += rtp_size; remain_size -= rtp_size; } From ff70ef233cf371ed0092b579521acb9866c3e1bf Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 20 Apr 2024 20:00:25 +0800 Subject: [PATCH 2/6] Fix bug where ts files are not written into m3u8 file during HLS playback. --- src/Record/HlsMaker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Record/HlsMaker.cpp b/src/Record/HlsMaker.cpp index 11d5190a..bc11028f 100644 --- a/src/Record/HlsMaker.cpp +++ b/src/Record/HlsMaker.cpp @@ -28,7 +28,7 @@ void HlsMaker::makeIndexFile(bool include_delay, bool eof) { GET_CONFIG(uint32_t, segDelay, Hls::kSegmentDelay); GET_CONFIG(uint32_t, segRetain, Hls::kSegmentRetain); std::deque> temp(_seg_dur_list); - if (!include_delay) { + if (!include_delay && _seg_number) { while (temp.size() > _seg_number) { temp.pop_front(); } From 44d645710872c940e8c01969fc055981e726d9bc Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 20 Apr 2024 21:15:47 +0800 Subject: [PATCH 3/6] Update ZLToolKit, support kqueue for macOS/BSD --- 3rdpart/ZLToolKit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 04d1c47d..43004bef 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 04d1c47d2568f5ce1ff84260cefaf2754e514a5e +Subproject commit 43004bef30cb4b48a7f8238027cee1054733f5b1 From e4de454d5d2c18733a76f9d8987a56ec7f7536b5 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 20 Apr 2024 22:25:21 +0800 Subject: [PATCH 4/6] Charset default to UTF-8 on Windows --- 3rdpart/ZLToolKit | 2 +- CMakeLists.txt | 2 +- conf/config.ini | 2 +- server/WebApi.cpp | 2 +- src/Common/config.cpp | 5 ----- src/Http/HttpClient.cpp | 3 ++- src/Http/HttpSession.cpp | 28 ++-------------------------- src/Http/HttpSession.h | 2 -- 8 files changed, 8 insertions(+), 38 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 43004bef..26d54bbc 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 43004bef30cb4b48a7f8238027cee1054733f5b1 +Subproject commit 26d54bbc7b1860a450434dce49bbc8fcbcbae88b diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b2519a..cd0124a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,7 @@ elseif(WIN32) if (MSVC) set(COMPILE_OPTIONS_DEFAULT # TODO: /wd4819 应该是不会生效 - "/wd4566;/wd4819" + "/wd4566;/wd4819;/utf-8" # warning C4530: C++ exception handler used, but unwind semantics are not enabled. "/EHsc") # disable Windows logo diff --git a/conf/config.ini b/conf/config.ini index 3c8b67c8..872d2d32 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -219,7 +219,7 @@ timeout_sec=15 retry_count=3 [http] -#http服务器字符编码,windows上默认gb2312 +#http服务器字符编码集 charSet=utf-8 #http链接超时时间 keepAliveSecond=30 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index a0690747..97260c0a 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -208,7 +208,7 @@ static ApiArgsType getAllArgs(const Parser &parser) { if (parser["Content-Type"].find("application/x-www-form-urlencoded") == 0) { auto contentArgs = parser.parseArgs(parser.content()); for (auto &pr : contentArgs) { - allArgs[pr.first] = HttpSession::urlDecodeComponent(pr.second); + allArgs[pr.first] = strCoding::UrlDecodeComponent(pr.second); } } else if (parser["Content-Type"].find("application/json") == 0) { try { diff --git a/src/Common/config.cpp b/src/Common/config.cpp index a34ee84f..5a538ab4 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -181,12 +181,7 @@ static onceToken token([]() { mINI::Instance()[kKeepAliveSecond] = 15; mINI::Instance()[kDirMenu] = true; mINI::Instance()[kVirtualPath] = ""; - -#if defined(_WIN32) - mINI::Instance()[kCharSet] = "gb2312"; -#else mINI::Instance()[kCharSet] = "utf-8"; -#endif mINI::Instance()[kRootPath] = "./www"; mINI::Instance()[kNotFound] = StrPrinter << "" diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index b9927934..84450d2b 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -66,7 +66,8 @@ void HttpClient::sendRequest(const string &url) { _http_persistent = true; if (_body && _body->remainSize()) { _header.emplace("Content-Length", to_string(_body->remainSize())); - _header.emplace("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); + GET_CONFIG(string, charSet, Http::kCharSet); + _header.emplace("Content-Type", "application/x-www-form-urlencoded; charset=" + charSet); } bool host_changed = (_last_host != host + ":" + to_string(port)) || (_is_https != is_https); diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index ba74d803..ba25f3f4 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -683,34 +683,10 @@ void HttpSession::sendResponse(int code, AsyncSender::onSocketFlushed(data); } -string HttpSession::urlDecodePath(const string &str) { - auto ret = strCoding::UrlDecodePath(str); -#ifdef _WIN32 - GET_CONFIG(string, charSet, Http::kCharSet); - bool isGb2312 = !strcasecmp(charSet.data(), "gb2312"); - if (isGb2312) { - ret = strCoding::UTF8ToGB2312(ret); - } -#endif // _WIN32 - return ret; -} - -string HttpSession::urlDecodeComponent(const string &str) { - auto ret = strCoding::UrlDecodeComponent(str); -#ifdef _WIN32 - GET_CONFIG(string, charSet, Http::kCharSet); - bool isGb2312 = !strcasecmp(charSet.data(), "gb2312"); - if (isGb2312) { - ret = strCoding::UTF8ToGB2312(ret); - } -#endif // _WIN32 - return ret; -} - void HttpSession::urlDecode(Parser &parser) { - parser.setUrl(urlDecodePath(parser.url())); + parser.setUrl(strCoding::UrlDecodePath(parser.url())); for (auto &pr : _parser.getUrlArgs()) { - const_cast(pr.second) = urlDecodeComponent(pr.second); + const_cast(pr.second) = strCoding::UrlDecodeComponent(pr.second); } } diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 0ffbf137..9f328063 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -44,8 +44,6 @@ public: void onRecv(const toolkit::Buffer::Ptr &) override; void onError(const toolkit::SockException &err) override; void onManager() override; - static std::string urlDecodePath(const std::string &str); - static std::string urlDecodeComponent(const std::string &str); void setTimeoutSec(size_t second); void setMaxReqSize(size_t max_req_size); From 2d66dd7cb3f8a81159a43e1345a19fbea17e2c06 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 20 Apr 2024 22:49:27 +0800 Subject: [PATCH 5/6] Fixing the problem of WebRTC handshake failure caused by unsupported RTP extensions (#3486) --- webrtc/RtpExt.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webrtc/RtpExt.cpp b/webrtc/RtpExt.cpp index d1ade570..e186cbf0 100644 --- a/webrtc/RtpExt.cpp +++ b/webrtc/RtpExt.cpp @@ -204,7 +204,8 @@ static unordered_map s_url_to_type = {RTP_EXT_M RtpExtType RtpExt::getExtType(const string &url) { auto it = s_url_to_type.find(url); if (it == s_url_to_type.end()) { - throw std::invalid_argument(string("未识别的rtp ext url类型:") + url); + WarnL << "unknown rtp ext url type: " << url; + return RtpExtType::padding; } return it->second; } From 664d0b67bc958ca7a9ecfba7e08a5a5608599ae3 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sun, 21 Apr 2024 11:31:43 +0800 Subject: [PATCH 6/6] Add the listRtpSender http api --- postman/ZLMediaKit.postman_collection.json | 41 ++++++++++++++++++++++ server/WebApi.cpp | 20 +++++++++++ src/Common/MultiMediaSourceMuxer.cpp | 6 ++++ src/Common/MultiMediaSourceMuxer.h | 2 ++ 4 files changed, 69 insertions(+) diff --git a/postman/ZLMediaKit.postman_collection.json b/postman/ZLMediaKit.postman_collection.json index ae3879b0..c3ddd249 100644 --- a/postman/ZLMediaKit.postman_collection.json +++ b/postman/ZLMediaKit.postman_collection.json @@ -2044,6 +2044,47 @@ }, "response": [] }, + { + "name": "获取rtp发送列表(listRtpSender)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{ZLMediaKit_URL}}/index/api/listRtpSender?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=test", + "host": [ + "{{ZLMediaKit_URL}}" + ], + "path": [ + "index", + "api", + "listRtpSender" + ], + "query": [ + { + "key": "secret", + "value": "{{ZLMediaKit_secret}}", + "description": "api操作密钥(配置文件配置)" + }, + { + "key": "vhost", + "value": "{{defaultVhost}}", + "description": "虚拟主机,例如__defaultVhost__" + }, + { + "key": "app", + "value": "live", + "description": "应用名,例如 live" + }, + { + "key": "stream", + "value": "test", + "description": "流id,例如 obs" + } + ] + } + }, + "response": [] + }, { "name": "获取版本信息(version)", "request": { diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 97260c0a..8ea758f3 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1347,6 +1347,26 @@ void installWebApi() { }); }); + api_regist("/index/api/listRtpSender",[](API_ARGS_MAP_ASYNC){ + CHECK_SECRET(); + CHECK_ARGS("vhost", "app", "stream"); + + auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]); + if (!src) { + throw ApiRetException("can not find the source stream", API::NotFound); + } + + auto muxer = src->getMuxer(); + CHECK(muxer, "get muxer from media source failed"); + + src->getOwnerPoller()->async([=]() mutable { + muxer->forEachRtpSender([&](const std::string &ssrc) mutable { + val["data"].append(ssrc); + }); + invoker(200, headerOut, val.toStyledString()); + }); + }); + api_regist("/index/api/startSendRtpPassive",[](API_ARGS_MAP_ASYNC){ CHECK_SECRET(); CHECK_ARGS("vhost", "app", "stream", "ssrc"); diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index fa46e4fa..fb00a668 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -173,6 +173,12 @@ std::string MultiMediaSourceMuxer::shortUrl() const { return _tuple.shortUrl(); } +void MultiMediaSourceMuxer::forEachRtpSender(const std::function &cb) const { + for (auto &pr : _rtp_sender) { + cb(pr.first); + } +} + MultiMediaSourceMuxer::MultiMediaSourceMuxer(const MediaTuple& tuple, float dur_sec, const ProtocolOption &option): _tuple(tuple) { if (!option.stream_replace.empty()) { // 支持在on_publish hook中替换stream_id diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 9ca34370..a9775c8e 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -133,6 +133,8 @@ public: const MediaTuple &getMediaTuple() const; std::string shortUrl() const; + void forEachRtpSender(const std::function &cb) const; + protected: /////////////////////////////////MediaSink override/////////////////////////////////