hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 9e6f44eba9f5e5717eb7deba8c76c096a98d6dc0 Mon Sep 17 00:00:00 2001
From: ctf <ctf@rock-chips.com>
Date: Tue, 8 Oct 2019 12:43:32 +0800
Subject: [PATCH 10/19] fix D-Bus failed to register media player interface
 
Signed-off-by: ctf <ctf@rock-chips.com>
---
 profiles/audio/avrcp.c | 45 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
 
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index d0f7f0c..729f586 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -3335,6 +3335,35 @@ static const struct media_player_callback ct_cbs = {
     .get_play_status = ct_get_play_status,
 };
 
+
+static struct avrcp_player *find_ct_player_by_path(struct avrcp *session, uint16_t id, char *path)
+{
+    GSList *l;
+    char *player_path = g_strdup_printf("%s/player%u", path, id);
+
+    for (l = session->controller->players; l; l = l->next) {
+        struct avrcp_player *player = l->data;
+
+        if(!player->user_data) {
+            DBG("player->user_data = NULL");
+            continue;
+        }
+
+        if(!strcmp(media_player_get_path(player->user_data), player_path)) {
+            if (player->id != id)
+                player->id = id;
+
+            DBG("Find player, id = %d, path = %s", id, player_path);
+            g_free(player_path);
+            return player;
+        }
+    }
+
+    DBG("No matching player, id = %d, path = %s", id, player_path);
+    g_free(player_path);
+    return NULL;
+}
+
 static struct avrcp_player *create_ct_player(struct avrcp *session,
                                 uint16_t id)
 {
@@ -3342,12 +3371,18 @@ static struct avrcp_player *create_ct_player(struct avrcp *session,
     struct media_player *mp;
     const char *path;
 
+    path = device_get_path(session->dev);
+    if(!path)
+        return NULL;
+
+    player = find_ct_player_by_path(session, id, path);
+    if(player != NULL)
+        return player;
+
     player = g_new0(struct avrcp_player, 1);
     player->id = id;
     player->sessions = g_slist_prepend(player->sessions, session);
 
-    path = device_get_path(session->dev);
-
     mp = media_player_controller_create(path, id);
     if (mp == NULL)
         return NULL;
@@ -3374,12 +3409,16 @@ static struct avrcp_player *find_ct_player(struct avrcp *session, uint16_t id)
         struct avrcp_player *player = l->data;
 
         if (player->id == 0) {
+            DBG("Find player, player->id = 0, id = %d", id);
             player->id = id;
+
             return player;
         }
 
-        if (player->id == id)
+        if (player->id == id) {
+            DBG("Find player, player->id = %d", player->id);
             return player;
+        }
     }
 
     return NULL;
-- 
2.20.1