blob: 3601356cdab3a71f26ff42b939878815296f6c7b (
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
|
// 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
#ifndef QFFMPEGAUDIOENCODER_P_H
#define QFFMPEGAUDIOENCODER_P_H
#include "qffmpeg_p.h"
#include "qffmpegencoderthread_p.h"
#include "private/qplatformmediarecorder_p.h"
#include <qaudiobuffer.h>
#include <queue>
#include <chrono>
QT_BEGIN_NAMESPACE
class QMediaEncoderSettings;
namespace QFFmpeg {
class AudioEncoder : public EncoderThread
{
public:
AudioEncoder(RecordingEngine &recordingEngine, const QAudioFormat &sourceFormat,
const QMediaEncoderSettings &settings);
void addBuffer(const QAudioBuffer &buffer);
protected:
bool checkIfCanPushFrame() const override;
private:
void open();
QAudioBuffer takeBuffer();
void retrievePackets();
void updateResampler();
void init() override;
void cleanup() override;
bool hasData() const override;
void processOne() override;
private:
std::queue<QAudioBuffer> m_audioBufferQueue;
// Arbitrarily chosen to limit audio queue duration
const std::chrono::microseconds m_maxQueueDuration = std::chrono::seconds(5);
std::chrono::microseconds m_queueDuration{ 0 };
AVStream *m_stream = nullptr;
AVCodecContextUPtr m_codecContext;
QAudioFormat m_format;
SwrContextUPtr m_resampler;
qint64 m_samplesWritten = 0;
const AVCodec *m_avCodec = nullptr;
QMediaEncoderSettings m_settings;
};
} // namespace QFFmpeg
QT_END_NAMESPACE
#endif
|