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

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegplaybackengineobject_p.h