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;
33class Q_MULTIMEDIA_EXPORT QAVFVideoDevices : public QPlatformVideoDevices
34{
35public:
36 // Takes a delegate to check whether a given CvPixelFormat is supported for a capture session.
37 // If given a nullptr, it assumes all formats are supported.
38 QAVFVideoDevices(
39 QPlatformMediaIntegration *integration,
40 std::function<bool(uint32_t)> &&isCvPixelFormatSupportedDelegate = nullptr);
41 ~QAVFVideoDevices();
42
43 // Returns true if the given CvPixelFormat is supported for camera capture session.
44 [[nodiscard]] bool isCvPixelFormatSupported(uint32_t cvPixelFormat) const;
45
46protected:
47 QList<QCameraDevice> findVideoInputs() const override;
48
49private:
50 QMacNotificationObserver m_deviceConnectedObserver;
51 QMacNotificationObserver m_deviceDisconnectedObserver;
52 std::function<bool(uint32_t)> m_isCvPixelFormatSupportedDelegate;
53
54 // We need to key-value observe the "suspended" value of all connected
55 // AVCaptureDevices in order to determine whether they should be exposed as
56 // QCameraDevice to the user.
57 struct ObservedAVCaptureDevice {
58 AVFScopedPointer<AVCaptureDevice> avCaptureDevice;
59 // Note: Observer holds weak ref to avCaptureDevice, and must
60 // be destroyed before avCaptureDevice.
61 QMacKeyValueObserver observer;
62 };
63
64 void clearObservedAvCaptureDevices();
65 void rebuildObserveredAvCaptureDevices();
66 // All modifications and read of m_observedAvCaptureDevices happen by
67 // posting jobs the QAVFVideoDevices' thread, and so this doesn't need a
68 // lock.
69 std::vector<ObservedAVCaptureDevice> m_observedAvCaptureDevices;
70};
71
72QT_END_NAMESPACE
73
74#endif