Keep stream capture failures and cursor snapshots tied to their source

This commit is contained in:
evgeny committed 2026-10-17 01:30:06 +02:00
1 parent 9c7d088f8b
commit fd73fae77f
3 files changed
+41 -25

No files matched your search

+20 -8
View File
@@ -502,6 +502,9 @@ void StreamPublishEngine::imageLoop() {
#ifdef HAVE_STREAM_CAPTURE
for (;;) {
QVideoFrame frame; uint64_t generation; int64_t pts; bool drawCursor;
#ifdef UTUN_STREAM_WIN_CURSOR
std::shared_ptr<StreamScreenCursor> cursor;
#endif
m->imageProgress("wait-frame");
{
std::unique_lock<std::mutex> lock(m->lock);
@@ -509,6 +512,10 @@ void StreamPublishEngine::imageLoop() {
if (m->imageStop) return;
frame = std::move(m->imageInput); generation = m->imageGeneration; pts = m->imagePts;
drawCursor = m->imageDrawCursor; m->imagePending = false;
if (!m->running || generation != m->sourceGeneration) continue;
#ifdef UTUN_STREAM_WIN_CURSOR
cursor = m->cursor;
#endif
}
int64_t convertAt = monotonicUs();
m->imageProgress("convert-frame");
@@ -520,25 +527,30 @@ void StreamPublishEngine::imageLoop() {
if (image.isNull()) {
DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop captured frame conversion failed generation=%llu format=%d size=%dx%d",
(unsigned long long)generation, frame.pixelFormat(), frame.width(), frame.height());
QMetaObject::invokeMethod(this, [this, generation] { sourceFailed(generation, text("Video frame conversion failed")); });
QMetaObject::invokeMethod(this, [this, generation] {
if (generation == m->sourceGeneration) sourceFailed(m->generation, text("Video frame conversion failed"));
});
continue;
}
#ifdef UTUN_STREAM_WIN_CURSOR
std::shared_ptr<StreamScreenCursor> cursor;
{ std::lock_guard<std::mutex> guard(m->lock); cursor = m->cursor; }
if (drawCursor && cursor && !cursor->draw(image)) {
QMetaObject::invokeMethod(this, [this, generation] { sourceFailed(generation, text("Could not capture the mouse cursor")); });
if (drawCursor && (!cursor || !cursor->draw(image))) {
if (!cursor) DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop cursor missing for captured frame generation=%llu", (unsigned long long)generation);
QMetaObject::invokeMethod(this, [this, generation] {
if (generation == m->sourceGeneration) sourceFailed(m->generation, text("Could not capture the mouse cursor"));
});
continue;
}
QVideoFrame preview = previewFrameFromImage(image);
if (!preview.isValid()) DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop preview frame unavailable generation=%llu",
(unsigned long long)generation);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
if (frame.rotation() != QtVideo::Rotation::None) image = image.transformed(QTransform().rotate(static_cast<int>(frame.rotation())));
if (frame.mirrored()) image = image.transformed(QTransform().scale(-1, 1));
#else
if (frame.rotationAngle()) image = image.transformed(QTransform().rotate(frame.rotationAngle()));
#endif
#ifdef UTUN_STREAM_WIN_CURSOR
QVideoFrame preview = previewFrameFromImage(image);
if (!preview.isValid()) DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop preview frame unavailable generation=%llu",
(unsigned long long)generation);
#endif
m->imageProgress("publish-image");
{