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 | #ifndef QENCODINGINITIALIZER_P_H |
5 | #define QENCODINGINITIALIZER_P_H |
6 | |
7 | #include "qobject.h" |
8 | #include "private/qmediainputencoderinterface_p.h" |
9 | #include <unordered_set> |
10 | #include <vector> |
11 | |
12 | // |
13 | // W A R N I N G |
14 | // ------------- |
15 | // |
16 | // This file is not part of the Qt API. It exists purely as an |
17 | // implementation detail. This header file may change from version to |
18 | // version without notice, or even be removed. |
19 | // |
20 | // We mean it. |
21 | // |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QFFmpegAudioInput; |
26 | class QPlatformVideoSource; |
27 | class QPlatformAudioBufferInput; |
28 | class QPlatformAudioBufferInputBase; |
29 | class QMediaInputEncoderInterface; |
30 | |
31 | namespace QFFmpeg { |
32 | |
33 | class RecordingEngine; |
34 | |
35 | // Initializes RecordingEngine with audio and video sources, potentially lazily |
36 | // upon first frame arrival if video frame format is not pre-determined. |
37 | class EncodingInitializer : public QObject, private QMediaInputEncoderInterface |
38 | { |
39 | public: |
40 | EncodingInitializer(RecordingEngine &engine); |
41 | |
42 | ~EncodingInitializer() override; |
43 | |
44 | void start(const std::vector<QPlatformAudioBufferInputBase *> &audioSources, |
45 | const std::vector<QPlatformVideoSource *> &videoSources); |
46 | |
47 | private: |
48 | void addAudioBufferInput(QPlatformAudioBufferInput *input); |
49 | |
50 | void addPendingAudioBufferInput(QPlatformAudioBufferInput *input); |
51 | |
52 | void addVideoSource(QPlatformVideoSource *source); |
53 | |
54 | void addPendingVideoSource(QPlatformVideoSource *source); |
55 | |
56 | void addPendingSource(QObject *source); |
57 | |
58 | void tryStartRecordingEngine(); |
59 | |
60 | private: |
61 | void emitStreamInitializationError(QString error); |
62 | |
63 | template <typename F> |
64 | void erasePendingSource(QObject *source, F &&functionOrError, bool destroyed = false); |
65 | |
66 | bool canPushFrame() const override; |
67 | |
68 | private: |
69 | RecordingEngine &m_recordingEngine; |
70 | std::unordered_set<QObject *> m_pendingSources; |
71 | }; |
72 | |
73 | } // namespace QFFmpeg |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | #endif // QENCODINGINITIALIZER_P_H |
78 |