From 46c08c01c51b43d08383e26f93f83e140d676c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Date: Fri, 11 Jan 2013 17:25:30 -0300 Subject: [PATCH] avrcp: Handle RegisterNotification for volume This commit answers a NOTIFY command to register for nofications of EVENT_VOLUME_CHANGED with an INTERIM response containing the current absolute volume value. --- profiles/audio/avrcp.c | 15 +++++++++++++++ profiles/audio/media.c | 4 ++-- profiles/audio/transport.c | 6 +++--- profiles/audio/transport.h | 5 ++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c index bb8ab245a..b1016dfeb 100644 --- a/profiles/audio/avrcp.c +++ b/profiles/audio/avrcp.c @@ -62,6 +62,7 @@ #include "avdtp.h" #include "sink.h" #include "player.h" +#include "transport.h" /* Company IDs for vendor dependent commands */ #define IEEEID_BTSIG 0x001958 @@ -1247,6 +1248,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp *session, uint8_t transaction) { struct avrcp_player *player = session->player; + struct audio_device *dev = session->dev; uint16_t len = ntohs(pdu->params_len); uint64_t uid; GList *settings; @@ -1292,6 +1294,17 @@ static uint8_t avrcp_handle_register_notification(struct avrcp *session, pdu->params[++len] = val; } + break; + case AVRCP_EVENT_VOLUME_CHANGED: + if (session->version < 0x0104) + goto err; + + pdu->params[1] = media_transport_get_device_volume(dev); + if (pdu->params[1] > 127) + goto err; + + len = 2; + break; default: /* All other events are not supported yet */ @@ -1414,6 +1427,8 @@ static const struct control_pdu_handler tg_control_handlers[] = { static const struct control_pdu_handler ct_control_handlers[] = { { AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS, avrcp_handle_get_capabilities }, + { AVRCP_REGISTER_NOTIFICATION, AVC_CTYPE_NOTIFY, + avrcp_handle_register_notification }, { }, }; diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 4b91656c0..15dab8cd2 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -411,8 +411,8 @@ static gboolean set_configuration(struct media_endpoint *endpoint, if (transport != NULL) return FALSE; - transport = media_transport_create(endpoint, device, - configuration, size); + transport = media_transport_create(device, configuration, size, + endpoint); if (transport == NULL) return FALSE; diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 7e44f207e..eae98ed13 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -768,11 +768,11 @@ static void source_state_changed(struct audio_device *dev, transport_update_playing(transport, FALSE); } -struct media_transport *media_transport_create(struct media_endpoint *endpoint, - struct audio_device *device, +struct media_transport *media_transport_create(struct audio_device *device, uint8_t *configuration, - size_t size) + size_t size, void *data) { + struct media_endpoint *endpoint = data; struct media_transport *transport; const char *uuid; static int fd = 0; diff --git a/profiles/audio/transport.h b/profiles/audio/transport.h index 78c6fa7fb..cd2fd6ee1 100644 --- a/profiles/audio/transport.h +++ b/profiles/audio/transport.h @@ -24,10 +24,9 @@ struct media_transport; -struct media_transport *media_transport_create(struct media_endpoint *endpoint, - struct audio_device *device, +struct media_transport *media_transport_create(struct audio_device *device, uint8_t *configuration, - size_t size); + size_t size, void *data); void media_transport_destroy(struct media_transport *transport); const char *media_transport_get_path(struct media_transport *transport); -- 2.47.3