summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorDmytro Poplavskiy <dmytro.poplavskiy@nokia.com>2011-11-28 15:00:26 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-28 11:56:42 +0100
commit3319639a6fd74d171224cb14c6e5bba0627621ba (patch)
treefba97b3abe6a84686f4983dbb9d2429ca7fe6baa /src/multimedia
parentbe7cc17cbfe2209c6da1ecd40f99df0149a2651d (diff)
Allow nested read only maps of QVideoFrame.
It's useful when video frame is accessed from multiple places like display and encoding. Change-Id: I8af175c780783216d8b7717cdf0744ad9bc95348 Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/video/qvideoframe.cpp54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index fdbe75080..0972f54e6 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -49,6 +49,7 @@
#include <qsize.h>
#include <qvariant.h>
#include <qvector.h>
+#include <qmutex.h>
#include <QDebug>
@@ -94,6 +95,7 @@ public:
, pixelFormat(format)
, fieldType(QVideoFrame::ProgressiveFrame)
, buffer(0)
+ , mappedCount(0)
{
}
@@ -111,6 +113,8 @@ public:
QVideoFrame::PixelFormat pixelFormat;
QVideoFrame::FieldType fieldType;
QAbstractVideoBuffer *buffer;
+ int mappedCount;
+ QMutex mapMutex;
private:
Q_DISABLE_COPY(QVideoFramePrivate)
@@ -528,6 +532,9 @@ QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
When access to the data is no longer needed be sure to call the unmap() function to release the
mapped memory and possibly update the video frame contents.
+ If the video frame is mapped in read only mode, it's allowed to map it for reading again,
+ in all the other cases it's necessary to unmap the frame first.
+
Returns true if the buffer was mapped to memory in the given \a mode and false otherwise.
\since 1.0
@@ -535,13 +542,34 @@ QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
*/
bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode)
{
- if (d->buffer != 0 && d->data == 0) {
- Q_ASSERT(d->bytesPerLine == 0);
- Q_ASSERT(d->mappedBytes == 0);
+ QMutexLocker lock(&d->mapMutex);
+
+ if (!d->buffer)
+ return false;
+
+ if (mode == QAbstractVideoBuffer::NotMapped)
+ return false;
+
+ if (d->mappedCount > 0) {
+ //it's allowed to map the video frame multiple times in read only mode
+ if (d->buffer->mapMode() == QAbstractVideoBuffer::ReadOnly
+ && mode == QAbstractVideoBuffer::ReadOnly) {
+ d->mappedCount++;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ Q_ASSERT(d->data == 0);
+ Q_ASSERT(d->bytesPerLine == 0);
+ Q_ASSERT(d->mappedBytes == 0);
- d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine);
+ d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine);
- return d->data != 0;
+ if (d->data) {
+ d->mappedCount++;
+ return true;
}
return false;
@@ -553,12 +581,26 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode)
If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly
flag this will persist the current content of the mapped memory to the video frame.
+ unmap() should not be called if map() function failed.
+
\since 1.0
\sa map()
*/
void QVideoFrame::unmap()
{
- if (d->data != 0) {
+ QMutexLocker lock(&d->mapMutex);
+
+ if (!d->buffer)
+ return;
+
+ if (d->mappedCount == 0) {
+ qWarning() << "QVideoFrame::unmap() was called more times then QVideoFrame::map()";
+ return;
+ }
+
+ d->mappedCount--;
+
+ if (d->mappedCount == 0) {
d->mappedBytes = 0;
d->bytesPerLine = 0;
d->data = 0;