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 
61  struct Configuration;
62 
63  struct Client
64  {
65  Client() = delete;
66 
67  static const Configuration& default_configuration();
68  };
69 
71  {
77  };
78 
80  {
84  };
85 
92  {
97  };
98 
100  {
105  };
106 
107  enum Lifetime
108  {
111  };
112 
113  enum Error
114  {
121  };
122 
123  Player(const Player&) = delete;
124  virtual ~Player();
125 
126  Player& operator=(const Player&) = delete;
127  bool operator==(const Player&) const = delete;
128 
129  virtual std::string uuid() const = 0;
130  virtual void reconnect() = 0;
131  virtual void abandon() = 0;
132 
133  virtual std::shared_ptr<TrackList> track_list() = 0;
134  virtual PlayerKey key() const = 0;
135 
136  virtual video::Sink::Ptr create_gl_texture_video_sink(std::uint32_t texture_id) = 0;
137 
138  virtual bool open_uri(const Track::UriType& uri) = 0;
139  virtual bool open_uri(const Track::UriType& uri, const HeadersType&) = 0;
140  virtual void next() = 0;
141  virtual void previous() = 0;
142  virtual void play() = 0;
143  virtual void pause() = 0;
144  virtual void stop() = 0;
145  virtual void seek_to(const std::chrono::microseconds& offset) = 0;
146 
147  virtual const core::Property<bool>& can_play() const = 0;
148  virtual const core::Property<bool>& can_pause() const = 0;
149  virtual const core::Property<bool>& can_seek() const = 0;
150  virtual const core::Property<bool>& can_go_previous() const = 0;
151  virtual const core::Property<bool>& can_go_next() const = 0;
152  virtual const core::Property<bool>& is_video_source() const = 0;
153  virtual const core::Property<bool>& is_audio_source() const = 0;
154  virtual const core::Property<PlaybackStatus>& playback_status() const = 0;
155  virtual const core::Property<LoopStatus>& loop_status() const = 0;
156  virtual const core::Property<PlaybackRate>& playback_rate() const = 0;
157  virtual const core::Property<bool>& shuffle() const = 0;
158  virtual const core::Property<Track::MetaData>& meta_data_for_current_track() const = 0;
159  virtual const core::Property<Volume>& volume() const = 0;
160  virtual const core::Property<PlaybackRate>& minimum_playback_rate() const = 0;
161  virtual const core::Property<PlaybackRate>& maximum_playback_rate() const = 0;
162  virtual const core::Property<int64_t>& position() const = 0;
163  virtual const core::Property<int64_t>& duration() const = 0;
164  virtual const core::Property<AudioStreamRole>& audio_stream_role() const = 0;
165  virtual const core::Property<Orientation>& orientation() const = 0;
166  virtual const core::Property<Lifetime>& lifetime() const = 0;
167 
168  virtual core::Property<LoopStatus>& loop_status() = 0;
169  virtual core::Property<PlaybackRate>& playback_rate() = 0;
170  virtual core::Property<bool>& shuffle() = 0;
171  virtual core::Property<Volume>& volume() = 0;
172  virtual core::Property<AudioStreamRole>& audio_stream_role() = 0;
173  virtual core::Property<Lifetime>& lifetime() = 0;
174 
175  virtual const core::Signal<int64_t>& seeked_to() const = 0;
176  virtual const core::Signal<void>& about_to_finish() const = 0;
177  virtual const core::Signal<void>& end_of_stream() const = 0;
178  virtual core::Signal<PlaybackStatus>& playback_status_changed() = 0;
179  virtual const core::Signal<video::Dimensions>& video_dimension_changed() const = 0;
181  virtual const core::Signal<Error>& error() const = 0;
182  protected:
183  Player();
184 
185 };
186 
187 // operator<< pretty prints the given playback status to the given output stream.
188 inline std::ostream& operator<<(std::ostream& out, Player::PlaybackStatus status)
189 {
190  switch (status)
191  {
192  case Player::PlaybackStatus::null:
193  return out << "PlaybackStatus::null";
194  case Player::PlaybackStatus::ready:
195  return out << "PlaybackStatus::ready";
196  case Player::PlaybackStatus::playing:
197  return out << "PlaybackStatus::playing";
198  case Player::PlaybackStatus::paused:
199  return out << "PlaybackStatus::paused";
200  case Player::PlaybackStatus::stopped:
201  return out << "PlaybackStatus::stopped";
202  }
203 
204  return out;
205 }
206 
207 inline std::ostream& operator<<(std::ostream& out, Player::LoopStatus loop_status)
208 {
209  switch (loop_status)
210  {
211  case Player::LoopStatus::none:
212  return out << "LoopStatus::none";
213  case Player::LoopStatus::track:
214  return out << "LoopStatus::track";
215  case Player::LoopStatus::playlist:
216  return out << "LoopStatus::playlist";
217  }
218 
219  return out;
220 }
221 
222 }
223 }
224 }
225 
226 #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:188
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
static const Configuration & default_configuration()
Definition: player.cpp:30
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