Samples: Bluetooth: Fix build errors for TMAP central
The TMAP central had a few bugs. It was also using the old BAP discovery API. The commit fixes the bugs, and updates it to use the new BAP discover API. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
567c39250e
commit
23a239e104
2 changed files with 72 additions and 106 deletions
|
@ -16,7 +16,6 @@
|
||||||
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
|
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
|
||||||
#include <zephyr/bluetooth/audio/cap.h>
|
#include <zephyr/bluetooth/audio/cap.h>
|
||||||
#include <zephyr/bluetooth/audio/bap.h>
|
#include <zephyr/bluetooth/audio/bap.h>
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
static struct k_work_delayable audio_send_work;
|
static struct k_work_delayable audio_send_work;
|
||||||
|
|
||||||
|
@ -207,84 +206,69 @@ static void print_codec_capabilities(const struct bt_codec *codec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_remote_codec(const struct bt_codec *codec_capabilities, int index,
|
static void print_remote_codec(const struct bt_codec *codec_capabilities, enum bt_audio_dir dir)
|
||||||
enum bt_audio_dir dir)
|
|
||||||
{
|
{
|
||||||
printk("#%u: codec_capabilities %p dir 0x%02x\n", index, codec_capabilities, dir);
|
printk("codec_capabilities %p dir 0x%02x\n", codec_capabilities, dir);
|
||||||
print_codec_capabilities(codec_capabilities);
|
print_codec_capabilities(codec_capabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index)
|
static void add_remote_sink(struct bt_bap_ep *ep)
|
||||||
{
|
{
|
||||||
printk("Sink #%u: ep %p\n", index, ep);
|
for (size_t i = 0U; i < ARRAY_SIZE(unicast_sink_eps); i++) {
|
||||||
|
if (unicast_sink_eps[i] == NULL) {
|
||||||
if (index > ARRAY_SIZE(unicast_sink_eps)) {
|
printk("Sink #%zu: ep %p\n", i, ep);
|
||||||
printk("Could not add sink ep[%u]\n", index);
|
unicast_sink_eps[i] = ep;
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
unicast_sink_eps[index] = ep;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_remote_source(struct bt_bap_ep *ep, uint8_t index)
|
|
||||||
{
|
|
||||||
printk("Source #%u: ep %p\n", index, ep);
|
|
||||||
|
|
||||||
if (index > ARRAY_SIZE(unicast_source_eps)) {
|
|
||||||
printk("Could not add source ep[%u]\n", index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unicast_source_eps[index] = ep;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep,
|
|
||||||
struct bt_bap_unicast_client_discover_params *params)
|
|
||||||
{
|
|
||||||
static bool codec_found;
|
|
||||||
static bool endpoint_found;
|
|
||||||
|
|
||||||
if (params->err != 0) {
|
|
||||||
printk("Discovery failed: %d\n", params->err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (codec != NULL) {
|
|
||||||
print_remote_codec(codec, params->num_caps, params->dir);
|
|
||||||
codec_found = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ep != NULL) {
|
|
||||||
if (params->dir == BT_AUDIO_DIR_SINK) {
|
|
||||||
add_remote_sink(ep, params->num_eps);
|
|
||||||
endpoint_found = true;
|
|
||||||
} else {
|
|
||||||
printk("Invalid param dir: %u\n", params->dir);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_remote_source(struct bt_bap_ep *ep)
|
||||||
|
{
|
||||||
|
for (size_t i = 0U; i < ARRAY_SIZE(unicast_source_eps); i++) {
|
||||||
|
if (unicast_source_eps[i] == NULL) {
|
||||||
|
printk("Source #%zu: ep %p\n", i, ep);
|
||||||
|
unicast_source_eps[i] = ep;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void discover_cb(struct bt_conn *conn, int err, enum bt_audio_dir dir)
|
||||||
|
{
|
||||||
|
if (err != 0) {
|
||||||
|
printk("Discovery failed: %d\n", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("Sink discover complete\n");
|
if (dir == BT_AUDIO_DIR_SINK) {
|
||||||
|
printk("Sink discover complete\n");
|
||||||
(void)memset(params, 0, sizeof(*params));
|
|
||||||
|
|
||||||
if (endpoint_found && codec_found) {
|
|
||||||
k_sem_give(&sem_discover_sink);
|
k_sem_give(&sem_discover_sink);
|
||||||
} else {
|
} else if (dir == BT_AUDIO_DIR_SOURCE) {
|
||||||
printk("Did not discover endpoint and codec\n");
|
printk("Discover sources complete: err %d\n", err);
|
||||||
|
k_sem_give(&sem_discover_source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pac_record_cb(struct bt_conn *conn, enum bt_audio_dir dir, const struct bt_codec *codec)
|
||||||
|
{
|
||||||
|
print_remote_codec(codec, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void endpoint_cb(struct bt_conn *conn, enum bt_audio_dir dir, struct bt_bap_ep *ep)
|
||||||
|
{
|
||||||
|
if (dir == BT_AUDIO_DIR_SOURCE) {
|
||||||
|
add_remote_source(ep);
|
||||||
|
} else if (dir == BT_AUDIO_DIR_SINK) {
|
||||||
|
add_remote_sink(ep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int discover_sinks(struct bt_conn *conn)
|
static int discover_sinks(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err;
|
||||||
static struct bt_bap_unicast_client_discover_params params;
|
|
||||||
|
|
||||||
params.func = discover_sink_cb;
|
err = bt_bap_unicast_client_discover(conn, BT_AUDIO_DIR_SINK);
|
||||||
params.dir = BT_AUDIO_DIR_SINK;
|
|
||||||
|
|
||||||
err = bt_bap_unicast_client_discover(conn, ¶ms);
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
printk("Failed to discover sink: %d\n", err);
|
printk("Failed to discover sink: %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -299,43 +283,11 @@ static int discover_sinks(struct bt_conn *conn)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void discover_sources_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep,
|
|
||||||
struct bt_bap_unicast_client_discover_params *params)
|
|
||||||
{
|
|
||||||
if (params->err != 0 && params->err != BT_ATT_ERR_ATTRIBUTE_NOT_FOUND) {
|
|
||||||
printk("Discovery failed: %d\n", params->err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (codec != NULL) {
|
|
||||||
print_remote_codec(codec, params->num_caps, params->dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ep != NULL) {
|
|
||||||
add_remote_source(ep, params->num_eps);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params->err == BT_ATT_ERR_ATTRIBUTE_NOT_FOUND) {
|
|
||||||
printk("Discover sinks completed without finding any source ASEs\n");
|
|
||||||
} else {
|
|
||||||
printk("Discover sources complete: err %d\n", params->err);
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)memset(params, 0, sizeof(*params));
|
|
||||||
k_sem_give(&sem_discover_source);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int discover_sources(struct bt_conn *conn)
|
static int discover_sources(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
static struct bt_bap_unicast_client_discover_params params;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
params.func = discover_sources_cb;
|
err = bt_bap_unicast_client_discover(conn, BT_AUDIO_DIR_SOURCE);
|
||||||
params.dir = BT_AUDIO_DIR_SOURCE;
|
|
||||||
|
|
||||||
err = bt_bap_unicast_client_discover(conn, ¶ms);
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
printk("Failed to discover sources: %d\n", err);
|
printk("Failed to discover sources: %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -350,6 +302,12 @@ static int discover_sources(struct bt_conn *conn)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct bt_bap_unicast_client_cb unicast_client_cbs = {
|
||||||
|
.discover = discover_cb,
|
||||||
|
.pac_record = pac_record_cb,
|
||||||
|
.endpoint = endpoint_cb,
|
||||||
|
};
|
||||||
|
|
||||||
static int unicast_group_create(struct bt_bap_unicast_group **out_unicast_group)
|
static int unicast_group_create(struct bt_bap_unicast_group **out_unicast_group)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -458,6 +416,12 @@ int cap_initiator_init(void)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = bt_bap_unicast_client_register_cb(&unicast_client_cbs);
|
||||||
|
if (err != 0) {
|
||||||
|
printk("Failed to register BAP unicast client callbacks (err %d)\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||||
bt_cap_stream_ops_register(&unicast_streams[i],
|
bt_cap_stream_ops_register(&unicast_streams[i],
|
||||||
&unicast_stream_ops);
|
&unicast_stream_ops);
|
||||||
|
|
|
@ -262,47 +262,47 @@ static int scan_and_connect(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = init();
|
err = init();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("Initializing TMAP and setting role\n");
|
printk("Initializing TMAP and setting role\n");
|
||||||
/* Initialize TMAP */
|
/* Initialize TMAP */
|
||||||
err = bt_tmap_register(BT_TMAP_ROLE_CG | BT_TMAP_ROLE_UMS);
|
err = bt_tmap_register(BT_TMAP_ROLE_CG | BT_TMAP_ROLE_UMS);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize CAP Initiator */
|
/* Initialize CAP Initiator */
|
||||||
err = cap_initiator_init();
|
err = cap_initiator_init();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
printk("CAP initialized\n");
|
printk("CAP initialized\n");
|
||||||
|
|
||||||
/* Initialize VCP Volume Controller */
|
/* Initialize VCP Volume Controller */
|
||||||
err = vcp_vol_ctlr_init();
|
err = vcp_vol_ctlr_init();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
printk("VCP initialized\n");
|
printk("VCP initialized\n");
|
||||||
|
|
||||||
/* Initialize MCP Server */
|
/* Initialize MCP Server */
|
||||||
err = mcp_server_init();
|
err = mcp_server_init();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
printk("MCP initialized\n");
|
printk("MCP initialized\n");
|
||||||
|
|
||||||
/* Initialize CCP Server */
|
/* Initialize CCP Server */
|
||||||
err = ccp_server_init();
|
err = ccp_server_init();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
printk("CCP initialized\n");
|
printk("CCP initialized\n");
|
||||||
|
|
||||||
|
@ -310,12 +310,12 @@ void main(void)
|
||||||
bt_le_scan_cb_register(&scan_callbacks);
|
bt_le_scan_cb_register(&scan_callbacks);
|
||||||
err = scan_and_connect();
|
err = scan_and_connect();
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_tmap_discover(default_conn, &tmap_callbacks);
|
err = bt_tmap_discover(default_conn, &tmap_callbacks);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_take(&sem_discovery_done, K_FOREVER);
|
k_sem_take(&sem_discovery_done, K_FOREVER);
|
||||||
|
@ -329,6 +329,8 @@ void main(void)
|
||||||
/* Discover and configure unicast streams */
|
/* Discover and configure unicast streams */
|
||||||
err = cap_initiator_setup(default_conn);
|
err = cap_initiator_setup(default_conn);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue