File indexing completed on 2024-12-22 04:40:20
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef PLAYER_H 0009 #define PLAYER_H 0010 0011 #include "videowidget.h" 0012 0013 #include "videoplayer/backend/ffplayer.h" 0014 #include "videoplayer/subtitletextoverlay.h" 0015 0016 #include <QPainterPath> 0017 #include <QString> 0018 #include <QStringList> 0019 #include <QMap> 0020 #include <QWidget> 0021 0022 namespace SubtitleComposer { 0023 0024 class VideoPlayer : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 enum State { 0030 Initialized, 0031 Opening, 0032 Stopped, 0033 Playing, 0034 Paused 0035 }; 0036 0037 static VideoPlayer * instance(); 0038 0039 bool init(QWidget *videoContainer); 0040 0041 inline State state() const { return m_state; } 0042 inline VideoWidget * videoWidget() { return m_videoWidget; } 0043 inline const QString & filePath() const { return m_filePath; } 0044 0045 inline bool isPlaying() const { return m_state == Playing; } 0046 inline bool isPaused() const { return m_state == Paused; } 0047 inline bool isStopped() const { return m_state <= Stopped; } 0048 inline double position() const { return m_player->position(); } 0049 inline double duration() const { return m_duration; } 0050 inline double fps() const { return m_fps; } 0051 inline double playSpeed() const { return m_playSpeed; } 0052 inline double volume() const { return m_volume; } 0053 inline bool isMuted() const { return m_muted; } 0054 inline int selectedAudioStream() const { return m_activeAudioStream; } 0055 0056 void playSpeed(double newRate); 0057 0058 inline const QStringList & textStreams() const { return m_textStreams; } 0059 inline const QStringList & audioStreams() const { return m_audioStreams; } 0060 0061 inline SubtitleTextOverlay & subtitleOverlay() { return m_subOverlay; } 0062 0063 bool playOnLoad(); 0064 0065 public slots: 0066 bool openFile(const QString &filePath); 0067 void closeFile(); 0068 0069 void play(); 0070 void pause(); 0071 void togglePlayPaused(); 0072 bool seek(double seconds); 0073 bool step(int frameOffset); 0074 bool stop(); 0075 bool selectAudioStream(int streamIndex); 0076 0077 void increaseVolume(double amount = 3.0); 0078 void decreaseVolume(double amount = 3.0); 0079 void setVolume(double volume); // [0.0 - 100.0] 0080 void setMuted(bool mute); 0081 0082 signals: 0083 void fileOpenError(const QString &filePath, const QString &reason); 0084 void fileOpened(const QString &filePath); 0085 void fileClosed(); 0086 0087 void playbackError(const QString &errorMessage = QString()); 0088 void playing(); 0089 void positionChanged(double seconds); 0090 void durationChanged(double seconds); 0091 void fpsChanged(double fps); 0092 void playSpeedChanged(double rate); 0093 void paused(); 0094 void stopped(); 0095 void textStreamsChanged(const QStringList &textStreams); 0096 void activeAudioStreamChanged(int audioStreamIndex); 0097 void audioStreamsChanged(const QStringList &audioStreams); 0098 0099 void volumeChanged(double volume); 0100 void muteChanged(bool muted); 0101 0102 void doubleClicked(const QPointF &point); 0103 void rightClicked(const QPointF &point); 0104 void leftClicked(const QPointF &point); 0105 void wheelUp(); 0106 void wheelDown(); 0107 0108 private: 0109 VideoPlayer(); 0110 virtual ~VideoPlayer(); 0111 0112 void reset(); 0113 void setupNotifications(); 0114 0115 private: 0116 FFPlayer *m_player; 0117 VideoWidget *m_videoWidget; 0118 SubtitleTextOverlay m_subOverlay; 0119 QString m_filePath; 0120 0121 State m_state; 0122 double m_duration; 0123 double m_fps; 0124 double m_playSpeed; 0125 QStringList m_textStreams; 0126 int m_activeAudioStream; 0127 QStringList m_audioStreams; 0128 0129 bool m_muted; 0130 double m_volume; 0131 }; 0132 } 0133 #endif