VideoStack: move sws execution to WorkThread and optimization interface (#3407)

VideoStack: move sws execution to WorkThread and optimization interface
This commit is contained in:
KkemChen 2024-03-23 20:47:38 +08:00 committed by GitHub
parent d638754364
commit 2e2823d4cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 19 deletions

View File

@ -62,15 +62,16 @@ void Channel::addParam(const std::weak_ptr<Param>& p)
void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
{
std::weak_ptr<Channel> weakSelf = shared_from_this();
// toolkit::WorkThreadPool::Instance().getFirstPoller()->async([weakSelf, frame]() {
auto self = weakSelf.lock();
if (!self) {
return;
}
self->_tmp = self->_sws->inputFrame(frame);
_poller = _poller ? _poller : toolkit::WorkThreadPool::Instance().getPoller();
_poller->async([weakSelf, frame]() {
auto self = weakSelf.lock();
if (!self) {
return;
}
self->_tmp = self->_sws->inputFrame(frame);
self->forEachParam([self](const Param::Ptr& p) { self->fillBuffer(p); });
// });
self->forEachParam([self](const Param::Ptr& p) { self->fillBuffer(p); });
});
}
void Channel::forEachParam(const std::function<void(const Param::Ptr&)>& func)
@ -440,6 +441,7 @@ int VideoStackManager::stopVideoStack(const std::string& id)
auto it = _stackMap.find(id);
if (it != _stackMap.end()) {
_stackMap.erase(it);
InfoL << "VideoStack stop: " << id;
return 0;
}
return -1;

View File

@ -80,6 +80,7 @@ class Channel : public std::enable_shared_from_this<Channel> {
std::vector<std::weak_ptr<Param>> _params;
mediakit::FFmpegSws::Ptr _sws;
toolkit::EventPoller::Ptr _poller;
};
class StackPlayer : public std::enable_shared_from_this<StackPlayer> {

View File

@ -1937,28 +1937,23 @@ void installWebApi() {
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
auto id = sender.getMediaTuple().stream;
VideoStackManager::Instance().stopVideoStack(id);
InfoL << "VideoStack: " << id <<" stop";
});
api_regist("/index/api/stack/start", [](API_ARGS_JSON_ASYNC) {
CHECK_SECRET();
auto ret = VideoStackManager::Instance().startVideoStack(allArgs.getArgs());
if (!ret) {
invoker(200, headerOut, "success");
} else {
invoker(200, headerOut, "failed");
}
val["code"] = ret;
val["msg"] = ret ? "failed" : "success";
invoker(200, headerOut, val.toStyledString());
});
api_regist("/index/api/stack/stop", [](API_ARGS_MAP_ASYNC) {
CHECK_SECRET();
CHECK_ARGS("id");
auto ret = VideoStackManager::Instance().stopVideoStack(allArgs["id"]);
if (!ret) {
invoker(200, headerOut, "success");
} else {
invoker(200, headerOut, "failed");
}
val["code"] = ret;
val["msg"] = ret ? "failed" : "success";
invoker(200, headerOut, val.toStyledString());
});
#endif
}