mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-21 09:07:49 +08:00
修复getMediaList接口线程安全问题 (#4526)
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
This commit is contained in:
parent
c9d3c5b516
commit
68cc757708
@ -913,21 +913,24 @@ void installWebApi() {
|
|||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
// 获取所有MediaSource列表 [AUTO-TRANSLATED:7bf16dc2]
|
// 获取所有MediaSource列表 [AUTO-TRANSLATED:7bf16dc2]
|
||||||
// Get all MediaSource lists
|
// Get all MediaSource lists
|
||||||
bool first = true;
|
std::list<MediaSource::Ptr> lst;
|
||||||
std::shared_ptr<Json::Value> done(new Json::Value(val), [invoker, headerOut](Json::Value *val) {
|
|
||||||
invoker(200, headerOut, val->toStyledString());
|
|
||||||
delete val;
|
|
||||||
});
|
|
||||||
MediaSource::for_each_media([&](const MediaSource::Ptr &media) {
|
MediaSource::for_each_media([&](const MediaSource::Ptr &media) {
|
||||||
if (first) {
|
lst.emplace_back(media);
|
||||||
first = false;
|
|
||||||
media->getOwnerPoller()->async([media, done]() mutable {
|
|
||||||
(*done)["data"].append(makeMediaSourceJson(*media));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
(*done)["data"].append(makeMediaSourceJson(*media));
|
|
||||||
}
|
|
||||||
}, allArgs["schema"], allArgs["vhost"], allArgs["app"], allArgs["stream"]);
|
}, allArgs["schema"], allArgs["vhost"], allArgs["app"], allArgs["stream"]);
|
||||||
|
|
||||||
|
if (lst.size() == 1) {
|
||||||
|
// 如果是搜索单一流,那么在它的归属线程中执行,用于获取丢包率参数
|
||||||
|
auto front = std::move(lst.front());
|
||||||
|
front->getOwnerPoller()->async([=]() mutable {
|
||||||
|
val["data"].append(makeMediaSourceJson(*front));
|
||||||
|
invoker(200, headerOut, val.toStyledString());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
for (auto &media : lst) {
|
||||||
|
val["data"].append(makeMediaSourceJson(*media));
|
||||||
|
}
|
||||||
|
invoker(200, headerOut, val.toStyledString());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 测试url http://127.0.0.1/index/api/isMediaOnline?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs [AUTO-TRANSLATED:126a75e8]
|
// 测试url http://127.0.0.1/index/api/isMediaOnline?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs [AUTO-TRANSLATED:126a75e8]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user