diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index a3ed16a..44f8929 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
.total_items = ct_get_total_numberofitems,
};
+static void set_ct_player(struct avrcp *session, struct avrcp_player *player)
+{
+ struct btd_service *service;
+
+ session->controller->player = player;
+ service = btd_device_get_service(session->dev, AVRCP_TARGET_UUID);
+ control_set_player(service, media_player_get_path(player->user_data));
+}
+
static struct avrcp_player *create_ct_player(struct avrcp *session,
uint16_t id)
{
player->destroy = (GDestroyNotify) media_player_destroy;
if (session->controller->player == NULL)
- session->controller->player = player;
+ set_ct_player(session, player);
session->controller->players = g_slist_prepend(
session->controller->players,
/* Check if current player is being removed */
if (controller->player == player)
- controller->player = g_slist_nth_data(
- controller->players, 0);
+ set_ct_player(session, g_slist_nth_data(
+ controller->players, 0));
}
player_destroy(player);
}
player->uid_counter = get_be16(&pdu->params[3]);
- session->controller->player = player;
+ set_ct_player(session, player);
if (player->features != NULL)
return;
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index d109d1f..edc4a98 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
#include "avctp.h"
#include "control.h"
+#include "player.h"
static GSList *devices = NULL;
struct btd_service *target;
struct btd_service *remote;
unsigned int avctp_id;
+ const char *player;
};
static void state_changed(struct btd_device *dev, avctp_state_t old_state,
switch (new_state) {
case AVCTP_STATE_DISCONNECTED:
control->session = NULL;
+ control->player = NULL;
g_dbus_emit_property_changed(conn, path,
AUDIO_CONTROL_INTERFACE, "Connected");
+ g_dbus_emit_property_changed(conn, path,
+ AUDIO_CONTROL_INTERFACE, "Player");
break;
case AVCTP_STATE_CONNECTING:
return TRUE;
}
+static gboolean control_player_exists(const GDBusPropertyTable *property,
+ void *data)
+{
+ struct control *control = data;
+
+ return control->player != NULL;
+}
+
+static gboolean control_get_player(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct control *control = data;
+
+ if (!control->player)
+ return FALSE;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+ &control->player);
+
+ return TRUE;
+}
+
static const GDBusMethodTable control_methods[] = {
{ GDBUS_DEPRECATED_METHOD("Play", NULL, NULL, control_play) },
{ GDBUS_DEPRECATED_METHOD("Pause", NULL, NULL, control_pause) },
static const GDBusPropertyTable control_properties[] = {
{ "Connected", "b", control_property_get_connected },
+ { "Player", "o", control_get_player, NULL, control_player_exists },
{ }
};
return 0;
}
+
+int control_set_player(struct btd_service *service, const char *path)
+{
+ struct control *control = btd_service_get_user_data(service);
+
+ if (!control->session)
+ return -ENOTCONN;
+
+ if (g_strcmp0(control->player, path) == 0)
+ return -EALREADY;
+
+ control->player = path;
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ device_get_path(control->dev),
+ AUDIO_CONTROL_INTERFACE, "Player");
+
+ return 0;
+}
diff --git a/profiles/audio/control.h b/profiles/audio/control.h
index 4bda896..aab2631 100644
--- a/profiles/audio/control.h
+++ b/profiles/audio/control.h
int control_connect(struct btd_service *service);
int control_disconnect(struct btd_service *service);
+
+int control_set_player(struct btd_service *service, const char *path);
diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 147bcbf..4736396 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
return mp;
}
+const char *media_player_get_path(struct media_player *mp)
+{
+ return mp->path;
+}
+
void media_player_set_duration(struct media_player *mp, uint32_t duration)
{
char *value, *curval;
diff --git a/profiles/audio/player.h b/profiles/audio/player.h
index 0871904..4ad8bfe 100644
--- a/profiles/audio/player.h
+++ b/profiles/audio/player.h
struct media_player *media_player_controller_create(const char *path,
uint16_t id);
+const char *media_player_get_path(struct media_player *mp);
void media_player_destroy(struct media_player *mp);
void media_player_set_duration(struct media_player *mp, uint32_t duration);
void media_player_set_position(struct media_player *mp, uint32_t position);