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 <boost/utility/identity_type.hpp>
43 namespace dbus = core::dbus;
49 static const std::string&
name()
51 static const std::string s{
"org.mpris.MediaPlayer2.Player"};
63 case core::ubuntu::media::Player::LoopStatus::none:
65 case core::ubuntu::media::Player::LoopStatus::track:
67 case core::ubuntu::media::Player::LoopStatus::playlist:
74 static constexpr
const char*
none{
"None"};
75 static constexpr
const char*
track{
"Track"};
76 static constexpr
const char*
playlist{
"Playlist"};
87 case core::ubuntu::media::Player::PlaybackStatus::null:
88 case core::ubuntu::media::Player::PlaybackStatus::ready:
89 case core::ubuntu::media::Player::PlaybackStatus::stopped:
92 case core::ubuntu::media::Player::PlaybackStatus::playing:
94 case core::ubuntu::media::Player::PlaybackStatus::paused:
101 static constexpr
const char*
playing{
"Playing"};
102 static constexpr
const char*
paused{
"Paused"};
103 static constexpr
const char*
stopped{
"Stopped"};
106 typedef std::map<std::string, core::dbus::types::Variant>
Dictionary;
108 DBUS_CPP_METHOD_DEF(Next,
Player)
109 DBUS_CPP_METHOD_DEF(Previous,
Player)
110 DBUS_CPP_METHOD_DEF(Pause,
Player)
111 DBUS_CPP_METHOD_DEF(PlayPause,
Player)
112 DBUS_CPP_METHOD_DEF(Stop,
Player)
113 DBUS_CPP_METHOD_DEF(Play,
Player)
114 DBUS_CPP_METHOD_DEF(Seek,
Player)
115 DBUS_CPP_METHOD_DEF(SetPosition,
Player)
116 DBUS_CPP_METHOD_DEF(CreateVideoSink,
Player)
117 DBUS_CPP_METHOD_DEF(Key,
Player)
118 DBUS_CPP_METHOD_DEF(OpenUri,
Player)
122 DBUS_CPP_SIGNAL_DEF(Seeked,
Player, std::int64_t)
123 DBUS_CPP_SIGNAL_DEF(EndOfStream,
Player,
void)
135 DBUS_CPP_WRITABLE_PROPERTY_DEF(PlaybackRate,
Player,
double)
136 DBUS_CPP_WRITABLE_PROPERTY_DEF(Rate,
Player,
double)
137 DBUS_CPP_WRITABLE_PROPERTY_DEF(Shuffle,
Player,
bool)
140 DBUS_CPP_WRITABLE_PROPERTY_DEF(Volume,
Player,
double)
141 DBUS_CPP_READABLE_PROPERTY_DEF(Position,
Player, std::int64_t)
142 DBUS_CPP_READABLE_PROPERTY_DEF(Duration,
Player, std::int64_t)
143 DBUS_CPP_READABLE_PROPERTY_DEF(MinimumRate,
Player,
double)
144 DBUS_CPP_READABLE_PROPERTY_DEF(MaximumRate,
Player,
double)
145 DBUS_CPP_READABLE_PROPERTY_DEF(IsVideoSource,
Player,
bool)
146 DBUS_CPP_READABLE_PROPERTY_DEF(IsAudioSource,
Player,
bool)
147 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoNext,
Player,
bool)
148 DBUS_CPP_READABLE_PROPERTY_DEF(CanGoPrevious,
Player,
bool)
149 DBUS_CPP_READABLE_PROPERTY_DEF(CanPlay,
Player,
bool)
150 DBUS_CPP_READABLE_PROPERTY_DEF(CanPause,
Player,
bool)
151 DBUS_CPP_READABLE_PROPERTY_DEF(CanSeek,
Player,
bool)
152 DBUS_CPP_READABLE_PROPERTY_DEF(CanControl,
Player,
bool)
160 static const std::vector<std::string> instance;
return instance;
183 Properties::TypedPlaybackStatus::ValueType
typed_playback_status{core::ubuntu::media::Player::PlaybackStatus::null};
185 Properties::TypedLoopStatus::ValueType
typed_loop_status{core::ubuntu::media::Player::LoopStatus::none};
187 Properties::Shuffle::ValueType
shuffle{
false};
189 Properties::Volume::ValueType
volume{0.f};
198 : configuration(configuration),
201 configuration.
object->template get_property<Properties::CanPlay>(),
202 configuration.
object->template get_property<Properties::CanPause>(),
203 configuration.
object->template get_property<Properties::CanSeek>(),
204 configuration.
object->template get_property<Properties::CanControl>(),
205 configuration.
object->template get_property<Properties::CanGoNext>(),
206 configuration.
object->template get_property<Properties::CanGoPrevious>(),
207 configuration.
object->template get_property<Properties::IsVideoSource>(),
208 configuration.
object->template get_property<Properties::IsAudioSource>(),
209 configuration.
object->template get_property<Properties::PlaybackStatus>(),
210 configuration.
object->template get_property<Properties::TypedPlaybackStatus>(),
211 configuration.
object->template get_property<Properties::LoopStatus>(),
212 configuration.
object->template get_property<Properties::TypedLoopStatus>(),
213 configuration.
object->template get_property<Properties::AudioStreamRole>(),
214 configuration.
object->template get_property<Properties::PlaybackRate>(),
215 configuration.
object->template get_property<Properties::Shuffle>(),
216 configuration.
object->template get_property<Properties::TypedMetaData>(),
217 configuration.
object->template get_property<Properties::Volume>(),
218 configuration.
object->template get_property<Properties::Position>(),
219 configuration.
object->template get_property<Properties::Duration>(),
220 configuration.
object->template get_property<Properties::MinimumRate>(),
221 configuration.
object->template get_property<Properties::MaximumRate>()
225 configuration.
object->template get_signal<Signals::Seeked>(),
226 configuration.
object->template get_signal<Signals::EndOfStream>(),
227 configuration.
object->template get_signal<Signals::PlaybackStatusChanged>(),
228 configuration.
object->template get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()
243 properties.audio_stream_role->set(core::ubuntu::media::Player::AudioStreamRole::multimedia);
253 on_property_value_changed<Properties::Position>(
position);
258 on_property_value_changed<Properties::Duration>(
duration);
261 properties.playback_status->changed().connect([
this](
const std::string& status)
263 on_property_value_changed<Properties::PlaybackStatus>(status);
266 properties.loop_status->changed().connect([
this](
const std::string& status)
268 on_property_value_changed<Properties::LoopStatus>(status);
272 template<
typename Property>
275 Dictionary dict; dict[Property::name()] = dbus::types::Variant::encode(value);
277 signals.properties_changed->emit(std::make_tuple(
278 dbus::traits::Service<Player>::interface_name(),
286 dict[Properties::CanPlay::name()] = dbus::types::Variant::encode(
properties.can_play->get());
287 dict[Properties::CanPause::name()] = dbus::types::Variant::encode(
properties.can_pause->get());
288 dict[Properties::CanSeek::name()] = dbus::types::Variant::encode(
properties.can_seek->get());
289 dict[Properties::CanControl::name()] = dbus::types::Variant::encode(
properties.can_control->get());
290 dict[Properties::CanGoNext::name()] = dbus::types::Variant::encode(
properties.can_go_next->get());
291 dict[Properties::CanGoPrevious::name()] = dbus::types::Variant::encode(
properties.can_go_previous->get());
292 dict[Properties::PlaybackStatus::name()] = dbus::types::Variant::encode(
properties.playback_status->get());
293 dict[Properties::TypedPlaybackStatus::name()] = dbus::types::Variant::encode(
properties.typed_playback_status->get());
294 dict[Properties::LoopStatus::name()] = dbus::types::Variant::encode(
properties.loop_status->get());
295 dict[Properties::TypedLoopStatus::name()] = dbus::types::Variant::encode(
properties.typed_loop_status->get());
296 dict[Properties::AudioStreamRole::name()] = dbus::types::Variant::encode(
properties.audio_stream_role->get());
297 dict[Properties::PlaybackRate::name()] = dbus::types::Variant::encode(
properties.playback_rate->get());
298 dict[Properties::Shuffle::name()] = dbus::types::Variant::encode(
properties.is_shuffle->get());
299 dict[Properties::Duration::name()] = dbus::types::Variant::encode(
properties.duration->get());
300 dict[Properties::Position::name()] = dbus::types::Variant::encode(
properties.position->get());
301 dict[Properties::MinimumRate::name()] = dbus::types::Variant::encode(
properties.minimum_playback_rate->get());
302 dict[Properties::MaximumRate::name()] = dbus::types::Variant::encode(
properties.maximum_playback_rate->get());
312 std::shared_ptr<core::dbus::Property<Properties::CanPlay>>
can_play;
313 std::shared_ptr<core::dbus::Property<Properties::CanPause>>
can_pause;
314 std::shared_ptr<core::dbus::Property<Properties::CanSeek>>
can_seek;
315 std::shared_ptr<core::dbus::Property<Properties::CanControl>>
can_control;
316 std::shared_ptr<core::dbus::Property<Properties::CanGoNext>>
can_go_next;
323 std::shared_ptr<core::dbus::Property<Properties::LoopStatus>>
loop_status;
326 std::shared_ptr<core::dbus::Property<Properties::PlaybackRate>>
playback_rate;
327 std::shared_ptr<core::dbus::Property<Properties::Shuffle>>
is_shuffle;
329 std::shared_ptr<core::dbus::Property<Properties::Volume>>
volume;
330 std::shared_ptr<core::dbus::Property<Properties::Position>>
position;
331 std::shared_ptr<core::dbus::Property<Properties::Duration>>
duration;
338 typename core::dbus::Signal<Signals::Seeked, Signals::Seeked::ArgumentType>::Ptr
seeked_to;
339 typename core::dbus::Signal<Signals::EndOfStream, Signals::EndOfStream::ArgumentType>::Ptr
end_of_stream;
340 typename core::dbus::Signal<Signals::PlaybackStatusChanged, Signals::PlaybackStatusChanged::ArgumentType>::Ptr
playback_status_changed;
344 core::dbus::interfaces::Properties::Signals::PropertiesChanged,
345 core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
352 #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
Properties::CanGoPrevious::ValueType can_go_previous
std::shared_ptr< core::dbus::Property< Properties::IsAudioSource > > is_audio_source
Properties::CanControl::ValueType can_control
std::shared_ptr< core::dbus::Property< Properties::LoopStatus > > loop_status
Properties::MaximumRate::ValueType maximum_rate
Properties::Volume::ValueType volume
static const std::string & name()
static constexpr const char * none
std::shared_ptr< core::dbus::Property< Properties::MinimumRate > > minimum_playback_rate
Properties::Duration::ValueType duration
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
Properties::CanGoNext::ValueType can_go_next
static constexpr const char * stopped
static const char * from(core::ubuntu::media::Player::PlaybackStatus status)
Properties::CanPause::ValueType can_pause
static const std::vector< std::string > & the_empty_list_of_invalidated_properties()
std::shared_ptr< core::dbus::Property< Properties::Shuffle > > is_shuffle
Properties::TypedPlaybackStatus::ValueType typed_playback_status
Properties::PlaybackStatus::ValueType playback_status
struct mpris::Player::Skeleton::Configuration::Defaults defaults
struct mpris::Player::Skeleton::@14 properties
Properties::Position::ValueType position
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::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
Properties::PlaybackRate::ValueType playback_rate
Properties::TypedLoopStatus::ValueType typed_loop_status
Properties::CanSeek::ValueType can_seek
Dictionary get_all_properties()
struct mpris::Player::Skeleton::@15 signals
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
Properties::TypedMetaData::ValueType typed_meta_data
Properties::IsAudioSource::ValueType is_audio_source
Skeleton(const Configuration &configuration)
std::shared_ptr< core::dbus::Property< Properties::TypedPlaybackStatus > > typed_playback_status
Properties::MinimumRate::ValueType minimum_rate
std::shared_ptr< core::dbus::Property< Properties::PlaybackStatus > > playback_status
Properties::CanPlay::ValueType can_play
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
Properties::IsVideoSource::ValueType is_video_source
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
Properties::LoopStatus::ValueType loop_status
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
Properties::Shuffle::ValueType shuffle