Skip to content

Commit b9a4deb

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: Shell: Replace hacky metadata handling
The hacky handle_metadata_update that copied the metadata to a variable, since stream->codec->meta could not be modified, has been replaced with a proper solution now that stream->codec->meta can be modified. It still only supports settings the streaming context, but it is much easier to expand now. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 2638a04 commit b9a4deb

File tree

1 file changed

+20
-53
lines changed
  • subsys/bluetooth/shell

1 file changed

+20
-53
lines changed

subsys/bluetooth/shell/bap.c

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -830,40 +830,17 @@ static uint16_t strmeta(const char *name)
830830
return 0u;
831831
}
832832

833-
static int handle_metadata_update(struct bt_codec *codec,
834-
const char *meta_str,
835-
struct bt_codec_data *meta_out[],
836-
size_t *meta_count_out)
833+
static int set_metadata(struct bt_codec *codec, const char *meta_str)
837834
{
838-
static struct bt_codec_data meta[CONFIG_BT_CODEC_MAX_METADATA_COUNT];
839-
size_t meta_count;
835+
uint16_t context;
840836

841-
/* We create a copy of the preset meta, as the presets cannot be modified */
842-
meta_count = codec->meta_count;
843-
(void)memset(meta, 0, sizeof(meta));
844-
845-
for (size_t i = 0U; i < meta_count; i++) {
846-
(void)memcpy(meta[i].value, codec->meta[i].data.data,
847-
codec->meta[i].data.data_len);
848-
meta[i].data.data_len = codec->meta[i].data.data_len;
849-
meta[i].data.type = codec->meta[i].data.type;
850-
meta[i].data.data = meta[i].value;
851-
}
852-
853-
if (meta_str != NULL) {
854-
uint16_t context;
855-
856-
context = strmeta(meta_str);
857-
if (context == 0) {
858-
return -ENOEXEC;
859-
}
860-
861-
/* TODO: Check the type and only overwrite the streaming context */
862-
sys_put_le16(context, meta[0].value);
837+
context = strmeta(meta_str);
838+
if (context == 0) {
839+
return -ENOEXEC;
863840
}
864841

865-
*meta_count_out = meta_count;
866-
*meta_out = meta;
842+
/* TODO: Check the type and only overwrite the streaming context */
843+
sys_put_le16(context, codec->meta[0].value);
867844

868845
return 0;
869846
}
@@ -1247,9 +1224,7 @@ static int cmd_qos(const struct shell *sh, size_t argc, char *argv[])
12471224

12481225
static int cmd_enable(const struct shell *sh, size_t argc, char *argv[])
12491226
{
1250-
struct bt_codec_data *meta;
12511227
struct bt_codec *codec;
1252-
size_t meta_count;
12531228
int err;
12541229

12551230
if (default_stream == NULL) {
@@ -1260,17 +1235,14 @@ static int cmd_enable(const struct shell *sh, size_t argc, char *argv[])
12601235
codec = default_stream->codec;
12611236

12621237
if (argc > 1) {
1263-
err = handle_metadata_update(codec, argv[1], &meta, &meta_count);
1264-
} else {
1265-
err = handle_metadata_update(codec, NULL, &meta, &meta_count);
1266-
}
1267-
1268-
if (err != 0) {
1269-
shell_error(sh, "Unable to handle metadata update: %d", err);
1270-
return err;
1238+
err = set_metadata(codec, argv[1]);
1239+
if (err != 0) {
1240+
shell_error(sh, "Unable to handle metadata update: %d", err);
1241+
return err;
1242+
}
12711243
}
12721244

1273-
err = bt_bap_stream_enable(default_stream, meta, meta_count);
1245+
err = bt_bap_stream_enable(default_stream, codec->meta, codec->meta_count);
12741246
if (err) {
12751247
shell_error(sh, "Unable to enable Channel");
12761248
return -ENOEXEC;
@@ -1338,9 +1310,7 @@ static int cmd_preset(const struct shell *sh, size_t argc, char *argv[])
13381310

13391311
static int cmd_metadata(const struct shell *sh, size_t argc, char *argv[])
13401312
{
1341-
struct bt_codec_data *meta;
13421313
struct bt_codec *codec;
1343-
size_t meta_count;
13441314
int err;
13451315

13461316
if (default_stream == NULL) {
@@ -1351,17 +1321,14 @@ static int cmd_metadata(const struct shell *sh, size_t argc, char *argv[])
13511321
codec = default_stream->codec;
13521322

13531323
if (argc > 1) {
1354-
err = handle_metadata_update(codec, argv[1], &meta, &meta_count);
1355-
} else {
1356-
err = handle_metadata_update(codec, NULL, &meta, &meta_count);
1357-
}
1358-
1359-
if (err != 0) {
1360-
shell_error(sh, "Unable to handle metadata update: %d", err);
1361-
return err;
1324+
err = set_metadata(codec, argv[1]);
1325+
if (err != 0) {
1326+
shell_error(sh, "Unable to handle metadata update: %d", err);
1327+
return err;
1328+
}
13621329
}
13631330

1364-
err = bt_bap_stream_metadata(default_stream, meta, meta_count);
1331+
err = bt_bap_stream_metadata(default_stream, codec->meta, codec->meta_count);
13651332
if (err) {
13661333
shell_error(sh, "Unable to set Channel metadata");
13671334
return -ENOEXEC;
@@ -2415,7 +2382,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
24152382
"[preset] [interval] [framing] [latency] [pd] [sdu] [phy]"
24162383
" [rtn]",
24172384
cmd_qos, 1, 8),
2418-
SHELL_CMD_ARG(enable, NULL, NULL, cmd_enable, 1, 1),
2385+
SHELL_CMD_ARG(enable, NULL, "[context]", cmd_enable, 1, 1),
24192386
SHELL_CMD_ARG(stop, NULL, NULL, cmd_stop, 1, 0),
24202387
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */
24212388
#if defined(CONFIG_BT_BAP_UNICAST_SERVER)

0 commit comments

Comments
 (0)