Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgstreamervideodevices.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
5#include <QtMultimedia/qmediadevices.h>
6#include <QtMultimedia/private/qcameradevice_p.h>
7
8#include <common/qgst_p.h>
11
13
14static gboolean deviceMonitorCallback(GstBus *, GstMessage *message, gpointer m)
15{
16 auto *manager = static_cast<QGstreamerVideoDevices *>(m);
18
19 switch (GST_MESSAGE_TYPE(message)) {
20 case GST_MESSAGE_DEVICE_ADDED:
21 gst_message_parse_device_added(message, &device);
22 manager->addDevice(std::move(device));
23 break;
24 case GST_MESSAGE_DEVICE_REMOVED:
25 gst_message_parse_device_removed(message, &device);
26 manager->removeDevice(std::move(device));
27 break;
28 default:
29 break;
30 }
31
32 return G_SOURCE_CONTINUE;
33}
34
36 : QPlatformVideoDevices(integration),
37 m_deviceMonitor{
38 gst_device_monitor_new(),
39 }
40{
41 gst_device_monitor_add_filter(m_deviceMonitor.get(), "Video/Source", nullptr);
42
43 QGstBusHandle bus{
44 gst_device_monitor_get_bus(m_deviceMonitor.get()),
45 };
46 gst_bus_add_watch(bus.get(), deviceMonitorCallback, this);
47 gst_device_monitor_start(m_deviceMonitor.get());
48
49 GList *devices = gst_device_monitor_get_devices(m_deviceMonitor.get());
50
53 device,
55 });
56 }
57
58 g_list_free(devices);
59}
60
62{
63 gst_device_monitor_stop(m_deviceMonitor.get());
64}
65
66QList<QCameraDevice> QGstreamerVideoDevices::videoDevices() const
67{
68 QList<QCameraDevice> devices;
69
70 for (const auto &device : m_videoSources) {
72
73 QGString desc{
74 gst_device_get_display_name(device.gstDevice.get()),
75 };
76 info->description = desc.toQString();
77 info->id = device.id;
78
79 if (QGstStructure properties = gst_device_get_properties(device.gstDevice.get());
80 !properties.isNull()) {
81 auto def = properties["is-default"].toBool();
82 info->isDefault = def && *def;
83 properties.free();
84 }
85
86 if (info->isDefault)
87 devices.prepend(info->create());
88 else
89 devices.append(info->create());
90
91 auto caps = QGstCaps(gst_device_get_caps(device.gstDevice.get()), QGstCaps::HasRef);
92 if (!caps.isNull()) {
93 QList<QCameraFormat> formats;
94 QSet<QSize> photoResolutions;
95
96 int size = caps.size();
97 for (int i = 0; i < size; ++i) {
98 auto cap = caps.at(i);
99
100 QSize resolution = cap.resolution();
101 if (!resolution.isValid())
102 continue;
103
104 auto pixelFormat = cap.pixelFormat();
105 auto frameRate = cap.frameRateRange();
106
107 auto *f = new QCameraFormatPrivate{ QSharedData(), pixelFormat, resolution,
108 frameRate.min, frameRate.max };
109 formats << f->create();
110 photoResolutions.insert(resolution);
111 }
112 info->videoFormats = formats;
113 // ### sort resolutions?
114 info->photoResolutions = photoResolutions.values();
115 }
116 }
117 return devices;
118}
119
121{
122 Q_ASSERT(gst_device_has_classes(device.get(), "Video/Source"));
123
124 auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
125 [&](const QGstRecordDevice &a) { return a.gstDevice == device; });
126
127 if (it != m_videoSources.end())
128 return;
129
130 m_videoSources.push_back(QGstRecordDevice{
131 std::move(device),
132 QByteArray::number(m_idGenerator),
133 });
135 m_idGenerator++;
136}
137
139{
140 auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
141 [&](const QGstRecordDevice &a) { return a.gstDevice == device; });
142
143 if (it != m_videoSources.end()) {
144 m_videoSources.erase(it);
146 }
147}
148
150{
151 auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
152 [&](const QGstRecordDevice &a) { return a.id == id; });
153 return it != m_videoSources.end() ? it->gstDevice.get() : nullptr;
154}
155
IOBluetoothDevice * device
\inmodule QtCore
Definition qbytearray.h:57
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
GstDevice * videoDevice(const QByteArray &id) const
QList< QCameraDevice > videoDevices() const override
QGstreamerVideoDevices(QPlatformMediaIntegration *integration)
void removeDevice(QGstDeviceHandle)
void addDevice(QGstDeviceHandle)
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
Definition qsize.h:25
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:127
Type get() const noexcept
QSet< QString >::iterator it
EGLint EGLint * formats
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
EGLDeviceEXT * devices
static QT_BEGIN_NAMESPACE gboolean deviceMonitorCallback(GstBus *, GstMessage *message, gpointer m)
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLuint GLsizei const GLchar * message
GLenum cap
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QNetworkAccessManager manager
QHostInfo info
[0]