audio/media: Add support for tracking Seeked signal
Luiz Augusto von Dentz
maintainerPATCH 1/3 audio/media: Add support for tracking Seeked signal
From: Luiz Augusto von Dentz <[email protected]>
This tracks Seeked signal and update the position in case it happens.
--- profiles/audio/media.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
profiles/audio/media.c +21 -0
@@ -96,6 +96,7 @@ struct media_player {guint watch;guint properties_watch;guint track_watch; +guint seek_watch;char *status;uint32_t position;uint32_t duration;
@@ -949,6 +950,7 @@ static void media_player_free(gpointer data)g_dbus_remove_watch (conn, mp->watch);g_dbus_remove_watch (conn, mp->properties_watch);g_dbus_remove_watch (conn, mp->track_watch); +g_dbus_remove_watch (conn, mp->seek_watch);if (mp->track)g_hash_table_unref (mp->track);
@@ -1681,6 +1683,21 @@ static gboolean properties_changed(DBusConnection *connection, DBusMessage *msg,return TRUE; } +static gboolean position_changed (DBusConnection *connection,DBusMessage *msg, +void *user_data) +{ +struct media_player *mp = user_data; +DBusMessageIter iter; + +DBG ("sender=%s path=%s" , mp->sender, mp->path); + +dbus_message_iter_init (msg, &iter); + +set_position (mp, &iter); + +return TRUE; +} + static struct media_player *media_player_create(struct media_adapter *adapter, const char *sender, const char *path,
@@ -1702,6 +1719,10 @@ static struct media_player *media_player_create(struct media_adapter *adapter, path,MEDIA_PLAYER_INTERFACE , properties_changed, mp, NULL); + mp->seek_watch =g_dbus_add_signal_watch (conn, sender, + path,MEDIA_PLAYER_INTERFACE , +"Seeked" , position_changed, + mp,NULL ); mp->player =avrcp_register_player (adapter->btd_adapter, &player_cb, mp, media_player_free);if (!mp->player) {
Signature · 1 line
1.8.3.1
Luiz Augusto von Dentz
maintainerPATCH 2/3 audio/media: Send status changed if position changes
From: Luiz Augusto von Dentz <[email protected]>
If position changes send a status changed event to force the position to be resynced.
--- profiles/audio/media.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
profiles/audio/media.c +15 -2
@@ -1306,13 +1306,21 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)static gboolean set_position (struct media_player *mp,DBusMessageIter *iter) {uint64_t value; +const char *status;if (dbus_message_iter_get_arg_type (iter) !=DBUS_TYPE_INT64 )return FALSE;dbus_message_iter_get_basic (iter, &value); - mp->position = value /1000 ; + value /=1000 ; + +if (value >get_position (mp)) + status ="forward-seek" ; +else + status ="reverse-seek" ; + + mp->position = value;g_timer_start (mp->timer);DBG ("Position=%u" , mp->position);
@@ -1327,9 +1335,14 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)* If position is the maximum value allowed or greater than track's * duration, we send a track-reached-end event. */ -if (mp->position ==UINT32_MAX || mp->position >= mp->duration) +if (mp->position ==UINT32_MAX || mp->position >= mp->duration) {avrcp_player_event (mp->player,AVRCP_EVENT_TRACK_REACHED_END ,NULL ); +return TRUE; + } + +/* Send a status change to force resync the position */ +avrcp_player_event (mp->player,AVRCP_EVENT_STATUS_CHANGED , status);return TRUE; }
Signature · 1 line
1.8.3.1
Luiz Augusto von Dentz
maintainerPATCH 3/3 tools/mpris-player: Forward player signals
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Forward signals received from player in the session bus to the system bus where bluetoothd can catch them.
--- tools/mpris-player.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
tools/mpris-player.c +15 -12
@@ -543,8 +543,8 @@ static void remove_player(DBusConnection *conn, const char *sender)g_free (owner); } -static gboolean properties_changed (DBusConnection *conn, -DBusMessage *msg,void *user_data) +static gboolean player_signal (DBusConnection *conn,DBusMessage *msg, +void *user_data) {DBusMessage *signal;DBusMessageIter iter, args;
@@ -558,17 +558,15 @@ static gboolean properties_changed(DBusConnection *conn,if (owner ==NULL ) goto done; - signal =dbus_message_new_signal (path,DBUS_INTERFACE_PROPERTIES , -"PropertiesChanged" ); + signal =dbus_message_new_signal (path,dbus_message_get_interface (msg), +dbus_message_get_member (msg));if (signal ==NULL ) { -fprintf (stderr,"Unable to allocate new %s.PropertisChanged" -" signal" ,DBUS_INTERFACE_PROPERTIES ); +fprintf (stderr,"Unable to allocate new %s.%s signal" , +dbus_message_get_interface (msg), +dbus_message_get_member (msg)); goto done; } -if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return DBUS_HANDLER_RESULT_NOT_YET_HANDLED ; -dbus_message_iter_init_append (signal, &args);append_iter (&args, &iter);
@@ -2512,7 +2510,7 @@ int main(int argc, char *argv[]) {GOptionContext *context;GError *error =NULL ; -guint owner_watch, properties_watch; +guint owner_watch, properties_watch, signal_watch;struct sigaction sa; context =g_option_context_new (NULL );
@@ -2554,10 +2552,14 @@ int main(int argc, char *argv[]) name_owner_changed, NULL, NULL); - properties_watch =g_dbus_add_properties_watch (session,NULL ,NULL ,MPRIS_PLAYER_INTERFACE , - properties_changed, + player_signal, +NULL ,NULL ); + + signal_watch =g_dbus_add_signal_watch (session,NULL ,NULL , +MPRIS_PLAYER_INTERFACE , +NULL , player_signal,NULL ,NULL );memset (&sa,0 ,sizeof (sa));
@@ -2578,6 +2580,7 @@ int main(int argc, char *argv[])g_dbus_remove_watch (session, owner_watch);g_dbus_remove_watch (session, properties_watch); +g_dbus_remove_watch (session, signal_watch);g_dbus_client_unref (client);
Signature · 1 line
1.8.3.1
Luiz Augusto von Dentz
maintainerHi,
Quoted 61 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This tracks Seeked signal and update the position in case it happens.
--- profiles/audio/media.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)profiles/audio/media.c +21
-1@@ -96,6 +96,7 @@ struct media_player {guint watch;guint properties_watch;guint track_watch; +guint seek_watch;char *status;uint32_t position;uint32_t duration;@@ -949,6 +950,7 @@ static void media_player_free(gpointer data)g_dbus_remove_watch (conn, mp->watch);g_dbus_remove_watch (conn, mp->properties_watch);g_dbus_remove_watch (conn, mp->track_watch); +g_dbus_remove_watch (conn, mp->seek_watch);if (mp->track)g_hash_table_unref (mp->track);@@ -1681,6 +1683,21 @@ static gboolean properties_changed(DBusConnection *connection, DBusMessage *msg,return TRUE; } +static gboolean position_changed (DBusConnection *connection,DBusMessage *msg, +void *user_data) +{ +struct media_player *mp = user_data; +DBusMessageIter iter; + +DBG ("sender=%s path=%s" , mp->sender, mp->path); + +dbus_message_iter_init (msg, &iter); + +set_position (mp, &iter); + +return TRUE; +} + static struct media_player *media_player_create(struct media_adapter *adapter, const char *sender, const char *path,@@ -1702,6 +1719,10 @@ static struct media_player *media_player_create(struct media_adapter *adapter, path,MEDIA_PLAYER_INTERFACE , properties_changed, mp, NULL); + mp->seek_watch =g_dbus_add_signal_watch (conn, sender, + path,MEDIA_PLAYER_INTERFACE , +"Seeked" , position_changed, + mp,NULL ); mp->player =avrcp_register_player (adapter->btd_adapter, &player_cb, mp, media_player_free);if (!mp->player) { --
Quoted 1 line
1.8.3.1
Pushed.
Signature · 1 line
Luiz Augusto von Dentz