Skip to contentSkip to conversation

transport: Fix set volume failure with invalid device volume

PATCH Superseded Jinwang Li 3 participants 4 messages Mar 5 – Mar 9 Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jinwang Li

author
#0 lore raw

PATCH v2 1/1 transport: Fix set volume failure with invalid device volume

When AVRCP is connected earlier than AVDTP, this invalid device volume causes the A2DP sink to reject the peer's registration for the EVENT_VOLUME_CHANGED notification. As a result, subsequent attempts to set the volume fail.

Fix this by ensuring a valid device volume is returned when the device volume is invalid, allowing volume registration to succeed.

Fixes fa7828bddd21 ("transport: Fix not being able to initialize volume properly")
---
 profiles/audio/transport.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Changes from v1:
- Return the max volume from media_transport_get_a2dp_volume() when there is no A2DP transport and the device volume is invalid.
- Restore the default device volume in device_new().
- Update the commit subject name.
- Link to v1
https://lore.kernel.org/all/[email protected]/

profiles/audio/transport.c +6 -1
index d9feef768..41d8d0a75 100644
@@ -2767,6 +2767,7 @@ static void media_transport_emit_volume(struct media_transport *transport)
 int media_transport_get_a2dp_volume(struct btd_device *dev)
 {
 	GSList *l;
+	int volume;
 
 	if (dev == NULL)
 		return -1;
@@ -2793,7 +2794,11 @@ int media_transport_get_a2dp_volume(struct btd_device *dev)
 	 * of ordering between AVRCP and A2DP session start. (Note BAP+VCP do
 	 * not have this issue.)
 	 */
-	return btd_device_get_volume(dev);
+	volume = btd_device_get_volume(dev);
+	if (volume < 0)
+		volume = 127;
+
+	return volume;
 }
 
 void media_transport_set_a2dp_volume(struct btd_device *dev, int volume)
Signature · 1 line
2.34.1
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1061791

---Test result---

Test Summary:

CheckPatch                    PENDING   0.32 seconds
GitLint                       PENDING   0.44 seconds
BuildEll                      PASS      21.59 seconds
BluezMake                     PASS      671.54 seconds
MakeCheck                     PASS      18.65 seconds
MakeDistcheck                 PASS      249.31 seconds
CheckValgrind                 PASS      302.37 seconds
CheckSmatch                   PASS      367.23 seconds
bluezmakeextell               PASS      185.41 seconds
IncrementalBuild              PENDING   0.33 seconds
ScanBuild                     PASS      1069.71 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Jinwang Li

Hi Jinwang,

Quoted 36 lines · Jinwang Li

When AVRCP is connected earlier than AVDTP, this invalid device volume causes the A2DP sink to reject the peer's registration for the EVENT_VOLUME_CHANGED notification. As a result, subsequent attempts to set the volume fail.

Fix this by ensuring a valid device volume is returned when the device volume is invalid, allowing volume registration to succeed.

Fixes fa7828bddd21 ("transport: Fix not being able to initialize volume properly")
---
 profiles/audio/transport.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Changes from v1:
- Return the max volume from media_transport_get_a2dp_volume() when there is no A2DP transport and the device volume is invalid.
- Restore the default device volume in device_new().
- Update the commit subject name.
- Link to v1
https://lore.kernel.org/all/[email protected]/

profiles/audio/transport.c +1 -0
index d9feef768..41d8d0a75 100644
@@ -2767,6 +2767,7 @@ static void media_transport_emit_volume(struct media_transport *transport)
 int media_transport_get_a2dp_volume(struct btd_device *dev)
 {
        GSList *l;
+       int volume;
 
        if (dev == NULL)
                return -1;

profiles/audio/transport.c int media_transport_get_a2dp_volume(struct btd_device *dev) · line 2799

Quoted 7 lines
profiles/audio/transport.c +3 -1
@@ -2793,7 +2794,11 @@ int media_transport_get_a2dp_volume(struct btd_device *dev)
         * of ordering between AVRCP and A2DP session start. (Note BAP+VCP do
         * not have this issue.)
         */
-       return btd_device_get_volume(dev);
+       volume = btd_device_get_volume(dev);
+       if (volume < 0)
+               volume = 127;

This doesn't work because the behavior differs depending on the role, as a source we need to return -1, so I suggest doing this instead:

profiles/audio/avrcp.c +8 -1
index 724b46c592ff..326dfdab7e3d 100644
@@ -4296,9 +4296,16 @@ static void target_init(struct avrcp *session)
        if (target->version < 0x0104)
                return;
 
-       if (avrcp_volume_supported(target))
+       if (avrcp_volume_supported(target)) {
                session->supported_events |=
                                (1 << AVRCP_EVENT_VOLUME_CHANGED);
+               /* Check if transport volume hasn't been initialized then set it
+                * to max so it works properly if the controller attempts to
+                * subscribe to AVRCP_EVENT_VOLUME_CHANGED.
+                */
+               if (media_transport_get_a2dp_volume(session->dev) < 0)
+                       media_transport_set_a2dp_volume(session->dev, 127);
+       }
 
        session->supported_events |=
                                (1 << AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED) |
Quoted 7 lines
profiles/audio/transport.c +1 -1
+       return volume;
 }
 
 void media_transport_set_a2dp_volume(struct btd_device *dev, int volume)
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
author
#3 lore raw

Hi Luiz,

Quoted 63 lines · Luiz Augusto von Dentz

Hi Jinwang,

Quoted 36 lines · Jinwang Li

When AVRCP is connected earlier than AVDTP, this invalid device volume causes the A2DP sink to reject the peer's registration for the EVENT_VOLUME_CHANGED notification. As a result, subsequent attempts to set the volume fail.

Fix this by ensuring a valid device volume is returned when the device volume is invalid, allowing volume registration to succeed.

Fixes fa7828bddd21 ("transport: Fix not being able to initialize volume properly")
---
  profiles/audio/transport.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

Changes from v1:
- Return the max volume from media_transport_get_a2dp_volume() when there is no A2DP transport and the device volume is invalid.
- Restore the default device volume in device_new().
- Update the commit subject name.
- Link to v1

    https://lore.kernel.org/all/[email protected]/
profiles/audio/transport.c +1 -0
index d9feef768..41d8d0a75 100644
@@ -2767,6 +2767,7 @@ static void media_transport_emit_volume(struct media_transport *transport)
  int media_transport_get_a2dp_volume(struct btd_device *dev)
  {
         GSList *l;
+       int volume;
 
         if (dev == NULL)
                 return -1;

profiles/audio/transport.c int media_transport_get_a2dp_volume(struct btd_device *dev) · line 2799

Quoted 7 lines
profiles/audio/transport.c +3 -1
@@ -2793,7 +2794,11 @@ int media_transport_get_a2dp_volume(struct btd_device *dev)
          * of ordering between AVRCP and A2DP session start. (Note BAP+VCP do
          * not have this issue.)
          */
-       return btd_device_get_volume(dev);
+       volume = btd_device_get_volume(dev);
+       if (volume < 0)
+               volume = 127;

This doesn't work because the behavior differs depending on the role, as a source we need to return -1, so I suggest doing this instead:

profiles/audio/avrcp.c +1 -1
index 724b46c592ff..326dfdab7e3d 100644
@@ -4296,9 +4296,16 @@ static void target_init(struct avrcp *session)
         if (target->version < 0x0104)
                 return;
 
-       if (avrcp_volume_supported(target))
+       if (avrcp_volume_supported(target)) {
                 session->supported_events |=
                                 (1 << AVRCP_EVENT_VOLUME_CHANGED);

profiles/audio/avrcp.c static void target_init(struct avrcp *session) · line 4311

Quoted 10 lines
profiles/audio/avrcp.c +7 -0
+               /* Check if transport volume hasn't been initialized then set it
+                * to max so it works properly if the controller attempts to
+                * subscribe to AVRCP_EVENT_VOLUME_CHANGED.
+                */
+               if (media_transport_get_a2dp_volume(session->dev) < 0)
+                       media_transport_set_a2dp_volume(session->dev, 127);
+       }
 
         session->supported_events |=
                                 (1 << AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED) |

I agree this is the correct approach, and I’ve verified that it resolves the volume registration issue. I’ll send a follow-up patch and include the credit.

Quoted 9 lines
Quoted 7 lines
profiles/audio/transport.c +1 -1
+       return volume;
  }
 
  void media_transport_set_a2dp_volume(struct btd_device *dev, int volume)
--

2.34.1