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 struct AVBackend
43 {
44  enum Backend
45  {
49  };
50 
55  static Backend get_backend_type();
56 };
57 
58 class Player : public std::enable_shared_from_this<Player>
59 {
60  public:
61  typedef double PlaybackRate;
62  typedef double Volume;
63  typedef uint32_t PlayerKey;
64  typedef void* GLConsumerWrapperHybris;
65  typedef std::map<std::string, std::string> HeadersType;
66 
67  struct Errors
68  {
69  Errors() = delete;
70 
71  struct OutOfProcessBufferStreamingNotSupported : public std::runtime_error
72  {
74  };
75 
76  struct InsufficientAppArmorPermissions : public std::runtime_error
77  {
78  InsufficientAppArmorPermissions(const std::string& err);
79  };
80 
81  struct UriNotFound : public std::runtime_error
82  {
83  UriNotFound(const std::string& err);
84  };
85  };
86 
87  struct Configuration;
88 
89  struct Client
90  {
91  Client() = delete;
92 
93  static const Configuration& default_configuration();
94  };
95 
97  {
103  };
104 
106  {
109  playlist
110  };
111 
118  {
122  phone
123  };
124 
126  {
130  rotate270
131  };
132 
133  enum Lifetime
134  {
136  resumable
137  };
138 
139  enum Error
140  {
146  service_missing_error
147  };
148 
149  Player(const Player&) = delete;
150  virtual ~Player();
151 
152  Player& operator=(const Player&) = delete;
153  bool operator==(const Player&) const = delete;
154 
155  virtual std::string uuid() const = 0;
156  virtual void reconnect() = 0;
157  virtual void abandon() = 0;
158 
159  virtual std::shared_ptr<TrackList> track_list() = 0;
160  virtual PlayerKey key() const = 0;
161 
162  virtual video::Sink::Ptr create_gl_texture_video_sink(std::uint32_t texture_id) = 0;
163 
164  virtual bool open_uri(const Track::UriType& uri) = 0;
165  virtual bool open_uri(const Track::UriType& uri, const HeadersType&) = 0;
166  virtual void next() = 0;
167  virtual void previous() = 0;
168  virtual void play() = 0;
169  virtual void pause() = 0;
170  virtual void stop() = 0;
171  virtual void seek_to(const std::chrono::microseconds& offset) = 0;
172 
173  virtual const core::Property<bool>& can_play() const = 0;
174  virtual const core::Property<bool>& can_pause() const = 0;
175  virtual const core::Property<bool>& can_seek() const = 0;
176  virtual const core::Property<bool>& can_go_previous() const = 0;
177  virtual const core::Property<bool>& can_go_next() const = 0;
178  virtual const core::Property<bool>& is_video_source() const = 0;
179  virtual const core::Property<bool>& is_audio_source() const = 0;
180  virtual const core::Property<PlaybackStatus>& playback_status() const = 0;
181  virtual const core::Property<AVBackend::Backend>& backend() const = 0;
182  virtual const core::Property<LoopStatus>& loop_status() const = 0;
183  virtual const core::Property<PlaybackRate>& playback_rate() const = 0;
184  virtual const core::Property<bool>& shuffle() const = 0;
185  virtual const core::Property<Track::MetaData>& meta_data_for_current_track() const = 0;
186  virtual const core::Property<Volume>& volume() const = 0;
187  virtual const core::Property<PlaybackRate>& minimum_playback_rate() const = 0;
188  virtual const core::Property<PlaybackRate>& maximum_playback_rate() const = 0;
189  virtual const core::Property<int64_t>& position() const = 0;
190  virtual const core::Property<int64_t>& duration() const = 0;
191  virtual const core::Property<AudioStreamRole>& audio_stream_role() const = 0;
192  virtual const core::Property<Orientation>& orientation() const = 0;
193  virtual const core::Property<Lifetime>& lifetime() const = 0;
194 
195  virtual core::Property<LoopStatus>& loop_status() = 0;
196  virtual core::Property<PlaybackRate>& playback_rate() = 0;
197  virtual core::Property<bool>& shuffle() = 0;
198  virtual core::Property<Volume>& volume() = 0;
199  virtual core::Property<AudioStreamRole>& audio_stream_role() = 0;
200  virtual core::Property<Lifetime>& lifetime() = 0;
201 
202  virtual const core::Signal<int64_t>& seeked_to() const = 0;
203  virtual const core::Signal<void>& about_to_finish() const = 0;
204  virtual const core::Signal<void>& end_of_stream() const = 0;
205  virtual core::Signal<PlaybackStatus>& playback_status_changed() = 0;
206  virtual const core::Signal<video::Dimensions>& video_dimension_changed() const = 0;
208  virtual const core::Signal<Error>& error() const = 0;
209  virtual const core::Signal<int>& buffering_changed() const = 0;
210 
211  protected:
212  Player();
213 
214 };
215 
216 // operator<< pretty prints the given playback status to the given output stream.
217 inline std::ostream& operator<<(std::ostream& out, Player::PlaybackStatus status)
218 {
219  switch (status)
220  {
221  case Player::PlaybackStatus::null:
222  return out << "PlaybackStatus::null";
223  case Player::PlaybackStatus::ready:
224  return out << "PlaybackStatus::ready";
225  case Player::PlaybackStatus::playing:
226  return out << "PlaybackStatus::playing";
227  case Player::PlaybackStatus::paused:
228  return out << "PlaybackStatus::paused";
229  case Player::PlaybackStatus::stopped:
230  return out << "PlaybackStatus::stopped";
231  }
232 
233  return out;
234 }
235 
236 inline std::ostream& operator<<(std::ostream& out, Player::LoopStatus loop_status)
237 {
238  switch (loop_status)
239  {
240  case Player::LoopStatus::none:
241  return out << "LoopStatus::none";
242  case Player::LoopStatus::track:
243  return out << "LoopStatus::track";
244  case Player::LoopStatus::playlist:
245  return out << "LoopStatus::playlist";
246  }
247 
248  return out;
249 }
250 
251 inline std::ostream& operator<<(std::ostream& out, Player::Error e)
252 {
253  switch (e)
254  {
255  case Player::Error::no_error:
256  return out << "Error::no_error";
257  case Player::Error::resource_error:
258  return out << "Error::resource_error";
259  case Player::Error::format_error:
260  return out << "Error::format_error";
261  case Player::Error::network_error:
262  return out << "Error::network_error";
263  case Player::Error::access_denied_error:
264  return out << "Error::access_denied_error";
265  case Player::Error::service_missing_error:
266  return out << "Error::service_missing_error";
267  default:
268  return out << "Unsupported Player error: " << e;
269  }
270 
271  return out;
272 }
273 
274 }
275 }
276 }
277 
278 #endif // CORE_UBUNTU_MEDIA_PLAYER_H_
void * GLConsumerWrapperHybris
Definition: player.h:64
bool operator==(IntWrapper< Tag, IntegerType > const &lhs, IntWrapper< Tag, IntegerType > const &rhs)
Definition: dimensions.h:97
Definition: player.h:33
std::ostream & operator<<(std::ostream &out, Player::PlaybackStatus status)
Definition: player.h:217
std::map< std::string, std::string > HeadersType
Definition: player.h:65
std::shared_ptr< Sink > Ptr
To save us some typing.
Definition: sink.h:39
static Backend get_backend_type()
Returns the type of audio/video decoding/encoding backend being used.
Definition: backend.cpp:26
std::string UriType
Definition: track.h:40