From 836bde2ba1a3fc5bdce51aad839e07fb7584af35 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Wed, 30 Oct 2019 14:01:18 +0100 Subject: Introduce MediaPlayer::videoOutput property This property holds the target video output, and allows to render video to multiple items. MediaPlayer { videoOutput: [videoOutput1, 1, "ignored", videoOutput2.videoSurface] } Incorrect inputs are ignored. The property also accepts single either QAbstractVideoSurface or QDeclarativeVideoOutput objects. Task-number: QTBUG-32939 Change-Id: I41fc557dcac60be6d70b3889036ff4ae75734cc0 Reviewed-by: Volker Hilsheimer --- src/imports/multimedia/qdeclarativeaudio.cpp | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/imports/multimedia/qdeclarativeaudio.cpp') diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 9d41c77fa..fcba6257d 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -45,12 +45,14 @@ #include #include +#include #include #include #include "qdeclarativeplaylist_p.h" #include "qdeclarativemediametadata_p.h" +#include #include #include @@ -129,6 +131,63 @@ QDeclarativeAudio::~QDeclarativeAudio() delete m_player; } +/*! + \since 5.15 + \qmlproperty url QtMultimedia::MediaPlayer::videoOutput + + This property holds the target video output. + Accepts one or an array of QAbstractVideoSurface or VideoOutput elements. + + \snippet multimedia-snippets/multiple-videooutputs.qml complete + + \sa QMediaPlayer::setVideoOutput() +*/ + +QVariant QDeclarativeAudio::videoOutput() const +{ + return m_videoOutput; +} + +void QDeclarativeAudio::setVideoOutput(const QVariant &v) +{ + if (m_videoOutput == v) + return; + + QAbstractVideoSurface *surface = nullptr; + auto vo = v.value(); + if (vo) + surface = vo->videoSurface(); + else + surface = v.value(); + + // If only one object has been passed. + if (surface) { + m_player->setVideoOutput(surface); + } else { + QVector surfaces; + // Check if it is an array. + auto arr = v.value(); + if (!arr.isNull()) { + const int len = arr.property("length").toInt(); + for (int i = 0; i < len; ++i) { + auto &&v = arr.property(i); + if (v.isQObject()) { + auto obj = v.toQObject(); + vo = qobject_cast(obj); + surface = vo ? vo->videoSurface() : qobject_cast(obj); + if (surface) + surfaces.append(surface); + } + } + } + + m_player->setVideoOutput(surfaces); + } + + m_videoOutput = v; + emit videoOutputChanged(); +} + /*! \qmlproperty enumeration QtMultimedia::Audio::availability -- cgit v1.2.3