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
qffmpegencoderthread_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#ifndef QFFMPEGENCODERTHREAD_P_H
4#define QFFMPEGENCODERTHREAD_P_H
5
7#include "qpointer.h"
8#include "qsemaphore.h"
9
10#include "private/qmediainputencoderinterface_p.h"
11
13
14namespace QFFmpeg {
15
16class RecordingEngine;
17
19{
21public:
23
24 void setPaused(bool paused);
25
26 void setAutoStop(bool autoStop);
27
28 void setSource(QObject *source) { m_source = source; }
29
30 QObject *source() const { return m_source; }
31
32 bool canPushFrame() const override { return m_canPushFrame.load(std::memory_order_relaxed); }
33
35
37
38 void startEncoding(bool noError);
39
40 bool isInitialized() const { return m_initialized; }
41
42protected:
43 bool init() override;
44
46
47 virtual bool checkIfCanPushFrame() const = 0;
48
50
52 {
53 return QScopeGuard([this, locker = ConsumerThread::lockLoopData()]() mutable {
54 const bool autoStopActivated = m_endOfSourceStream && m_autoStop;
55 const bool canPush = !autoStopActivated && !m_paused && checkIfCanPushFrame();
56 locker.unlock();
57 if (m_canPushFrame.exchange(canPush, std::memory_order_relaxed) != canPush)
58 emit canPushFrameChanged();
59 });
60 }
61
66
67protected:
68 bool m_paused = false;
69 bool m_endOfSourceStream = false;
70 bool m_autoStop = false;
71 bool m_initialized = false;
72 bool m_encodingStarted = false;
73 std::atomic_bool m_canPushFrame = false;
77};
78
79} // namespace QFFmpeg
80
82
83#endif
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
FFmpeg thread that is used to implement a consumer pattern.
void dataReady()
Wake thread from sleep and process data until hasData() returns false.
void setSource(QObject *source)
void setAutoStop(bool autoStop)
void startEncoding(bool noError)
bool init() override
Called on this thread when thread starts.
bool canPushFrame() const override
RecordingEngine & m_recordingEngine
virtual bool checkIfCanPushFrame() const =0
const AVCodec * findAVEncoder(AVCodecID codecId, const std::function< AVScore(const AVCodec *)> &scoresGetter)
const AVChannelLayout * getCodecChannelLayouts(const AVCodec *codec)
Definition qffmpeg_p.h:147
const int * getCodecSampleRates(const AVCodec *codec)
Definition qffmpeg_p.h:136
AVSampleFormat adjustSampleFormat(const AVSampleFormat *supportedFormats, AVSampleFormat requested)
bool findAndOpenAVEncoder(AVCodecID codecId, const std::function< AVScore(const AVCodec *)> &scoresGetter, const std::function< bool(const AVCodec *)> &codecOpener)
const AVSampleFormat * getCodecSampleFormats(const AVCodec *codec)
Definition qffmpeg_p.h:127
Q_STATIC_LOGGING_CATEGORY(qLcEncodingFormatContext, "qt.multimedia.ffmpeg.encodingformatcontext")
bool operator!=(const AVAudioFormat &lhs, const AVAudioFormat &rhs)
int adjustSampleRate(const int *supportedRates, int requested)
void applyExperimentalCodecOptions(const AVCodec *codec, AVDictionary **opts)
Definition qffmpeg.cpp:50
#define QT_FFMPEG_HAS_AV_CHANNEL_LAYOUT
constexpr AVScore DefaultAVScore
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
AVAudioFormat(const QAudioFormat &audioFormat)