Qt 6.x
The Qt SDK
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 "qmediadevices.h"
6#include "private/qcameradevice_p.h"
7
11#include "qgstutils_p.h"
12
14
15static gboolean deviceMonitor(GstBus *, GstMessage *message, gpointer m)
16{
17 auto *manager = static_cast<QGstreamerVideoDevices *>(m);
18 GstDevice *device = nullptr;
19
20 switch (GST_MESSAGE_TYPE (message)) {
21 case GST_MESSAGE_DEVICE_ADDED:
22 gst_message_parse_device_added(message, &device);
23 manager->addDevice(device);
24 break;
25 case GST_MESSAGE_DEVICE_REMOVED:
26 gst_message_parse_device_removed(message, &device);
27 manager->removeDevice(device);
28 break;
29 default:
30 break;
31 }
32 if (device)
33 gst_object_unref (device);
34
35 return G_SOURCE_CONTINUE;
36}
37
39 : QPlatformVideoDevices(integration)
40{
41 GstDeviceMonitor *monitor;
42 GstBus *bus;
43
44 monitor = gst_device_monitor_new();
45
46 gst_device_monitor_add_filter (monitor, nullptr, nullptr);
47
48 bus = gst_device_monitor_get_bus(monitor);
49 gst_bus_add_watch(bus, deviceMonitor, this);
50 gst_object_unref(bus);
51
52 gst_device_monitor_start(monitor);
53
54 auto devices = gst_device_monitor_get_devices(monitor);
55
56 while (devices) {
57 GstDevice *device = static_cast<GstDevice *>(devices->data);
59 gst_object_unref(device);
60 devices = g_list_delete_link(devices, devices);
61 }
62}
63
65{
67
68 for (auto device : m_videoSources) {
70 auto *desc = gst_device_get_display_name(device.gstDevice);
71 info->description = QString::fromUtf8(desc);
72 g_free(desc);
73 info->id = device.id;
74
75 if (QGstStructure properties = gst_device_get_properties(device.gstDevice); !properties.isNull()) {
76 auto def = properties["is-default"].toBool();
77 info->isDefault = def && *def;
78 properties.free();
79 }
80
81 if (info->isDefault)
82 devices.prepend(info->create());
83 else
84 devices.append(info->create());
85
86 auto caps = QGstCaps(gst_device_get_caps(device.gstDevice), QGstCaps::HasRef);
87 if (!caps.isNull()) {
89 QSet<QSize> photoResolutions;
90
91 int size = caps.size();
92 for (int i = 0; i < size; ++i) {
93 auto cap = caps.at(i);
94
95 QSize resolution = cap.resolution();
96 if (!resolution.isValid())
97 continue;
98
99 auto pixelFormat = cap.pixelFormat();
100 auto frameRate = cap.frameRateRange();
101
102 auto *f = new QCameraFormatPrivate{
103 QSharedData(),
104 pixelFormat,
105 resolution,
106 frameRate.min,
107 frameRate.max
108 };
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 if (gst_device_has_classes(device, "Video/Source")) {
123 gst_object_ref(device);
124 m_videoSources.push_back({device, QByteArray::number(m_idGenerator)});
126 m_idGenerator++;
127 }
128}
129
131{
132 auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
133 [=](const QGstDevice &a) { return a.gstDevice == device; });
134
135 if (it != m_videoSources.end()) {
136 m_videoSources.erase(it);
138 }
139
140 gst_object_unref(device);
141}
142
144{
145 auto it = std::find_if(m_videoSources.begin(), m_videoSources.end(),
146 [=](const QGstDevice &a) { return a.id == id; });
147 return it != m_videoSources.end() ? it->gstDevice : nullptr;
148}
149
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.
@ HasRef
Definition qgst_p.h:163
GstDevice * videoDevice(const QByteArray &id) const
QList< QCameraDevice > videoDevices() const override
QGstreamerVideoDevices(QPlatformMediaIntegration *integration)
Definition qlist.h:74
Definition qset.h:18
qsizetype size() const
Definition qset.h:50
QList< T > values() const
Definition qset.h:297
iterator insert(const T &value)
Definition qset.h:155
\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:126
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5857
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 deviceMonitor(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 emit
@ desc
QFileInfo info(fileName)
[8]
QNetworkAccessManager manager