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 <QtFFmpegMediaPluginImpl/private/qffmpegplaybackenginedefs_p.h> |
18 | #include "qthread.h" |
19 | #include "qatomic.h" |
20 | #include <chrono> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QTimer; |
25 | |
26 | namespace QFFmpeg { |
27 | |
28 | class PlaybackEngineObject : public QObject |
29 | { |
30 | Q_OBJECT |
31 | public: |
32 | using TimePoint = std::chrono::steady_clock::time_point; |
33 | using TimePointOpt = std::optional<TimePoint>; |
34 | using Id = quint64; |
35 | |
36 | PlaybackEngineObject(); |
37 | |
38 | ~PlaybackEngineObject() override; |
39 | |
40 | bool isPaused() const; |
41 | |
42 | bool isAtEnd() const; |
43 | |
44 | void kill(); |
45 | |
46 | void setPaused(bool isPaused); |
47 | |
48 | Id id() const; |
49 | |
50 | signals: |
51 | void atEnd(); |
52 | |
53 | void error(int code, const QString &errorString); |
54 | |
55 | protected: |
56 | QTimer &timer(); |
57 | |
58 | void scheduleNextStep(bool allowDoImmediatelly = true); |
59 | |
60 | virtual void onPauseChanged(); |
61 | |
62 | virtual bool canDoNextStep() const; |
63 | |
64 | virtual std::chrono::milliseconds timerInterval() const; |
65 | |
66 | void setAtEnd(bool isAtEnd); |
67 | |
68 | virtual void doNextStep() { } |
69 | |
70 | private slots: |
71 | void onTimeout(); |
72 | |
73 | private: |
74 | std::unique_ptr<QTimer> m_timer; |
75 | |
76 | QAtomicInteger<bool> m_paused = true; |
77 | QAtomicInteger<bool> m_atEnd = false; |
78 | QAtomicInteger<bool> m_deleting = false; |
79 | const Id m_id; |
80 | }; |
81 | } // namespace QFFmpeg |
82 | |
83 | QT_END_NAMESPACE |
84 | |
85 | #endif // QFFMPEGPLAYBACKENGINEOBJECT_P_H |
86 | |