audio/avrcp: Fix missing event for volume control
Luiz Augusto von Dentz
maintainerPATCH v2 1/5 audio/avrcp: Fix missing event for volume control
From: Luiz Augusto von Dentz <[email protected]>
CT and TG are always relative to client and server role, so although TG is associated with a player and CT with a remote controller in case of volume control the CT is in fact the player and the TG the remote controller, because of that PTS will not register any TG record when testing this thus controller_init will not register the necessary events.
--- profiles/audio/avrcp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
profiles/audio/avrcp.c +2 -4
@@ -3805,7 +3805,8 @@ static void target_init(struct avrcp *session) session->supported_events |= (1 <<AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED ) | - (1 <<AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED ); + (1 <<AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED ) | + (1 <<AVRCP_EVENT_VOLUME_CHANGED );/* Only check capabilities if controller is not supported */ if (session->controller ==NULL )
@@ -3831,9 +3832,6 @@ static void controller_init(struct avrcp *session)DBG ("%p version 0x%04x" , controller, controller->version); -if (controller->version >=0x0104 ) - session->supported_events |= (1 <<AVRCP_EVENT_VOLUME_CHANGED ); - service =btd_device_get_service (session->dev,AVRCP_TARGET_UUID );btd_service_connecting_complete (service,0 );
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH v2 2/5 audio/avrcp: Fix rejecting SetAbsoluteVolume without a player
From: Luiz Augusto von Dentz <[email protected]>
A player is not necessary in order for SetAbsoluteVolume to work.
--- profiles/audio/avrcp.c | 4 ---- 1 file changed, 4 deletions(-)
profiles/audio/avrcp.c +0 -4
@@ -1676,16 +1676,12 @@ static uint8_t avrcp_handle_set_absolute_volume(struct avrcp *session,struct avrcp_header *pdu, uint8_t transaction) { -struct avrcp_player *player = session->controller->player; uint16_t len = ntohs(pdu->params_len);uint8_t volume;if (len !=1 ) goto err; -if (!player) - goto err; - volume = pdu->params[0 ] &0x7F ;media_transport_update_device_volume (session->dev, volume);
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH v2 3/5 audio/avrcp: Enable volume notifications
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
When acting as a TG volume changes should be notified using RegisterNotification not SetAbsoluteVolume as the later is a CT operation.
--- profiles/audio/avrcp.c | 61 ++++++++++++++++++++++++++++++++++++++++++---- profiles/audio/avrcp.h | 2 +- profiles/audio/transport.c | 5 ++-- 3 files changed, 60 insertions(+), 8 deletions(-)
profiles/audio/avrcp.c +56 -5
@@ -4135,7 +4135,53 @@ static gboolean avrcp_handle_set_volume(struct avctp *conn,return FALSE; } -int avrcp_set_volume (struct btd_device *dev,uint8_t volume) +static int avrcp_event (struct avrcp *session,uint8_t id,const void *data) +{ +uint8_t buf[AVRCP_HEADER_LENGTH +2 ]; +struct avrcp_header *pdu = (void *) buf; +uint8_t code; +uint16_t size; +int err; + +/* Verify that the event is registered */ +if (!(session->registered_events & (1 << id))) +return -ENOENT ; + +memset (buf,0 ,sizeof (buf)); + +set_company_id (pdu->company_id,IEEEID_BTSIG ); + pdu->pdu_id =AVRCP_REGISTER_NOTIFICATION ; + code =AVC_CTYPE_CHANGED ; + pdu->params[0 ] = id; + +DBG ("id=%u" , id); + +switch (id) { +case AVRCP_EVENT_VOLUME_CHANGED : + size =2 ; +memcpy (&pdu->params[1 ], data,sizeof (uint8_t )); +break ; +default : +error ("Unknown event %u" , id); +return -EINVAL ; + } + + pdu->params_len =htons (size); + + err =avctp_send_vendordep (session->conn, + session->transaction_events[id], + code,AVC_SUBUNIT_PANEL , + buf, size +AVRCP_HEADER_LENGTH ); +if (err <0 ) +return err; + +/* Unregister event as per AVRCP 1.3 spec, section 5.4.2 */ + session->registered_events ^=1 << id; + +return err; +} + +int avrcp_set_volume (struct btd_device *dev,uint8_t volume,bool notify) {struct avrcp_server *server;struct avrcp *session;
@@ -4147,18 +4193,23 @@ int avrcp_set_volume(struct btd_device *dev, uint8_t volume)return -EINVAL ; session =find_session (server->sessions, dev); -if (session ==NULL || session->target ==NULL ) +if (session ==NULL )return -ENOTCONN ; -if (session->target->version <0x0104 ) +if (notify) { +if (!session->target) +return -ENOTSUP ; +return avrcp_event (session,AVRCP_EVENT_VOLUME_CHANGED , + &volume); + } + +if (!session->controller || session->controller->version <0x0104 )return -ENOTSUP ;memset (buf,0 ,sizeof (buf));set_company_id (pdu->company_id,IEEEID_BTSIG ); -DBG ("volume=%u" , volume); - pdu->pdu_id =AVRCP_SET_ABSOLUTE_VOLUME ; pdu->params[0 ] = volume; pdu->params_len =htons (1 );
profiles/audio/avrcp.h +1 -1
@@ -103,7 +103,7 @@ struct avrcp_player_cb {bool (*previous) (void *user_data); }; -int avrcp_set_volume (struct btd_device *dev,uint8_t volume); +int avrcp_set_volume (struct btd_device *dev,uint8_t volume,bool notify); struct avrcp_player *avrcp_register_player(struct btd_adapter *adapter, struct avrcp_player_cb *cb,
profiles/audio/transport.c +3 -2
@@ -671,7 +671,8 @@ static void set_volume(const GDBusPropertyTable *property, }if (a2dp->volume != volume) -avrcp_set_volume (transport->device, volume); +avrcp_set_volume (transport->device, volume, + transport->source_watch ? true : false); a2dp->volume = volume;
@@ -817,7 +818,7 @@ static int media_transport_init_sink(struct media_transport *transport) transport->destroy = destroy_a2dp; a2dp->volume =127 ; -avrcp_set_volume (transport->device, a2dp->volume); +avrcp_set_volume (transport->device, a2dp->volume, true); transport->source_watch =source_add_state_cb (service, source_state_changed, transport);
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH v2 4/5 audio/transport: Fix not emitting Volume changes
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If Volume is changed locally the change should be propagated using PropertiesChanged.
--- profiles/audio/transport.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
profiles/audio/transport.c +13 -4
@@ -653,6 +653,7 @@ static void set_volume(const GDBusPropertyTable *property,struct media_transport *transport = data;struct a2dp_transport *a2dp = transport->data;uint16_t volume; +bool notify;if (dbus_message_iter_get_arg_type (iter) !=DBUS_TYPE_UINT16 ) { g_dbus_pending_property_error(id,
@@ -670,13 +671,21 @@ static void set_volume(const GDBusPropertyTable *property,return ; } -if (a2dp->volume != volume) -avrcp_set_volume (transport->device, volume, - transport->source_watch ? true : false); +g_dbus_pending_property_success (id); + +if (a2dp->volume == volume) +return ; a2dp->volume = volume; -g_dbus_pending_property_success (id); + notify = transport->source_watch ? true : false; +if (notify) +g_dbus_emit_property_changed (btd_get_dbus_connection (), + transport->path, +MEDIA_TRANSPORT_INTERFACE , +"Volume" ); + +avrcp_set_volume (transport->device, volume, notify); }static const GDBusMethodTable transport_methods[] = {
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH v2 5/5 audio/transport: Fix emitting volume changed too soon
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The volume should start at maximum (127) but at that point there is no reason to notify the remote since there is no stream ongoing so no changes can be applied.
--- profiles/audio/transport.c | 1 - 1 file changed, 1 deletion(-)
profiles/audio/transport.c +0 -1
@@ -827,7 +827,6 @@ static int media_transport_init_sink(struct media_transport *transport) transport->destroy = destroy_a2dp; a2dp->volume =127 ; -avrcp_set_volume (transport->device, a2dp->volume, true); transport->source_watch =source_add_state_cb (service, source_state_changed, transport);
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerHi,
Quoted 36 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
CT and TG are always relative to client and server role, so although TG is associated with a player and CT with a remote controller in case of volume control the CT is in fact the player and the TG the remote controller, because of that PTS will not register any TG record when testing this thus
controller_initwill not register the necessary events.--- profiles/audio/avrcp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)profiles/audio/avrcp.c +2
-5@@ -3805,7 +3805,8 @@ static void target_init(struct avrcp *session) session->supported_events |= (1 <<AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED ) | - (1 <<AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED ); + (1 <<AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED ) | + (1 <<AVRCP_EVENT_VOLUME_CHANGED );/* Only check capabilities if controller is not supported */ if (session->controller ==NULL )@@ -3831,9 +3832,6 @@ static void controller_init(struct avrcp *session)DBG ("%p version 0x%04x" , controller, controller->version); -if (controller->version >=0x0104 ) - session->supported_events |= (1 <<AVRCP_EVENT_VOLUME_CHANGED ); - service =btd_device_get_service (session->dev,AVRCP_TARGET_UUID );btd_service_connecting_complete (service,0 ); --
Quoted 1 line
2.4.3
Pushed.
Signature · 1 line
Luiz Augusto von Dentz