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

Implement Unicast Server Advertising Data #442

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 38 additions & 1 deletion bumble/profiles/bap.py
Expand Up @@ -24,8 +24,9 @@
import struct
import functools
import logging
from typing import Optional, List, Union, Type, Dict, Any, Tuple, cast
from typing import Optional, List, Union, Type, Dict, Any, Tuple

from bumble import core
from bumble import colors
from bumble import device
from bumble import hci
Expand Down Expand Up @@ -228,6 +229,14 @@ class SupportedFrameDuration(enum.IntFlag):
DURATION_10000_US_PREFERRED = 0b0010


class AnnouncementType(enum.IntEnum):
'''Basic Audio Profile, 3.5.3. Additional Audio Stream Control Service requirements'''

# fmt: off
GENERAL = 0x00
TARGETED = 0x01


# -----------------------------------------------------------------------------
# ASE Operations
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -453,6 +462,34 @@ class AudioRole(enum.IntEnum):
SOURCE = hci.HCI_LE_Setup_ISO_Data_Path_Command.Direction.HOST_TO_CONTROLLER


@dataclasses.dataclass
class UnicastServerAdvertisingData:
"""Advertising Data for ASCS."""

announcement_type: AnnouncementType = AnnouncementType.TARGETED
available_audio_contexts: ContextType = ContextType.MEDIA
metadata: bytes = b''

def __bytes__(self) -> bytes:
return bytes(
core.AdvertisingData(
[
(
core.AdvertisingData.SERVICE_DATA_16_BIT_UUID,
struct.pack(
'<2sBIB',
gatt.GATT_AUDIO_STREAM_CONTROL_SERVICE.to_bytes(),
self.announcement_type,
self.available_audio_contexts,
len(self.metadata),
)
+ self.metadata,
)
]
)
)


# -----------------------------------------------------------------------------
# Utils
# -----------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions examples/run_unicast_server.py
Expand Up @@ -22,14 +22,14 @@
import struct
import secrets
from bumble.core import AdvertisingData
from bumble.device import Device, CisLink, AdvertisingParameters
from bumble.device import Device, CisLink
from bumble.hci import (
CodecID,
CodingFormat,
OwnAddressType,
HCI_IsoDataPacket,
)
from bumble.profiles.bap import (
UnicastServerAdvertisingData,
CodecSpecificCapabilities,
ContextType,
AudioLocation,
Expand Down Expand Up @@ -141,6 +141,7 @@ async def main() -> None:
)
)
+ csis.get_advertising_data()
+ bytes(UnicastServerAdvertisingData())
)
subprocess = await asyncio.create_subprocess_shell(
f'dlc3 | ffplay pipe:0',
Expand Down Expand Up @@ -178,7 +179,7 @@ def on_cis(cis_link: CisLink):

device.once('cis_establishment', on_cis)

advertising_set = await device.create_advertising_set(
await device.create_advertising_set(
advertising_data=advertising_data,
)

Expand Down
2 changes: 2 additions & 0 deletions examples/run_vcp_renderer.py
Expand Up @@ -31,6 +31,7 @@
OwnAddressType,
)
from bumble.profiles.bap import (
UnicastServerAdvertisingData,
CodecSpecificCapabilities,
ContextType,
AudioLocation,
Expand Down Expand Up @@ -151,6 +152,7 @@ def on_volume_state(volume_setting: int, muted: int, change_counter: int):
)
)
+ csis.get_advertising_data()
+ bytes(UnicastServerAdvertisingData())
)

await device.create_advertising_set(
Expand Down