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 QFFMPEGRECORDINGENGINEUTILS_P_H
5#define QFFMPEGRECORDINGENGINEUTILS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qobject.h"
19#include <queue>
20
21QT_BEGIN_NAMESPACE
22
23class QMediaInputEncoderInterface;
24class QPlatformVideoSource;
25
26namespace QFFmpeg {
27
28constexpr qint64 VideoFrameTimeBase = 1000000; // us in sec
29
30class EncoderThread;
31
32template <typename T>
33T dequeueIfPossible(std::queue<T> &queue)
34{
35 if (queue.empty())
36 return T{};
37
38 auto result = std::move(queue.front());
39 queue.pop();
40 return result;
41}
42
43void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *);
44
45void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder);
46
47template <typename Encoder, typename Source>
48void connectEncoderToSource(Encoder *encoder, Source *source)
49{
50 Q_ASSERT(!encoder->source());
51 encoder->setSource(source);
52
53 if constexpr (std::is_same_v<Source, QPlatformVideoSource>) {
54 QObject::connect(source, &Source::newVideoFrame, encoder, &Encoder::addFrame,
55 Qt::DirectConnection);
56
57 QObject::connect(source, &Source::activeChanged, encoder, [=]() {
58 if (!source->isActive())
59 encoder->setEndOfSourceStream();
60 });
61 } else {
62 QObject::connect(source, &Source::newAudioBuffer, encoder, &Encoder::addBuffer,
63 Qt::DirectConnection);
64 }
65
66 // TODO:
67 // QObject::connect(source, &Source::disconnectedFromSession, encoder, [=]() {
68 // encoder->setSourceEndOfStream();
69 // });
70
71 setEncoderUpdateConnection(source, encoder);
72 setEncoderInterface(source, encoder);
73}
74
75void disconnectEncoderFromSource(EncoderThread *encoder);
76
77} // namespace QFFmpeg
78
79QT_END_NAMESPACE
80
81#endif // QFFMPEGRECORDINGENGINEUTILS_P_H
82

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegrecordingengineutils_p.h