20 #ifndef MPRIS_PLAYER_H_ 21 #define MPRIS_PLAYER_H_ 28 #include <core/dbus/bus.h> 29 #include <core/dbus/macros.h> 30 #include <core/dbus/object.h> 31 #include <core/dbus/property.h> 32 #include <core/dbus/interfaces/properties.h> 33 #include <core/dbus/types/any.h> 34 #include <core/dbus/types/object_path.h> 35 #include <core/dbus/types/variant.h> 37 #include <core/dbus/types/stl/tuple.h> 39 #include <boost/utility/identity_type.hpp> 55 static const std::string&
name()
57 static const std::string s{
"org.mpris.MediaPlayer2.Player"};
69 case core::ubuntu::media::Player::LoopStatus::none:
71 case core::ubuntu::media::Player::LoopStatus::track:
73 case core::ubuntu::media::Player::LoopStatus::playlist:
80 static constexpr
const char*
none{
"None"};
81 static constexpr
const char*
track{
"Track"};
82 static constexpr
const char*
playlist{
"Playlist"};
93 case core::ubuntu::media::Player::PlaybackStatus::null:
94 case core::ubuntu::media::Player::PlaybackStatus::ready:
95 case core::ubuntu::media::Player::PlaybackStatus::stopped:
98 case core::ubuntu::media::Player::PlaybackStatus::playing:
100 case core::ubuntu::media::Player::PlaybackStatus::paused:
107 static constexpr
const char* playing{
"Playing"};
108 static constexpr
const char* paused{
"Paused"};
109 static constexpr
const char* stopped{
"Stopped"};
116 static constexpr
const char*
name 118 "mpris.Player.Error.OutOfProcessBufferStreamingNotSupported" 124 static constexpr
const char*
name 126 "mpris.Player.Error.InsufficientAppArmorPermissions" 132 static constexpr
const char*
name 134 "mpris.Player.Error.UriNotFound" 139 typedef std::map<std::string, core::dbus::types::Variant>
Dictionary;
141 DBUS_CPP_METHOD_DEF(Next,
Player)
142 DBUS_CPP_METHOD_DEF(Previous,
Player)
143 DBUS_CPP_METHOD_DEF(Pause,
Player)
144 DBUS_CPP_METHOD_DEF(PlayPause,
Player)
145 DBUS_CPP_METHOD_DEF(Stop,
Player)
146 DBUS_CPP_METHOD_DEF(Play,
Player)
147 DBUS_CPP_METHOD_DEF(Seek,
Player)
148 DBUS_CPP_METHOD_DEF(SetPosition,
Player)
149 DBUS_CPP_METHOD_DEF(CreateVideoSink,
Player)
150 DBUS_CPP_METHOD_DEF(Key,
Player)
151 DBUS_CPP_METHOD_DEF(OpenUri,
Player)
152 DBUS_CPP_METHOD_DEF(OpenUriExtended,
Player)
156 DBUS_CPP_SIGNAL_DEF(Seeked,
Player, std::int64_t)
157 DBUS_CPP_SIGNAL_DEF(AboutToFinish,
Player,
void)
158 DBUS_CPP_SIGNAL_DEF(EndOfStream,
Player,
void)
162 DBUS_CPP_SIGNAL_DEF(Buffering,
Player,
int)
175 DBUS_CPP_WRITABLE_PROPERTY_DEF(PlaybackRate,
Player,
double)
176 DBUS_CPP_WRITABLE_PROPERTY_DEF(Rate,
Player,
double)
177 DBUS_CPP_WRITABLE_PROPERTY_DEF(Shuffle,
Player,
bool)
179 DBUS_CPP_WRITABLE_PROPERTY_DEF(Volume,
Player,
double)
180 DBUS_CPP_READABLE_PROPERTY_DEF(Position,
Player, std::int64_t)
181 DBUS_CPP_READABLE_PROPERTY_DEF(Duration,
Player, std::int64_t)
182 DBUS_CPP_READABLE_PROPERTY_DEF(MinimumRate,
Player,
double)
183 DBUS_CPP_READABLE_PROPERTY_DEF(MaximumRate,
Player,
double)
184 DBUS_CPP_READABLE_PROPERTY_DEF(IsVideoSource,
Player,
bool)
185 DBUS_CPP_READABLE_PROPERTY_DEF(IsAudioSource,
Player,
bool)
186 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoNext,
Player,
bool)
187 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoPrevious,
Player,
bool)
188 DBUS_CPP_READABLE_PROPERTY_DEF(CanPlay,
Player,
bool)
189 DBUS_CPP_READABLE_PROPERTY_DEF(CanPause,
Player,
bool)
190 DBUS_CPP_READABLE_PROPERTY_DEF(CanSeek,
Player,
bool)
191 DBUS_CPP_READABLE_PROPERTY_DEF(CanControl,
Player,
bool)
199 static const std::vector<std::string> instance;
return instance;
213 Properties::CanPlay::ValueType can_play{
false};
214 Properties::CanPause::ValueType can_pause{
false};
215 Properties::CanSeek::ValueType can_seek{
true};
216 Properties::CanControl::ValueType can_control{
true};
217 Properties::CanGoNext::ValueType can_go_next{
false};
218 Properties::CanGoPrevious::ValueType can_go_previous{
false};
219 Properties::IsVideoSource::ValueType is_video_source{
false};
220 Properties::IsAudioSource::ValueType is_audio_source{
true};
222 Properties::TypedPlaybackStatus::ValueType typed_playback_status{core::ubuntu::media::Player::PlaybackStatus::null};
223 Properties::TypedBackend::ValueType typed_backend{core::ubuntu::media::AVBackend::Backend::none};
225 Properties::TypedLoopStatus::ValueType typed_loop_status{core::ubuntu::media::Player::LoopStatus::none};
226 Properties::PlaybackRate::ValueType playback_rate{1.f};
227 Properties::Shuffle::ValueType shuffle{
false};
228 Properties::Metadata::ValueType meta_data{};
229 Properties::Volume::ValueType volume{0.f};
230 Properties::Position::ValueType position{0};
231 Properties::Duration::ValueType duration{0};
232 Properties::MinimumRate::ValueType minimum_rate{1.f};
233 Properties::MaximumRate::ValueType maximum_rate{1.f};
234 Properties::Orientation::ValueType orientation{core::ubuntu::media::Player::Orientation::rotate0};
239 : configuration(configuration),
242 configuration.
object->template get_property<Properties::CanPlay>(),
243 configuration.
object->template get_property<Properties::CanPause>(),
244 configuration.
object->template get_property<Properties::CanSeek>(),
245 configuration.
object->template get_property<Properties::CanControl>(),
246 configuration.
object->template get_property<Properties::CanGoNext>(),
247 configuration.
object->template get_property<Properties::CanGoPrevious>(),
248 configuration.
object->template get_property<Properties::IsVideoSource>(),
249 configuration.
object->template get_property<Properties::IsAudioSource>(),
250 configuration.
object->template get_property<Properties::PlaybackStatus>(),
251 configuration.
object->template get_property<Properties::TypedPlaybackStatus>(),
252 configuration.
object->template get_property<Properties::TypedBackend>(),
253 configuration.
object->template get_property<Properties::LoopStatus>(),
254 configuration.
object->template get_property<Properties::TypedLoopStatus>(),
255 configuration.
object->template get_property<Properties::AudioStreamRole>(),
256 configuration.
object->template get_property<Properties::Orientation>(),
257 configuration.
object->template get_property<Properties::Lifetime>(),
258 configuration.
object->template get_property<Properties::PlaybackRate>(),
259 configuration.
object->template get_property<Properties::Shuffle>(),
260 configuration.
object->template get_property<Properties::Metadata>(),
261 configuration.
object->template get_property<Properties::Volume>(),
262 configuration.
object->template get_property<Properties::Position>(),
263 configuration.
object->template get_property<Properties::Duration>(),
264 configuration.
object->template get_property<Properties::MinimumRate>(),
265 configuration.
object->template get_property<Properties::MaximumRate>()
269 configuration.object->template get_signal<Signals::Seeked>(),
270 configuration.object->template get_signal<Signals::AboutToFinish>(),
271 configuration.object->template get_signal<Signals::EndOfStream>(),
272 configuration.object->template get_signal<Signals::PlaybackStatusChanged>(),
273 configuration.object->template get_signal<Signals::VideoDimensionChanged>(),
274 configuration.object->template get_signal<Signals::Error>(),
275 configuration.object->template get_signal<Signals::Buffering>(),
276 configuration.object->template get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()
279 properties.can_play->set(configuration.defaults.can_play);
280 properties.can_pause->set(configuration.defaults.can_pause);
281 properties.can_seek->set(configuration.defaults.can_seek);
282 properties.can_control->set(configuration.defaults.can_control);
283 properties.can_go_next->set(configuration.defaults.can_go_next);
284 properties.can_go_previous->set(configuration.defaults.can_go_previous);
285 properties.is_video_source->set(configuration.defaults.is_video_source);
286 properties.is_audio_source->set(configuration.defaults.is_audio_source);
287 properties.playback_status->set(configuration.defaults.playback_status);
288 properties.typed_playback_status->set(configuration.defaults.typed_playback_status);
289 properties.typed_backend->set(configuration.defaults.typed_backend);
290 properties.loop_status->set(configuration.defaults.loop_status);
291 properties.typed_loop_status->set(configuration.defaults.typed_loop_status);
292 properties.audio_stream_role->set(core::ubuntu::media::Player::AudioStreamRole::multimedia);
293 properties.orientation->set(core::ubuntu::media::Player::Orientation::rotate0);
294 properties.lifetime->set(core::ubuntu::media::Player::Lifetime::normal);
295 properties.playback_rate->set(configuration.defaults.playback_rate);
296 properties.shuffle->set(configuration.defaults.shuffle);
297 properties.meta_data_for_current_track->set(configuration.defaults.meta_data);
298 properties.position->set(configuration.defaults.position);
299 properties.duration->set(configuration.defaults.duration);
300 properties.minimum_playback_rate->set(configuration.defaults.minimum_rate);
301 properties.maximum_playback_rate->set(configuration.defaults.maximum_rate);
306 on_property_value_changed<Properties::Orientation>(o);
309 properties.position->changed().connect([
this](std::int64_t position)
311 on_property_value_changed<Properties::Position>(position);
314 properties.duration->changed().connect([
this](std::int64_t duration)
316 on_property_value_changed<Properties::Duration>(duration);
319 properties.playback_status->changed().connect([
this](
const std::string& status)
321 on_property_value_changed<Properties::PlaybackStatus>(status);
324 properties.loop_status->changed().connect([
this](
const std::string& status)
326 on_property_value_changed<Properties::LoopStatus>(status);
329 properties.shuffle->changed().connect([
this](
bool shuffle)
331 on_property_value_changed<Properties::Shuffle>(shuffle);
334 properties.can_play->changed().connect([
this](
bool can_play)
336 on_property_value_changed<Properties::CanPlay>(can_play);
339 properties.can_pause->changed().connect([
this](
bool can_pause)
341 on_property_value_changed<Properties::CanPause>(can_pause);
344 properties.can_go_next->changed().connect([
this](
bool can_go_next)
346 on_property_value_changed<Properties::CanGoNext>(can_go_next);
349 properties.can_go_previous->changed().connect([
this](
bool can_go_previous)
351 on_property_value_changed<Properties::CanGoPrevious>(can_go_previous);
355 template<
typename Property>
358 Dictionary dict; dict[Property::name()] = dbus::types::Variant::encode(value);
360 signals.properties_changed->emit(std::make_tuple(
361 dbus::traits::Service<Player>::interface_name(),
363 the_empty_list_of_invalidated_properties()));
369 dict[Properties::CanPlay::name()] = dbus::types::Variant::encode(properties.can_play->get());
370 dict[Properties::CanPause::name()] = dbus::types::Variant::encode(properties.can_pause->get());
371 dict[Properties::CanSeek::name()] = dbus::types::Variant::encode(properties.can_seek->get());
372 dict[Properties::CanControl::name()] = dbus::types::Variant::encode(properties.can_control->get());
373 dict[Properties::CanGoNext::name()] = dbus::types::Variant::encode(properties.can_go_next->get());
374 dict[Properties::CanGoPrevious::name()] = dbus::types::Variant::encode(properties.can_go_previous->get());
375 dict[Properties::PlaybackStatus::name()] = dbus::types::Variant::encode(properties.playback_status->get());
376 dict[Properties::TypedPlaybackStatus::name()] = dbus::types::Variant::encode(properties.typed_playback_status->get());
377 dict[Properties::TypedBackend::name()] = dbus::types::Variant::encode(properties.typed_backend->get());
378 dict[Properties::LoopStatus::name()] = dbus::types::Variant::encode(properties.loop_status->get());
379 dict[Properties::TypedLoopStatus::name()] = dbus::types::Variant::encode(properties.typed_loop_status->get());
380 dict[Properties::AudioStreamRole::name()] = dbus::types::Variant::encode(properties.audio_stream_role->get());
381 dict[Properties::Orientation::name()] = dbus::types::Variant::encode(properties.orientation->get());
382 dict[Properties::Lifetime::name()] = dbus::types::Variant::encode(properties.lifetime->get());
383 dict[Properties::PlaybackRate::name()] = dbus::types::Variant::encode(properties.playback_rate->get());
384 dict[Properties::Shuffle::name()] = dbus::types::Variant::encode(properties.shuffle->get());
385 dict[Properties::Metadata::name()] = dbus::types::Variant::encode(properties.meta_data_for_current_track->get());
386 dict[Properties::Duration::name()] = dbus::types::Variant::encode(properties.duration->get());
387 dict[Properties::Position::name()] = dbus::types::Variant::encode(properties.position->get());
388 dict[Properties::MinimumRate::name()] = dbus::types::Variant::encode(properties.minimum_playback_rate->get());
389 dict[Properties::MaximumRate::name()] = dbus::types::Variant::encode(properties.maximum_playback_rate->get());
399 std::shared_ptr<core::dbus::Property<Properties::CanPlay>>
can_play;
400 std::shared_ptr<core::dbus::Property<Properties::CanPause>>
can_pause;
401 std::shared_ptr<core::dbus::Property<Properties::CanSeek>>
can_seek;
402 std::shared_ptr<core::dbus::Property<Properties::CanControl>>
can_control;
403 std::shared_ptr<core::dbus::Property<Properties::CanGoNext>>
can_go_next;
410 std::shared_ptr<core::dbus::Property<Properties::TypedBackend>>
typed_backend;
411 std::shared_ptr<core::dbus::Property<Properties::LoopStatus>>
loop_status;
414 std::shared_ptr<core::dbus::Property<Properties::Orientation>>
orientation;
415 std::shared_ptr<core::dbus::Property<Properties::Lifetime>>
lifetime;
416 std::shared_ptr<core::dbus::Property<Properties::PlaybackRate>>
playback_rate;
417 std::shared_ptr<core::dbus::Property<Properties::Shuffle>>
shuffle;
419 std::shared_ptr<core::dbus::Property<Properties::Volume>>
volume;
420 std::shared_ptr<core::dbus::Property<Properties::Position>>
position;
421 std::shared_ptr<core::dbus::Property<Properties::Duration>>
duration;
428 typename core::dbus::Signal<Signals::Seeked, Signals::Seeked::ArgumentType>::Ptr
seeked_to;
429 typename core::dbus::Signal<Signals::AboutToFinish, Signals::AboutToFinish::ArgumentType>::Ptr
about_to_finish;
430 typename core::dbus::Signal<Signals::EndOfStream, Signals::EndOfStream::ArgumentType>::Ptr
end_of_stream;
431 typename core::dbus::Signal<Signals::PlaybackStatusChanged, Signals::PlaybackStatusChanged::ArgumentType>::Ptr
playback_status_changed;
432 typename core::dbus::Signal<Signals::VideoDimensionChanged, Signals::VideoDimensionChanged::ArgumentType>::Ptr
video_dimension_changed;
433 typename core::dbus::Signal<Signals::Error, Signals::Error::ArgumentType>::Ptr
error;
434 typename core::dbus::Signal<Signals::Buffering, Signals::Buffering::ArgumentType>::Ptr
buffering_changed;
438 core::dbus::interfaces::Properties::Signals::PropertiesChanged,
439 core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
446 #endif // MPRIS_PLAYER_H_ std::shared_ptr< core::dbus::Property< Properties::Duration > > duration
void on_property_value_changed(const typename Property::ValueType &value)
std::shared_ptr< core::dbus::Property< Properties::AudioStreamRole > > audio_stream_role
std::shared_ptr< core::dbus::Property< Properties::IsAudioSource > > is_audio_source
std::shared_ptr< core::dbus::Property< Properties::Metadata > > meta_data_for_current_track
std::shared_ptr< core::dbus::Property< Properties::LoopStatus > > loop_status
static const std::string & name()
static constexpr const char * none
std::shared_ptr< core::dbus::Property< Properties::MinimumRate > > minimum_playback_rate
core::dbus::Object::Ptr object
static constexpr const char * playlist
static constexpr const char * paused
std::shared_ptr< core::dbus::Property< Properties::MaximumRate > > maximum_playback_rate
static constexpr const char * stopped
static const char * from(core::ubuntu::media::Player::PlaybackStatus status)
core::dbus::Signal< Signals::VideoDimensionChanged, Signals::VideoDimensionChanged::ArgumentType >::Ptr video_dimension_changed
static const std::vector< std::string > & the_empty_list_of_invalidated_properties()
std::map< std::string, core::dbus::types::Variant > Dictionary
static const char * from(core::ubuntu::media::Player::LoopStatus status)
core::dbus::Signal< Signals::Buffering, Signals::Buffering::ArgumentType >::Ptr buffering_changed
Configuration configuration
std::shared_ptr< core::dbus::Property< Properties::Shuffle > > shuffle
core::dbus::Signal< Signals::AboutToFinish, Signals::AboutToFinish::ArgumentType >::Ptr about_to_finish
std::shared_ptr< core::dbus::Property< Properties::IsVideoSource > > is_video_source
std::shared_ptr< core::dbus::Property< Properties::TypedLoopStatus > > typed_loop_status
std::shared_ptr< core::dbus::Property< Properties::CanGoPrevious > > can_go_previous
std::shared_ptr< core::dbus::Property< Properties::CanPause > > can_pause
std::shared_ptr< core::dbus::Property< Properties::Lifetime > > lifetime
Dictionary get_all_properties()
std::shared_ptr< core::dbus::Property< Properties::Volume > > volume
std::shared_ptr< core::dbus::Property< Properties::CanSeek > > can_seek
std::shared_ptr< core::dbus::Property< Properties::TypedBackend > > typed_backend
static constexpr const char * track
core::dbus::Signal< Signals::Seeked, Signals::Seeked::ArgumentType >::Ptr seeked_to
std::shared_ptr< core::dbus::Property< Properties::Orientation > > orientation
Skeleton(const Configuration &configuration)
std::shared_ptr< core::dbus::Property< Properties::TypedPlaybackStatus > > typed_playback_status
std::shared_ptr< core::dbus::Property< Properties::PlaybackStatus > > playback_status
core::dbus::Signal< Signals::EndOfStream, Signals::EndOfStream::ArgumentType >::Ptr end_of_stream
std::shared_ptr< core::dbus::Property< Properties::CanPlay > > can_play
std::shared_ptr< core::dbus::Property< Properties::CanControl > > can_control
static constexpr const char * playing
std::shared_ptr< core::dbus::Property< Properties::Position > > position
std::shared_ptr< core::dbus::Property< Properties::CanGoNext > > can_go_next
std::shared_ptr< core::dbus::Property< Properties::PlaybackRate > > playback_rate
dbus::Signal< core::dbus::interfaces::Properties::Signals::PropertiesChanged, core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType >::Ptr properties_changed
core::dbus::Signal< Signals::PlaybackStatusChanged, Signals::PlaybackStatusChanged::ArgumentType >::Ptr playback_status_changed
core::dbus::Signal< Signals::Error, Signals::Error::ArgumentType >::Ptr error