From a35f84a4f9844142d51490a231fe5638b936d4fc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Sep 2008 21:42:29 +0200 Subject: instead of failing when the requested sampling rate is not available find the next one that is higher --- src/modules/bluetooth/module-bluetooth-device.c | 42 ++++++++++++++----------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'src/modules/bluetooth/module-bluetooth-device.c') 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; -- cgit