diff --git a/server/VideoStack.cpp b/server/VideoStack.cpp index ff4804f1..d5168147 100644 --- a/server/VideoStack.cpp +++ b/server/VideoStack.cpp @@ -62,15 +62,16 @@ void Channel::addParam(const std::weak_ptr& p) void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame) { std::weak_ptr 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& 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; diff --git a/server/VideoStack.h b/server/VideoStack.h index d4378ab3..99455b40 100644 --- a/server/VideoStack.h +++ b/server/VideoStack.h @@ -80,6 +80,7 @@ class Channel : public std::enable_shared_from_this { std::vector> _params; mediakit::FFmpegSws::Ptr _sws; + toolkit::EventPoller::Ptr _poller; }; class StackPlayer : public std::enable_shared_from_this { diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 9ea3681d..9b1c8ba9 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -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 }