Music Hub  ..
A session-wide music playback service
player.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013-2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  * Jim Hodapp <jim.hodapp@canonical.com>
18  */
19 #ifndef CORE_UBUNTU_MEDIA_PLAYER_H_
20 #define CORE_UBUNTU_MEDIA_PLAYER_H_
21 
22 #include <core/media/track.h>
23 
25 #include <core/media/video/sink.h>
26 
27 #include <core/property.h>
28 
29 #include <chrono>
30 #include <iosfwd>
31 #include <memory>
32 
33 namespace core
34 {
35 namespace ubuntu
36 {
37 namespace media
38 {
39 class Service;
40 class TrackList;
41 
42 class Player : public std::enable_shared_from_this<Player>
43 {
44  public:
45  typedef double PlaybackRate;
46  typedef double Volume;
47  typedef uint32_t PlayerKey;
48  typedef void* GLConsumerWrapperHybris;
49  typedef std::map<std::string, std::string> HeadersType;
50 
51  struct Errors
52  {
53  Errors() = delete;
54 
55  struct OutOfProcessBufferStreamingNotSupported : public std::runtime_error
56  {
58  };
59 
60  struct InsufficientAppArmorPermissions : public std::runtime_error
61  {
62  InsufficientAppArmorPermissions(const std::string& err);
63  };
64 
65  struct UriNotFound : public std::runtime_error
66  {
67  UriNotFound(const std::string& err);
68  };
69  };
70 
71  struct Configuration;
72 
73  struct Client
74  {
75  Client() = delete;
76 
77  static const Configuration& default_configuration();
78  };
79 
81  {
87  };
88 
90  {
94  };
95 
102  {
107  };
108 
110  {
115  };
116 
117  enum Lifetime
118  {
121  };
122 
123  enum Error
124  {
131  };
132 
133  Player(const Player&) = delete;
134  virtual ~Player();
135 
136  Player& operator=(const Player&) = delete;
137  bool operator==(const Player&) const = delete;
138 
139  virtual std::string uuid() const = 0;
140  virtual void reconnect() = 0;
141  virtual void abandon() = 0;
142 
143  virtual std::shared_ptr<TrackList> track_list() = 0;
144  virtual PlayerKey key() const = 0;
145 
146  virtual video::Sink::Ptr create_gl_texture_video_sink(std::uint32_t texture_id) = 0;
147 
148  virtual bool open_uri(const Track::UriType& uri) = 0;
149  virtual bool open_uri(const Track::UriType& uri, const HeadersType&) = 0;
150  virtual void next() = 0;
151  virtual void previous() = 0;
152  virtual void play() = 0;
153  virtual void pause() = 0;
154  virtual void stop() = 0;
155  virtual void seek_to(const std::chrono::microseconds& offset) = 0;
156 
157  virtual const core::Property<bool>& can_play() const = 0;
158  virtual const core::Property<bool>& can_pause() const = 0;
159  virtual const core::Property<bool>& can_seek() const = 0;
160  virtual const core::Property<bool>& can_go_previous() const = 0;
161  virtual const core::Property<bool>& can_go_next() const = 0;
162  virtual const core::Property<bool>& is_video_source() const = 0;
163  virtual const core::Property<bool>& is_audio_source() const = 0;
164  virtual const core::Property<PlaybackStatus>& playback_status() const = 0;
165  virtual const core::Property<LoopStatus>& loop_status() const = 0;
166  virtual const core::Property<PlaybackRate>& playback_rate() const = 0;
167  virtual const core::Property<bool>& shuffle() const = 0;
168  virtual const core::Property<Track::MetaData>& meta_data_for_current_track() const = 0;
169  virtual const core::Property<Volume>& volume() const = 0;
170  virtual const core::Property<PlaybackRate>& minimum_playback_rate() const = 0;
171  virtual const core::Property<PlaybackRate>& maximum_playback_rate() const = 0;
172  virtual const core::Property<int64_t>& position() const = 0;
173  virtual const core::Property<int64_t>& duration() const = 0;
174  virtual const core::Property<AudioStreamRole>& audio_stream_role() const = 0;
175  virtual const core::Property<Orientation>& orientation() const = 0;
176  virtual const core::Property<Lifetime>& lifetime() const = 0;
177 
178  virtual core::Property<LoopStatus>& loop_status() = 0;
179  virtual core::Property<PlaybackRate>& playback_rate() = 0;
180  virtual core::Property<bool>& shuffle() = 0;
181  virtual core::Property<Volume>& volume() = 0;
182  virtual core::Property<AudioStreamRole>& audio_stream_role() = 0;
183  virtual core::Property<Lifetime>& lifetime() = 0;
184 
185  virtual const core::Signal<int64_t>& seeked_to() const = 0;
186  virtual const core::Signal<void>& about_to_finish() const = 0;
187  virtual const core::Signal<void>& end_of_stream() const = 0;
188  virtual core::Signal<PlaybackStatus>& playback_status_changed() = 0;
189  virtual const core::Signal<video::Dimensions>& video_dimension_changed() const = 0;
191  virtual const core::Signal<Error>& error() const = 0;
192  protected:
193  Player();
194 
195 };
196 
197 // operator<< pretty prints the given playback status to the given output stream.
198 inline std::ostream& operator<<(std::ostream& out, Player::PlaybackStatus status)
199 {
200  switch (status)
201  {
202  case Player::PlaybackStatus::null:
203  return out << "PlaybackStatus::null";
204  case Player::PlaybackStatus::ready:
205  return out << "PlaybackStatus::ready";
206  case Player::PlaybackStatus::playing:
207  return out << "PlaybackStatus::playing";
208  case Player::PlaybackStatus::paused:
209  return out << "PlaybackStatus::paused";
210  case Player::PlaybackStatus::stopped:
211  return out << "PlaybackStatus::stopped";
212  }
213 
214  return out;
215 }
216 
217 inline std::ostream& operator<<(std::ostream& out, Player::LoopStatus loop_status)
218 {
219  switch (loop_status)
220  {
221  case Player::LoopStatus::none:
222  return out << "LoopStatus::none";
223  case Player::LoopStatus::track:
224  return out << "LoopStatus::track";
225  case Player::LoopStatus::playlist:
226  return out << "LoopStatus::playlist";
227  }
228 
229  return out;
230 }
231 
232 }
233 }
234 }
235 
236 #endif // CORE_UBUNTU_MEDIA_PLAYER_H_
virtual const core::Property< PlaybackStatus > & playback_status() const =0
void * GLConsumerWrapperHybris
Definition: player.h:48
virtual const core::Property< int64_t > & position() const =0
virtual const core::Property< bool > & is_video_source() const =0
virtual const core::Property< bool > & can_play() const =0
bool operator==(const Player &) const =delete
virtual const core::Property< bool > & can_seek() const =0
virtual const core::Property< Track::MetaData > & meta_data_for_current_track() const =0
virtual void previous()=0
virtual const core::Property< int64_t > & duration() const =0
Definition: player.h:33
std::ostream & operator<<(std::ostream &out, Player::PlaybackStatus status)
Definition: player.h:198
virtual void abandon()=0
virtual const core::Property< bool > & can_go_previous() const =0
virtual core::Signal< PlaybackStatus > & playback_status_changed()=0
virtual const core::Property< bool > & shuffle() const =0
std::map< std::string, std::string > HeadersType
Definition: player.h:49
virtual const core::Property< bool > & is_audio_source() const =0
virtual const core::Signal< video::Dimensions > & video_dimension_changed() const =0
virtual const core::Property< PlaybackRate > & playback_rate() const =0
Player & operator=(const Player &)=delete
virtual const core::Property< Volume > & volume() const =0
virtual const core::Signal< void > & about_to_finish() const =0
virtual bool open_uri(const Track::UriType &uri)=0
virtual const core::Property< bool > & can_pause() const =0
std::shared_ptr< Sink > Ptr
To save us some typing.
Definition: sink.h:39
virtual video::Sink::Ptr create_gl_texture_video_sink(std::uint32_t texture_id)=0
virtual const core::Property< bool > & can_go_next() const =0
virtual const core::Signal< void > & end_of_stream() const =0
virtual void reconnect()=0
virtual const core::Property< PlaybackRate > & maximum_playback_rate() const =0
virtual const core::Property< Lifetime > & lifetime() const =0
std::string UriType
Definition: track.h:40
virtual PlayerKey key() const =0
virtual const core::Property< AudioStreamRole > & audio_stream_role() const =0
virtual const core::Signal< Error > & error() const =0
virtual const core::Property< PlaybackRate > & minimum_playback_rate() const =0
virtual std::string uuid() const =0
virtual const core::Signal< int64_t > & seeked_to() const =0
virtual const core::Property< LoopStatus > & loop_status() const =0
virtual const core::Property< Orientation > & orientation() const =0
virtual std::shared_ptr< TrackList > track_list()=0
virtual void seek_to(const std::chrono::microseconds &offset)=0