From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/4] android/avrcp: Add support to receive volume changed notifications
Date: Fri, 7 Mar 2014 14:15:41 +0200 [thread overview]
Message-ID: <1394194543-3095-2-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1394194543-3095-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This checks if remote stack supports volume changed notification and
in case it does register to receive notification when volume changes.
---
android/avrcp.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/android/avrcp.c b/android/avrcp.c
index 1d211ad..978e6c0 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -700,6 +700,83 @@ static const struct avrcp_control_handler control_handlers[] = {
{ },
};
+static gboolean register_notification_rsp(struct avctp *conn,
+ uint8_t code, uint8_t subunit,
+ uint8_t *operands, size_t operand_count,
+ void *user_data)
+{
+ struct avrcp_device *dev = user_data;
+ struct hal_ev_avrcp_volume_changed ev;
+ uint8_t *params;
+
+ if (code != AVC_CTYPE_INTERIM && code != AVC_CTYPE_CHANGED)
+ return FALSE;
+
+ if (operands == NULL || operand_count < 7)
+ return FALSE;
+
+ params = &operands[7];
+
+ if (params == NULL || params[0] != AVRCP_EVENT_VOLUME_CHANGED)
+ return FALSE;
+
+ switch (code) {
+ case AVC_CTYPE_INTERIM:
+ ev.type = HAL_AVRCP_EVENT_TYPE_INTERIM;
+ break;
+ case AVC_CTYPE_CHANGED:
+ ev.type = HAL_AVRCP_EVENT_TYPE_CHANGED;
+ break;
+ default:
+ return FALSE;
+ }
+
+ ev.volume = params[1] & 0x7F;
+
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_EV_AVRCP_VOLUME_CHANGED,
+ sizeof(ev), &ev);
+
+ if (code == AVC_CTYPE_INTERIM)
+ return TRUE;
+
+ avrcp_register_notification(dev->session, params[0], 0,
+ register_notification_rsp, dev);
+ return FALSE;
+}
+
+static gboolean get_capabilities_rsp(struct avctp *conn,
+ uint8_t code, uint8_t subunit,
+ uint8_t *operands, size_t operand_count,
+ void *user_data)
+{
+ struct avrcp_device *dev = user_data;
+ uint8_t *params;
+ uint8_t count;
+
+ if (operands == NULL || operand_count < 7)
+ return FALSE;
+
+ params = &operands[7];
+
+ if (params == NULL || params[0] != CAP_EVENTS_SUPPORTED)
+ return FALSE;
+
+ for (count = params[1]; count > 0; count--) {
+ uint8_t event = params[1 + count];
+
+ if (event != AVRCP_EVENT_VOLUME_CHANGED)
+ continue;
+
+ avrcp_register_notification(dev->session, event, 0,
+ register_notification_rsp,
+ dev);
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
static int avrcp_device_add_session(struct avrcp_device *dev, int fd,
uint16_t imtu, uint16_t omtu)
{
@@ -732,6 +809,14 @@ static int avrcp_device_add_session(struct avrcp_device *dev, int fd,
ev.features |= HAL_AVRCP_FEATURE_METADATA;
+ if (dev->version < 0x0104)
+ goto done;
+
+ ev.features |= HAL_AVRCP_FEATURE_ABSOLUTE_VOLUME;
+
+ avrcp_get_capabilities(dev->session, CAP_EVENTS_SUPPORTED,
+ get_capabilities_rsp, dev);
+
done:
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_AVRCP,
HAL_EV_AVRCP_REMOTE_FEATURES,
--
1.8.5.3
next prev parent reply other threads:[~2014-03-07 12:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-07 12:15 [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_register_notification function Luiz Augusto von Dentz
2014-03-07 12:15 ` Luiz Augusto von Dentz [this message]
2014-03-07 12:15 ` [PATCH BlueZ 3/4] android/avrcp-lib: Add avrcp_set_volume function Luiz Augusto von Dentz
2014-03-07 12:15 ` [PATCH BlueZ 4/4] android/avrcp: Add support to set volume command Luiz Augusto von Dentz
2014-03-07 12:22 ` [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_register_notification function Andrei Emeltchenko
2014-03-07 13:00 ` Luiz Augusto von Dentz
2014-03-07 13:09 ` Andrei Emeltchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394194543-3095-2-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox