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