Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qffmpegrecordingengineutils_p.h
Go to the documentation of this file.
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 <QtMultimedia/qvideoframe.h>
20#include <optional>
21#include <queue>
22
23QT_BEGIN_NAMESPACE
24
25class QMediaInputEncoderInterface;
26class QPlatformVideoSource;
27
28namespace QFFmpeg {
29
30constexpr qint64 VideoFrameTimeBase = 1000000; // us in sec
31
32// Fallback frame rate used when no real rate is known (e.g. variable-rate sources
33// with untimed frames), chosen to keep pts advancing and satisfy players/muxers
34// that require a valid duration.
35constexpr int DefaultVideoFrameRate = 30;
36
37class EncoderThread;
38
39struct FrameInfo
40{
42 bool adjustTimeBase{ false };
44};
45
46template <typename T>
47T dequeueIfPossible(std::queue<T> &queue)
48{
49 if (queue.empty())
50 return T{};
51
52 auto result = std::move(queue.front());
53 queue.pop();
54 return result;
55}
56
57void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *);
58
59void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder);
60
61template <typename Encoder, typename Source>
62void connectEncoderToSource(Encoder *encoder, Source *source)
63{
64 Q_ASSERT(!encoder->source());
65 encoder->setSource(source);
66
67 if constexpr (std::is_same_v<Source, QPlatformVideoSource>) {
68 QObject::connect(source, &Source::newVideoFrame, encoder, &Encoder::addFrame,
69 Qt::DirectConnection);
70
71 QObject::connect(source, &Source::activeChanged, encoder, [=]() {
72 if (!source->isActive())
73 encoder->setEndOfSourceStream();
74 });
75 } else {
76 QObject::connect(source, &Source::newAudioBuffer, encoder, &Encoder::addBuffer,
77 Qt::DirectConnection);
78 }
79
80 // TODO:
81 // QObject::connect(source, &Source::disconnectedFromSession, encoder, [=]() {
82 // encoder->setSourceEndOfStream();
83 // });
84
85 setEncoderUpdateConnection(source, encoder);
86 setEncoderInterface(source, encoder);
87}
88
90
91} // namespace QFFmpeg
92
93QT_END_NAMESPACE
94
95#endif // QFFMPEGRECORDINGENGINEUTILS_P_H
The QAudioFormat class stores audio stream parameter information.
bool init() override
Called on this thread when thread starts.
AudioEncoder(RecordingEngine &recordingEngine, const QAudioFormat &sourceFormat, const QMediaEncoderSettings &settings)
void addBuffer(const QAudioBuffer &buffer)
void cleanup() override
Called on this thread before thread exits.
bool hasData() const override
Must return true when data is available for processing.
void processOne() override
Process one work item.
bool checkIfCanPushFrame() const override
Q_STATIC_LOGGING_CATEGORY(qLCAndroidVideoDevices, "qt.multimedia.ffmpeg.android.videoDevices")
QT_MANGLE_NAMESPACE(QMacScreenCaptureStreamDelegate) QMacScreenCaptureStreamDelegate
void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *)
void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder)
T dequeueIfPossible(std::queue< T > &queue)
void disconnectEncoderFromSource(EncoderThread *encoder)
constexpr int DefaultVideoFrameRate
void connectEncoderToSource(Encoder *encoder, Source *source)
constexpr qint64 VideoFrameTimeBase
static constexpr bool audioEncoderExtendedTracing
Combined button and popup list for selecting options.
std::optional< qint64 > overriddenPts