From 5c80c75ed994e90a625dd2d034f8900bb0a9c774 Mon Sep 17 00:00:00 2001 From: sbkyy <135107730+sbkyy@users.noreply.github.com> Date: Sat, 26 Oct 2024 09:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvideo=20stack=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /index/api/stack/reset 在相同url和通分辨率多次调用channel析构没画面的问题 是在 VideoStackManager::parseParams 函数里 多次 (*params)[i * cols + j] = nullptr; 导致 channel 计数器为0,析构没画面。 同时修复cpu占用过高问题。 --- server/VideoStack.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/VideoStack.cpp b/server/VideoStack.cpp index 76b5ad49..6ae4a005 100644 --- a/server/VideoStack.cpp +++ b/server/VideoStack.cpp @@ -23,7 +23,11 @@ INSTANCE_IMP(VideoStackManager) -Param::~Param() { VideoStackManager::Instance().unrefChannel(id, width, height, pixfmt); } +Param::~Param() { + auto strongChn= weak_chn.lock(); + if (!strongChn) { return; } + VideoStackManager::Instance().unrefChannel(id, width, height, pixfmt); +} Channel::Channel(const std::string& id, int width, int height, AVPixelFormat pixfmt) : _id(id), _width(width), _height(height), _pixfmt(pixfmt) { @@ -278,7 +282,9 @@ void VideoStack::start() { _dev->inputYUV((char**)_buffer->get()->data, _buffer->get()->linesize, pts); pts += frameInterval; - } + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } } }); }