1 /*
2 * Copyright 2024 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 #include "broadcast_configuration_provider.h"
18
19 #include "internal_include/stack_config.h"
20
21 namespace bluetooth::le_audio {
22 namespace broadcaster {
23 /* Software codec configuration provider */
GetBroadcastConfig(const std::vector<std::pair<types::LeAudioContextType,uint8_t>> & subgroup_quality)24 BroadcastConfiguration GetBroadcastConfig(
25 const std::vector<std::pair<types::LeAudioContextType, uint8_t>>&
26 subgroup_quality) {
27 // Select the SW codec parameters based on the first subgroup audio context
28 // Note that the HW offloader may support more quality subgroups.
29 // TODO: Unify the quality selection logic with GetBroadcastOffloadConfig()
30 auto context = types::AudioContexts(subgroup_quality.at(0).first);
31
32 const std::string* options =
33 stack_config_get_interface()->get_pts_broadcast_audio_config_options();
34 if (options) {
35 if (!options->compare("lc3_stereo_48_1_2")) return lc3_stereo_48_1_2;
36 if (!options->compare("lc3_stereo_48_2_2")) return lc3_stereo_48_2_2;
37 if (!options->compare("lc3_stereo_48_3_2")) return lc3_stereo_48_3_2;
38 if (!options->compare("lc3_stereo_48_4_2")) return lc3_stereo_48_4_2;
39 }
40
41 // High quality, Low Latency
42 if (context.test_any(types::LeAudioContextType::GAME |
43 types::LeAudioContextType::LIVE))
44 return lc3_stereo_24_2_1;
45
46 // Standard quality, Low Latency
47 if (context.test(types::LeAudioContextType::INSTRUCTIONAL))
48 return lc3_mono_16_2_1;
49
50 // Standard quality, High Reliability
51 if (context.test_any(types::LeAudioContextType::SOUNDEFFECTS |
52 types::LeAudioContextType::UNSPECIFIED))
53 return lc3_stereo_16_2_2;
54
55 if (context.test_any(types::LeAudioContextType::ALERTS |
56 types::LeAudioContextType::NOTIFICATIONS |
57 types::LeAudioContextType::EMERGENCYALARM))
58 return lc3_mono_16_2_2;
59
60 // High quality, High Reliability
61 if (context.test(types::LeAudioContextType::MEDIA)) return lc3_stereo_24_2_2;
62
63 // Defaults: Standard quality, High Reliability
64 return lc3_mono_16_2_2;
65 }
66 } // namespace broadcaster
67 } // namespace bluetooth::le_audio