summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2024-04-02 21:13:49 +0200
committerJøger Hansegård <joger.hansegard@qt.io>2024-04-04 18:40:28 +0200
commit40410efc3df4d5ab8b47c8121313a74231dd7061 (patch)
tree60fa9561666f80e9deb50b8e75c51f6c07b36951 /src/multimedia
parenta78317573ed9b51469f7b10160864d9cef0ce198 (diff)
Tighten ownership of video buffers in QVideoFrame
Switch to std::unique_ptr to prevent future lifetime management bugs Task-number: QTBUG-122099 Pick-to: 6.7 6.6 6.5 Change-Id: I453915a135e07dd175bf3632724a3d7d8200b47d Reviewed-by: Tim Blechmann <tim@klingt.org> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/video/qvideoframe.cpp6
-rw-r--r--src/multimedia/video/qvideoframe_p.h4
2 files changed, 4 insertions, 6 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index 8c57ce54b..0126af750 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -76,7 +76,7 @@ QVideoFrame::QVideoFrame()
QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format)
: d(new QVideoFramePrivate(format))
{
- d->buffer = buffer;
+ d->buffer.reset(buffer);
}
/*!
@@ -84,7 +84,7 @@ QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &
*/
QAbstractVideoBuffer *QVideoFrame::videoBuffer() const
{
- return d ? d->buffer : nullptr;
+ return d ? d->buffer.get() : nullptr;
}
/*!
@@ -102,7 +102,7 @@ QVideoFrame::QVideoFrame(const QVideoFrameFormat &format)
// Check the memory was successfully allocated.
if (!data.isEmpty())
- d->buffer = new QMemoryVideoBuffer(data, textureDescription->strideForWidth(format.frameWidth()));
+ d->buffer = std::make_unique<QMemoryVideoBuffer>(data, textureDescription->strideForWidth(format.frameWidth()));
}
}
diff --git a/src/multimedia/video/qvideoframe_p.h b/src/multimedia/video/qvideoframe_p.h
index 1a43ae49d..24d8452b4 100644
--- a/src/multimedia/video/qvideoframe_p.h
+++ b/src/multimedia/video/qvideoframe_p.h
@@ -28,8 +28,6 @@ public:
QVideoFramePrivate() = default;
QVideoFramePrivate(const QVideoFrameFormat &format) : format(format) { }
- ~QVideoFramePrivate() { delete buffer; }
-
static QVideoFramePrivate *handle(QVideoFrame &frame) { return frame.d.get(); };
QVideoFrame adoptThisByVideoFrame()
@@ -43,7 +41,7 @@ public:
qint64 endTime = -1;
QAbstractVideoBuffer::MapData mapData;
QVideoFrameFormat format;
- QAbstractVideoBuffer *buffer = nullptr;
+ std::unique_ptr<QAbstractVideoBuffer> buffer;
int mappedCount = 0;
QMutex mapMutex;
QString subtitleText;