summaryrefslogtreecommitdiffstats
path: root/src/multimedia/video
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-05-19 21:15:31 +0200
committerLars Knoll <lars.knoll@qt.io>2021-05-21 09:53:05 +0000
commit84fc04caae9103aea0bbf0fe6d33143e2a28425f (patch)
treedbd40816c3d1153af560aef08d9222d993983cc9 /src/multimedia/video
parentf3526fd7af8b9ca7e2929c21e5bd364fad0eaa3e (diff)
Clean up the videoOutput() API
The current API was rather messy, with multiple overloads. Change this and make the videoOutput a QObject * based property. To account for QVideoSink, add a videoSink()/setVideoSink() overload. This also helps identifying the correct sink in all cases. Add some code to protect against deletion of the videoOutput or videoSink from somewhere else. Adjust autotests and fix the qquickvideooutput autotests. With this change we are now passing all existing autotests again on Linux/gstreamer. Change-Id: I77b9863e88a7863abf27ab465fadd9c24f486502 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/multimedia/video')
-rw-r--r--src/multimedia/video/qvideosink.cpp25
-rw-r--r--src/multimedia/video/qvideosink.h4
2 files changed, 29 insertions, 0 deletions
diff --git a/src/multimedia/video/qvideosink.cpp b/src/multimedia/video/qvideosink.cpp
index 22692ddd7..3776b603b 100644
--- a/src/multimedia/video/qvideosink.cpp
+++ b/src/multimedia/video/qvideosink.cpp
@@ -41,6 +41,8 @@
#include "qvideoframeformat.h"
#include "qvideoframe.h"
+#include "qmediaplayer.h"
+#include "qmediacapturesession.h"
#include <qvariant.h>
#include <qpainter.h>
@@ -62,8 +64,21 @@ public:
{
delete videoSink;
}
+ void unregisterSource()
+ {
+ if (!source)
+ return;
+ auto *old = source;
+ source = nullptr;
+ if (auto *player = qobject_cast<QMediaPlayer *>(old))
+ player->setVideoSink(nullptr);
+ else if (auto *capture = qobject_cast<QMediaCaptureSession *>(old))
+ capture->setVideoSink(nullptr);
+ }
+
QVideoSink *q_ptr = nullptr;
QPlatformVideoSink *videoSink = nullptr;
+ QObject *source = nullptr;
bool fullScreen = false;
WId window = 0;
QRhi *rhi = nullptr;
@@ -117,6 +132,7 @@ QVideoSink::QVideoSink(QObject *parent)
*/
QVideoSink::~QVideoSink()
{
+ d->unregisterSource();
delete d;
}
@@ -386,6 +402,15 @@ QSize QVideoSink::videoSize() const
return d->videoSink->nativeSize();
}
+void QVideoSink::setSource(QObject *source)
+{
+ if (d->source == source)
+ return;
+ if (source)
+ d->unregisterSource();
+ d->source = source;
+}
+
QT_END_NAMESPACE
#include "moc_qvideosink.cpp"
diff --git a/src/multimedia/video/qvideosink.h b/src/multimedia/video/qvideosink.h
index 7802c32ed..93506db37 100644
--- a/src/multimedia/video/qvideosink.h
+++ b/src/multimedia/video/qvideosink.h
@@ -109,6 +109,10 @@ Q_SIGNALS:
void aspectRatioModeChanged(Qt::AspectRatioMode mode);
private:
+ friend class QMediaPlayerPrivate;
+ friend class QMediaCaptureSessionPrivate;
+ void setSource(QObject *source);
+
QVideoSinkPrivate *d = nullptr;
};