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
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtFFmpegMediaPluginImpl/private/qffmpegthread_p.h>
18
19#include <QtCore/qfuture.h>
20#include <QtCore/qpointer.h>
21#include <QtCore/qpromise.h>
22#include <QtMultimedia/private/qmediainputencoderinterface_p.h>
23
24#include <atomic>
25
26QT_BEGIN_NAMESPACE
27
28namespace QFFmpeg {
29
30class RecordingEngine;
31
33{
35public:
37
38 void setPaused(bool paused);
39
40 void setAutoStop(bool autoStop);
41
42 void setSource(QObject *source) { m_source = source; }
43
44 QObject *source() const { return m_source; }
45
46 bool canPushFrame() const override { return m_canPushFrame.load(std::memory_order_relaxed); }
47
49
50 bool isEndOfSourceStream() const { return m_endOfSourceStream.load(std::memory_order_acquire); }
51
52 bool isInitialized() const { return m_initialized; }
53
54 QFuture<bool> resolvedFuture() const { return m_resolvedPromise.future(); }
55
56protected:
57 bool init() override;
58
60
61 virtual bool checkIfCanPushFrame() const = 0;
62
63 void resetEndOfSourceStream() { m_endOfSourceStream.store(false, std::memory_order_release); }
64
66 {
67 return QScopeGuard([this, locker = ConsumerThread::lockLoopData()]() mutable {
68 const bool autoStopActivated = m_endOfSourceStream && m_autoStop;
69 const bool canPush = !autoStopActivated && !m_paused && checkIfCanPushFrame();
70 locker.unlock();
71 if (m_canPushFrame.exchange(canPush, std::memory_order_relaxed) != canPush)
72 Q_EMIT canPushFrameChanged();
73 });
74 }
75
76 void markResolved(bool succeeded);
77
78 virtual void handlePausedChanged(bool /*paused*/) { }
79
83
84protected:
85 bool m_paused = false;
86 std::atomic_bool m_endOfSourceStream = false;
87 bool m_autoStop = false;
88 bool m_initialized = false;
89 bool m_encodingStarted = false;
90 std::atomic_bool m_canPushFrame = false;
94};
95
96} // namespace QFFmpeg
97
98QT_END_NAMESPACE
99
100#endif
void markResolved(bool succeeded)
virtual void handlePausedChanged(bool)
std::atomic_bool m_endOfSourceStream
void setSource(QObject *source)
void setAutoStop(bool autoStop)
QFuture< bool > resolvedFuture() const
bool init() override
Called on this thread when thread starts.
bool canPushFrame() const override
RecordingEngine & m_recordingEngine
virtual bool checkIfCanPushFrame() const =0
Combined button and popup list for selecting options.