1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #ifdef TARGET_FLOSS 20 #include <audio_hal_interface/audio_linux.h> 21 #else 22 #include <hardware/audio.h> 23 #endif 24 25 #include <hardware/bt_le_audio.h> 26 27 #include <bitset> 28 #include <vector> 29 30 #include "audio_hal_client/audio_hal_client.h" 31 #include "le_audio_types.h" 32 33 namespace bluetooth::le_audio { 34 namespace utils { 35 types::LeAudioContextType AudioContentToLeAudioContext( 36 audio_content_type_t content_type, audio_usage_t usage); 37 types::AudioContexts GetAudioContextsFromSourceMetadata( 38 const std::vector<struct playback_track_metadata_v7>& source_metadata); 39 types::AudioContexts GetAudioContextsFromSinkMetadata( 40 const std::vector<struct record_track_metadata_v7>& sink_metadata); GetTargetLatencyForAudioContext(types::LeAudioContextType ctx)41inline uint8_t GetTargetLatencyForAudioContext(types::LeAudioContextType ctx) { 42 switch (ctx) { 43 case types::LeAudioContextType::GAME: 44 FALLTHROUGH_INTENDED; 45 case types::LeAudioContextType::VOICEASSISTANTS: 46 FALLTHROUGH_INTENDED; 47 case types::LeAudioContextType::LIVE: 48 FALLTHROUGH_INTENDED; 49 case types::LeAudioContextType::CONVERSATIONAL: 50 FALLTHROUGH_INTENDED; 51 case types::LeAudioContextType::RINGTONE: 52 return types::kTargetLatencyLower; 53 54 default: 55 return types::kTargetLatencyUndefined; 56 } 57 58 return types::kTargetLatencyUndefined; 59 } 60 61 /* Helpers to get btle_audio_codec_config_t for Java */ 62 bluetooth::le_audio::btle_audio_codec_index_t 63 translateBluetoothCodecFormatToCodecType(uint8_t codec_format); 64 65 bluetooth::le_audio::btle_audio_sample_rate_index_t 66 translateToBtLeAudioCodecConfigSampleRate(uint32_t sample_rate_capa); 67 bluetooth::le_audio::btle_audio_bits_per_sample_index_t 68 translateToBtLeAudioCodecConfigBitPerSample(uint8_t bits_per_sample); 69 bluetooth::le_audio::btle_audio_channel_count_index_t 70 translateToBtLeAudioCodecConfigChannelCount(uint8_t channel_count); 71 bluetooth::le_audio::btle_audio_frame_duration_index_t 72 translateToBtLeAudioCodecConfigFrameDuration(int frame_duration); 73 void fillStreamParamsToBtLeAudioCodecConfig( 74 const std::vector<struct set_configurations::AseConfiguration>& confs, 75 bluetooth::le_audio::btle_audio_codec_config_t& out_config); 76 77 std::vector<bluetooth::le_audio::btle_audio_codec_config_t> 78 GetRemoteBtLeAudioCodecConfigFromPac( 79 const types::PublishedAudioCapabilities& group_pacs); 80 bool IsCodecUsingLtvFormat(const types::LeAudioCodecId& codec_id); 81 types::LeAudioConfigurationStrategy GetStrategyForAseConfig( 82 const std::vector<le_audio::set_configurations::AseConfiguration>& cfgs, 83 uint8_t device_cnt); 84 ::bluetooth::le_audio::LeAudioCodecConfiguration 85 GetAudioSessionCodecConfigFromAudioSetConfiguration( 86 const ::bluetooth::le_audio::set_configurations::AudioSetConfiguration& 87 audio_set_conf, 88 uint8_t remote_direction); 89 const struct types::acs_ac_record* GetConfigurationSupportedPac( 90 const ::bluetooth::le_audio::types::PublishedAudioCapabilities& pacs, 91 const ::bluetooth::le_audio::set_configurations::CodecConfigSetting& 92 codec_config_setting); 93 } // namespace utils 94 } // namespace bluetooth::le_audio 95