Skip to content

Commit

Permalink
Bluetooth: Audio: Add implementation for PBP and dedicated sample apps.
Browse files Browse the repository at this point in the history
PBP API allows sources to create a Public Broadcast Announcement.
PBP API to parse a Public Broadcast Announcement.

public_broadcast_source application starts extended advertising and
includes a Public Broadcast Announcement. The advertised broadcast
audio stream quality will cycle between high and standard quality.

public_broadcast_sink application scans for broadcast sources and
synchronizes to the first found source which defines a Public Broadcast
Announcement including a High Quality Public Broadcast Audio Stream
configuration.

Add bsim tests for Public Broadcast Profile APIs.

Add shell implementation for Public Broadcast Profile APIs.

Signed-off-by: Daniela Andreea Dumitrache <[email protected]>
  • Loading branch information
andreeaDumitrache committed Dec 5, 2023
1 parent 063ce9c commit 3372312
Show file tree
Hide file tree
Showing 35 changed files with 2,493 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/connectivity/bluetooth/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ Bluetooth APIs
shell/iso.rst
shell/mcp.rst
shell/tmap.rst
shell/pbp.rst
20 changes: 20 additions & 0 deletions doc/connectivity/bluetooth/api/shell/pbp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Bluetooth: Public Broadcast Profile Shell
#########################################

This document describes how to run the Public Broadcast Profile functionality.
PBP does not have an associated service. Its purpose is to enable a faster, more
efficient discovery of Broadcast Sources that are transmitting audio with commonly used codec configurations.

Using the PBP Shell
*******************

When the Bluetooth stack has been initialized (:code:`bt init`), the Public Broadcast Profile is ready to run.
To set the Public Broadcast Announcement features call :code:`pbp set_features`.

.. code-block:: console
pbp --help
pbp - Bluetooth PBP shell commands
Subcommands:
set_features :Set the Public Broadcast Announcement features
78 changes: 78 additions & 0 deletions include/zephyr/bluetooth/audio/pbp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2023 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_PBP_
#define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_PBP_

/**
* @brief Public Broadcast Profile (PBP)
*
* @defgroup bt_pbp Public Broadcast Profile (PBP)
*
* @ingroup bluetooth
* @{
*
* [Experimental] Users should note that the APIs can change
* as a part of ongoing development.
*/

#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/audio/audio.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Public Broadcast Announcement features */
enum bt_pbp_announcement_feature {
/** Broadcast Streams encryption status */
BT_PBP_ANNOUNCEMENT_FEATURE_ENCRYPTION = BIT(0),
/** Standard Quality Public Broadcast Audio configuration */
BT_PBP_ANNOUNCEMENT_FEATURE_STANDARD_QUALITY = BIT(1),
/** High Quality Public Broadcast Audio configuration */
BT_PBP_ANNOUNCEMENT_FEATURE_HIGH_QUALITY = BIT(2),
};

/**
* @brief Creates a Public Broadcast Announcement based on the information received
* in the features parameter.
*
* @param meta Metadata to be included in the advertising data
* @param features Public Broadcast Announcement features
* @param meta_len Size of the metadata fields to be included in the advertising data
* @param pba_data_buf Pointer to store the PBA advertising data. Buffer size needs to be
* meta_len + 3 (service UUID + PBA feature + metadata).
*
* @return 0 on success or an appropriate error code.
*/
int bt_pbp_get_announcement(const uint8_t meta[], size_t meta_len,
enum bt_pbp_announcement_feature features,
struct net_buf_simple *pba_data_buf);

/**
* @brief Parses the received advertising data corresponding to a Public Broadcast
* Announcement. Returns the advertised Public BroadcastAnnouncement features.
* and metadata.
*
* @param data Advertising data to be checked
* @param source_features Sink stream configuration preferences
* @param meta Pointer to copy the metadata present in the advertising data
*
* @return parsed metadata length on success or an appropriate error code
*/
int bt_pbp_parse_announcement(struct bt_data *data,
enum bt_pbp_announcement_feature *source_features,
uint8_t *meta);

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_PBP_ */
11 changes: 11 additions & 0 deletions samples/bluetooth/public_broadcast_sink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(pbp_broadcast_sink)

target_sources(app PRIVATE
src/main.c
)

zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
15 changes: 15 additions & 0 deletions samples/bluetooth/public_broadcast_sink/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

source "share/sysbuild/Kconfig"

config NET_CORE_BOARD
string
default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp"
default "nrf5340_audio_dk_nrf5340_cpunet" if $(BOARD) = "nrf5340_audio_dk_nrf5340_cpuapp"
default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp"

config NET_CORE_IMAGE_HCI_IPC
bool "HCI IPC image on network core"
default y
depends on NET_CORE_BOARD != ""
77 changes: 77 additions & 0 deletions samples/bluetooth/public_broadcast_sink/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.. zephyr:code-sample:: bluetooth_public_broadcast_sink
:name: Bluetooth: Public Broadcast Sink
:relevant-api: bluetooth

Bluetooth: Public Broadcast Sink

Overview
********

Application demonstrating the LE Public Broadcast Profile sink functionality.
Starts by scanning for LE Audio broadcast sources and then synchronizes to
the first found source which defines a Public Broadcast Announcement including
a High Quality Public Broadcast Audio Stream configuration.

This sample can be found under
:zephyr_file:`samples/bluetooth/public_broadcast_sink` in the Zephyr tree.

Check the :ref:`bluetooth samples section <bluetooth-samples>` for general information.

Requirements
************

* BlueZ running on the host, or
* A board with Bluetooth Low Energy 5.2 support

Building and Running
********************

When building targeting an nrf52 series board with the Zephyr Bluetooth Controller,
use `-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf` to enable the required ISO
feature support.

Building for an nrf5340dk
-------------------------

You can build both the application core image and an appropriate controller image for the network
core with:

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/public_broadcast_sink/
:board: nrf5340dk_nrf5340_cpuapp
:goals: build
:west-args: --sysbuild

If you prefer to only build the application core image, you can do so by doing instead:

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/public_broadcast_sink/
:board: nrf5340dk_nrf5340_cpuapp
:goals: build

In that case you can pair this application core image with the
:ref:`hci_ipc sample <bluetooth-hci-ipc-sample>`
:zephyr_file:`samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf` configuration.

Building for a simulated nrf5340bsim
------------------------------------

Similarly to how you would for real HW, you can do:

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/public_broadcast_sink/
:board: nrf5340bsim_nrf5340_cpuapp
:goals: build
:west-args: --sysbuild

Note this will produce a Linux executable in `./build/zephyr/zephyr.exe`.
For more information, check :ref:`this board documentation <nrf5340bsim>`.

Building for a simulated nrf52_bsim
-----------------------------------

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/public_broadcast_sink/
:board: nrf52_bsim
:goals: build
:gen-args: -DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Zephyr Bluetooth Controller
CONFIG_BT_LL_SW_SPLIT=y

# Enable support for Broadcast ISO Sync
CONFIG_BT_CTLR_SYNC_ISO=y

# Supports the highest SDU size required by any BAP LC3 presets (155)
CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=155

# Supports the highest advertising data that is set in a single HCI command in
# Zephyr Bluetooth Controller
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=191

# Number of supported streams
CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2
CONFIG_BT_CTLR_ISOAL_SINKS=2
34 changes: 34 additions & 0 deletions samples/bluetooth/public_broadcast_sink/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_PAC_SNK=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_AUDIO=y
CONFIG_UTF8=y

CONFIG_BT_SMP=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_L2CAP_TX_BUF_COUNT=20
CONFIG_BT_HCI_ACL_FLOW_CONTROL=n
CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE=196

# CAP
CONFIG_BT_CAP_ACCEPTOR=y

# BAP support
CONFIG_BT_BAP_SCAN_DELEGATOR=y
CONFIG_BT_BAP_BROADCAST_SINK=y
CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT=1
CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT=1

# Support an ISO channel per ASE
CONFIG_BT_ISO_MAX_CHAN=2

# Sink PAC Location Support
CONFIG_BT_PAC_SNK_LOC=y

# Generic config
CONFIG_BT_EXT_ADV=y
CONFIG_BT_DEVICE_NAME="PBP Broadcast Sink"

# PBP Support
CONFIG_BT_PBP=y
26 changes: 26 additions & 0 deletions samples/bluetooth/public_broadcast_sink/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sample:
description: Bluetooth Low Energy Audio PBP Broadcast Sink sample
name: Bluetooth Low Energy Audio PBP Broadcast Sink sample
tests:
sample.bluetooth.public_broadcast_sink:
harness: bluetooth
platform_allow:
- qemu_cortex_m3
- qemu_x86
- nrf5340dk_nrf5340_cpuapp
integration_platforms:
- qemu_x86
- nrf5340dk_nrf5340_cpuapp
tags: bluetooth
sysbuild: true
sample.bluetooth.public_broadcast_sink.bt_ll_sw_split:
harness: bluetooth
platform_allow:
- nrf52_bsim
- nrf52833dk_nrf52820
- nrf52833dk_nrf52833
integration_platforms:
- nrf52_bsim
- nrf52833dk_nrf52833
extra_args: OVERLAY_CONFIG=overlay-bt_ll_sw_split.conf
tags: bluetooth
Loading

0 comments on commit 3372312

Please sign in to comment.