mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
bluez5: add SBC XQ support with a config option
This commit is contained in:
parent
860389492b
commit
4440ede41c
3 changed files with 38 additions and 9 deletions
|
|
@ -83,9 +83,10 @@ static int codec_fill_caps(const struct a2dp_codec *codec, uint32_t flags,
|
|||
return sizeof(a2dp_sbc);
|
||||
}
|
||||
|
||||
static uint8_t default_bitpool(uint8_t freq, uint8_t mode)
|
||||
static uint8_t default_bitpool(uint8_t freq, uint8_t mode, bool xq)
|
||||
{
|
||||
/* These bitpool values were chosen based on the A2DP spec recommendation */
|
||||
/* A2DP spec v1.2 states that all SNK implementation shall handle bitrates
|
||||
of up to 512 kbps (~ bitpool = 76 stereo, or 2x38 dual channel). */
|
||||
switch (freq) {
|
||||
case SBC_SAMPLING_FREQ_16000:
|
||||
case SBC_SAMPLING_FREQ_32000:
|
||||
|
|
@ -95,22 +96,22 @@ static uint8_t default_bitpool(uint8_t freq, uint8_t mode)
|
|||
switch (mode) {
|
||||
case SBC_CHANNEL_MODE_MONO:
|
||||
case SBC_CHANNEL_MODE_DUAL_CHANNEL:
|
||||
return 31;
|
||||
return xq ? 38 : 31;
|
||||
|
||||
case SBC_CHANNEL_MODE_STEREO:
|
||||
case SBC_CHANNEL_MODE_JOINT_STEREO:
|
||||
return 53;
|
||||
return xq ? 64 : 53;
|
||||
}
|
||||
return 53;
|
||||
case SBC_SAMPLING_FREQ_48000:
|
||||
switch (mode) {
|
||||
case SBC_CHANNEL_MODE_MONO:
|
||||
case SBC_CHANNEL_MODE_DUAL_CHANNEL:
|
||||
return 29;
|
||||
return xq ? 35 : 29;
|
||||
|
||||
case SBC_CHANNEL_MODE_STEREO:
|
||||
case SBC_CHANNEL_MODE_JOINT_STEREO:
|
||||
return 51;
|
||||
return xq ? 62 : 51;
|
||||
}
|
||||
return 51;
|
||||
}
|
||||
|
|
@ -123,10 +124,18 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags,
|
|||
{
|
||||
a2dp_sbc_t conf;
|
||||
int bitpool;
|
||||
bool xq = false;
|
||||
const char *str;
|
||||
|
||||
if (caps_size < sizeof(conf))
|
||||
return -EINVAL;
|
||||
|
||||
if (settings) {
|
||||
if ((str = spa_dict_lookup(settings, "codec.sbc.enable-xq")) != NULL &&
|
||||
(strcmp(str, "true") == 0 || atoi(str)))
|
||||
xq = true;
|
||||
}
|
||||
|
||||
memcpy(&conf, caps, sizeof(conf));
|
||||
|
||||
if (conf.frequency & SBC_SAMPLING_FREQ_48000)
|
||||
|
|
@ -140,6 +149,10 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags,
|
|||
else
|
||||
return -ENOTSUP;
|
||||
|
||||
if (xq) {
|
||||
if (conf.channel_mode & SBC_CHANNEL_MODE_DUAL_CHANNEL)
|
||||
conf.channel_mode = SBC_CHANNEL_MODE_DUAL_CHANNEL;
|
||||
}
|
||||
if (conf.channel_mode & SBC_CHANNEL_MODE_JOINT_STEREO)
|
||||
conf.channel_mode = SBC_CHANNEL_MODE_JOINT_STEREO;
|
||||
else if (conf.channel_mode & SBC_CHANNEL_MODE_STEREO)
|
||||
|
|
@ -176,7 +189,7 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags,
|
|||
else
|
||||
return -ENOTSUP;
|
||||
|
||||
bitpool = default_bitpool(conf.frequency, conf.channel_mode);
|
||||
bitpool = default_bitpool(conf.frequency, conf.channel_mode, xq);
|
||||
|
||||
conf.min_bitpool = SPA_MAX(SBC_MIN_BITPOOL, conf.min_bitpool);
|
||||
conf.max_bitpool = SPA_MIN(bitpool, conf.max_bitpool);
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ struct spa_bt_monitor {
|
|||
struct spa_bt_backend *backend_hsp_native;
|
||||
struct spa_bt_backend *backend_ofono;
|
||||
struct spa_bt_backend *backend_hsphfpd;
|
||||
|
||||
unsigned int enable_sbc_xq:1;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -156,8 +158,13 @@ static DBusHandlerResult endpoint_select_configuration(DBusConnection *conn, DBu
|
|||
spa_log_debug(monitor->log, " %d: %02x", i, cap[i]);
|
||||
|
||||
codec = a2dp_endpoint_to_codec(path);
|
||||
if (codec != NULL)
|
||||
res = codec->select_config(codec, 0, cap, size, NULL, config);
|
||||
if (codec != NULL) {
|
||||
struct spa_dict_item items[1];
|
||||
|
||||
items[0] = SPA_DICT_ITEM_INIT("codec.sbc.enable-xq", monitor->enable_sbc_xq ? "true" : "false");
|
||||
|
||||
res = codec->select_config(codec, 0, cap, size, &SPA_DICT_INIT_ARRAY(items), config);
|
||||
}
|
||||
else
|
||||
res = -ENOTSUP;
|
||||
|
||||
|
|
@ -2191,6 +2198,14 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
|
||||
register_media_application(this);
|
||||
|
||||
if (info) {
|
||||
const char *str;
|
||||
|
||||
if ((str = spa_dict_lookup(info, "bluez5.sbc-xq-support")) != NULL &&
|
||||
(strcmp(str, "true") == 0 || atoi(str)))
|
||||
this->enable_sbc_xq = true;
|
||||
}
|
||||
|
||||
this->backend_hsp_native = backend_hsp_native_new(this, this->conn, support, n_support);
|
||||
this->backend_ofono = backend_ofono_new(this, this->conn, info, support, n_support);
|
||||
this->backend_hsphfpd = backend_hsphfpd_new(this, this->conn, info, support, n_support);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue