summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2024-03-11 17:56:00 +0100
committerArtem Dyomin <artem.dyomin@qt.io>2024-03-19 22:04:25 +0100
commit537fae96a9fabec2203460e786ff62075cf43bb8 (patch)
tree8ed9fb6b5982986bd0335b40a941573bd0b3b57b /src/multimedia
parentcc8492f75c285b58b90c16d8712b19ba181db443 (diff)
Fix mapping of QVideoFrame in write mode
After mapping of QVideoFrame with a write mode, we get this: - the hw frame in QFFmpegVideoBuffer is not valid anymore - the cached QImage is not valid anymore The implemented approach might be revisited if we decide to implement copy-on-modify idiom for QVideoFrame instead of buffer sharing. Fixes: QTBUG-123131 Pick-to: 6.7 6.6 6.5 Change-Id: I1c1662c5a4ac6f5bffa2cea8e36c4fbf60c20f64 Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/video/qvideoframe.cpp15
-rw-r--r--src/multimedia/video/qvideoframe_p.h3
2 files changed, 14 insertions, 4 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index e58c7b2c4..8c57ce54b 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -427,6 +427,15 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
}
d->mappedCount++;
+
+ // unlock mapMutex to avoid potential deadlock imageMutex <--> mapMutex
+ lock.unlock();
+
+ if ((mode & QVideoFrame::WriteOnly) != 0) {
+ QMutexLocker lock(&d->imageMutex);
+ d->image = {};
+ }
+
return true;
}
@@ -667,10 +676,12 @@ QImage QVideoFrame::toImage() const
if (!isValid())
return {};
- std::call_once(d->imageOnceFlag, [this]() {
+ QMutexLocker lock(&d->imageMutex);
+
+ if (d->image.isNull()) {
const bool mirrorY = surfaceFormat().scanLineDirection() != QVideoFrameFormat::TopToBottom;
d->image = qImageFromVideoFrame(*this, rotation(), mirrored(), mirrorY);
- });
+ }
return d->image;
}
diff --git a/src/multimedia/video/qvideoframe_p.h b/src/multimedia/video/qvideoframe_p.h
index f5037f7a5..1a43ae49d 100644
--- a/src/multimedia/video/qvideoframe_p.h
+++ b/src/multimedia/video/qvideoframe_p.h
@@ -19,7 +19,6 @@
#include "qabstractvideobuffer_p.h"
#include <qmutex.h>
-#include <mutex> // std::once
QT_BEGIN_NAMESPACE
@@ -51,7 +50,7 @@ public:
QtVideo::Rotation rotation = QtVideo::Rotation::None;
bool mirrored = false;
QImage image;
- std::once_flag imageOnceFlag;
+ QMutex imageMutex;
private:
Q_DISABLE_COPY(QVideoFramePrivate)