diff options
Diffstat (limited to 'src/multimedia/video')
-rw-r--r-- | src/multimedia/video/qvideosink.cpp | 25 | ||||
-rw-r--r-- | src/multimedia/video/qvideosink.h | 4 |
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; }; |