Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: pacs: Add dynamic PACS registration #83730

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

fredrikdanebjer
Copy link
Contributor

Added option to set the PACS Characteristics through the bap API, making PACS configuration runtime available. Source and Sink PAC, as well as Source/Sink PAC Location is can be set through a register function in the PACS api.

@@ -321,6 +321,10 @@ Bluetooth Audio
* :kconfig:option:`CONFIG_BT_PAC_SNK`
* :kconfig:option:`CONFIG_BT_PAC_SRC`

* PACS have been changed to support dynamic, runtime configuration. This means that PACS now has
to be regsitered with :c:func:`bt_pacs_register` before it can be used. All Kconfig option still
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some typo:

regsitered -> registered
Runetime -> Runtime

doc/releases/migration-guide-4.1.rst Outdated Show resolved Hide resolved
include/zephyr/bluetooth/audio/pacs.h Outdated Show resolved Hide resolved
@@ -45,6 +45,18 @@ struct bt_pacs_cap {
sys_snode_t _node;
};


/** Structure for registering PACS */
struct bt_bap_pacs_register_param {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also add support for registering initial values here? i.e. the initial contexts, locations and records?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but it could also make sense not to do it. The current content of struct bt_bap_pacs_register_param strictly necessary to run the service, and they cannot easily be changed, in fact they would need a reregistration to change.

Contexts, locations, and records can more easily change at runtime.

I would prefer to keep it as is for now - but if you really want this change Im happy to create an issue for future change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :) It makes sense to keep as is, with the caveat that the default values are invalid, so the user shall call the other functions afterwards (similar as they have to today)

samples/bluetooth/bap_broadcast_sink/src/main.c Outdated Show resolved Hide resolved
samples/bluetooth/bap_unicast_server/src/main.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
@fredrikdanebjer fredrikdanebjer force-pushed the dyn_pacs branch 2 times, most recently from 756ef02 to eebe150 Compare January 20, 2025 05:44
doc/releases/migration-guide-4.1.rst Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
include/zephyr/bluetooth/audio/pacs.h Outdated Show resolved Hide resolved
include/zephyr/bluetooth/audio/pacs.h Outdated Show resolved Hide resolved
include/zephyr/bluetooth/audio/pacs.h Outdated Show resolved Hide resolved
Comment on lines +104 to +124
* @return 0 in case of success or negative value in case of error.
*/
int bt_pacs_register(const struct bt_bap_pacs_register_param *param);

/**
* @brief Unregister the Published Audio Capability Service instance.
*
* @return 0 in case of success or negative value in case of error.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, please use @retval instead of @return and specific the possible return values. It makes it easier for applications to know exactly which return values can be expected, and why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it as is, as it will forward error codes from other functions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it as is, as it will forward error codes from other functions.

That's one of the reasons to use retval: Simply forwarding error will make it harder to handle cases as an application.

We do not have any requirement in the coding guidelines for this, so I won't block the PR on this

samples/bluetooth/cap_acceptor/src/main.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
doc/releases/migration-guide-4.1.rst Outdated Show resolved Hide resolved
include/zephyr/bluetooth/audio/pacs.h Outdated Show resolved Hide resolved
Comment on lines +104 to +124
* @return 0 in case of success or negative value in case of error.
*/
int bt_pacs_register(const struct bt_bap_pacs_register_param *param);

/**
* @brief Unregister the Published Audio Capability Service instance.
*
* @return 0 in case of success or negative value in case of error.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it as is, as it will forward error codes from other functions.

That's one of the reasons to use retval: Simply forwarding error will make it harder to handle cases as an application.

We do not have any requirement in the coding guidelines for this, so I won't block the PR on this

subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/pacs.c Outdated Show resolved Hide resolved
@fredrikdanebjer fredrikdanebjer force-pushed the dyn_pacs branch 2 times, most recently from a76a429 to c9b2e77 Compare January 21, 2025 13:52
Comment on lines 54 to 64
bool snk_pac;
#endif /* CONFIG_BT_PAC_SNK */

#if defined(CONFIG_BT_PAC_SNK_LOC)
/**
* @brief Enables or disables registration of Sink Location Characteristic.
*
* Registration of Sink Location is dependent on @ref bt_bap_pacs_register_param.snk_pac
* also being set.
*/
bool snk_loc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm starting to wonder if we should add chrc or attr to these names? Or prefix them with register_?

If we ever want to expand bt_bap_pacs_register_param to also contain default values, snk_pac and snk_loc are the obvious names for the default sink PAC record and sink location

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think we should make those name changes in such a patch where it becomes relevant then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. At least while the API is still unstable we can more easily do that, but will be much harder to do later

@fredrikdanebjer fredrikdanebjer force-pushed the dyn_pacs branch 2 times, most recently from bba57c3 to d48096c Compare January 22, 2025 08:05
Added option to set the PACS Characteristics through the bap API,
making PACS configuration runtime available. Source and Sink PAC, as
well as Source/Sink PAC Location is can be set through a register
function in the PACS api.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
Copy link
Contributor

@larsgk larsgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - should we have a before/after RAM/ROM usage check?

@Thalley
Copy link
Collaborator

Thalley commented Jan 22, 2025

LGTM - should we have a before/after RAM/ROM usage check?

Would be nice if you can provide that @fredrikdanebjer :) Just so that we are aware of what I assume will be a memory increase

@kartben kartben merged commit 21b5f0c into zephyrproject-rtos:main Jan 22, 2025
27 checks passed
@fredrikdanebjer
Copy link
Contributor Author

fredrikdanebjer commented Jan 22, 2025

LGTM - should we have a before/after RAM/ROM usage check?

Would be nice if you can provide that @fredrikdanebjer :) Just so that we are aware of what I assume will be a memory increase

Before pacs.c:
724/5394 RAM/ROM
After pacs.c:
1116/6104 RAM/ROM

Built with audio_shell using:
west build -b nrf5340_audio_dk/nrf5340/cpuapp -d build/nrf5340audiodk/audio_shell tests/bluetooth/shell/ --pristine -- -DCONF_FILE=audio.conf -DOVERLAY_CONFIG=boards/nrf5340_audio_dk_nrf5340_cpuapp.conf

You can find the full reports attached.

post_ram.txt
post_rom.txt
pre_ram.txt
pre_rom.txt

@Thalley
Copy link
Collaborator

Thalley commented Jan 23, 2025

Before pacs.c:
724/5394 RAM/ROM
After pacs.c:
1116/6104 RAM/ROM

Alright, so that's quite a significant change. I guess it's the same for the others.

400 more RAM sounds like a lot. Is it mainly the pacs_attr array?

@fredrikdanebjer
Copy link
Contributor Author

@Thalley Yes, pacs_attrs make up of 380 bytes. As a reference for other services we did this for:
ascs_attr 320 bytes
has_attrs 200 bytes
vcs_attrs 220 bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants