bluez5: indicate to LC3 plugin whether endpoint is sink/duplex

The codec can make use of information on whether the endpoint is sink,
and whether there will be both sink and source configured.
This commit is contained in:
Pauli Virtanen 2023-11-27 22:00:13 +02:00 committed by Wim Taymans
parent 9474030582
commit 08819e3d17
2 changed files with 24 additions and 3 deletions

View file

@ -44,6 +44,8 @@ struct pac_data {
int index;
uint32_t locations;
uint32_t channel_allocation;
bool sink;
bool duplex;
};
typedef struct {
@ -52,6 +54,8 @@ typedef struct {
uint32_t channels;
uint16_t framelen;
uint8_t n_blks;
bool sink;
bool duplex;
} bap_lc3_t;
static const struct {
@ -282,6 +286,9 @@ static bool select_config(bap_lc3_t *conf, const struct pac_data *pac, struct sp
return false;
memset(conf, 0, sizeof(*conf));
conf->sink = pac->sink;
conf->duplex = pac->duplex;
conf->frame_duration = 0xFF;
/* XXX: we always use one frame block */
@ -514,6 +521,7 @@ static int conf_cmp(const bap_lc3_t *conf1, int res1, const bap_lc3_t *conf2, in
PREFER_BOOL(conf->channels & LC3_CHAN_1);
PREFER_BOOL(conf->rate & (LC3_CONFIG_FREQ_48KHZ | LC3_CONFIG_FREQ_32KHZ | \
LC3_CONFIG_FREQ_24KHZ | LC3_CONFIG_FREQ_16KHZ | LC3_CONFIG_FREQ_8KHZ));
PREFER_BOOL(conf->rate & LC3_CONFIG_FREQ_48KHZ);
PREFER_BOOL(conf->rate & LC3_CONFIG_FREQ_32KHZ);
PREFER_BOOL(conf->rate & LC3_CONFIG_FREQ_24KHZ);
@ -551,6 +559,7 @@ static int codec_select_config(const struct media_codec *codec, uint32_t flags,
uint8_t *data = config;
uint32_t locations = 0;
uint32_t channel_allocation = 0;
bool sink = false, duplex = false;
struct spa_debug_log_ctx debug_ctx = SPA_LOG_DEBUG_INIT(log, SPA_LOG_LEVEL_TRACE);
int i;
@ -567,6 +576,12 @@ static int codec_select_config(const struct media_codec *codec, uint32_t flags,
if (spa_atob(spa_dict_lookup(settings, "bluez5.bap.debug")))
debug_ctx = SPA_LOG_DEBUG_INIT(log, SPA_LOG_LEVEL_DEBUG);
/* Is remote endpoint sink or source */
sink = spa_atob(spa_dict_lookup(settings, "bluez5.bap.sink"));
/* Is remote endpoint duplex */
duplex = spa_atob(spa_dict_lookup(settings, "bluez5.bap.duplex"));
}
/* Select best conf from those possible */
@ -582,6 +597,8 @@ static int codec_select_config(const struct media_codec *codec, uint32_t flags,
for (i = 0; i < npacs; ++i) {
pacs[i].locations = locations;
pacs[i].channel_allocation = channel_allocation;
pacs[i].sink = sink;
pacs[i].duplex = duplex;
}
qsort(pacs, npacs, sizeof(struct pac_data), pac_cmp);

View file

@ -882,10 +882,10 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe
int res;
const struct media_codec *codec;
struct spa_bt_remote_endpoint *ep;
bool sink;
bool sink, duplex;
const char *err_msg = "Unknown error";
struct spa_dict settings;
struct spa_dict_item setting_items[SPA_N_ELEMENTS(monitor->global_setting_items) + 3];
struct spa_dict_item setting_items[SPA_N_ELEMENTS(monitor->global_setting_items) + 5];
int i;
const char *endpoint_path = NULL;
@ -933,11 +933,13 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe
spa_scnprintf(channel_allocation, sizeof(channel_allocation), "%"PRIu32, endpoint_qos.channel_allocation);
ep = remote_endpoint_find(monitor, endpoint_path);
if (!ep) {
if (!ep || !ep->device) {
spa_log_warn(monitor->log, "Unable to find remote endpoint for %s", endpoint_path);
goto error_invalid;
}
duplex = SPA_FLAG_IS_SET(ep->device->profiles, SPA_BT_PROFILE_BAP_DUPLEX);
/* Call of SelectProperties means that local device acts as an initiator
* and therefor remote endpoint is an acceptor
*/
@ -947,6 +949,8 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe
setting_items[i] = monitor->global_settings.items[i];
setting_items[i++] = SPA_DICT_ITEM_INIT("bluez5.bap.locations", locations);
setting_items[i++] = SPA_DICT_ITEM_INIT("bluez5.bap.channel-allocation", channel_allocation);
setting_items[i++] = SPA_DICT_ITEM_INIT("bluez5.bap.sink", sink ? "true" : "false");
setting_items[i++] = SPA_DICT_ITEM_INIT("bluez5.bap.duplex", duplex ? "true" : "false");
setting_items[i++] = SPA_DICT_ITEM_INIT("bluez5.bap.debug", "true");
settings = SPA_DICT_INIT(setting_items, i);
spa_assert((size_t)i <= SPA_N_ELEMENTS(setting_items));