Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgstreamervideosource.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtMultimedia/private/qplatformcamera_p.h>
8#include <QtMultimedia/private/qplatformmediaintegration_p.h>
9
10#include <QtCore/qdebug.h>
11
13
14void QGStreamerVideoSourcePrivate::createPlatformCamera(QGStreamerVideoSource *source,
15 GstElementOrDescription elementOrDesc,
16 bool active)
17{
18 Q_ASSERT(!platformCamera);
19
20 auto maybePlatformCamera = QPlatformMediaIntegration::instance()->createGStreamerVideoSource(
21 source, elementOrDesc);
22 if (!maybePlatformCamera) {
23 qWarning() << "Failed to initialize QGStreamerVideoSource" << maybePlatformCamera.error();
24 return;
25 }
26
27 if (auto gstBinDesc = std::get_if<QString>(&elementOrDesc))
28 gstBinDescription = std::move(*gstBinDesc);
29
30 platformCamera = *maybePlatformCamera;
31
32 if (active)
33 platformCamera->setActive(true);
34
35 QObject::connect(platformCamera, &QPlatformVideoSource::activeChanged, source,
36 &QGStreamerVideoSource::activeChanged);
37}
38
39QGStreamerVideoSource::QGStreamerVideoSource(const QString &gstBinDescription, QObject *parent)
40 : QGStreamerVideoSource(parent)
41{
42 Q_D(QGStreamerVideoSource);
43 d->createPlatformCamera(this, gstBinDescription);
44}
45
46QGStreamerVideoSource::QGStreamerVideoSource(GstElement *gstElement, QObject *parent)
47 : QGStreamerVideoSource(parent)
48{
49 Q_D(QGStreamerVideoSource);
50 d->createPlatformCamera(this, gstElement);
51}
52
53QGStreamerVideoSource::QGStreamerVideoSource(QObject *parent)
54 : QObject(*new QGStreamerVideoSourcePrivate, parent)
55{
56}
57
58QGStreamerVideoSource::~QGStreamerVideoSource() = default;
59
60bool QGStreamerVideoSource::isActive() const
61{
62 Q_D(const QGStreamerVideoSource);
63 return d->platformCamera && d->platformCamera->isActive();
64}
65
66QString QGStreamerVideoSource::gstBinDescription() const
67{
68 Q_D(const QGStreamerVideoSource);
69 return d->gstBinDescription;
70}
71
72GstElement *QGStreamerVideoSource::gstElement() const
73{
74 Q_D(const QGStreamerVideoSource);
75 return d->platformCamera ? d->platformCamera->rawGstElement() : nullptr;
76}
77
78void QGStreamerVideoSource::setActive(bool active)
79{
80 Q_D(const QGStreamerVideoSource);
81 if (d->platformCamera)
82 d->platformCamera->setActive(active);
83}
84
85QPlatformCamera *QGStreamerVideoSource::platformVideoSource() const
86{
87 Q_D(const QGStreamerVideoSource);
88 return d->platformCamera;
89}
90
91QMediaCaptureSession *QGStreamerVideoSource::captureSession() const
92{
93 Q_D(const QGStreamerVideoSource);
94 return d->captureSession;
95}
96
97void QGStreamerVideoSource::setCaptureSession(QMediaCaptureSession *session)
98{
99 Q_D(QGStreamerVideoSource);
100 d->captureSession = session;
101}
102
103QT_END_NAMESPACE
Combined button and popup list for selecting options.