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
qffmpegplaybackengineobject_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 QFFMPEGPLAYBACKENGINEOBJECT_P_H
4#define QFFMPEGPLAYBACKENGINEOBJECT_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 <QtCore/qatomic.h>
18#include <QtCore/qthread.h>
19#include <QtCore/qcoreevent.h>
20#include <QtCore/qcoreapplication.h>
21#include <QtMultimedia/qmediaplayer.h>
22#include <QtFFmpegMediaPluginImpl/private/qffmpegplaybackenginedefs_p.h>
23#include <QtFFmpegMediaPluginImpl/private/qffmpegplaybackutils_p.h>
24
25#include <chrono>
26#include <optional>
27
28QT_BEGIN_NAMESPACE
29
30class QChronoTimer;
31
32namespace QFFmpeg {
33
35{
37
38 static constexpr QEvent::Type FuncEventType = QEvent::User;
39 class FuncEvent : public QEvent
40 {
41 public:
42 FuncEvent() : QEvent(FuncEventType) { }
43 virtual void invoke() = 0;
44 };
45
46 template <typename F>
47 class FuncEventImpl final : public FuncEvent
48 {
49 public:
50 explicit FuncEventImpl(F &&f) : m_func(std::forward<F>(f)) { }
51 void invoke() override { m_func(); }
52
53 private:
54 std::decay_t<F> m_func;
55 };
56
57public:
58 using TimePoint = std::chrono::steady_clock::time_point;
59 using TimePointOpt = std::optional<TimePoint>;
60
61 explicit PlaybackEngineObject(const PlaybackEngineObjectID &id);
62
64
65 bool isPaused() const;
66
67 bool isAtEnd() const;
68
69 void kill();
70
71 void setPaused(bool isPaused);
72
73 quint64 objectID() const { return m_id.objectID; }
74
77
78 void error(QMediaPlayer::Error, const QString &errorString);
79
80protected:
81 bool event(QEvent *e) override;
82
83 bool checkSessionID(quint64 sessionID) const { return sessionID == m_id.sessionID; }
84
85 bool checkID(const PlaybackEngineObjectID &id) const
86 {
87 return checkSessionID(id.sessionID) && id.objectID == objectID();
88 }
89
91 {
92 Q_ASSERT(thread()->isCurrentThread());
93 return m_id;
94 }
95
96 template <typename F>
98 {
99 Q_ASSERT(!thread()->isCurrentThread());
100 // Note, that the event loop takes ownership of the event
101 QCoreApplication::postEvent(this, new FuncEventImpl<F>(std::forward<F>(f)),
102 Qt::HighEventPriority);
103 }
104
105 QChronoTimer &timer();
106
107 void scheduleNextStep();
108
109 virtual void onPauseChanged();
110
111 virtual bool canDoNextStep() const;
112
113 virtual TimePoint nextTimePoint() const;
114
115 void setAtEnd(bool isAtEnd);
116
117 virtual void doNextStep() { }
118
119private slots:
120 void onTimeout();
121
122private:
123 enum class StepType : uint8_t { None, Timeout, Immediate };
124
125 void doNextStep(StepType type);
126
127 bool isValid() const { return m_invalidateCounter.load(std::memory_order_relaxed) == 0; }
128
129 std::unique_ptr<QChronoTimer> m_timer;
130
131 QAtomicInteger<bool> m_paused = true;
132 QAtomicInteger<bool> m_atEnd = false;
133 std::atomic_int m_invalidateCounter = 0;
134 PlaybackEngineObjectID m_id;
135
136 TimePointOpt m_nextTimePoint;
137 TimePointOpt m_timePoint;
138 StepType m_stepType = StepType::None;
139};
140} // namespace QFFmpeg
141
142QT_END_NAMESPACE
143
144#endif // QFFMPEGPLAYBACKENGINEOBJECT_P_H
bool checkID(const PlaybackEngineObjectID &id) const
bool checkSessionID(quint64 sessionID) const
void error(QMediaPlayer::Error, const QString &errorString)
const PlaybackEngineObjectID & id() const
PlaybackEngineObject(const PlaybackEngineObjectID &id)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
std::chrono::steady_clock::time_point TimePoint
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
Combined button and popup list for selecting options.