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
qavfcamerautility_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QAVFCAMERAUTILITY_P_H
5#define QAVFCAMERAUTILITY_P_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 <QtCore/qglobal.h>
19#include <QtCore/qdebug.h>
20#include <QtCore/qlist.h>
21#include <QtCore/qsize.h>
22#include <QtCore/qtclasshelpermacros.h>
23
24#include <QtMultimedia/qcameradevice.h>
25#include <QtMultimedia/qtmultimediaexports.h>
26
27#import <AVFoundation/AVCaptureDevice.h>
28#import <AVFoundation/AVCaptureSession.h>
29
30QT_BEGIN_NAMESPACE
31
32class AVFConfigurationLock
33{
34public:
35 explicit AVFConfigurationLock(AVCaptureDevice *captureDevice)
36 : m_captureDevice(captureDevice),
37 m_locked(false)
38 {
39 Q_ASSERT(m_captureDevice);
40 NSError *error = nil;
41 m_locked = [m_captureDevice lockForConfiguration:&error];
42 }
43
44 ~AVFConfigurationLock()
45 {
46 if (m_locked)
47 [m_captureDevice unlockForConfiguration];
48 }
49
50 operator bool() const
51 {
52 return m_locked;
53 }
54
55private:
56 Q_DISABLE_COPY(AVFConfigurationLock)
57
58 AVCaptureDevice *m_captureDevice;
59 bool m_locked;
60};
61
63 void operator()(NSObject *obj)
64 {
65 if (obj)
66 [obj release];
67 }
68};
69
70template<class T>
72{
73public:
76 operator T*() const
77 {
78 // Quite handy operator to enable Obj-C messages: [ptr someMethod];
79 return data();
80 }
81
82 T *data() const
83 {
84 return static_cast<T *>(get());
85 }
86
87 T *take()
88 {
89 return static_cast<T *>(release());
90 }
91};
92
93template<>
94class AVFScopedPointer<dispatch_queue_t>
95{
96public:
97 AVFScopedPointer() : m_queue(nullptr) {}
98 explicit AVFScopedPointer(dispatch_queue_t q) : m_queue(q) {}
99 AVFScopedPointer(AVFScopedPointer &&other) noexcept :
100 m_queue{ std::exchange(other.m_queue, nullptr) }
101 {}
102
103 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(AVFScopedPointer)
104
105 ~AVFScopedPointer()
106 {
107 if (m_queue)
108 dispatch_release(m_queue);
109 }
110
111 void swap(AVFScopedPointer &other)
112 {
113 std::swap(m_queue, other.m_queue);
114 }
115
116 operator dispatch_queue_t() const
117 {
118 // Quite handy operator to enable Obj-C messages: [ptr someMethod];
119 return m_queue;
120 }
121
122 dispatch_queue_t data() const
123 {
124 return m_queue;
125 }
126
127 void reset(dispatch_queue_t q = nullptr)
128 {
129 if (m_queue)
130 dispatch_release(m_queue);
131 m_queue = q;
132 }
133
134private:
135 dispatch_queue_t m_queue;
136
137 Q_DISABLE_COPY(AVFScopedPointer)
138};
139
141Q_MULTIMEDIA_EXPORT AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection);
142
143Q_MULTIMEDIA_EXPORT AVCaptureDeviceFormat *qt_convert_to_capture_device_format(
144 AVCaptureDevice *captureDevice, const QCameraFormat &format,
145 const std::function<bool(uint32_t)> &cvFormatValidator = nullptr);
146Q_MULTIMEDIA_EXPORT QList<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice,
147 FourCharCode preferredFormat);
148Q_MULTIMEDIA_EXPORT QSize qt_device_format_resolution(AVCaptureDeviceFormat *format);
149Q_MULTIMEDIA_EXPORT QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format);
150Q_MULTIMEDIA_EXPORT QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format);
151Q_MULTIMEDIA_EXPORT QList<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format);
152Q_MULTIMEDIA_EXPORT AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice, const QSize &res,
153 FourCharCode preferredFormat, bool stillImage = true);
154Q_MULTIMEDIA_EXPORT AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice,
155 FourCharCode preferredFormat,
156 Float64 fps);
157Q_MULTIMEDIA_EXPORT AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *format, Float64 fps);
158Q_MULTIMEDIA_EXPORT bool qt_format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps);
159
160Q_MULTIMEDIA_EXPORT bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2);
161Q_MULTIMEDIA_EXPORT bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps);
162
163Q_MULTIMEDIA_EXPORT AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection);
164Q_MULTIMEDIA_EXPORT void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection,
165 qreal minFPS, qreal maxFPS);
166
167Q_MULTIMEDIA_EXPORT QList<AudioValueRange> qt_supported_sample_rates_for_format(int codecId);
168Q_MULTIMEDIA_EXPORT QList<AudioValueRange> qt_supported_bit_rates_for_format(int codecId);
169Q_MULTIMEDIA_EXPORT std::optional<QList<UInt32>> qt_supported_channel_counts_for_format(int codecId);
170Q_MULTIMEDIA_EXPORT QList<UInt32> qt_supported_channel_layout_tags_for_format(int codecId, int noChannels);
171
172QT_END_NAMESPACE
173
174#endif // QAVFCAMERAUTILITY_P_H
\inmodule QtCore
Definition qsize.h:26
void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS)
Q_MULTIMEDIA_EXPORT bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2)
Q_MULTIMEDIA_EXPORT bool qt_format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps)
Q_MULTIMEDIA_EXPORT bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps)
std::pair< qreal, qreal > AVFPSRange
void operator()(NSObject *obj)