From 2facdb6949dfc1d1107736295448d65c7626ba7b Mon Sep 17 00:00:00 2001 From: evgeny Date: Sun, 18 Oct 2026 16:54:36 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B4=D0=B0=D1=87=D1=83=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D0=BE=D0=B3=D0=BE=20GPU=20=D0=B4=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B3=D0=BE=20IDR=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/chatgui/src/call_video_encoder.cpp | 8 ++++++++ tools/chatgui/src/live_video_encoder.cpp | 4 ++++ tools/chatgui/tests/test_call_video_encoder.cpp | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/chatgui/src/call_video_encoder.cpp b/tools/chatgui/src/call_video_encoder.cpp index 81777736..6bf15e1e 100644 --- a/tools/chatgui/src/call_video_encoder.cpp +++ b/tools/chatgui/src/call_video_encoder.cpp @@ -121,6 +121,14 @@ bool CallVideoEncoder::encode(const QImage& image, uint64_t pts, bool forceKey, (unsigned long long)m_request, m_switchInputs, (long long)frames.size(), qPrintable(m_replacement->error())); completion = {m_format.generation, m_request, 0}; m_request = 0; m_pendingBitrate = 0; m_replacement.reset(); frames.clear(); key = true; m_keyPending = false; + } else if (m_replacement && frames.isEmpty()) { + // До первого нового IDR продолжаем выдавать только старые кадры с PTS раньше границы замены. + // Уже выданный PTS не может обогнать ожидаемый IDR и сделать его устаревшим. + QList previous; + if (m_encoder->encode(image, pts, false, previous)) { + for (auto& frame : previous) if (frame.pts < m_switchPts) frames.push_back(std::move(frame)); + } else DEBUG_WARN(DEBUG_CATEGORY_CALL, "old GPU failed while replacement is pending request=%llu: %s", + (unsigned long long)m_request, qPrintable(m_encoder->error())); } } if (!encoded) encoded = m_encoder->encode(image, pts, key, frames); diff --git a/tools/chatgui/src/live_video_encoder.cpp b/tools/chatgui/src/live_video_encoder.cpp index 3103a9be..f778bf3c 100644 --- a/tools/chatgui/src/live_video_encoder.cpp +++ b/tools/chatgui/src/live_video_encoder.cpp @@ -215,6 +215,7 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) { if (m->forcedKeys) av_dict_set(&options, "forced_idr", "1", 0); if (constrained) { av_dict_set(&options, "rc", "cbr", 0); + av_dict_set(&options, "skip_frame", "0", 0); av_dict_set(&options, "profile", config.codec == STREAM_MEDIA_H264 ? "constrained_baseline" : "main", 0); if (config.codec == STREAM_MEDIA_H265) av_dict_set(&options, "profile_tier", "main", 0); } @@ -282,6 +283,9 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) { return false; } verified = {frame}; + if (constrained) DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, + "call GPU probe name=%s pts=%llu pipeline_frames=%d time_base=%d/%d", + name.constData(), (unsigned long long)pts, attempt, c->time_base.num, c->time_base.den); return true; } output.clear(); diff --git a/tools/chatgui/tests/test_call_video_encoder.cpp b/tools/chatgui/tests/test_call_video_encoder.cpp index da176ce5..9c370039 100644 --- a/tools/chatgui/tests/test_call_video_encoder.cpp +++ b/tools/chatgui/tests/test_call_video_encoder.cpp @@ -236,7 +236,7 @@ private slots: QVERIFY(output.front().key); pts += 1000000; if (!completion.request) QTest::qWait(33); } while (!completion.request && deadline.elapsed() < 3000); - QCOMPARE(completion.request, uint64_t(2)); QCOMPARE(completion.bitrate, 300000u); QVERIFY(output.key); + QCOMPARE(completion.request, uint64_t(2)); QCOMPARE(completion.bitrate, 300000u); QVERIFY(output.front().key); encoder.close(); QVERIFY(!encoder.requestBitrate(9, 3, 500000)); } };