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
qavfcamerarotationtracker.mm
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
#
include
<
QtFFmpegMediaPluginImpl
/
private
/
qavfcamerarotationtracker_p
.
h
>
5
6
#
include
<
QtCore
/
qassert
.
h
>
7
8
#
include
<
AVFoundation
/
AVFoundation
.
h
>
9
10
#
include
<
cmath
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
QFFmpeg
{
15
16
AvfCameraRotationTracker
::
AvfCameraRotationTracker
(
AVCaptureDevice
*
avCaptureDevice
)
17
{
18
Q_ASSERT
(
avCaptureDevice
);
19
20
m_avCaptureDevice
=
AVFScopedPointer
{ [
avCaptureDevice
retain
] };
21
22
// Use RotationCoordinator if we can.
23
if
(@
available
(
macOS
14.0,
iOS
17.0, *)) {
24
m_avRotationCoordinator
=
AVFScopedPointer
{ [[
AVCaptureDeviceRotationCoordinator
alloc
]
25
initWithDevice
:
m_avCaptureDevice
26
previewLayer
:
nil
] };
27
}
28
}
29
30
AvfCameraRotationTracker
::
AvfCameraRotationTracker
(
AvfCameraRotationTracker
&&
other
)
noexcept
31
:
m_avCaptureDevice
{
std
::
exchange
(
other
.
m_avCaptureDevice
, {}) }
32
{
33
if
(@
available
(
macOS
14.0, *)) {
34
m_avRotationCoordinator
=
std
::
exchange
(
other
.
m_avRotationCoordinator
, {});
35
}
36
}
37
38
AvfCameraRotationTracker
::~
AvfCameraRotationTracker
()
39
{
40
clear
();
41
}
42
43
void
AvfCameraRotationTracker
::
swap
(
AvfCameraRotationTracker
&
other
)
44
{
45
std
::
swap
(
m_avCaptureDevice
,
other
.
m_avCaptureDevice
);
46
if
(@
available
(
macOS
14.0,
iOS
17.0, *)) {
47
std
::
swap
(
m_avRotationCoordinator
,
other
.
m_avRotationCoordinator
);
48
}
49
}
50
51
void
AvfCameraRotationTracker
::
clear
()
52
{
53
if
(
m_avCaptureDevice
)
54
m_avCaptureDevice
.
reset
();
55
56
if
(@
available
(
macOS
14.0, *)) {
57
if
(
m_avRotationCoordinator
) {
58
m_avRotationCoordinator
.
reset
();
59
}
60
}
61
}
62
63
int
AvfCameraRotationTracker
::
rotationDegrees
()
const
64
{
65
if
(
m_avCaptureDevice
==
nullptr
)
66
return
0;
67
68
if
(@
available
(
macOS
14.0, *)) {
69
// This code assumes that AVCaptureDeviceRotationCoordinator
70
// .videoRotationAngleForHorizonLevelCapture returns degrees that are divisible by 90.
71
// This has been the case during testing.
72
//
73
// TODO: Some rotations are not valid for preview on some devices (such as
74
// iPhones not being allowed to have an upside-down window). This usage of the
75
// rotation coordinator will still return it as a valid preview rotation, and
76
// might cause bugs on iPhone previews.
77
if
(
m_avRotationCoordinator
!=
nullptr
)
78
return
std
::
lround
(
79
m_avRotationCoordinator
.
data
().
videoRotationAngleForHorizonLevelCapture
);
80
}
81
82
return
0;
83
}
84
85
}
// namespace QFFmpeg end
86
87
QT_END_NAMESPACE
QFFmpeg::AvioWriteBufferType
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
Definition
qffmpegioutils_p.h:29
qtmultimedia
src
plugins
multimedia
ffmpeg
darwin
qavfcamerarotationtracker.mm
Generated on
for Qt by
1.16.1