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