1 | // Copyright (C) 2022 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 | #ifndef QFFMPEGRESAMPLER_P_H |
4 | #define QFFMPEGRESAMPLER_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists purely as an |
11 | // implementation detail. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include "qaudiobuffer.h" |
18 | #include "qffmpeg_p.h" |
19 | #include "private/qplatformaudioresampler_p.h" |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | namespace QFFmpeg |
24 | { |
25 | class Codec; |
26 | } |
27 | |
28 | class QFFmpegResampler : public QPlatformAudioResampler |
29 | { |
30 | public: |
31 | QFFmpegResampler(const QAudioFormat &inputFormat, const QAudioFormat &outputFormat); |
32 | QFFmpegResampler(const QFFmpeg::Codec *codec, const QAudioFormat &outputFormat, |
33 | qint64 startTime = 0); |
34 | |
35 | ~QFFmpegResampler() override; |
36 | |
37 | QAudioBuffer resample(const char* data, size_t size) override; |
38 | |
39 | QAudioBuffer resample(const AVFrame *frame); |
40 | |
41 | qint64 samplesProcessed() const { return m_samplesProcessed; } |
42 | void setSampleCompensation(qint32 delta, quint32 distance); |
43 | qint32 activeSampleCompensationDelta() const; |
44 | |
45 | private: |
46 | int adjustMaxOutSamples(int inputSamplesCount); |
47 | |
48 | QAudioBuffer resample(const uint8_t **inputData, int inputSamplesCount); |
49 | |
50 | private: |
51 | QAudioFormat m_inputFormat; |
52 | QAudioFormat m_outputFormat; |
53 | qint64 m_startTime = 0; |
54 | QFFmpeg::SwrContextUPtr m_resampler; |
55 | qint64 m_samplesProcessed = 0; |
56 | qint64 m_endCompensationSample = std::numeric_limits<qint64>::min(); |
57 | qint32 m_sampleCompensationDelta = 0; |
58 | }; |
59 | |
60 | QT_END_NAMESPACE |
61 | |
62 | #endif |
63 | |