Music Hub  ..
A session-wide music playback service
player.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2021-2022 UBports Foundation.
3  *
4  * Contact: Alberto Mardegan <mardy@users.sourceforge.net>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LOMIRI_MEDIAHUB_PLAYER_H
20 #define LOMIRI_MEDIAHUB_PLAYER_H
21 
22 #include "track.h"
23 
24 #include <QObject>
25 #include <QScopedPointer>
26 #include <QString>
27 
28 class QUrl;
29 
30 namespace lomiri {
31 namespace MediaHub {
32 
33 class Error;
34 class Service;
35 class TrackList;
36 class VideoSink;
37 
38 class PlayerPrivate;
39 class MH_EXPORT Player: public QObject
40 {
41  Q_OBJECT
42  Q_DISABLE_COPY(Player)
43  Q_PROPERTY(bool canPlay READ canPlay NOTIFY controlsChanged)
44  Q_PROPERTY(bool canPause READ canPause NOTIFY controlsChanged)
45  Q_PROPERTY(bool canSeek READ canSeek NOTIFY controlsChanged)
46  Q_PROPERTY(bool canGoPrevious READ canGoPrevious NOTIFY controlsChanged)
47  Q_PROPERTY(bool canGoNext READ canGoNext NOTIFY controlsChanged)
48 
49  Q_PROPERTY(bool isVideoSource READ isVideoSource NOTIFY sourceTypeChanged)
50  Q_PROPERTY(bool isAudioSource READ isAudioSource NOTIFY sourceTypeChanged)
51 
52  Q_PROPERTY(PlaybackStatus playbackStatus READ playbackStatus
53  NOTIFY playbackStatusChanged)
54  Q_PROPERTY(bool shuffle READ shuffle WRITE setShuffle
55  NOTIFY shuffleChanged)
56  Q_PROPERTY(Volume volume READ volume WRITE setVolume NOTIFY volumeChanged)
57  Q_PROPERTY(Track::MetaData metaDataForCurrentTrack
58  READ metaDataForCurrentTrack
59  NOTIFY metaDataForCurrentTrackChanged)
60 
61  Q_PROPERTY(PlaybackRate playbackRate
62  READ playbackRate WRITE setPlaybackRate
63  NOTIFY playbackRateChanged)
64  Q_PROPERTY(PlaybackRate minimumPlaybackRate READ minimumPlaybackRate
65  NOTIFY minimumPlaybackRateChanged)
66  Q_PROPERTY(PlaybackRate maximumPlaybackRate READ maximumPlaybackRate
67  NOTIFY maximumPlaybackRateChanged)
68 
69  Q_PROPERTY(quint64 position READ position NOTIFY positionChanged)
70  Q_PROPERTY(quint64 duration READ duration NOTIFY durationChanged)
71  Q_PROPERTY(Orientation orientation READ orientation
72  NOTIFY orientationChanged)
73 
74  Q_PROPERTY(LoopStatus loopStatus READ loopStatus WRITE setLoopStatus
75  NOTIFY loopStatusChanged)
76  Q_PROPERTY(AudioStreamRole audioStreamRole
77  READ audioStreamRole WRITE setAudioStreamRole
78  NOTIFY audioStreamRoleChanged)
79 
80 public:
81  typedef double PlaybackRate;
82  typedef double Volume;
83  typedef QMap<QString, QString> Headers;
84 
91  };
92  Q_ENUM(PlaybackStatus)
93 
94  enum LoopStatus {
98  };
99  Q_ENUM(LoopStatus)
100 
101 
111  };
112  Q_ENUM(AudioStreamRole)
113 
114  enum Orientation {
119  };
120  Q_ENUM(Orientation)
121 
122  /* Do we need a link to the Service? We could call CreateSession
123  * internally.
124  */
125  Player(QObject *parent = nullptr);
126  virtual ~Player();
127 
128  QString uuid() const;
129 
130  /*
131  * Unused methods:
132  * - reconnect
133  * - abandon
134  */
135 
136  void setTrackList(TrackList *trackList);
137  TrackList *trackList() const;
138 
139  // The returned object is owned by the Player
140  VideoSink &createGLTextureVideoSink(uint32_t textureId);
141 
142  void openUri(const QUrl &uri, const Headers &headers = {});
143  void goToNext();
144  void goToPrevious();
145  void play();
146  void pause();
147  void stop();
148  void seekTo(uint64_t microseconds);
149 
150  /*
151  * Property accessors
152  */
153  bool canPlay() const;
154  bool canPause() const;
155  bool canSeek() const;
156  bool canGoPrevious() const;
157  bool canGoNext() const;
158 
159  bool isVideoSource() const;
160  bool isAudioSource() const;
161 
162  PlaybackStatus playbackStatus() const;
163  void setPlaybackRate(PlaybackRate rate);
164  PlaybackRate playbackRate() const;
165  void setShuffle(bool shuffle);
166  bool shuffle() const;
167  void setVolume(Volume volume);
168  Volume volume() const;
169  Track::MetaData metaDataForCurrentTrack() const;
170  PlaybackRate minimumPlaybackRate() const;
171  PlaybackRate maximumPlaybackRate() const;
172  quint64 position() const;
173  quint64 duration() const;
174  Orientation orientation() const;
175  void setLoopStatus(LoopStatus loopStatus);
176  LoopStatus loopStatus() const;
177  void setAudioStreamRole(AudioStreamRole role);
178  AudioStreamRole audioStreamRole() const;
179 
180 Q_SIGNALS:
181  void controlsChanged();
182  void sourceTypeChanged();
183  void playbackStatusChanged();
184  void backendChanged();
185  void metaDataForCurrentTrackChanged();
186  void loopStatusChanged();
187  void playbackRateChanged();
188  void shuffleChanged();
189  void volumeChanged();
190  void minimumPlaybackRateChanged();
191  void maximumPlaybackRateChanged();
192  void positionChanged(quint64 microseconds);
193  void durationChanged(quint64 microseconds);
194  void audioStreamRoleChanged();
195  void orientationChanged();
196 
197  void seekedTo(quint64 microseconds);
198  void aboutToFinish();
199  void endOfStream();
200  void videoDimensionChanged(const QSize &size);
202  void errorOccurred(const Error &error);
203  void bufferingChanged(int percent);
204  void serviceDisconnected();
205  void serviceReconnected();
206 
207 private:
208  Q_DECLARE_PRIVATE(Player)
209  QScopedPointer<PlayerPrivate> d_ptr;
210 };
211 
212 } // namespace MediaHub
213 } // namespace lomiri
214 
215 #endif // LOMIRI_MEDIAHUB_PLAYER_H
QObject
lomiri::MediaHub::Player::Rotate270
@ Rotate270
Definition: player.h:118
lomiri::MediaHub::Player::PlaybackRate
double PlaybackRate
Definition: player.h:81
lomiri::MediaHub::Player::Headers
QMap< QString, QString > Headers
Definition: player.h:83
lomiri::MediaHub::Player::Stopped
@ Stopped
Definition: player.h:90
lomiri::MediaHub::Player::Rotate180
@ Rotate180
Definition: player.h:117
lomiri::MediaHub::Player::PhoneRole
@ PhoneRole
Definition: player.h:110
lomiri::MediaHub::Player::Null
@ Null
Definition: player.h:86
MH_EXPORT
#define MH_EXPORT
Definition: global.h:27
lomiri::MediaHub::VideoSink
A video sink abstracts a queue of buffers, that receives a stream of decoded video buffers from an ar...
Definition: video_sink.h:34
lomiri::MediaHub::Player::Rotate0
@ Rotate0
Definition: player.h:115
lomiri::MediaHub::Player::AlarmRole
@ AlarmRole
Definition: player.h:107
lomiri::MediaHub::Player::Ready
@ Ready
Definition: player.h:87
lomiri::MediaHub::Player::Paused
@ Paused
Definition: player.h:89
lomiri::MediaHub::Player::LoopStatus
LoopStatus
Definition: player.h:94
lomiri::MediaHub::Player::Volume
double Volume
Definition: player.h:82
lomiri::MediaHub::Track
Definition: track.h:44
lomiri::MediaHub::Player::MultimediaRole
@ MultimediaRole
Definition: player.h:109
lomiri::MediaHub::Player::LoopNone
@ LoopNone
Definition: player.h:95
lomiri::MediaHub::Player::Orientation
Orientation
Definition: player.h:114
lomiri::MediaHub::Player::AudioStreamRole
AudioStreamRole
Definition: player.h:106
lomiri::MediaHub::Player::PlaybackStatus
PlaybackStatus
Definition: player.h:85
lomiri::MediaHub::Player::Playing
@ Playing
Definition: player.h:88
lomiri::MediaHub::Player::Rotate90
@ Rotate90
Definition: player.h:116
lomiri::MediaHub::Player::AlertRole
@ AlertRole
Definition: player.h:108
lomiri::MediaHub::TrackList
Definition: track_list.h:35
lomiri
Definition: dbus_utils.h:24
DBusConstants::Error
Error
Definition: dbus_constants.h:59
lomiri::MediaHub::Player::LoopPlaylist
@ LoopPlaylist
Definition: player.h:97
lomiri::MediaHub::Player
Definition: player.h:39
track.h
lomiri::MediaHub::Player::LoopTrack
@ LoopTrack
Definition: player.h:96