AVRCP: Add define for VolumeChanged event
Luiz Augusto von Dentz
maintainerPATCH 1/3 AVRCP: Add define for VolumeChanged event
From: Luiz Augusto von Dentz <[email protected]>
--- audio/avrcp.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
audio/avrcp.h +2 -1
@@ -73,7 +73,8 @@#define AVRCP_EVENT_TRACK_CHANGED 0x02#define AVRCP_EVENT_TRACK_REACHED_END 0x03#define AVRCP_EVENT_TRACK_REACHED_START 0x04 -#define AVRCP_EVENT_LAST AVRCP_EVENT_TRACK_REACHED_START +#define AVRCP_EVENT_VOLUME_CHANGED 0x0d +#define AVRCP_EVENT_LAST AVRCP_EVENT_VOLUME_CHANGEDstruct avrcp_player_cb {int (*get_setting) (uint8_t attr,void *user_data);
Signature · 1 line
1.7.7.6
Luiz Augusto von Dentz
maintainerPATCH 2/3 AVRCP: Subscribe for VolumeChanged Notification
From: Luiz Augusto von Dentz <[email protected]>
If the remote device support version 1.4 or latter send register command for VolumeChanged event:
< AVCTP: Command : pt 0x00 transaction 0 pid 0x110e
AV/C: Notify: address 0x48 opcode 0x00
Subunit: Panel
Opcode: Vendor Dependent
Company ID: 0x001958
AVRCP: RegisterNotification: pt Single len 0x0005
EventID: 0x0d (EVENT_VOLUME_CHANGED)
Interval: 0x00000000 (0 seconds)Quoted 1 line
AVCTP: Response : pt
0x00transaction 0 pid0x110e
AV/C: Interim: address 0x48 opcode 0x00
Subunit: Panel
Opcode: Vendor Dependent
Company ID: 0x001958
AVRCP: RegisterNotification: pt Single len 0x0002
EventID: 0x0d (EVENT_VOLUME_CHANGED)
Volume: 100.00% (127/127)
---
audio/avctp.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++-----
audio/avctp.h | 7 ++++
audio/avrcp.c | 69 +++++++++++++++++++++++++++++++++++++++++-
audio/avrcp.h | 1 +
audio/media.c | 31 ++++++++++++++++++-
audio/transport.c | 15 +++++++++
audio/transport.h | 2 +
7 files changed, 201 insertions(+), 10 deletions(-)audio/avctp.c +78 -8
@@ -121,6 +121,12 @@ struct avctp_server {GSList *sessions; }; +struct avctp_rsp_handler { +uint8_t id; +avctp_rsp_cb func; +void *user_data; +}; +struct avctp {struct avctp_server *server;bdaddr_t dst;
@@ -135,6 +141,7 @@ struct avctp {uint16_t mtu;uint8_t key_quirks[256 ]; +GSList *handlers; };struct avctp_pdu_handler {
@@ -162,6 +169,7 @@ static struct {static GSList *callbacks =NULL ;static GSList *servers =NULL ;static GSList *handlers =NULL ; +static uint8_t id =0 ;static void auth_cb (DBusError *derr,void *user_data);
@@ -349,6 +357,7 @@ static void avctp_disconnected(struct avctp *session) } server->sessions =g_slist_remove (server->sessions, session); +g_slist_free_full (session->handlers, g_free);g_free (session); }
@@ -396,6 +405,35 @@ static void avctp_set_state(struct avctp *session, avctp_state_t new_state) } } +static void handle_response (struct avctp *session,struct avctp_header *avctp, +struct avc_header *avc,uint8_t *operands, +size_t operand_count) +{ +GSList *l; + +for (l = session->handlers; l; l = l->next) { +struct avctp_rsp_handler *handler = l->data; + +if (handler->id == avctp->transaction) { +gboolean ret = FALSE; + +if (handler->func) + ret = handler->func (session, avc->code, + avc->subunit_type, + operands, operand_count, + handler->user_data); + +if (ret) +return ; + + session->handlers =g_slist_remove (session->handlers, + handler); +g_free (handler); +return ; + } + } +} +static gboolean session_cb (GIOChannel *chan,GIOCondition cond,gpointer data) {
@@ -448,8 +486,10 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond, avc->code, avc->subunit_type, avc->subunit_id, avc->opcode, operand_count); -if (avctp->cr ==AVCTP_RESPONSE ) +if (avctp->cr ==AVCTP_RESPONSE ) { +handle_response (session, avctp, avc, operands, operand_count);return TRUE; + } packet_size =AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH ; avctp->cr =AVCTP_RESPONSE ;
@@ -856,14 +896,13 @@ int avctp_send_passthrough(struct avctp *session, uint8_t op)struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH ];uint8_t *operands = &buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH ];int sk; -static uint8_t transaction =0 ;if (session->state !=AVCTP_STATE_CONNECTED )return -ENOTCONN ;memset (buf,0 ,sizeof (buf)); - avctp->transaction = transaction++; + avctp->transaction = id++; avctp->packet_type =AVCTP_PACKET_SINGLE ; avctp->cr =AVCTP_COMMAND ; avctp->pid =htons (AV_REMOTE_SVCLASS_ID );
@@ -881,7 +920,7 @@ int avctp_send_passthrough(struct avctp *session, uint8_t op)return -errno;/* Button release */ - avctp->transaction = transaction++; + avctp->transaction = id++; operands[0 ] |=0x80 ;if (write (sk, buf,sizeof (buf)) <0 )
@@ -890,8 +929,8 @@ int avctp_send_passthrough(struct avctp *session, uint8_t op)return 0 ; } -int avctp_send_vendordep (struct avctp *session,uint8_t transaction, -uint8_t code,uint8_t subunit, +static int avctp_send (struct avctp *session,uint8_t transaction,uint8_t cr, +uint8_t code,uint8_t subunit,uint8_t opcode,uint8_t *operands,size_t operand_count) {uint8_t *buf;
@@ -914,12 +953,12 @@ int avctp_send_vendordep(struct avctp *session, uint8_t transaction, avctp->transaction = transaction; avctp->packet_type =AVCTP_PACKET_SINGLE ; - avctp->cr =AVCTP_RESPONSE ; + avctp->cr = cr; avctp->pid =htons (AV_REMOTE_SVCLASS_ID ); avc->code = code; avc->subunit_type = subunit; - avc->opcode =AVC_OP_VENDORDEP ; + avc->opcode = opcode;memcpy (pdu, operands, operand_count);
@@ -930,6 +969,37 @@ int avctp_send_vendordep(struct avctp *session, uint8_t transaction,return err; } +int avctp_send_vendordep (struct avctp *session,uint8_t transaction, +uint8_t code,uint8_t subunit, +uint8_t *operands,size_t operand_count) +{ +return avctp_send (session, transaction,AVCTP_RESPONSE , code, subunit, +AVC_OP_VENDORDEP , operands, operand_count); +} + +int avctp_send_vendordep_req (struct avctp *session,uint8_t code, +uint8_t subunit,uint8_t *operands, +size_t operand_count, +avctp_rsp_cb func,void *user_data) +{ +struct avctp_rsp_handler *handler; +int err; + + err =avctp_send (session, id++,AVCTP_COMMAND , code, subunit, +AVC_OP_VENDORDEP , operands, operand_count); +if (err <0 ) +return err; + + handler = g_new0(struct avctp_rsp_handler, 1); + handler->id = id; + handler->func = func; + handler->user_data = user_data; + + session->handlers =g_slist_prepend (session->handlers, handler); + +return 0 ; +} +unsigned int avctp_add_state_cb (avctp_state_cb cb,void *user_data) {struct avctp_state_callback *state_cb;
audio/avctp.h +7 -0
@@ -78,6 +78,9 @@ typedef size_t (*avctp_pdu_cb) (struct avctp *session, uint8_t transaction, uint8_t *code, uint8_t *subunit, uint8_t *operands, size_t operand_count, void *user_data); +typedef gboolean (*avctp_rsp_cb ) (struct avctp *session,uint8_t code, +uint8_t subunit,uint8_t *operands, +size_t operand_count,void *user_data);unsigned int avctp_add_state_cb (avctp_state_cb cb,void *user_data);gboolean avctp_remove_state_cb (unsigned int id);
@@ -97,3 +100,7 @@ int avctp_send_passthrough(struct avctp *session, uint8_t op);int avctp_send_vendordep (struct avctp *session,uint8_t transaction,uint8_t code,uint8_t subunit,uint8_t *operands,size_t operand_count); +int avctp_send_vendordep_req (struct avctp *session,uint8_t code, +uint8_t subunit,uint8_t *operands, +size_t operand_count, +avctp_rsp_cb func,void *user_data);
audio/avrcp.c +68 -1
104 lines not on this page · raw message
audio/avrcp.h +1 -0
@@ -84,6 +84,7 @@ struct avrcp_player_cb { GList *(*list_metadata) (void *user_data);uint8_t (*get_status) (void *user_data);uint32_t (*get_position) (void *user_data); +void (*set_volume) (uint8_t volume,struct audio_device *dev,void *user_data); };int avrcp_register (DBusConnection *conn,const bdaddr_t *src,GKeyFile *config);
audio/media.c +30 -1
@@ -103,6 +103,7 @@ struct media_player {guint track_watch;uint8_t status;uint32_t position; +uint8_t volume;GTimer *timer; };
@@ -1340,6 +1341,33 @@ static uint32_t get_position(void *user_data)return mp->position + sec *1000 + msec; } +static void set_volume (uint8_t volume,struct audio_device *dev,void *user_data) +{ +struct media_player *mp = user_data; +GSList *l; + +if (mp->volume == volume) +return ; + + mp->volume = volume; + +for (l = mp->adapter->endpoints; l; l = l->next) { + +struct media_endpoint *endpoint; +struct media_transport *transport; + +if (l->data ==NULL ) +continue ; + + endpoint = l->data; + transport =find_device_transport (endpoint, dev); + +if (transport ==NULL ) +continue ; + +media_transport_update_volume (transport, volume); + } +}static struct avrcp_player_cb player_cb = { .get_setting = get_setting, .set_setting = set_setting,
@@ -1347,7 +1375,8 @@ static struct avrcp_player_cb player_cb = { .get_uid = get_uid, .get_metadata = get_metadata, .get_position = get_position, - .get_status = get_status + .get_status = get_status, + .set_volume = set_volume };static void media_player_exit (DBusConnection *connection,void *user_data)
audio/transport.c +15 -0
@@ -77,6 +77,7 @@ struct media_transport {uint16_t omtu;/* Transport output mtu */ uint16_t delay;/* Transport delay (a2dp only) */ unsigned int nrec_id;/* Transport nrec watch (headset only) */ +uint8_t volume;/* Transport volume */ gboolean read_lock;gboolean write_lock;gboolean in_use;
@@ -1063,3 +1064,17 @@ struct audio_device *media_transport_get_dev(struct media_transport *transport) {return transport->device; } + +void media_transport_update_volume (struct media_transport *transport, +uint8_t volume) +{ +/* Check if volume really changed */ +if (transport->volume == volume) +return ; + + transport->volume = volume; + +emit_property_changed (transport->conn, transport->path, +MEDIA_TRANSPORT_INTERFACE ,"Volume" , +DBUS_TYPE_BYTE , &transport->volume); +}
audio/transport.h +2 -0
@@ -35,5 +35,7 @@ const char *media_transport_get_path(struct media_transport *transport);struct audio_device *media_transport_get_dev (struct media_transport *transport);void media_transport_update_delay (struct media_transport *transport,uint16_t delay); +void media_transport_update_volume (struct media_transport *transport, +uint8_t volume);void transport_get_properties (struct media_transport *transport,DBusMessageIter *iter);
Signature · 1 line
1.7.7.6
Re: [PATCH BlueZ 2/3] AVRCP: Subscribe for VolumeChanged Notification
Hi Luiz,
audio/avrcp.c static void state_changed(struct audio_device *dev, avctp_state_t old_state, · line 1220
Quoted 13 lines · Luiz Augusto von Dentz
audio/avrcp.c +13
-0+DBG ("1" ); + +if (sdp_get_profile_descs (rec, &list) <0 ) +return ; + + desc = list->data; + +DBG ("2" ); + +if (desc && desc->version >=0x0104 ) { +DBG ("3" ); +register_volume_notification (player); + }
The "1", "2" and "3" logs should probably be removed or at least changed to something more meaningful.
Johan
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 2/3] AVRCP: Subscribe for VolumeChanged Notification
Hi,
Quoted 19 lines · Johan Hedberg
Hi Luiz,
audio/avrcp.c static void state_changed(struct audio_device *dev, avctp_state_t old_state, · line 1220
Quoted 13 lines · Luiz Augusto von Dentz
+
DBG("1");audio/avrcp.c +12
-0+ + if (sdp_get_profile_descs(rec, &list) < 0) + return; + + desc = list->data; + + DBG("2"); + + if (desc && desc->version >= 0x0104) { + DBG("3"); + register_volume_notification(player); + }The "1", "2" and "3" logs should probably be removed or at least changed to something more meaningful.
Opps
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerPATCH 3/3 AVRCP: Bump TG record to 1.4
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The only mandatory feature for 1.4 is absolute volume control which is now supported.
--- audio/avrcp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
audio/avrcp.c +1 -1
@@ -243,7 +243,7 @@ static sdp_record_t *avrcp_tg_record(void)sdp_record_t *record;sdp_data_t *psm, *version, *features;uint16_t lp =AVCTP_PSM ; -uint16_t avrcp_ver =0x0103 , avctp_ver =0x0103 , feat =0x000f ; +uint16_t avrcp_ver =0x0104 , avctp_ver =0x0103 , feat =0x000f ; record =sdp_record_alloc ();if (!record)
Signature · 1 line
1.7.7.6