Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qffmpegaudioencoderutils.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 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
"qffmpegaudioencoderutils_p.h"
5
#
include
"qalgorithms.h"
6
7
QT_BEGIN_NAMESPACE
8
9
namespace
QFFmpeg
{
10
11
AVSampleFormat
adjustSampleFormat
(QSpan<
const
AVSampleFormat> supportedFormats, AVSampleFormat requested)
12
{
13
auto
calcScore = [requested](AVSampleFormat format) {
14
if
(format == requested)
15
return
BestAVScore;
16
if
(format == av_get_planar_sample_fmt(requested))
17
return
BestAVScore - 1;
18
19
const
int
bps = av_get_bytes_per_sample(format);
20
const
int
bpsRequested = av_get_bytes_per_sample(requested);
21
// choose the closest one with higher bps
22
if
(bps >= bpsRequested)
23
return
DefaultAVScore - (bps - bpsRequested);
24
25
// choose the closest one with lower bps, considering a priority penalty
26
return
DefaultAVScore - (bpsRequested - bps) - 1000000;
27
};
28
29
const
auto
result = findBestAVValue(supportedFormats, calcScore);
30
return
result.value_or(requested);
31
}
32
33
int
adjustSampleRate
(QSpan<
const
int
> supportedRates,
int
requested)
34
{
35
auto
calcScore = [requested](
int
rate) {
36
if
(requested == rate)
37
return
BestAVScore;
38
39
// choose the closest one with higher rate
40
if
(rate >= requested)
41
return
DefaultAVScore - (rate - requested);
42
43
// choose the closest one with lower rate, considering a priority penalty
44
return
DefaultAVScore - (requested - rate) - 1000000;
45
};
46
47
const
auto
result = findBestAVValue(supportedRates, calcScore);
48
return
result.value_or(requested);
49
}
50
51
static
AVScore
calculateScoreByChannelsCount
(
int
supportedChannelsNumber,
52
int
requestedChannelsNumber)
53
{
54
// choose the closest one with higher channels number
55
if
(supportedChannelsNumber >= requestedChannelsNumber)
56
return
AVScore{ requestedChannelsNumber - supportedChannelsNumber };
57
58
// choose the closest one with lower channels number, considering a priority penalty
59
return
AVScore{ supportedChannelsNumber - requestedChannelsNumber - 10000 };
60
}
61
62
static
AVScore
calculateScoreByChannelsMask
(
int
supportedChannelsNumber, uint64_t supportedMask,
63
int
requestedChannelsNumber, uint64_t requestedMask)
64
{
65
if
((supportedMask & requestedMask) == requestedMask)
66
return
BestAVScore - qPopulationCount(supportedMask & ~requestedMask);
67
68
return
calculateScoreByChannelsCount(supportedChannelsNumber, requestedChannelsNumber);
69
}
70
71
ChannelLayoutT
adjustChannelLayout
(QSpan<
const
ChannelLayoutT> supportedLayouts,
72
const
ChannelLayoutT &requested)
73
{
74
#
if
QT_FFMPEG_HAS_AV_CHANNEL_LAYOUT
75
auto
calcScore = [&requested](
const
ChannelLayoutT &layout) {
76
if
(layout == requested)
77
return
BestAVScore;
78
79
// The only realistic case for now:
80
// layout.order == requested.order == AV_CHANNEL_ORDER_NATIVE
81
// Let's consider other orders to make safe code
82
83
if
(layout.order == AV_CHANNEL_ORDER_CUSTOM || requested.order == AV_CHANNEL_ORDER_CUSTOM)
84
return
calculateScoreByChannelsCount(layout.nb_channels, requested.nb_channels) - 1000;
85
86
const
auto
offset = layout.order == requested.order ? 1 : 100;
87
88
return
calculateScoreByChannelsMask(layout.nb_channels, layout.u.mask,
89
requested.nb_channels, requested.u.mask)
90
- offset;
91
};
92
93
const
auto
result = findBestAVValue(supportedLayouts, calcScore);
94
return
result.value_or(requested);
95
#
else
96
auto
calcScore = [requested](ChannelLayoutT mask) {
97
return
calculateScoreByChannelsMask(qPopulationCount(mask), mask,
98
qPopulationCount(requested), requested);
99
};
100
101
const
auto
result = findBestAVValue(supportedLayouts, calcScore);
102
return
result.value_or(requested);
103
#
endif
104
}
105
106
}
// namespace QFFmpeg
107
108
QT_END_NAMESPACE
QFFmpeg
Definition
qandroidcacertificates.cpp:26
QFFmpeg::adjustSampleFormat
AVSampleFormat adjustSampleFormat(QSpan< const AVSampleFormat > supportedFormats, AVSampleFormat requested)
Definition
qffmpegaudioencoderutils.cpp:11
QFFmpeg::calculateScoreByChannelsCount
static AVScore calculateScoreByChannelsCount(int supportedChannelsNumber, int requestedChannelsNumber)
Definition
qffmpegaudioencoderutils.cpp:51
QFFmpeg::calculateScoreByChannelsMask
static AVScore calculateScoreByChannelsMask(int supportedChannelsNumber, uint64_t supportedMask, int requestedChannelsNumber, uint64_t requestedMask)
Definition
qffmpegaudioencoderutils.cpp:62
QFFmpeg::adjustChannelLayout
ChannelLayoutT adjustChannelLayout(QSpan< const ChannelLayoutT > supportedLayouts, const ChannelLayoutT &requested)
Definition
qffmpegaudioencoderutils.cpp:71
QFFmpeg::adjustSampleRate
int adjustSampleRate(QSpan< const int > supportedRates, int requested)
Definition
qffmpegaudioencoderutils.cpp:33
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
plugins
multimedia
ffmpeg
recordingengine
qffmpegaudioencoderutils.cpp
Generated on
for Qt by
1.18.0