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> 53 static const std::string&
name()
55 static const std::string s{
"org.mpris.MediaPlayer2.Player"};
67 case core::ubuntu::media::Player::LoopStatus::none:
69 case core::ubuntu::media::Player::LoopStatus::track:
71 case core::ubuntu::media::Player::LoopStatus::playlist:
78 static constexpr
const char*
none{
"None"};
79 static constexpr
const char*
track{
"Track"};
80 static constexpr
const char*
playlist{
"Playlist"};
91 case core::ubuntu::media::Player::PlaybackStatus::null:
92 case core::ubuntu::media::Player::PlaybackStatus::ready:
93 case core::ubuntu::media::Player::PlaybackStatus::stopped:
96 case core::ubuntu::media::Player::PlaybackStatus::playing:
98 case core::ubuntu::media::Player::PlaybackStatus::paused:
105 static constexpr
const char* playing{
"Playing"};
106 static constexpr
const char* paused{
"Paused"};
107 static constexpr
const char* stopped{
"Stopped"};
114 static constexpr
const char*
name 116 "mpris.Player.Error.OutOfProcessBufferStreamingNotSupported" 122 static constexpr
const char*
name 124 "mpris.Player.Error.InsufficientAppArmorPermissions" 130 static constexpr
const char*
name 132 "mpris.Player.Error.UriNotFound" 137 typedef std::map<std::string, core::dbus::types::Variant>
Dictionary;
139 DBUS_CPP_METHOD_DEF(Next,
Player)
140 DBUS_CPP_METHOD_DEF(Previous,
Player)
141 DBUS_CPP_METHOD_DEF(Pause,
Player)
142 DBUS_CPP_METHOD_DEF(PlayPause,
Player)
143 DBUS_CPP_METHOD_DEF(Stop,
Player)
144 DBUS_CPP_METHOD_DEF(Play,
Player)
145 DBUS_CPP_METHOD_DEF(Seek,
Player)
146 DBUS_CPP_METHOD_DEF(SetPosition,
Player)
147 DBUS_CPP_METHOD_DEF(CreateVideoSink,
Player)
148 DBUS_CPP_METHOD_DEF(Key,
Player)
149 DBUS_CPP_METHOD_DEF(OpenUri,
Player)
150 DBUS_CPP_METHOD_DEF(OpenUriExtended,
Player)
154 DBUS_CPP_SIGNAL_DEF(Seeked,
Player, std::int64_t)
155 DBUS_CPP_SIGNAL_DEF(AboutToFinish,
Player,
void)
156 DBUS_CPP_SIGNAL_DEF(EndOfStream,
Player,
void)
172 DBUS_CPP_WRITABLE_PROPERTY_DEF(PlaybackRate,
Player,
double)
173 DBUS_CPP_WRITABLE_PROPERTY_DEF(Rate,
Player,
double)
174 DBUS_CPP_WRITABLE_PROPERTY_DEF(Shuffle,
Player,
bool)
175 DBUS_CPP_READABLE_PROPERTY_DEF(Metadata,
Player, Dictionary)
177 DBUS_CPP_WRITABLE_PROPERTY_DEF(Volume,
Player,
double)
178 DBUS_CPP_READABLE_PROPERTY_DEF(Position,
Player, std::int64_t)
179 DBUS_CPP_READABLE_PROPERTY_DEF(Duration,
Player, std::int64_t)
180 DBUS_CPP_READABLE_PROPERTY_DEF(MinimumRate,
Player,
double)
181 DBUS_CPP_READABLE_PROPERTY_DEF(MaximumRate,
Player,
double)
182 DBUS_CPP_READABLE_PROPERTY_DEF(IsVideoSource,
Player,
bool)
183 DBUS_CPP_READABLE_PROPERTY_DEF(IsAudioSource,
Player,
bool)
184 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoNext,
Player,
bool)
185 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoPrevious,
Player,
bool)
186 DBUS_CPP_READABLE_PROPERTY_DEF(CanPlay,
Player,
bool)
187 DBUS_CPP_READABLE_PROPERTY_DEF(CanPause,
Player,
bool)
188 DBUS_CPP_READABLE_PROPERTY_DEF(CanSeek,
Player,
bool)
189 DBUS_CPP_READABLE_PROPERTY_DEF(CanControl,
Player,
bool)
197 static const std::vector<std::string> instance;
return instance;
211 Properties::CanPlay::ValueType can_play{
false};
212 Properties::CanPause::ValueType can_pause{
false};
213 Properties::CanSeek::ValueType can_seek{
true};
214 Properties::CanControl::ValueType can_control{
true};
215 Properties::CanGoNext::ValueType can_go_next{
false};
216 Properties::CanGoPrevious::ValueType can_go_previous{
false};
217 Properties::IsVideoSource::ValueType is_video_source{
false};
218 Properties::IsAudioSource::ValueType is_audio_source{
true};
220 Properties::TypedPlaybackStatus::ValueType typed_playback_status{core::ubuntu::media::Player::PlaybackStatus::null};
222 Properties::TypedLoopStatus::ValueType typed_loop_status{core::ubuntu::media::Player::LoopStatus::none};
223 Properties::PlaybackRate::ValueType playback_rate{1.f};
224 Properties::Shuffle::ValueType shuffle{
false};
225 Properties::TypedMetaData::ValueType typed_meta_data{};
226 Properties::Volume::ValueType volume{0.f};
227 Properties::Position::ValueType position{0};
228 Properties::Duration::ValueType duration{0};
229 Properties::MinimumRate::ValueType minimum_rate{1.f};
230 Properties::MaximumRate::ValueType maximum_rate{1.f};
231 Properties::Orientation::ValueType orientation{core::ubuntu::media::Player::Orientation::rotate0};
236 : configuration(configuration),
239 configuration.
object->template get_property<Properties::CanPlay>(),
240 configuration.
object->template get_property<Properties::CanPause>(),
241 configuration.
object->template get_property<Properties::CanSeek>(),
242 configuration.
object->template get_property<Properties::CanControl>(),
243 configuration.
object->template get_property<Properties::CanGoNext>(),
244 configuration.
object->template get_property<Properties::CanGoPrevious>(),
245 configuration.
object->template get_property<Properties::IsVideoSource>(),
246 configuration.
object->template get_property<Properties::IsAudioSource>(),
247 configuration.
object->template get_property<Properties::PlaybackStatus>(),
248 configuration.
object->template get_property<Properties::TypedPlaybackStatus>(),
249 configuration.
object->template get_property<Properties::LoopStatus>(),
250 configuration.
object->template get_property<Properties::TypedLoopStatus>(),
251 configuration.
object->template get_property<Properties::AudioStreamRole>(),
252 configuration.
object->template get_property<Properties::Orientation>(),
253 configuration.
object->template get_property<Properties::Lifetime>(),
254 configuration.
object->template get_property<Properties::PlaybackRate>(),
255 configuration.
object->template get_property<Properties::Shuffle>(),
256 configuration.
object->template get_property<Properties::TypedMetaData>(),
257 configuration.
object->template get_property<Properties::Volume>(),
258 configuration.
object->template get_property<Properties::Position>(),
259 configuration.
object->template get_property<Properties::Duration>(),
260 configuration.
object->template get_property<Properties::MinimumRate>(),
261 configuration.
object->template get_property<Properties::MaximumRate>()
265 configuration.object->template get_signal<Signals::Seeked>(),
266 configuration.object->template get_signal<Signals::AboutToFinish>(),
267 configuration.object->template get_signal<Signals::EndOfStream>(),
268 configuration.object->template get_signal<Signals::PlaybackStatusChanged>(),
269 configuration.object->template get_signal<Signals::VideoDimensionChanged>(),
270 configuration.object->template get_signal<Signals::Error>(),
271 configuration.object->template get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()
274 properties.can_play->set(configuration.defaults.can_play);
275 properties.can_pause->set(configuration.defaults.can_pause);
276 properties.can_seek->set(configuration.defaults.can_seek);
277 properties.can_control->set(configuration.defaults.can_control);
278 properties.can_go_next->set(configuration.defaults.can_go_next);
279 properties.can_go_previous->set(configuration.defaults.can_go_previous);
280 properties.is_video_source->set(configuration.defaults.is_video_source);
281 properties.is_audio_source->set(configuration.defaults.is_audio_source);
282 properties.playback_status->set(configuration.defaults.playback_status);
283 properties.typed_playback_status->set(configuration.defaults.typed_playback_status);
284 properties.loop_status->set(configuration.defaults.loop_status);
285 properties.typed_loop_status->set(configuration.defaults.typed_loop_status);
286 properties.audio_stream_role->set(core::ubuntu::media::Player::AudioStreamRole::multimedia);
287 properties.orientation->set(core::ubuntu::media::Player::Orientation::rotate0);
288 properties.lifetime->set(core::ubuntu::media::Player::Lifetime::normal);
289 properties.playback_rate->set(configuration.defaults.playback_rate);
290 properties.shuffle->set(configuration.defaults.shuffle);
291 properties.position->set(configuration.defaults.position);
292 properties.duration->set(configuration.defaults.duration);
293 properties.minimum_playback_rate->set(configuration.defaults.minimum_rate);
294 properties.maximum_playback_rate->set(configuration.defaults.maximum_rate);
299 on_property_value_changed<Properties::Orientation>(o);
302 properties.position->changed().connect([
this](std::int64_t position)
304 on_property_value_changed<Properties::Position>(position);
307 properties.duration->changed().connect([
this](std::int64_t duration)
309 on_property_value_changed<Properties::Duration>(duration);
312 properties.playback_status->changed().connect([
this](
const std::string& status)
314 on_property_value_changed<Properties::PlaybackStatus>(status);
317 properties.loop_status->changed().connect([
this](
const std::string& status)
319 on_property_value_changed<Properties::LoopStatus>(status);
322 properties.shuffle->changed().connect([
this](
bool shuffle)
324 on_property_value_changed<Properties::Shuffle>(shuffle);
327 properties.can_play->changed().connect([
this](
bool can_play)
329 on_property_value_changed<Properties::CanPlay>(can_play);
332 properties.can_pause->changed().connect([
this](
bool can_pause)
334 on_property_value_changed<Properties::CanPause>(can_pause);
337 properties.can_go_next->changed().connect([
this](
bool can_go_next)
339 on_property_value_changed<Properties::CanGoNext>(can_go_next);
342 properties.can_go_previous->changed().connect([
this](
bool can_go_previous)
344 on_property_value_changed<Properties::CanGoPrevious>(can_go_previous);
348 template<
typename Property>
351 Dictionary dict; dict[Property::name()] = dbus::types::Variant::encode(value);
353 signals.properties_changed->emit(std::make_tuple(
354 dbus::traits::Service<Player>::interface_name(),
356 the_empty_list_of_invalidated_properties()));
362 dict[Properties::CanPlay::name()] = dbus::types::Variant::encode(properties.can_play->get());
363 dict[Properties::CanPause::name()] = dbus::types::Variant::encode(properties.can_pause->get());
364 dict[Properties::CanSeek::name()] = dbus::types::Variant::encode(properties.can_seek->get());
365 dict[Properties::CanControl::name()] = dbus::types::Variant::encode(properties.can_control->get());
366 dict[Properties::CanGoNext::name()] = dbus::types::Variant::encode(properties.can_go_next->get());
367 dict[Properties::CanGoPrevious::name()] = dbus::types::Variant::encode(properties.can_go_previous->get());
368 dict[Properties::PlaybackStatus::name()] = dbus::types::Variant::encode(properties.playback_status->get());
369 dict[Properties::TypedPlaybackStatus::name()] = dbus::types::Variant::encode(properties.typed_playback_status->get());
370 dict[Properties::LoopStatus::name()] = dbus::types::Variant::encode(properties.loop_status->get());
371 dict[Properties::TypedLoopStatus::name()] = dbus::types::Variant::encode(properties.typed_loop_status->get());
372 dict[Properties::AudioStreamRole::name()] = dbus::types::Variant::encode(properties.audio_stream_role->get());
373 dict[Properties::Orientation::name()] = dbus::types::Variant::encode(properties.orientation->get());
374 dict[Properties::Lifetime::name()] = dbus::types::Variant::encode(properties.lifetime->get());
375 dict[Properties::PlaybackRate::name()] = dbus::types::Variant::encode(properties.playback_rate->get());
376 dict[Properties::Shuffle::name()] = dbus::types::Variant::encode(properties.shuffle->get());
377 dict[Properties::Duration::name()] = dbus::types::Variant::encode(properties.duration->get());
378 dict[Properties::Position::name()] = dbus::types::Variant::encode(properties.position->get());
379 dict[Properties::MinimumRate::name()] = dbus::types::Variant::encode(properties.minimum_playback_rate->get());
380 dict[Properties::MaximumRate::name()] = dbus::types::Variant::encode(properties.maximum_playback_rate->get());
390 std::shared_ptr<core::dbus::Property<Properties::CanPlay>>
can_play;
391 std::shared_ptr<core::dbus::Property<Properties::CanPause>>
can_pause;
392 std::shared_ptr<core::dbus::Property<Properties::CanSeek>>
can_seek;
393 std::shared_ptr<core::dbus::Property<Properties::CanControl>>
can_control;
394 std::shared_ptr<core::dbus::Property<Properties::CanGoNext>>
can_go_next;
401 std::shared_ptr<core::dbus::Property<Properties::LoopStatus>>
loop_status;
404 std::shared_ptr<core::dbus::Property<Properties::Orientation>>
orientation;
405 std::shared_ptr<core::dbus::Property<Properties::Lifetime>>
lifetime;
406 std::shared_ptr<core::dbus::Property<Properties::PlaybackRate>>
playback_rate;
407 std::shared_ptr<core::dbus::Property<Properties::Shuffle>>
shuffle;
409 std::shared_ptr<core::dbus::Property<Properties::Volume>>
volume;
410 std::shared_ptr<core::dbus::Property<Properties::Position>>
position;
411 std::shared_ptr<core::dbus::Property<Properties::Duration>>
duration;
418 typename core::dbus::Signal<Signals::Seeked, Signals::Seeked::ArgumentType>::Ptr
seeked_to;
419 typename core::dbus::Signal<Signals::AboutToFinish, Signals::AboutToFinish::ArgumentType>::Ptr
about_to_finish;
420 typename core::dbus::Signal<Signals::EndOfStream, Signals::EndOfStream::ArgumentType>::Ptr
end_of_stream;
421 typename core::dbus::Signal<Signals::PlaybackStatusChanged, Signals::PlaybackStatusChanged::ArgumentType>::Ptr
playback_status_changed;
422 typename core::dbus::Signal<Signals::VideoDimensionChanged, Signals::VideoDimensionChanged::ArgumentType>::Ptr
video_dimension_changed;
423 typename core::dbus::Signal<Signals::Error, Signals::Error::ArgumentType>::Ptr
error;
427 core::dbus::interfaces::Properties::Signals::PropertiesChanged,
428 core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
435 #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::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)
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
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
std::shared_ptr< core::dbus::Property< Properties::TypedMetaData > > typed_meta_data_for_current_track
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