Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-21 Thread via GitHub


sjanc merged PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


KKopyscinski commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1515625513


##
apps/bttester/src/btp_bap.c:
##
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* btp_bap.c - Bluetooth Basic Audio Profile Tester */
+
+
+#if MYNEWT_VAL(BLE_ISO_BROADCASTER)
+
+#include "btp/btp_bap.h"
+#include "syscfg/syscfg.h"
+
+
+#include "btp/btp.h"
+#include "console/console.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "math.h"
+
+#include "audio/ble_audio_broadcast_source.h"
+#include "audio/ble_audio.h"
+#include "host/ble_iso.h"
+
+#include "bsp/bsp.h"
+
+
+#define BROADCAST_ADV_INSTANCE 1
+
+static struct ble_audio_big_subgroup big_subgroup;
+
+static uint8_t id_addr_type;
+static uint8_t audio_data[155];
+static uint16_t max_sdu;
+static uint32_t sdu_interval;
+
+static struct ble_audio_base tester_base;
+
+static os_membuf_t bis_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES),
+sizeof(struct ble_audio_bis))
+];
+static struct os_mempool bis_pool;
+
+static os_membuf_t codec_spec_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES) * 2, 19)
+];
+static struct os_mempool codec_spec_pool;
+
+static uint16_t bis_handles[MYNEWT_VAL(BLE_ISO_MAX_BISES)];
+/* The timer callout */
+static struct os_callout audio_broadcast_callout;
+
+struct ble_iso_big_params big_params;
+
+static int audio_data_offset;
+
+static void
+audio_broadcast_event_cb(struct os_event *ev)
+{
+assert(ev != NULL);
+uint32_t ev_start_time = os_cputime_ticks_to_usecs(os_cputime_get32());
+
+if (audio_data_offset + 2 * max_sdu >= sizeof(audio_data)) {
+audio_data_offset = 0;
+}
+
+uint8_t lr_payload[max_sdu * 2];
+memcpy(lr_payload, audio_data + audio_data_offset, max_sdu);
+memcpy(lr_payload + max_sdu, audio_data + audio_data_offset,
+   max_sdu);
+ble_iso_tx(bis_handles[0], (void *)(lr_payload),
+   max_sdu * 2);
+
+audio_data_offset += max_sdu;
+
+/** Use cputime to time BROADCAST_SDU_INTVL, as these ticks are more
+ *  accurate than os_time ones. This assures that we do not push
+ *  LC3 data to ISO before interval, which could lead to
+ *  controller running out of buffers. This is only needed because
+ *  we already have coded data in an array - in real world application
+ *  we usually wait for new audio to arrive, and lose time to code it too.
+ */
+while (os_cputime_ticks_to_usecs(os_cputime_get32()) - ev_start_time <
+   (sdu_interval));
+
+os_callout_reset(_broadcast_callout, 0);
+}
+
+static int
+iso_event(struct ble_iso_event *event, void *arg)
+{
+int i;
+
+switch (event->type) {
+case BLE_ISO_EVENT_BIG_CREATE_COMPLETE:
+console_printf("BIG created\n");
+if (event->big_created.desc.num_bis >
+MYNEWT_VAL(BROADCASTER_CHAN_NUM)) {
+return BLE_HS_EINVAL;
+}
+for (i = 0; i < MYNEWT_VAL(BROADCASTER_CHAN_NUM); i++) {
+bis_handles[i] = event->big_created.desc.conn_handle[i];
+}
+return 0;
+case BLE_ISO_EVENT_BIG_TERMINATE_COMPLETE:
+console_printf("BIG terminated\n");
+return 0;
+default:
+return BLE_HS_ENOTSUP;
+}
+}
+
+static uint8_t
+supported_commands(const void *cmd, uint16_t cmd_len,
+   void *rsp, uint16_t *rsp_len)
+{
+struct btp_bap_read_supported_commands_rp *rp = rsp;
+
+/* octet 0 */
+tester_set_bit(rp->data, BTP_BAP_READ_SUPPORTED_COMMANDS);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_SETUP);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_RELEASE);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_STOP);
+
+/* octet 1 */
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_STOP);
+
+*rsp_len = sizeof(*rp) + 2;
+
+return BTP_STATUS_SUCCESS;
+}
+
+static int
+base_create(const struct bap_broadcast_source_setup_cmd *cmd)
+{
+struct ble_audio_bis *bis;
+uint8_t 

Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


KKopyscinski commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1515614306


##
apps/bttester/src/btp_bap.c:
##
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* btp_bap.c - Bluetooth Basic Audio Profile Tester */
+
+
+#if MYNEWT_VAL(BLE_ISO_BROADCASTER)
+
+#include "btp/btp_bap.h"
+#include "syscfg/syscfg.h"
+
+
+#include "btp/btp.h"
+#include "console/console.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "math.h"
+
+#include "audio/ble_audio_broadcast_source.h"
+#include "audio/ble_audio.h"
+#include "host/ble_iso.h"
+
+#include "bsp/bsp.h"
+
+
+#define BROADCAST_ADV_INSTANCE 1
+
+static struct ble_audio_big_subgroup big_subgroup;
+
+static uint8_t id_addr_type;
+static uint8_t audio_data[155];
+static uint16_t max_sdu;
+static uint32_t sdu_interval;
+
+static struct ble_audio_base tester_base;
+
+static os_membuf_t bis_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES),
+sizeof(struct ble_audio_bis))
+];
+static struct os_mempool bis_pool;
+
+static os_membuf_t codec_spec_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ISO_MAX_BISES) * 2, 19)
+];
+static struct os_mempool codec_spec_pool;
+
+static uint16_t bis_handles[MYNEWT_VAL(BLE_ISO_MAX_BISES)];
+/* The timer callout */
+static struct os_callout audio_broadcast_callout;
+
+struct ble_iso_big_params big_params;
+
+static int audio_data_offset;
+
+static void
+audio_broadcast_event_cb(struct os_event *ev)
+{
+assert(ev != NULL);
+uint32_t ev_start_time = os_cputime_ticks_to_usecs(os_cputime_get32());
+
+if (audio_data_offset + 2 * max_sdu >= sizeof(audio_data)) {
+audio_data_offset = 0;
+}
+
+uint8_t lr_payload[max_sdu * 2];
+memcpy(lr_payload, audio_data + audio_data_offset, max_sdu);
+memcpy(lr_payload + max_sdu, audio_data + audio_data_offset,
+   max_sdu);
+ble_iso_tx(bis_handles[0], (void *)(lr_payload),
+   max_sdu * 2);
+
+audio_data_offset += max_sdu;
+
+/** Use cputime to time BROADCAST_SDU_INTVL, as these ticks are more
+ *  accurate than os_time ones. This assures that we do not push
+ *  LC3 data to ISO before interval, which could lead to
+ *  controller running out of buffers. This is only needed because
+ *  we already have coded data in an array - in real world application

Review Comment:
   ```suggestion
*  we already have coded in an array - in real world application
   ```
   nitpick: this is filled with pattern, so not encoded



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


KKopyscinski commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1515610962


##
apps/bttester/src/btp_bap.c:
##
@@ -0,0 +1,454 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* btp_bap.c - Bluetooth Basic Audio Profile Tester */
+
+
+#include "btp/btp_bap.h"
+#include "syscfg/syscfg.h"
+
+//#if MYNEWT_VAL(BLE_ISO_BROADCASTER)
+
+#include "btp/btp.h"
+#include "console/console.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+
+#include "host/ble_audio_broadcast.h"
+#include "host/ble_audio_common.h"
+#include "host/ble_iso.h"
+
+#include "hal/hal_gpio.h"
+#include "bsp/bsp.h"
+
+#include "audio_data.h"
+
+#include "host/ble_audio_broadcast.h"
+
+#define BROADCAST_ADV_INSTANCE 1
+#define BROADCASTER_INTERRUPT_TASK_PRIO4
+#define BROADCASTER_INTERRUPT_TASK_STACK_SZ512
+
+static struct ble_audio_big_subgroup big_subgroup;
+static uint16_t max_sdu;
+static uint32_t sdu_interval;
+
+static uint8_t id_addr_type;
+
+static struct ble_audio_base tester_base;
+
+static os_membuf_t bis_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS),
+sizeof(struct ble_audio_bis))
+];
+static struct os_mempool bis_pool;
+
+static os_membuf_t codec_spec_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS) * 2, 19)
+];
+static struct os_mempool codec_spec_pool;
+
+static uint16_t bis_handles[MYNEWT_VAL(BLE_MAX_BIS)];
+/* The timer callout */
+static struct os_callout audio_broadcast_callout;
+
+static int audio_data_offset;
+static struct os_task broadcaster_interrupt_task_str;
+static struct os_eventq broadcaster_interrupt_eventq;
+static os_stack_t 
broadcaster_interrupt_task_stack[BROADCASTER_INTERRUPT_TASK_STACK_SZ];
+
+static void
+broadcaster_interrupt_task(void *arg)
+{
+while (1) {
+os_eventq_run(_interrupt_eventq);
+}
+}
+
+
+
+static uint8_t
+supported_commands(const void *cmd, uint16_t cmd_len,
+   void *rsp, uint16_t *rsp_len)
+{
+struct btp_bap_read_supported_commands_rp *rp = rsp;
+
+/* octet 0 */
+tester_set_bit(rp->data, BTP_BAP_READ_SUPPORTED_COMMANDS);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_SETUP);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_RELEASE);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_STOP);
+
+/* octet 1 */
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_STOP);
+
+*rsp_len = sizeof(*rp) + 2;
+
+return BTP_STATUS_SUCCESS;
+}
+
+static int
+broadcast_destroy_fn(struct ble_audio_base *base, void *args)
+{
+struct ble_audio_bis *bis;
+
+STAILQ_FOREACH(bis, _subgroup.bises, next) {
+os_memblock_put(_spec_pool, bis->codec_spec_config);
+os_memblock_put(_pool, bis);
+}
+
+memset(_subgroup, 0, sizeof(big_subgroup));
+
+return 0;
+}
+
+static int
+base_create(const struct bap_broadcast_source_setup_cmd *cmd)
+{
+struct ble_audio_bis *bis;
+uint16_t sampling_freq = cmd->cc_ltvs[0];
+uint16_t frame_duration = cmd->cc_ltvs[1];
+uint16_t chan_loc = BLE_AUDIO_LOCATION_FRONT_LEFT |
+BLE_AUDIO_LOCATION_FRONT_RIGHT;
+uint8_t codec_spec_config[] = 
+BLE_AUDIO_BUILD_CODEC_CONFIG(sampling_freq, frame_duration, chan_loc,
+ max_sdu * 2, );
+
+tester_base.broadcast_id = 0x42;
+tester_base.presentation_delay = 2;
+
+big_subgroup.bis_cnt = MYNEWT_VAL(BROADCASTER_CHAN_NUM);
+
+/** LC3 */
+big_subgroup.codec_id.format = 0x06;
+
+big_subgroup.codec_spec_config_len = 0;

Review Comment:
   BAP spec, 3.7.2.2. Rule 4:
   
   Codec_Specific_Configuration parameters shall be present at Level 2 and may 
be present at
   Level 3. If an identical Codec_Specific_Configuration parameter value is 
present at Level 2 and at
   Level 3, the Codec_Specific_Configuration parameter value at Level 3 shall 
be treated as the only
   instance of that Codec_Specific_Configuration parameter value present. Where 
a
   Codec_Specific_Configuration parameter value includes 

Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


KKopyscinski commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1515607308


##
apps/bttester/src/btp_bap.c:
##
@@ -0,0 +1,454 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* btp_bap.c - Bluetooth Basic Audio Profile Tester */
+
+
+#include "btp/btp_bap.h"
+#include "syscfg/syscfg.h"
+
+//#if MYNEWT_VAL(BLE_ISO_BROADCASTER)
+
+#include "btp/btp.h"
+#include "console/console.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+
+#include "host/ble_audio_broadcast.h"
+#include "host/ble_audio_common.h"
+#include "host/ble_iso.h"
+
+#include "hal/hal_gpio.h"
+#include "bsp/bsp.h"
+
+#include "audio_data.h"
+
+#include "host/ble_audio_broadcast.h"
+
+#define BROADCAST_ADV_INSTANCE 1
+#define BROADCASTER_INTERRUPT_TASK_PRIO4
+#define BROADCASTER_INTERRUPT_TASK_STACK_SZ512
+
+static struct ble_audio_big_subgroup big_subgroup;
+static uint16_t max_sdu;
+static uint32_t sdu_interval;
+
+static uint8_t id_addr_type;
+
+static struct ble_audio_base tester_base;
+
+static os_membuf_t bis_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS),
+sizeof(struct ble_audio_bis))
+];
+static struct os_mempool bis_pool;
+
+static os_membuf_t codec_spec_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS) * 2, 19)
+];
+static struct os_mempool codec_spec_pool;
+
+static uint16_t bis_handles[MYNEWT_VAL(BLE_MAX_BIS)];
+/* The timer callout */
+static struct os_callout audio_broadcast_callout;
+
+static int audio_data_offset;
+static struct os_task broadcaster_interrupt_task_str;
+static struct os_eventq broadcaster_interrupt_eventq;
+static os_stack_t 
broadcaster_interrupt_task_stack[BROADCASTER_INTERRUPT_TASK_STACK_SZ];
+
+static void
+broadcaster_interrupt_task(void *arg)
+{
+while (1) {
+os_eventq_run(_interrupt_eventq);
+}
+}
+
+
+
+static uint8_t
+supported_commands(const void *cmd, uint16_t cmd_len,
+   void *rsp, uint16_t *rsp_len)
+{
+struct btp_bap_read_supported_commands_rp *rp = rsp;
+
+/* octet 0 */
+tester_set_bit(rp->data, BTP_BAP_READ_SUPPORTED_COMMANDS);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_SETUP);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_RELEASE);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_STOP);
+
+/* octet 1 */
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_STOP);
+
+*rsp_len = sizeof(*rp) + 2;
+
+return BTP_STATUS_SUCCESS;
+}
+
+static int
+broadcast_destroy_fn(struct ble_audio_base *base, void *args)
+{
+struct ble_audio_bis *bis;
+
+STAILQ_FOREACH(bis, _subgroup.bises, next) {
+os_memblock_put(_spec_pool, bis->codec_spec_config);
+os_memblock_put(_pool, bis);
+}
+
+memset(_subgroup, 0, sizeof(big_subgroup));
+
+return 0;
+}
+
+static int
+base_create(const struct bap_broadcast_source_setup_cmd *cmd)
+{
+struct ble_audio_bis *bis;
+uint16_t sampling_freq = cmd->cc_ltvs[0];
+uint16_t frame_duration = cmd->cc_ltvs[1];
+uint16_t chan_loc = BLE_AUDIO_LOCATION_FRONT_LEFT |
+BLE_AUDIO_LOCATION_FRONT_RIGHT;
+uint8_t codec_spec_config[] = 
+BLE_AUDIO_BUILD_CODEC_CONFIG(sampling_freq, frame_duration, chan_loc,
+ max_sdu * 2, );
+
+tester_base.broadcast_id = 0x42;
+tester_base.presentation_delay = 2;
+
+big_subgroup.bis_cnt = MYNEWT_VAL(BROADCASTER_CHAN_NUM);
+
+/** LC3 */
+big_subgroup.codec_id.format = 0x06;
+
+big_subgroup.codec_spec_config_len = 0;

Review Comment:
   According to spec, afaik, it's correct to have subgroup config and only 
bises with different one should have it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


szymon-czapracki commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1514711895


##
apps/bttester/src/btp_bap.c:
##
@@ -0,0 +1,454 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* btp_bap.c - Bluetooth Basic Audio Profile Tester */
+
+
+#include "btp/btp_bap.h"
+#include "syscfg/syscfg.h"
+
+//#if MYNEWT_VAL(BLE_ISO_BROADCASTER)
+
+#include "btp/btp.h"
+#include "console/console.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+
+#include "host/ble_audio_broadcast.h"
+#include "host/ble_audio_common.h"
+#include "host/ble_iso.h"
+
+#include "hal/hal_gpio.h"
+#include "bsp/bsp.h"
+
+#include "audio_data.h"
+
+#include "host/ble_audio_broadcast.h"
+
+#define BROADCAST_ADV_INSTANCE 1
+#define BROADCASTER_INTERRUPT_TASK_PRIO4
+#define BROADCASTER_INTERRUPT_TASK_STACK_SZ512
+
+static struct ble_audio_big_subgroup big_subgroup;
+static uint16_t max_sdu;
+static uint32_t sdu_interval;
+
+static uint8_t id_addr_type;
+
+static struct ble_audio_base tester_base;
+
+static os_membuf_t bis_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS),
+sizeof(struct ble_audio_bis))
+];
+static struct os_mempool bis_pool;
+
+static os_membuf_t codec_spec_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_BIS) * 2, 19)
+];
+static struct os_mempool codec_spec_pool;
+
+static uint16_t bis_handles[MYNEWT_VAL(BLE_MAX_BIS)];
+/* The timer callout */
+static struct os_callout audio_broadcast_callout;
+
+static int audio_data_offset;
+static struct os_task broadcaster_interrupt_task_str;
+static struct os_eventq broadcaster_interrupt_eventq;
+static os_stack_t 
broadcaster_interrupt_task_stack[BROADCASTER_INTERRUPT_TASK_STACK_SZ];
+
+static void
+broadcaster_interrupt_task(void *arg)
+{
+while (1) {
+os_eventq_run(_interrupt_eventq);
+}
+}
+
+
+
+static uint8_t
+supported_commands(const void *cmd, uint16_t cmd_len,
+   void *rsp, uint16_t *rsp_len)
+{
+struct btp_bap_read_supported_commands_rp *rp = rsp;
+
+/* octet 0 */
+tester_set_bit(rp->data, BTP_BAP_READ_SUPPORTED_COMMANDS);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_SETUP);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_RELEASE);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_STOP);
+
+/* octet 1 */
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_START);
+tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_STOP);
+
+*rsp_len = sizeof(*rp) + 2;
+
+return BTP_STATUS_SUCCESS;
+}
+
+static int
+broadcast_destroy_fn(struct ble_audio_base *base, void *args)
+{
+struct ble_audio_bis *bis;
+
+STAILQ_FOREACH(bis, _subgroup.bises, next) {
+os_memblock_put(_spec_pool, bis->codec_spec_config);
+os_memblock_put(_pool, bis);
+}
+
+memset(_subgroup, 0, sizeof(big_subgroup));
+
+return 0;
+}
+
+static int
+base_create(const struct bap_broadcast_source_setup_cmd *cmd)
+{
+struct ble_audio_bis *bis;
+uint16_t sampling_freq = cmd->cc_ltvs[0];
+uint16_t frame_duration = cmd->cc_ltvs[1];
+uint16_t chan_loc = BLE_AUDIO_LOCATION_FRONT_LEFT |
+BLE_AUDIO_LOCATION_FRONT_RIGHT;
+uint8_t codec_spec_config[] = 
+BLE_AUDIO_BUILD_CODEC_CONFIG(sampling_freq, frame_duration, chan_loc,
+ max_sdu * 2, );
+
+tester_base.broadcast_id = 0x42;
+tester_base.presentation_delay = 2;
+
+big_subgroup.bis_cnt = MYNEWT_VAL(BROADCASTER_CHAN_NUM);
+
+/** LC3 */
+big_subgroup.codec_id.format = 0x06;
+
+big_subgroup.codec_spec_config_len = 0;

Review Comment:
   Is this necessary to have a whole subgroup set config? Maybe this would be 
better so we can add specified bises if tests demand it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


szymon-czapracki commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1514710553


##
apps/bttester/src/audio_data.h:
##


Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Add broadcast support in bttester [mynewt-nimble]

2024-03-06 Thread via GitHub


szymon-czapracki commented on code in PR #1698:
URL: https://github.com/apache/mynewt-nimble/pull/1698#discussion_r1514709259


##
apps/bttester/src/btp/btp_bap.h:
##
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BTP_BAP_
+#define H_BTP_BAP_
+
+#include "nimble/ble.h"
+#include 
+
+#ifndef __packed
+#define __packed__attribute__((__packed__))
+#endif
+
+/* BAP Service */
+/* commands */
+#define BTP_BAP_READ_SUPPORTED_COMMANDS 0x01
+struct btp_bap_read_supported_commands_rp {
+uint8_t data[0];
+} __packed;
+
+#define BTP_BAP_DISCOVER0x02
+#define BTP_BAP_SEND0x03
+#define BTP_BAP_BROADCAST_SOURCE_SETUP  0x04
+struct bap_broadcast_source_setup_cmd {
+uint8_t streams_per_subgroup;
+uint8_t subgroups;
+uint8_t sdu_interval[3];
+uint8_t framing;
+uint16_t max_sdu;
+uint8_t rtn;
+uint16_t max_transport_lat;
+uint8_t presentation_delay[3];
+uint8_t coding_fmt;
+uint16_t vid;
+uint16_t cid;
+uint8_t cc_ltvs_len;
+uint8_t cc_ltvs[];
+} __packed;
+
+struct codec_config {

Review Comment:
   Deleted



##
apps/bttester/syscfg.yml:
##
@@ -145,3 +145,38 @@ syscfg.vals:
 
 BLE_MESH_ADV_BUF_COUNT: 20
 BLE_MESH_TX_SEG_MAX: 6
+
+BLE_VERSION: 54
+BLE_ISO: 1
+BLE_ISO_BROADCASTER: 1
+BLE_MAX_BIG: 1
+BLE_MAX_BIS: 1
+BLE_EXT_ADV: 1
+BLE_PERIODIC_ADV: 1
+BLE_EXT_ADV_MAX_SIZE: 261
+BLE_MULTI_ADV_INSTANCES: 2
+MSYS_1_BLOCK_COUNT: 32
+BLE_PHY_2M: 1
+
+syscfg.defs:

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org