mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
VideoStack: move sws execution to WorkThread and optimization interface (#3407)
VideoStack: move sws execution to WorkThread and optimization interface
This commit is contained in:
parent
d638754364
commit
2e2823d4cf
@ -62,15 +62,16 @@ void Channel::addParam(const std::weak_ptr<Param>& p)
|
|||||||
void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
|
void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
|
||||||
{
|
{
|
||||||
std::weak_ptr<Channel> weakSelf = shared_from_this();
|
std::weak_ptr<Channel> weakSelf = shared_from_this();
|
||||||
// toolkit::WorkThreadPool::Instance().getFirstPoller()->async([weakSelf, frame]() {
|
_poller = _poller ? _poller : toolkit::WorkThreadPool::Instance().getPoller();
|
||||||
auto self = weakSelf.lock();
|
_poller->async([weakSelf, frame]() {
|
||||||
if (!self) {
|
auto self = weakSelf.lock();
|
||||||
return;
|
if (!self) {
|
||||||
}
|
return;
|
||||||
self->_tmp = self->_sws->inputFrame(frame);
|
}
|
||||||
|
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)
|
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);
|
auto it = _stackMap.find(id);
|
||||||
if (it != _stackMap.end()) {
|
if (it != _stackMap.end()) {
|
||||||
_stackMap.erase(it);
|
_stackMap.erase(it);
|
||||||
|
InfoL << "VideoStack stop: " << id;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -80,6 +80,7 @@ class Channel : public std::enable_shared_from_this<Channel> {
|
|||||||
std::vector<std::weak_ptr<Param>> _params;
|
std::vector<std::weak_ptr<Param>> _params;
|
||||||
|
|
||||||
mediakit::FFmpegSws::Ptr _sws;
|
mediakit::FFmpegSws::Ptr _sws;
|
||||||
|
toolkit::EventPoller::Ptr _poller;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StackPlayer : public std::enable_shared_from_this<StackPlayer> {
|
class StackPlayer : public std::enable_shared_from_this<StackPlayer> {
|
||||||
|
@ -1937,28 +1937,23 @@ void installWebApi() {
|
|||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
||||||
auto id = sender.getMediaTuple().stream;
|
auto id = sender.getMediaTuple().stream;
|
||||||
VideoStackManager::Instance().stopVideoStack(id);
|
VideoStackManager::Instance().stopVideoStack(id);
|
||||||
InfoL << "VideoStack: " << id <<" stop";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api_regist("/index/api/stack/start", [](API_ARGS_JSON_ASYNC) {
|
api_regist("/index/api/stack/start", [](API_ARGS_JSON_ASYNC) {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
auto ret = VideoStackManager::Instance().startVideoStack(allArgs.getArgs());
|
auto ret = VideoStackManager::Instance().startVideoStack(allArgs.getArgs());
|
||||||
if (!ret) {
|
val["code"] = ret;
|
||||||
invoker(200, headerOut, "success");
|
val["msg"] = ret ? "failed" : "success";
|
||||||
} else {
|
invoker(200, headerOut, val.toStyledString());
|
||||||
invoker(200, headerOut, "failed");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api_regist("/index/api/stack/stop", [](API_ARGS_MAP_ASYNC) {
|
api_regist("/index/api/stack/stop", [](API_ARGS_MAP_ASYNC) {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("id");
|
CHECK_ARGS("id");
|
||||||
auto ret = VideoStackManager::Instance().stopVideoStack(allArgs["id"]);
|
auto ret = VideoStackManager::Instance().stopVideoStack(allArgs["id"]);
|
||||||
if (!ret) {
|
val["code"] = ret;
|
||||||
invoker(200, headerOut, "success");
|
val["msg"] = ret ? "failed" : "success";
|
||||||
} else {
|
invoker(200, headerOut, val.toStyledString());
|
||||||
invoker(200, headerOut, "failed");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user