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
qavfvideodevices_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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
4#ifndef QAVFVIDEODEVICES_H
5#define QAVFVIDEODEVICES_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qplatformvideodevices_p.h>
19
20#include <QtCore/private/qcore_mac_p.h>
21
22#include <QtMultimedia/private/qavfcamerautility_p.h>
23#include <QtMultimedia/qtmultimediaexports.h>
24
25#include <functional>
26#include <vector>
27
28#import <AVFoundation/AVCaptureDevice.h>
29
30QT_BEGIN_NAMESPACE
31
32class QPlatformMediaIntegration;
33
34// This class is always moved to the main-thread upon construction.
35// All changes and events happens on the main-thread.
36class Q_MULTIMEDIA_EXPORT QAVFVideoDevices : public QPlatformVideoDevices
37{
38public:
39 // Takes a delegate to check whether a given CvPixelFormat is supported for a capture session.
40 // If given a nullptr, it assumes all formats are supported.
41 QAVFVideoDevices(
42 QPlatformMediaIntegration *integration,
43 std::function<bool(uint32_t)> &&isCvPixelFormatSupportedDelegate = nullptr);
44 ~QAVFVideoDevices();
45
46 // Returns true if the given CvPixelFormat is supported for camera capture session.
47 [[nodiscard]] bool isCvPixelFormatSupported(uint32_t cvPixelFormat) const;
48
49protected:
50 QList<QCameraDevice> findVideoInputs() const override;
51
52private:
53 void onAvCaptureDevicesChanged();
54
55private:
56 // In rare cases, m_avDiscoverySession may be null. See QTBUG-144218.
57 AVFScopedPointer<AVCaptureDeviceDiscoverySession> m_avDiscoverySession;
58 // Note: Observer holds weak ref to AVCaptureDeviceDiscoverySession, and must
59 // be destroyed before AVCaptureDeviceDiscoverySession.
60 QMacKeyValueObserver m_avDiscoverySessionObserver;
61
62 std::function<bool(uint32_t)> m_isCvPixelFormatSupportedDelegate;
63
64 // We need to key-value observe the "suspended" value of all connected
65 // AVCaptureDevices in order to determine whether they should be exposed as
66 // QCameraDevice to the user.
67 struct ObservedAVCaptureDevice {
68 AVFScopedPointer<AVCaptureDevice> avCaptureDevice;
69 // Note: Observer holds weak ref to avCaptureDevice, and must
70 // be destroyed before avCaptureDevice.
71 QMacKeyValueObserver observer;
72 };
73
74 void rebuildObserveredAvCaptureDevices();
75 // All modifications and read of m_observedAvCaptureDevices happen by
76 // posting jobs the QAVFVideoDevices' thread, and so this doesn't need a
77 // lock.
78 std::vector<ObservedAVCaptureDevice> m_observedAvCaptureDevices;
79};
80
81QT_END_NAMESPACE
82
83#endif