3#include <QtCore/QThread>
4#include <QtGui/QWindow>
5#include <QtMultimedia/QVideoFrame>
6#include <QtMultimedia/QVideoSink>
7#include <QtQuick/QQuickItem>
8#include <QtQuick/QQuickWindow>
16 , _element(element ?
GStreamer::adoptElement(GST_ELEMENT(gst_object_ref(element))) :
nullptr)
21 _releaseElementBinding();
26 (void) QObject::disconnect(_visibilityConnection);
27 _videoOutput = videoOutput;
32 if (QQuickWindow* window = videoOutput ? videoOutput->window() :
nullptr) {
33 _visibilityConnection = QObject::connect(window, &QWindow::visibilityChanged,
this,
34 &QGCQVideoSinkController::_applyWindowVisibility);
36 _applyWindowVisibility();
39void QGCQVideoSinkController::_applyWindowVisibility()
41 const QWindow*
const window = _videoOutput ? _videoOutput->window() :
nullptr;
42 const QWindow::Visibility visibility = window ? window->visibility() : QWindow::Hidden;
43 setActive((visibility != QWindow::Hidden) && (visibility != QWindow::Minimized));
48 if (thread() != QThread::currentThread()) {
49 qCCritical(QGCQVideoSinkControllerLog) <<
"called from wrong thread";
53 if (!_element || _bindingReleased)
55 g_object_set(_element.get(),
"active", active ? TRUE : FALSE,
nullptr);
60 if (thread() != QThread::currentThread()) {
61 qCCritical(QGCQVideoSinkControllerLog) <<
"called from wrong thread";
66 if (_sinkDestroyedConnection) {
67 QObject::disconnect(_sinkDestroyedConnection);
68 _sinkDestroyedConnection = {};
70 QVideoSink* raw = sink.data();
74 _releaseElementBinding();
78 g_object_set(_element.get(),
"qvideosink",
static_cast<gpointer
>(raw),
"active", _active ? TRUE : FALSE,
nullptr);
79 if (_videoSink != raw) {
80 _clearVideoSinkFrame();
83 _sinkDestroyedConnection =
84 QObject::connect(raw, &QObject::destroyed,
this, [
this]() {
setVideoSink(QPointer<QVideoSink>()); });
85 _bindingReleased =
false;
90 if (thread() != QThread::currentThread()) {
91 qCCritical(QGCQVideoSinkControllerLog) <<
"called from wrong thread";
94 _releaseElementBinding();
99 if (thread() != QThread::currentThread()) {
100 qCCritical(QGCQVideoSinkControllerLog) <<
"called from wrong thread";
104 _videoSink->setVideoFrame(QVideoFrame());
115 g_object_get(_element.get(),
"picture-width", &width,
"picture-height", &height,
nullptr);
116 return ((width > 0) && (height > 0)) ? QSize(width, height) : QSize();
119void QGCQVideoSinkController::_releaseElementBinding()
121 if (!_element || _bindingReleased)
124 if (_sinkDestroyedConnection) {
125 QObject::disconnect(_sinkDestroyedConnection);
126 _sinkDestroyedConnection = {};
128 g_object_set(_element.get(),
"active", FALSE,
"qvideosink",
static_cast<gpointer
>(
nullptr),
nullptr);
129 _bindingReleased =
true;
130 _clearVideoSinkFrame();
133void QGCQVideoSinkController::_clearVideoSinkFrame()
struct _GstElement GstElement
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QGCQVideoSinkController(GstElement *element, QObject *parent=nullptr)
~QGCQVideoSinkController() override
void setActive(bool active)
void setVideoSink(QPointer< QVideoSink > sink)
void followWindowVisibility(QQuickItem *videoOutput)
QSize pictureSize() const