Return-Path: From: Michal Labedzki To: CC: Michal Labedzki Subject: [PATCH 11/13] AVRCP: Handle SetAddressedPlayer command from remote controller Date: Wed, 6 Jun 2012 18:06:09 +0200 Message-ID: <1338998771-18683-11-git-send-email-michal.labedzki@tieto.com> In-Reply-To: <1338998771-18683-1-git-send-email-michal.labedzki@tieto.com> References: <1338998771-18683-1-git-send-email-michal.labedzki@tieto.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-bluetooth-owner@vger.kernel.org List-ID: Set player selected by controller as addressed player. --- audio/avrcp.c | 33 +++++++++++++++++++++++++++++++++ audio/avrcp.h | 1 + audio/media.c | 15 ++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/audio/avrcp.c b/audio/avrcp.c index b095884..249ed8e 100644 --- a/audio/avrcp.c +++ b/audio/avrcp.c @@ -1118,6 +1118,37 @@ err: return AVC_CTYPE_REJECTED; } +static uint8_t avrcp_handle_set_addressed_player(struct avrcp_player *player, + struct avrcp_header *pdu, + uint8_t transaction) +{ + uint16_t len = ntohs(pdu->params_len); + uint16_t player_id; + + if (len != sizeof(player_id)) { + pdu->params[0] = STATUS_INVALID_PARAMETER; + return AVC_CTYPE_REJECTED; + } + + player_id = bt_get_be16(pdu->params); + + DBG("Remote controller set addressed player id=%u", player_id); + + pdu->params_len = htons(1); + + if (!player->cb->set_addressed_player(player_id, player->user_data)) { + if (g_slist_length(player->server->players) == 0) + pdu->params[0] = STATUS_NO_AVAILABLE_PLAYERS; + else + pdu->params[0] = STATUS_INVALID_PLAYER_ID; + + return AVC_CTYPE_REJECTED; + } + + pdu->params[0] = STATUS_OK; + return AVC_CTYPE_ACCEPTED; +} + static struct pdu_handler { uint8_t pdu_id; uint8_t code; @@ -1153,6 +1184,8 @@ static struct pdu_handler { avrcp_handle_request_continuing }, { AVRCP_ABORT_CONTINUING, AVC_CTYPE_CONTROL, avrcp_handle_abort_continuing }, + { AVRCP_SET_ADDRESSED_PLAYER, AVC_CTYPE_CONTROL, + avrcp_handle_set_addressed_player }, { }, }; diff --git a/audio/avrcp.h b/audio/avrcp.h index e83e2de..d6b62e2 100644 --- a/audio/avrcp.h +++ b/audio/avrcp.h @@ -104,6 +104,7 @@ struct avrcp_player_cb { void *user_data); uint16_t (*get_player_id) (void *user_data); uint16_t (*get_uid_counter) (void *user_data); + gboolean (*set_addressed_player) (uint16_t player_id, void *user_data); }; int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config); diff --git a/audio/media.c b/audio/media.c index 516f12e..c59997b 100644 --- a/audio/media.c +++ b/audio/media.c @@ -1469,6 +1469,18 @@ static gboolean media_set_addressed_player(struct media_adapter *adapter, return TRUE; } +static gboolean set_addressed_player(uint16_t player_id, void *user_data) +{ + struct media_player *player = user_data; + struct media_player *mp; + + mp = media_adapter_find_player_by_id(player->adapter, NULL, player_id); + if (!mp) + return FALSE; + + return media_set_addressed_player(player->adapter, player->sender, mp->path, FALSE); +} + static struct avrcp_player_cb player_cb = { .get_setting = get_setting, .set_setting = set_setting, @@ -1479,7 +1491,8 @@ static struct avrcp_player_cb player_cb = { .get_status = get_status, .set_volume = set_volume, .get_player_id = get_player_id, - .get_uid_counter = get_uid_counter + .get_uid_counter = get_uid_counter, + .set_addressed_player = set_addressed_player }; static void media_player_exit(DBusConnection *connection, void *user_data) -- on behalf of ST-Ericsson