[v8,05/12] bluetooth: Clean up SBC bitpool calculation

Submitted by Pali Rohár on April 6, 2019, 9:16 a.m.

Details

Message ID 20190406091607.29092-6-pali.rohar@gmail.com
State Accepted
Headers show
Series "New API for Bluetooth A2DP codecs" ( rev: 55 54 53 52 51 50 49 48 47 46 45 44 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Pali Rohár April 6, 2019, 9:16 a.m.
Remove dead code and replace numeric bitpool values by macro definitions.

Maximal bitpool value in fill_capabilities() was reduced from 64 to 53
(SBC_BITPOOL_HQ_JOINT_STEREO_44100) because default_bitpool() already set
maximal value to 53.

This patch does not change SBC behavior as maximal bitpool was already
limited to 53. So it is just clean up.
---
 src/modules/bluetooth/a2dp-codec-sbc.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/bluetooth/a2dp-codec-sbc.c b/src/modules/bluetooth/a2dp-codec-sbc.c
index e590cf01a..523350b6d 100644
--- a/src/modules/bluetooth/a2dp-codec-sbc.c
+++ b/src/modules/bluetooth/a2dp-codec-sbc.c
@@ -104,7 +104,7 @@  static uint8_t fill_capabilities(uint8_t capabilities_buffer[254]) {
     capabilities->subbands = SBC_SUBBANDS_4 | SBC_SUBBANDS_8;
     capabilities->block_length = SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 | SBC_BLOCK_LENGTH_12 | SBC_BLOCK_LENGTH_16;
     capabilities->min_bitpool = SBC_MIN_BITPOOL;
-    capabilities->max_bitpool = 64;
+    capabilities->max_bitpool = SBC_BITPOOL_HQ_JOINT_STEREO_44100;
 
     return sizeof(*capabilities);
 }
@@ -158,41 +158,38 @@  static uint8_t default_bitpool(uint8_t freq, uint8_t mode) {
     switch (freq) {
         case SBC_SAMPLING_FREQ_16000:
         case SBC_SAMPLING_FREQ_32000:
-            return 53;
+            switch (mode) {
+                case SBC_CHANNEL_MODE_MONO:
+                case SBC_CHANNEL_MODE_DUAL_CHANNEL:
+                case SBC_CHANNEL_MODE_STEREO:
+                case SBC_CHANNEL_MODE_JOINT_STEREO:
+                    return SBC_BITPOOL_HQ_JOINT_STEREO_44100;
+            }
 
         case SBC_SAMPLING_FREQ_44100:
-
             switch (mode) {
                 case SBC_CHANNEL_MODE_MONO:
                 case SBC_CHANNEL_MODE_DUAL_CHANNEL:
-                    return 31;
+                    return SBC_BITPOOL_HQ_MONO_44100;
 
                 case SBC_CHANNEL_MODE_STEREO:
                 case SBC_CHANNEL_MODE_JOINT_STEREO:
-                    return 53;
+                    return SBC_BITPOOL_HQ_JOINT_STEREO_44100;
             }
 
-            pa_log_warn("Invalid channel mode %u", mode);
-            return 53;
-
         case SBC_SAMPLING_FREQ_48000:
-
             switch (mode) {
                 case SBC_CHANNEL_MODE_MONO:
                 case SBC_CHANNEL_MODE_DUAL_CHANNEL:
-                    return 29;
+                    return SBC_BITPOOL_HQ_MONO_48000;
 
                 case SBC_CHANNEL_MODE_STEREO:
                 case SBC_CHANNEL_MODE_JOINT_STEREO:
-                    return 51;
+                    return SBC_BITPOOL_HQ_JOINT_STEREO_48000;
             }
-
-            pa_log_warn("Invalid channel mode %u", mode);
-            return 51;
     }
 
-    pa_log_warn("Invalid sampling freq %u", freq);
-    return 53;
+    pa_assert_not_reached();
 }
 
 static uint8_t fill_preferred_configuration(const pa_sample_spec *default_sample_spec, const uint8_t *capabilities_buffer, uint8_t capabilities_size, uint8_t config_buffer[254]) {