OSDN Git Service

audio/player: Add support for setting current Item object
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sat, 25 May 2013 22:34:20 +0000 (15:34 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 17 Jun 2013 15:13:53 +0000 (18:13 +0300)
This introduces media_player_set_playlist_item which is used when the
current item UID is known, with this the application can tell what
is the current item in the playlist.

profiles/audio/avrcp.c
profiles/audio/player.c
profiles/audio/player.h

index cbac603..539684d 100644 (file)
@@ -1961,6 +1961,9 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
        struct media_player *mp = player->user_data;
        int i;
 
+       if (player->uid > 0)
+               media_player_set_playlist_item(mp, player->uid);
+
        for (i = 0; count > 0; count--) {
                uint32_t id;
                uint16_t charset, len;
index 9bd8b26..c151560 100644 (file)
@@ -102,16 +102,18 @@ struct media_player {
 static void append_metadata(void *key, void *value, void *user_data)
 {
        DBusMessageIter *dict = user_data;
+       const char *strkey = key;
 
-       if (strcasecmp((char *) key, "Duration") == 0 ||
-                       strcasecmp((char *) key, "TrackNumber") == 0 ||
-                       strcasecmp((char *) key, "NumberOfTracks") == 0)  {
+       if (strcasecmp(strkey, "Duration") == 0 ||
+                       strcasecmp(strkey, "TrackNumber") == 0 ||
+                       strcasecmp(strkey, "NumberOfTracks") == 0)  {
                uint32_t num = atoi(value);
                dict_append_entry(dict, key, DBUS_TYPE_UINT32, &num);
-               return;
+       } else if (strcasecmp(strkey, "Item") == 0) {
+               dict_append_entry(dict, key, DBUS_TYPE_OBJECT_PATH, &value);
+       } else {
+               dict_append_entry(dict, key, DBUS_TYPE_STRING, &value);
        }
-
-       dict_append_entry(dict, key, DBUS_TYPE_STRING, &value);
 }
 
 static struct pending_req *find_pending(struct media_player *mp,
@@ -1290,6 +1292,34 @@ static struct media_item *media_folder_find_item(struct media_folder *folder,
        return NULL;
 }
 
+void media_player_set_playlist_item(struct media_player *mp, uint64_t uid)
+{
+       struct media_folder *folder = mp->playlist;
+       struct media_item *item;
+
+       DBG("%" PRIu64 "", uid);
+
+       if (folder == NULL)
+               return;
+
+       item = media_folder_find_item(folder, uid);
+       if (item == NULL) {
+               warn("Item not found");
+               return;
+       }
+
+       if (item == g_hash_table_lookup(mp->track, "Item"))
+               return;
+
+       if (mp->process_id == 0) {
+               g_hash_table_remove_all(mp->track);
+               mp->process_id = g_idle_add(process_metadata_changed, mp);
+       }
+
+       g_hash_table_replace(mp->track, g_strdup("Item"),
+                                               g_strdup(item->path));
+}
+
 static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg,
                                                                void *data)
 {
index 4626a24..3a388d2 100644 (file)
@@ -77,6 +77,7 @@ void media_player_set_searchable(struct media_player *mp, bool enabled);
 void media_player_set_folder(struct media_player *mp, const char *path,
                                                                uint32_t items);
 void media_player_set_playlist(struct media_player *mp, const char *name);
+void media_player_set_playlist_item(struct media_player *mp, uint64_t uid);
 
 struct media_item *media_player_create_folder(struct media_player *mp,
                                                const char *name,