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