summaryrefslogtreecommitdiffstats
path: root/src/modules/bluetooth
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-09-29 21:42:29 +0200
committerLennart Poettering <lennart@poettering.net>2008-09-29 21:42:29 +0200
commita35f84a4f9844142d51490a231fe5638b936d4fc (patch)
treefc1d94d185c3d6cc5bf285b4f4437a3d86872a69 /src/modules/bluetooth
parentaa1974b7a022db6b3733ec8247c863ca3e9e6c5d (diff)
instead of failing when the requested sampling rate is not available find the next one that is higher
Diffstat (limited to 'src/modules/bluetooth')
-rw-r--r--src/modules/bluetooth/module-bluetooth-device.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 86109f70..75d313c8 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -252,33 +252,37 @@ static uint8_t default_bitpool(uint8_t freq, uint8_t mode) {
static int bt_a2dp_init(struct userdata *u) {
sbc_capabilities_t *cap = &u->a2dp.sbc_capabilities;
- unsigned int max_bitpool, min_bitpool;
-
- switch (u->ss.rate) {
- case 48000:
- cap->frequency = BT_SBC_SAMPLING_FREQ_48000;
- break;
- case 44100:
- cap->frequency = BT_SBC_SAMPLING_FREQ_44100;
- break;
- case 32000:
- cap->frequency = BT_SBC_SAMPLING_FREQ_32000;
+ uint8_t max_bitpool, min_bitpool;
+ unsigned i;
+
+ static const struct {
+ uint32_t rate;
+ uint8_t cap;
+ } freq_table[] = {
+ { 16000U, BT_SBC_SAMPLING_FREQ_16000 },
+ { 32000U, BT_SBC_SAMPLING_FREQ_32000 },
+ { 44100U, BT_SBC_SAMPLING_FREQ_44100 },
+ { 48000U, BT_SBC_SAMPLING_FREQ_48000 }
+ };
+
+ /* Find the lowest freq that is at least as high as the requested
+ * sampling rate */
+ for (i = 0; i < PA_ELEMENTSOF(freq_table); i++)
+ if (freq_table[i].rate >= u->ss.rate || i == PA_ELEMENTSOF(freq_table)-1 ) {
+ u->ss.rate = freq_table[i].rate;
+ cap->frequency = freq_table[i].cap;
break;
- case 16000:
- cap->frequency = BT_SBC_SAMPLING_FREQ_16000;
- break;
- default:
- pa_log_error("Rate %d not supported", u->ss.rate);
- return -1;
- }
+ }
- if (u->ss.channels == 2) {
+ if (u->ss.channels >= 2) {
if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_JOINT_STEREO)
cap->channel_mode = BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
else if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_STEREO)
cap->channel_mode = BT_A2DP_CHANNEL_MODE_STEREO;
else if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL)
cap->channel_mode = BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL;
+
+ u->ss.channels = 2;
} else {
if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_MONO)
cap->channel_mode = BT_A2DP_CHANNEL_MODE_MONO;