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
32class EncoderThread;
33
34struct FrameInfo
35{
37 bool adjustTimeBase{ false };
39};
40
41template <typename T>
42T dequeueIfPossible(std::queue<T> &queue)
43{
44 if (queue.empty())
45 return T{};
46
47 auto result = std::move(queue.front());
48 queue.pop();
49 return result;
50}
51
52void setEncoderInterface(QObject *source, QMediaInputEncoderInterface *);
53
54void setEncoderUpdateConnection(QObject *source, EncoderThread *encoder);
55
56template <typename Encoder, typename Source>
57void connectEncoderToSource(Encoder *encoder, Source *source)
58{
59 Q_ASSERT(!encoder->source());
60 encoder->setSource(source);
61
62 if constexpr (std::is_same_v<Source, QPlatformVideoSource>) {
63 QObject::connect(source, &Source::newVideoFrame, encoder, &Encoder::addFrame,
64 Qt::DirectConnection);
65
66 QObject::connect(source, &Source::activeChanged, encoder, [=]() {
67 if (!source->isActive())
68 encoder->setEndOfSourceStream();
69 });
70 } else {
71 QObject::connect(source, &Source::newAudioBuffer, encoder, &Encoder::addBuffer,
72 Qt::DirectConnection);
73 }
74
75 // TODO:
76 // QObject::connect(source, &Source::disconnectedFromSession, encoder, [=]() {
77 // encoder->setSourceEndOfStream();
78 // });
79
80 setEncoderUpdateConnection(source, encoder);
81 setEncoderInterface(source, encoder);
82}
83
85
86} // namespace QFFmpeg
87
88QT_END_NAMESPACE
89
90#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)
void connectEncoderToSource(Encoder *encoder, Source *source)
bool findAndOpenAVEncoder(AVCodecID codecId, const std::function< AVScore(const Codec &)> &scoresGetter, const std::function< bool(const Codec &)> &codecOpener)
constexpr qint64 VideoFrameTimeBase
static constexpr bool audioEncoderExtendedTracing
Combined button and popup list for selecting options.
std::optional< qint64 > overriddenPts