diff --git a/lib/gst/clapper/gstclapper-mpris-private.h b/lib/gst/clapper/gstclapper-mpris-private.h index a44a51fc..a121de8f 100644 --- a/lib/gst/clapper/gstclapper-mpris-private.h +++ b/lib/gst/clapper/gstclapper-mpris-private.h @@ -31,6 +31,9 @@ void gst_clapper_mpris_set_clapper (GstClapperMpris *self, GstC G_GNUC_INTERNAL void gst_clapper_mpris_set_playback_status (GstClapperMpris *self, const gchar *status); +G_GNUC_INTERNAL +void gst_clapper_mpris_set_media_info (GstClapperMpris *self, GstClapperMediaInfo *info); + G_END_DECLS #endif /* __GST_CLAPPER_MPRIS_PRIVATE_H__ */ diff --git a/lib/gst/clapper/gstclapper-mpris.c b/lib/gst/clapper/gstclapper-mpris.c index 5a495914..60968a4b 100644 --- a/lib/gst/clapper/gstclapper-mpris.c +++ b/lib/gst/clapper/gstclapper-mpris.c @@ -43,6 +43,8 @@ struct _GstClapperMpris GstClapperMprisMediaPlayer2 *base_skeleton; GstClapperMprisMediaPlayer2Player *player_skeleton; + GstClapperMediaInfo *media_info; + guint name_id; /* Properties */ @@ -52,6 +54,8 @@ struct _GstClapperMpris gchar *desktop_entry; gchar *default_art_url; + gboolean parse_media_info; + /* Current status */ gchar *playback_status; gboolean can_play; @@ -111,6 +115,9 @@ gst_clapper_mpris_init (GstClapperMpris * self) self->default_art_url = NULL; self->playback_status = g_strdup ("Stopped"); + self->can_play = FALSE; + self->parse_media_info = FALSE; + self->media_info = NULL; GST_TRACE_OBJECT (self, "Initialized"); } @@ -230,6 +237,8 @@ gst_clapper_mpris_finalize (GObject * object) g_object_unref (self->base_skeleton); if (self->player_skeleton) g_object_unref (self->player_skeleton); + if (self->media_info) + g_object_unref (self->media_info); g_mutex_clear (&self->lock); g_cond_clear (&self->cond); @@ -376,6 +385,51 @@ mpris_update_props_dispatch (gpointer user_data) GST_DEBUG_OBJECT (self, "Updating MPRIS props"); g_mutex_lock (&self->lock); + if (self->parse_media_info) { + GVariantBuilder builder; + guint64 duration; + const gchar *track_id, *uri, *title; + + GST_DEBUG_OBJECT (self, "Parsing media info"); + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + + track_id = _get_mpris_trackid (self); + uri = gst_clapper_media_info_get_uri (self->media_info); + title = gst_clapper_media_info_get_title (self->media_info); + + if (track_id) { + g_variant_builder_add (&builder, "{sv}", "mpris:trackid", + g_variant_new_string (track_id)); + GST_DEBUG_OBJECT (self, "mpris:trackid: %s", track_id); + } + if (uri) { + g_variant_builder_add (&builder, "{sv}", "xesam:url", + g_variant_new_string (uri)); + GST_DEBUG_OBJECT (self, "xesam:url: %s", uri); + } + if (title) { + g_variant_builder_add (&builder, "{sv}", "xesam:title", + g_variant_new_string (title)); + GST_DEBUG_OBJECT (self, "xesam:title: %s", title); + } + + duration = gst_clapper_media_info_get_duration (self->media_info); + duration = (duration != GST_CLOCK_TIME_NONE) ? duration / GST_USECOND : 0; + g_variant_builder_add (&builder, "{sv}", "mpris:length", g_variant_new_uint64 (duration)); + GST_DEBUG_OBJECT (self, "mpris:length: %ld", duration); + + /* TODO: Check for image sample */ + if (self->default_art_url) { + g_variant_builder_add (&builder, "{sv}", "mpris:artUrl", g_variant_new_string (self->default_art_url)); + GST_DEBUG_OBJECT (self, "mpris:artUrl: %s", self->default_art_url); + } + + GST_DEBUG_OBJECT (self, "Media info parsed"); + self->parse_media_info = FALSE; + + gst_clapper_mpris_media_player2_player_set_metadata ( + self->player_skeleton, g_variant_builder_end (&builder)); + } if (gst_clapper_mpris_media_player2_player_get_can_play ( self->player_skeleton) != self->can_play) { /* "can-play" is bound with "can-pause" */ @@ -391,6 +445,7 @@ mpris_update_props_dispatch (gpointer user_data) } g_mutex_unlock (&self->lock); + GST_DEBUG_OBJECT (self, "MPRIS props updated"); return G_SOURCE_REMOVE; } @@ -502,6 +557,19 @@ gst_clapper_mpris_set_playback_status (GstClapperMpris * self, const gchar * sta mpris_dispatcher_update_dispatch (self); } +void +gst_clapper_mpris_set_media_info (GstClapperMpris *self, GstClapperMediaInfo *info) +{ + g_mutex_lock (&self->lock); + if (self->media_info) + g_object_unref (self->media_info); + self->media_info = info; + self->parse_media_info = TRUE; + g_mutex_unlock (&self->lock); + + mpris_dispatcher_update_dispatch (self); +} + /** * gst_clapper_mpris_new: * @own_name: DBus own name diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index 1cd77591..8b6e14c6 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -1682,6 +1682,15 @@ state_changed_cb (G_GNUC_UNUSED GstBus * bus, GstMessage * msg, self->cached_duration = GST_CLOCK_TIME_NONE; } emit_media_info_updated (self); + if (self->mpris) { + GstClapperMediaInfo *info; + + g_mutex_lock (&self->lock); + info = gst_clapper_media_info_copy (self->media_info); + g_mutex_unlock (&self->lock); + + gst_clapper_mpris_set_media_info (self->mpris, info); + } } if (new_state == GST_STATE_PAUSED