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
qffmpegrenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QFFMPEGRENDERER_P_H
4#define QFFMPEGRENDERER_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/qffmpegplaybackengineobject_p.h>
18#include <QtFFmpegMediaPluginImpl/private/qffmpegtimecontroller_p.h>
19#include <QtFFmpegMediaPluginImpl/private/qffmpegframe_p.h>
20
21#include <QtCore/qpointer.h>
22#include <QtCore/qqueue.h>
23
24#include <chrono>
25
26QT_BEGIN_NAMESPACE
27
28namespace QFFmpeg {
29
31{
33public:
35
36 Renderer(const PlaybackEngineObjectID &id, const TimeController &tc);
37
39
41
42 void setPlaybackRate(float rate);
43
44 void doForceStep();
45
46 bool isStepForced() const;
47
48 void setTimeController(const TimeController &tc);
49
50 void seek(quint64 sessionId, const TimeController &tc, const LoopOffset &offset);
51
52public slots:
53
55
56 void render(Frame);
57
60
61 void synchronized(PlaybackEngineObjectID id, TimePoint tp, TrackPosition pos);
62
64
65 void loopChanged(PlaybackEngineObjectID id, TrackPosition offset, int index);
66
67protected:
68 bool setForceStepDone();
69
71
72 bool canDoNextStep() const override;
73
74 TimePoint nextTimePoint() const override;
75
76 virtual void seekInternal() { }
77
78 virtual void onPlaybackRateChanged() { }
79
81 {
82 bool done = true;
83 std::chrono::microseconds recheckInterval = std::chrono::microseconds(0);
84 };
85
86 virtual RenderingResult renderInternal(Frame frame) = 0;
87
88 float playbackRate() const;
89
90 std::chrono::microseconds frameDelay(const Frame &frame,
91 TimePoint timePoint = SteadyClock::now()) const;
92
93 void changeRendererTime(std::chrono::microseconds offset);
94
95 template<typename Output, typename ChangeHandler>
96 void setOutputInternal(QPointer<Output> &actual, Output *desired, ChangeHandler &&changeHandler)
97 {
98 const auto connectionType =
99 thread()->isCurrentThread() ? Qt::AutoConnection : Qt::BlockingQueuedConnection;
100 auto doer = [desired, changeHandler, &actual]() {
101 const auto prev = std::exchange(actual, desired);
102 if (prev != desired)
103 changeHandler(prev);
104 };
105 QMetaObject::invokeMethod(this, doer, connectionType);
106 }
107
108private:
109 void doNextStep() override;
110
111private:
112 struct SessionContext
113 {
114 TimeController timeController;
115 int loopIndex = 0;
116 TrackPosition lastFrameEnd = timeController.currentPosition();
117 QAtomicInteger<qint64> lastPosition = lastFrameEnd.get();
118 QAtomicInteger<qint64> seekPos = lastFrameEnd.get();
119 QQueue<Frame> frames = {};
120 std::optional<TimePoint> explicitNextFrameTime = {};
121 };
122
123 SessionContext m_sessionCtx;
124 QAtomicInteger<bool> m_isStepForced = false;
125};
126
127} // namespace QFFmpeg
128
129QT_END_NAMESPACE
130
131#endif // QFFMPEGRENDERER_P_H
void onPauseChanged() override
std::chrono::microseconds frameDelay(const Frame &frame, TimePoint timePoint=SteadyClock::now()) const
Renderer(const PlaybackEngineObjectID &id, const TimeController &tc)
void doNextStep() override
void loopChanged(PlaybackEngineObjectID id, TrackPosition offset, int index)
virtual RenderingResult renderInternal(Frame frame)=0
bool canDoNextStep() const override
void setTimeController(const TimeController &tc)
void setPlaybackRate(float rate)
void seek(quint64 sessionId, const TimeController &tc, const LoopOffset &offset)
float playbackRate() const
TimePoint nextTimePoint() const override
virtual void seekInternal()
TrackPosition lastPosition() const
virtual void onPlaybackRateChanged()
void setOutputInternal(QPointer< Output > &actual, Output *desired, ChangeHandler &&changeHandler)
void synchronized(PlaybackEngineObjectID id, TimePoint tp, TrackPosition pos)
void changeRendererTime(std::chrono::microseconds offset)
bool isStepForced() const
TrackPosition seekPosition() const
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
std::chrono::microseconds recheckInterval