[pulseaudio-discuss] [PATCH v4 09/41] bluetooth: Implement org.bluez.MediaEndpoint1.SelectConfiguration()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Sat Sep 21 03:16:41 PDT 2013
On Wed, 2013-09-18 at 16:17 -0500, jprvita at gmail.com wrote:
> static DBusMessage *endpoint_select_configuration(DBusConnection *conn, DBusMessage *m, void *userdata) {
> + pa_bluetooth_discovery *y = userdata;
> + a2dp_sbc_t *cap, config;
> + uint8_t *pconf = (uint8_t *) &config;
> + int i, size;
> DBusMessage *r;
> + DBusError err;
>
> - pa_assert_se(r = dbus_message_new_error(m, BLUEZ_MEDIA_ENDPOINT_INTERFACE ".Error.NotImplemented",
> - "Method not implemented"));
> + static const struct {
> + uint32_t rate;
> + uint8_t cap;
> + } freq_table[] = {
> + { 16000U, SBC_SAMPLING_FREQ_16000 },
> + { 32000U, SBC_SAMPLING_FREQ_32000 },
> + { 44100U, SBC_SAMPLING_FREQ_44100 },
> + { 48000U, SBC_SAMPLING_FREQ_48000 }
> + };
> +
> + dbus_error_init(&err);
> +
> + if (!dbus_message_get_args(m, &err, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &cap, &size, DBUS_TYPE_INVALID)) {
> + pa_log_error("Endpoint SelectConfiguration(): %s", err.message);
> + dbus_error_free(&err);
> + goto fail;
> + }
> +
> + if (size != sizeof(config)) {
> + pa_log_error("Capabilities array has invalid size");
> + goto fail;
> + }
> +
> + pa_zero(config);
> +
> + /* Find the lowest freq that is at least as high as the requested sampling rate */
> + for (i = 0; (unsigned) i < PA_ELEMENTSOF(freq_table); i++)
> + if (freq_table[i].rate >= y->core->default_sample_spec.rate && (cap->frequency & freq_table[i].cap)) {
> + config.frequency = freq_table[i].cap;
> + break;
> + }
>
> + if ((unsigned) i == PA_ELEMENTSOF(freq_table)) {
> + for (--i; i >= 0; i--) {
> + if (cap->frequency & freq_table[i].cap) {
> + config.frequency = freq_table[i].cap;
> + break;
> + }
> + }
> +
> + if (i < 0) {
> + pa_log_error("Not suitable sample rate");
> + goto fail;
> + }
> + }
> +
> + pa_assert((unsigned) i < PA_ELEMENTSOF(freq_table));
> +
> + if (y->core->default_sample_spec.channels <= 1)
> + if (cap->channel_mode & SBC_CHANNEL_MODE_MONO)
> + config.channel_mode = SBC_CHANNEL_MODE_MONO;
You forgot to fix this code. The problem still exists that if
default_sample_spec.channels is 1 and the cap->channel_mode doesn't
contain SBC_CHANNEL_MODE_MONO, then config.channel_mode is left
uninitialized.
--
Tanu
More information about the pulseaudio-discuss
mailing list