1 /* 2 * Copyright 2019 HIMSA II K/S - www.himsa.com. Represented by EHIMA - 3 * www.ehima.com 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #pragma once 19 20 #include <array> 21 #include <map> 22 #include <optional> 23 #include <vector> 24 25 #include "raw_address.h" 26 27 namespace bluetooth { 28 namespace le_audio { 29 30 enum class ConnectionState { 31 DISCONNECTED = 0, 32 CONNECTING, 33 CONNECTED, 34 DISCONNECTING 35 }; 36 37 enum class GroupStatus { 38 INACTIVE = 0, 39 ACTIVE, 40 TURNED_IDLE_DURING_CALL, 41 }; 42 43 enum class GroupStreamStatus { 44 IDLE = 0, 45 STREAMING, 46 RELEASING, 47 SUSPENDING, 48 SUSPENDED, 49 CONFIGURED_AUTONOMOUS, 50 CONFIGURED_BY_USER, 51 DESTROYED, 52 }; 53 54 enum class GroupNodeStatus { 55 ADDED = 1, 56 REMOVED, 57 }; 58 59 typedef enum { 60 LE_AUDIO_CODEC_INDEX_SOURCE_LC3 = 0, 61 LE_AUDIO_CODEC_INDEX_SOURCE_MAX 62 } btle_audio_codec_index_t; 63 64 typedef struct { 65 btle_audio_codec_index_t codec_type; 66 ToString__anon1718ae97020867 std::string ToString() const { 68 std::string codec_name_str; 69 70 switch (codec_type) { 71 case LE_AUDIO_CODEC_INDEX_SOURCE_LC3: 72 codec_name_str = "LC3"; 73 break; 74 default: 75 codec_name_str = "Unknown LE codec " + std::to_string(codec_type); 76 break; 77 } 78 return "codec: " + codec_name_str; 79 } 80 } btle_audio_codec_config_t; 81 82 class LeAudioClientCallbacks { 83 public: 84 virtual ~LeAudioClientCallbacks() = default; 85 86 /* Callback to notify Java that stack is ready */ 87 virtual void OnInitialized(void) = 0; 88 89 /** Callback for profile connection state change */ 90 virtual void OnConnectionState(ConnectionState state, 91 const RawAddress& address) = 0; 92 93 /* Callback with group status update */ 94 virtual void OnGroupStatus(int group_id, GroupStatus group_status) = 0; 95 96 /* Callback with node status update */ 97 virtual void OnGroupNodeStatus(const RawAddress& bd_addr, int group_id, 98 GroupNodeStatus node_status) = 0; 99 /* Callback for newly recognized or reconfigured existing le audio group */ 100 virtual void OnAudioConf(uint8_t direction, int group_id, 101 uint32_t snk_audio_location, 102 uint32_t src_audio_location, 103 uint16_t avail_cont) = 0; 104 /* Callback for sink audio location recognized */ 105 virtual void OnSinkAudioLocationAvailable(const RawAddress& address, 106 uint32_t snk_audio_locations) = 0; 107 /* Callback with local codec capabilities */ 108 virtual void OnAudioLocalCodecCapabilities( 109 std::vector<btle_audio_codec_config_t> local_input_capa_codec_conf, 110 std::vector<btle_audio_codec_config_t> local_output_capa_codec_conf) = 0; 111 /* Callback with group codec configurations */ 112 virtual void OnAudioGroupCodecConf( 113 int group_id, btle_audio_codec_config_t input_codec_conf, 114 btle_audio_codec_config_t output_codec_conf, 115 std::vector<btle_audio_codec_config_t> input_selectable_codec_conf, 116 std::vector<btle_audio_codec_config_t> output_selectable_codec_conf) = 0; 117 }; 118 119 class LeAudioClientInterface { 120 public: 121 virtual ~LeAudioClientInterface() = default; 122 123 /* Register the LeAudio callbacks */ 124 virtual void Initialize( 125 LeAudioClientCallbacks* callbacks, 126 const std::vector<btle_audio_codec_config_t>& offloading_preference) = 0; 127 128 /** Connect to LEAudio */ 129 virtual void Connect(const RawAddress& address) = 0; 130 131 /** Disconnect from LEAudio */ 132 virtual void Disconnect(const RawAddress& address) = 0; 133 134 /* Cleanup the LeAudio */ 135 virtual void Cleanup(void) = 0; 136 137 /* Called when LeAudio is unbonded. */ 138 virtual void RemoveDevice(const RawAddress& address) = 0; 139 140 /* Attach le audio node to group */ 141 virtual void GroupAddNode(int group_id, const RawAddress& addr) = 0; 142 143 /* Detach le audio node from a group */ 144 virtual void GroupRemoveNode(int group_id, const RawAddress& addr) = 0; 145 146 /* Set active le audio group */ 147 virtual void GroupSetActive(int group_id) = 0; 148 149 /* Set codec config preference */ 150 virtual void SetCodecConfigPreference( 151 int group_id, btle_audio_codec_config_t input_codec_config, 152 btle_audio_codec_config_t output_codec_config) = 0; 153 154 /* Set Ccid for context type */ 155 virtual void SetCcidInformation(int ccid, int context_type) = 0; 156 157 /* Set In call flag */ 158 virtual void SetInCall(bool in_call) = 0; 159 }; 160 161 /* Represents the broadcast source state. */ 162 enum class BroadcastState { 163 STOPPED = 0, 164 CONFIGURING, 165 CONFIGURED, 166 STOPPING, 167 STREAMING, 168 }; 169 170 using BroadcastId = uint32_t; 171 static constexpr BroadcastId kBroadcastIdInvalid = 0x00000000; 172 using BroadcastCode = std::array<uint8_t, 16>; 173 174 /* Content Metadata LTV Types */ 175 constexpr uint8_t kLeAudioMetadataTypePreferredAudioContext = 0x01; 176 constexpr uint8_t kLeAudioMetadataTypeStreamingAudioContext = 0x02; 177 constexpr uint8_t kLeAudioMetadataTypeProgramInfo = 0x03; 178 constexpr uint8_t kLeAudioMetadataTypeLanguage = 0x04; 179 constexpr uint8_t kLeAudioMetadataTypeCcidList = 0x05; 180 181 /* Codec specific LTV Types */ 182 constexpr uint8_t kLeAudioCodecLC3TypeSamplingFreq = 0x01; 183 constexpr uint8_t kLeAudioCodecLC3TypeFrameDuration = 0x02; 184 constexpr uint8_t kLeAudioCodecLC3TypeAudioChannelAllocation = 0x03; 185 constexpr uint8_t kLeAudioCodecLC3TypeOctetPerFrame = 0x04; 186 constexpr uint8_t kLeAudioCodecLC3TypeCodecFrameBlocksPerSdu = 0x05; 187 188 struct BasicAudioAnnouncementCodecConfig { 189 /* 5 octets for the Codec ID */ 190 uint8_t codec_id; 191 uint16_t vendor_company_id; 192 uint16_t vendor_codec_id; 193 194 /* Codec params - series of LTV formatted triplets */ 195 std::map<uint8_t, std::vector<uint8_t>> codec_specific_params; 196 }; 197 198 struct BasicAudioAnnouncementBisConfig { 199 std::map<uint8_t, std::vector<uint8_t>> codec_specific_params; 200 uint8_t bis_index; 201 }; 202 203 struct BasicAudioAnnouncementSubgroup { 204 /* Subgroup specific codec configuration and metadata */ 205 BasicAudioAnnouncementCodecConfig codec_config; 206 // Content metadata 207 std::map<uint8_t, std::vector<uint8_t>> metadata; 208 // Broadcast channel configuration 209 std::vector<BasicAudioAnnouncementBisConfig> bis_configs; 210 }; 211 212 struct BasicAudioAnnouncementData { 213 /* Announcement Header fields */ 214 uint32_t presentation_delay; 215 216 /* Subgroup specific configurations */ 217 std::vector<BasicAudioAnnouncementSubgroup> subgroup_configs; 218 }; 219 220 struct BroadcastMetadata { 221 uint16_t pa_interval; 222 RawAddress addr; 223 uint8_t addr_type; 224 uint8_t adv_sid; 225 226 BroadcastId broadcast_id; 227 std::optional<BroadcastCode> broadcast_code; 228 229 /* Presentation delay and subgroup configurations */ 230 BasicAudioAnnouncementData basic_audio_announcement; 231 }; 232 233 class LeAudioBroadcasterCallbacks { 234 public: 235 virtual ~LeAudioBroadcasterCallbacks() = default; 236 /* Callback for the newly created broadcast event. */ 237 virtual void OnBroadcastCreated(uint32_t broadcast_id, bool success) = 0; 238 239 /* Callback for the destroyed broadcast event. */ 240 virtual void OnBroadcastDestroyed(uint32_t broadcast_id) = 0; 241 /* Callback for the broadcast source state event. */ 242 virtual void OnBroadcastStateChanged(uint32_t broadcast_id, 243 BroadcastState state) = 0; 244 /* Callback for the broadcast metadata change. */ 245 virtual void OnBroadcastMetadataChanged( 246 uint32_t broadcast_id, const BroadcastMetadata& broadcast_metadata) = 0; 247 }; 248 249 class LeAudioBroadcasterInterface { 250 public: 251 virtual ~LeAudioBroadcasterInterface() = default; 252 /* Register the LeAudio Broadcaster callbacks */ 253 virtual void Initialize(LeAudioBroadcasterCallbacks* callbacks) = 0; 254 /* Stop the LeAudio Broadcaster and all active broadcasts */ 255 virtual void Stop(void) = 0; 256 /* Cleanup the LeAudio Broadcaster */ 257 virtual void Cleanup(void) = 0; 258 /* Create Broadcast instance */ 259 virtual void CreateBroadcast(std::vector<uint8_t> metadata, 260 std::optional<BroadcastCode> broadcast_code) = 0; 261 /* Update the ongoing Broadcast metadata */ 262 virtual void UpdateMetadata(uint32_t broadcast_id, 263 std::vector<uint8_t> metadata) = 0; 264 265 /* Start the existing Broadcast stream */ 266 virtual void StartBroadcast(uint32_t broadcast_id) = 0; 267 /* Pause the ongoing Broadcast stream */ 268 virtual void PauseBroadcast(uint32_t broadcast_id) = 0; 269 /* Stop the Broadcast (no stream, no periodic advertisements */ 270 virtual void StopBroadcast(uint32_t broadcast_id) = 0; 271 /* Destroy the existing Broadcast instance */ 272 virtual void DestroyBroadcast(uint32_t broadcast_id) = 0; 273 /* Get Broadcast Metadata */ 274 virtual void GetBroadcastMetadata(uint32_t broadcast_id) = 0; 275 }; 276 277 } /* namespace le_audio */ 278 } /* namespace bluetooth */ 279