• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(audio_content_type_t content_type,
36                                                        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)41 inline uint8_t GetTargetLatencyForAudioContext(types::LeAudioContextType ctx) {
42   switch (ctx) {
43     case types::LeAudioContextType::MEDIA:
44       return types::kTargetLatencyHigherReliability;
45 
46     case types::LeAudioContextType::LIVE:
47       FALLTHROUGH_INTENDED;
48     case types::LeAudioContextType::GAME:
49       return types::kTargetLatencyLower;
50 
51     case types::LeAudioContextType::RINGTONE:
52       FALLTHROUGH_INTENDED;
53     case types::LeAudioContextType::CONVERSATIONAL:
54       return types::kTargetLatencyBalancedLatencyReliability;
55 
56     default:
57       return types::kTargetLatencyUndefined;
58   }
59 
60   return types::kTargetLatencyUndefined;
61 }
62 
63 /* Helpers to get btle_audio_codec_config_t for Java */
64 bluetooth::le_audio::btle_audio_codec_index_t translateBluetoothCodecFormatToCodecType(
65         uint8_t codec_format);
66 
67 bluetooth::le_audio::btle_audio_sample_rate_index_t translateToBtLeAudioCodecConfigSampleRate(
68         uint32_t sample_rate_capa);
69 bluetooth::le_audio::btle_audio_bits_per_sample_index_t translateToBtLeAudioCodecConfigBitPerSample(
70         uint8_t bits_per_sample);
71 bluetooth::le_audio::btle_audio_channel_count_index_t translateToBtLeAudioCodecConfigChannelCount(
72         uint8_t channel_count);
73 bluetooth::le_audio::btle_audio_frame_duration_index_t translateToBtLeAudioCodecConfigFrameDuration(
74         int frame_duration);
75 void fillStreamParamsToBtLeAudioCodecConfig(
76         const std::vector<struct types::AseConfiguration>& confs,
77         bluetooth::le_audio::btle_audio_codec_config_t& out_config);
78 
79 std::vector<bluetooth::le_audio::btle_audio_codec_config_t> GetRemoteBtLeAudioCodecConfigFromPac(
80         const types::PublishedAudioCapabilities& group_pacs);
81 bool IsCodecUsingLtvFormat(const types::LeAudioCodecId& codec_id);
82 types::LeAudioConfigurationStrategy GetStrategyForAseConfig(
83         const std::vector<le_audio::types::AseConfiguration>& cfgs, uint8_t device_cnt);
84 ::bluetooth::le_audio::LeAudioCodecConfiguration
85 GetAudioSessionCodecConfigFromAudioSetConfiguration(
86         const ::bluetooth::le_audio::types::AudioSetConfiguration& audio_set_conf,
87         uint8_t remote_direction);
88 const struct types::acs_ac_record* GetConfigurationSupportedPac(
89         const ::bluetooth::le_audio::types::PublishedAudioCapabilities& pacs,
90         const ::bluetooth::le_audio::types::CodecConfigSetting& codec_config_setting);
91 bool IsAseConfigMatchedWithPreferredRequirements(
92         const std::vector<struct types::AseConfiguration>& ase_confs,
93         const std::vector<
94                 CodecManager::UnicastConfigurationRequirements::DeviceDirectionRequirements>& reqs,
95         uint8_t channel_cnt_per_ase);
96 }  // namespace utils
97 }  // namespace bluetooth::le_audio
98