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/////////////////////////////////