diff mbox series

[BlueZ,2/5] shared/bap: Add support to set stream metadata

Message ID 20221029170408.175533-3-abhay.maheshbhai.maheta@intel.com
State New
Headers show
Series To add support for Metadata, CID, VID | expand

Commit Message

Abhay Maheta Oct. 29, 2022, 5:04 p.m. UTC
From: "Maheta, Abhay" <abhay.maheshbhai.maheta@intel.com>

This adds new API to set stream metadata.
---
 src/shared/bap.c | 20 ++++++++++++++++----
 src/shared/bap.h |  2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)

Comments

Luiz Augusto von Dentz Oct. 31, 2022, 9:13 p.m. UTC | #1
Hi Abhay,

On Sat, Oct 29, 2022 at 9:54 AM Abhay Maheta
<abhay.maheshbhai.maheta@intel.com> wrote:
>
> From: "Maheta, Abhay" <abhay.maheshbhai.maheta@intel.com>
>
> This adds new API to set stream metadata.
> ---
>  src/shared/bap.c | 20 ++++++++++++++++----
>  src/shared/bap.h |  2 ++
>  2 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/src/shared/bap.c b/src/shared/bap.c
> index 0ae0eba33..cc89d65a3 100644
> --- a/src/shared/bap.c
> +++ b/src/shared/bap.c
> @@ -2787,7 +2787,7 @@ static void bap_parse_pacs(struct bt_bap *bap, uint8_t type,
>                 struct bt_pac *p;
>                 struct bt_ltv *cc;
>                 struct bt_pac_metadata *meta;
> -               struct iovec data, metadata;
> +               struct iovec data, *metadata = NULL;
>
>                 p = iov_pull_mem(&iov, sizeof(*p));
>                 if (!p) {
> @@ -2816,13 +2816,16 @@ static void bap_parse_pacs(struct bt_bap *bap, uint8_t type,
>                 data.iov_len = p->cc_len;
>                 data.iov_base = cc;
>
> -               metadata.iov_len = meta->len;
> -               metadata.iov_base = meta->data;
> +               if (meta->len) {
> +                       metadata = new0(struct iovec, 1);
> +                       metadata->iov_len = meta->len;
> +                       metadata->iov_base = meta->data;
> +               }

Not quite sure why we need to allocate memory on the heap here?
bap_pac_new does iov_dup so it would end up having the same result,
besides I think metadata is liked now since I don't see any free.

>                 iov_pull_mem(&iov, meta->len);
>
>                 pac = bap_pac_new(bap->rdb, NULL, type, &p->codec, NULL, &data,
> -                                                               &metadata);
> +                                                               metadata);
>                 if (!pac)
>                         continue;
>
> @@ -4567,6 +4570,15 @@ struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream)
>         return &stream->qos;
>  }
>
> +void bt_bap_stream_set_metadata(struct bt_bap_stream *stream,
> +                               struct iovec *meta)
> +{
> +       if (!stream)
> +               return;
> +
> +       stream->meta = meta;

Were we probably need to use iov_dup as well, in fact we do have
stream_metada that should handle this properly so perhaps you want to
update bt_bap_stream_metadata and check if the has _not_ been enabled
yet just call stream_medata with rsp=NULL so this would store the
contents of meta into stream->meta locally instead of attempt to use
BT_ASCS_METADATA to update it in the server.

> +}
> +
>  struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream)
>  {
>         if (!stream)
> diff --git a/src/shared/bap.h b/src/shared/bap.h
> index 923669f32..0c83726da 100644
> --- a/src/shared/bap.h
> +++ b/src/shared/bap.h
> @@ -249,6 +249,8 @@ uint8_t bt_bap_stream_get_dir(struct bt_bap_stream *stream);
>  uint32_t bt_bap_stream_get_location(struct bt_bap_stream *stream);
>  struct iovec *bt_bap_stream_get_config(struct bt_bap_stream *stream);
>  struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream);
> +void bt_bap_stream_set_metadata(struct bt_bap_stream *stream,
> +                                       struct iovec *meta);
>  struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream);
>
>  struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream);
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 0ae0eba33..cc89d65a3 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2787,7 +2787,7 @@  static void bap_parse_pacs(struct bt_bap *bap, uint8_t type,
 		struct bt_pac *p;
 		struct bt_ltv *cc;
 		struct bt_pac_metadata *meta;
-		struct iovec data, metadata;
+		struct iovec data, *metadata = NULL;
 
 		p = iov_pull_mem(&iov, sizeof(*p));
 		if (!p) {
@@ -2816,13 +2816,16 @@  static void bap_parse_pacs(struct bt_bap *bap, uint8_t type,
 		data.iov_len = p->cc_len;
 		data.iov_base = cc;
 
-		metadata.iov_len = meta->len;
-		metadata.iov_base = meta->data;
+		if (meta->len) {
+			metadata = new0(struct iovec, 1);
+			metadata->iov_len = meta->len;
+			metadata->iov_base = meta->data;
+		}
 
 		iov_pull_mem(&iov, meta->len);
 
 		pac = bap_pac_new(bap->rdb, NULL, type, &p->codec, NULL, &data,
-								&metadata);
+								metadata);
 		if (!pac)
 			continue;
 
@@ -4567,6 +4570,15 @@  struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream)
 	return &stream->qos;
 }
 
+void bt_bap_stream_set_metadata(struct bt_bap_stream *stream,
+				struct iovec *meta)
+{
+	if (!stream)
+		return;
+
+	stream->meta = meta;
+}
+
 struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream)
 {
 	if (!stream)
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 923669f32..0c83726da 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -249,6 +249,8 @@  uint8_t bt_bap_stream_get_dir(struct bt_bap_stream *stream);
 uint32_t bt_bap_stream_get_location(struct bt_bap_stream *stream);
 struct iovec *bt_bap_stream_get_config(struct bt_bap_stream *stream);
 struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream);
+void bt_bap_stream_set_metadata(struct bt_bap_stream *stream,
+					struct iovec *meta);
 struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream);
 
 struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream);