blob: 417219a48eec4ab9f8feec951809c4c826421027 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qffmpegavaudioformat_p.h"
#include "qaudioformat.h"
#include "qffmpegmediaformatinfo_p.h"
extern "C" {
#include <libavutil/opt.h>
}
QT_BEGIN_NAMESPACE
namespace QFFmpeg {
AVAudioFormat::AVAudioFormat(const AVCodecContext *context)
: sampleFormat(context->sample_fmt), sampleRate(context->sample_rate)
{
#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
if (context->channel_layout) {
channelLayoutMask = context->channel_layout;
} else {
const auto channelConfig =
QAudioFormat::defaultChannelConfigForChannelCount(context->channels);
channelLayoutMask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
}
#else
channelLayout = context->ch_layout;
#endif
}
AVAudioFormat::AVAudioFormat(const AVCodecParameters *codecPar)
: sampleFormat(AVSampleFormat(codecPar->format)), sampleRate(codecPar->sample_rate)
{
#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
if (codecPar->channel_layout) {
channelLayoutMask = codecPar->channel_layout;
} else {
const auto channelConfig =
QAudioFormat::defaultChannelConfigForChannelCount(codecPar->channels);
channelLayoutMask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
}
#else
channelLayout = codecPar->ch_layout;
#endif
}
AVAudioFormat::AVAudioFormat(const QAudioFormat &audioFormat)
: sampleFormat(QFFmpegMediaFormatInfo::avSampleFormat(audioFormat.sampleFormat())),
sampleRate(audioFormat.sampleRate())
{
const auto channelConfig = audioFormat.channelConfig() == QAudioFormat::ChannelConfigUnknown
? QAudioFormat::defaultChannelConfigForChannelCount(audioFormat.channelCount())
: audioFormat.channelConfig();
const auto mask = QFFmpegMediaFormatInfo::avChannelLayout(channelConfig);
#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
channelLayoutMask = mask;
#else
av_channel_layout_from_mask(&channelLayout, mask);
#endif
}
bool operator==(const AVAudioFormat &lhs, const AVAudioFormat &rhs)
{
return lhs.sampleFormat == rhs.sampleFormat && lhs.sampleRate == rhs.sampleRate &&
#if QT_FFMPEG_OLD_CHANNEL_LAYOUT
lhs.channelLayoutMask == rhs.channelLayoutMask
#else
lhs.channelLayout == rhs.channelLayout
#endif
;
}
} // namespace QFFmpeg
QT_END_NAMESPACE
|