1 /*
2 * Copyright (C) 2016 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 <media/TypeConverter.h>
18
19 namespace android {
20
21 #define MAKE_STRING_FROM_ENUM(string) { #string, string }
22 #define TERMINATOR { .literal = nullptr }
23
24 template <>
25 const OutputDeviceConverter::Table OutputDeviceConverter::mTable[] = {
26 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_NONE),
27 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_EARPIECE),
28 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPEAKER),
29 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPEAKER_SAFE),
30 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_WIRED_HEADSET),
31 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_WIRED_HEADPHONE),
32 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO),
33 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET),
34 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
35 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_SCO),
36 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP),
37 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES),
38 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
39 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_A2DP),
40 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_AUX_DIGITAL),
41 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_HDMI),
42 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET),
43 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
44 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_ACCESSORY),
45 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_DEVICE),
46 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_USB),
47 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_REMOTE_SUBMIX),
48 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_TELEPHONY_TX),
49 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_LINE),
50 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_HDMI_ARC),
51 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPDIF),
52 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_FM),
53 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_AUX_LINE),
54 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_IP),
55 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BUS),
56 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_PROXY),
57 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_HEADSET),
58 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_DEFAULT),
59 // STUB must be after DEFAULT, so the latter is picked up by toString first.
60 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_STUB),
61 TERMINATOR
62 };
63
64 template <>
65 const InputDeviceConverter::Table InputDeviceConverter::mTable[] = {
66 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_NONE),
67 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_COMMUNICATION),
68 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
69 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
70 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
71 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ALL_SCO),
72 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
73 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
74 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
75 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
76 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
77 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
78 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
79 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
80 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
81 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
82 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
83 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ALL_USB),
84 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
85 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
86 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
87 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
88 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
89 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
90 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
91 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUS),
92 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_PROXY),
93 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_HEADSET),
94 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DEFAULT),
95 // STUB must be after DEFAULT, so the latter is picked up by toString first.
96 MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_STUB),
97 TERMINATOR
98 };
99
100
101 template <>
102 const OutputFlagConverter::Table OutputFlagConverter::mTable[] = {
103 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_NONE),
104 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
105 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
106 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_FAST),
107 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
108 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
109 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
110 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
111 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_TTS),
112 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_RAW),
113 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_SYNC),
114 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO),
115 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM),
116 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ),
117 MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_VOIP_RX),
118 TERMINATOR
119 };
120
121
122 template <>
123 const InputFlagConverter::Table InputFlagConverter::mTable[] = {
124 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_NONE),
125 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_FAST),
126 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
127 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_RAW),
128 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_SYNC),
129 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_MMAP_NOIRQ),
130 MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_VOIP_TX),
131 TERMINATOR
132 };
133
134
135 template <>
136 const FormatConverter::Table FormatConverter::mTable[] = {
137 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_16_BIT),
138 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_BIT),
139 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_32_BIT),
140 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
141 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_FLOAT),
142 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
143 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MP3),
144 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_NB),
145 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_WB),
146 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC),
147 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_MAIN),
148 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LC),
149 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SSR),
150 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LTP),
151 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V1),
152 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SCALABLE),
153 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ERLC),
154 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LD),
155 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V2),
156 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ELD),
157 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_MAIN),
158 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LC),
159 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_SSR),
160 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LTP),
161 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1),
162 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_SCALABLE),
163 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_ERLC),
164 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LD),
165 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2),
166 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_ELD),
167 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_VORBIS),
168 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V1),
169 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V2),
170 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_OPUS),
171 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AC3),
172 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_E_AC3),
173 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS),
174 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS_HD),
175 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_IEC61937),
176 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DOLBY_TRUEHD),
177 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRC),
178 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCB),
179 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCWB),
180 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCNW),
181 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADIF),
182 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_WMA),
183 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_WMA_PRO),
184 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_WB_PLUS),
185 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MP2),
186 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_QCELP),
187 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DSD),
188 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_FLAC),
189 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_ALAC),
190 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APE),
191 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS),
192 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_SBC),
193 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX),
194 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX_HD),
195 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AC4),
196 MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_LDAC),
197 TERMINATOR
198 };
199
200
201 template <>
202 const OutputChannelConverter::Table OutputChannelConverter::mTable[] = {
203 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_MONO),
204 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_STEREO),
205 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_2POINT1),
206 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_QUAD),
207 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_SURROUND),
208 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_PENTA),
209 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
210 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_6POINT1),
211 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
212 TERMINATOR
213 };
214
215
216 template <>
217 const InputChannelConverter::Table InputChannelConverter::mTable[] = {
218 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_MONO),
219 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_STEREO),
220 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_FRONT_BACK),
221 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_6),
222 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO),
223 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO),
224 MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_VOICE_CALL_MONO),
225 TERMINATOR
226 };
227
228 template <>
229 const ChannelIndexConverter::Table ChannelIndexConverter::mTable[] = {
230 {"AUDIO_CHANNEL_INDEX_MASK_1", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_1)},
231 {"AUDIO_CHANNEL_INDEX_MASK_2", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_2)},
232 {"AUDIO_CHANNEL_INDEX_MASK_3", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_3)},
233 {"AUDIO_CHANNEL_INDEX_MASK_4", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_4)},
234 {"AUDIO_CHANNEL_INDEX_MASK_5", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_5)},
235 {"AUDIO_CHANNEL_INDEX_MASK_6", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_6)},
236 {"AUDIO_CHANNEL_INDEX_MASK_7", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_7)},
237 {"AUDIO_CHANNEL_INDEX_MASK_8", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_8)},
238 TERMINATOR
239 };
240
241
242 template <>
243 const GainModeConverter::Table GainModeConverter::mTable[] = {
244 MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_JOINT),
245 MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_CHANNELS),
246 MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_RAMP),
247 TERMINATOR
248 };
249
250
251 template <>
252 const StreamTypeConverter::Table StreamTypeConverter::mTable[] = {
253 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_VOICE_CALL),
254 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_SYSTEM),
255 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_RING),
256 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_MUSIC),
257 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ALARM),
258 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_NOTIFICATION),
259 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_BLUETOOTH_SCO ),
260 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ENFORCED_AUDIBLE),
261 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_DTMF),
262 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_TTS),
263 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ACCESSIBILITY),
264 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_REROUTING),
265 MAKE_STRING_FROM_ENUM(AUDIO_STREAM_PATCH),
266 TERMINATOR
267 };
268
269 template<>
270 const AudioModeConverter::Table AudioModeConverter::mTable[] = {
271 MAKE_STRING_FROM_ENUM(AUDIO_MODE_INVALID),
272 MAKE_STRING_FROM_ENUM(AUDIO_MODE_CURRENT),
273 MAKE_STRING_FROM_ENUM(AUDIO_MODE_NORMAL),
274 MAKE_STRING_FROM_ENUM(AUDIO_MODE_RINGTONE),
275 MAKE_STRING_FROM_ENUM(AUDIO_MODE_IN_CALL),
276 MAKE_STRING_FROM_ENUM(AUDIO_MODE_IN_COMMUNICATION),
277 TERMINATOR
278 };
279
280 template <>
281 const UsageTypeConverter::Table UsageTypeConverter::mTable[] = {
282 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_UNKNOWN),
283 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_MEDIA),
284 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_VOICE_COMMUNICATION),
285 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING),
286 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_ALARM),
287 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION),
288 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE),
289 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST),
290 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT),
291 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED),
292 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_NOTIFICATION_EVENT),
293 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY),
294 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE),
295 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_ASSISTANCE_SONIFICATION),
296 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_GAME),
297 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_VIRTUAL_SOURCE),
298 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_CNT),
299 MAKE_STRING_FROM_ENUM(AUDIO_USAGE_MAX),
300 TERMINATOR
301 };
302
303 template <>
304 const SourceTypeConverter::Table SourceTypeConverter::mTable[] = {
305 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_DEFAULT),
306 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_MIC),
307 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_VOICE_UPLINK),
308 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_VOICE_DOWNLINK),
309 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_VOICE_CALL),
310 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_CAMCORDER),
311 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_VOICE_RECOGNITION),
312 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_VOICE_COMMUNICATION),
313 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_REMOTE_SUBMIX),
314 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_UNPROCESSED),
315 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_CNT),
316 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_MAX),
317 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_FM_TUNER),
318 MAKE_STRING_FROM_ENUM(AUDIO_SOURCE_HOTWORD),
319 TERMINATOR
320 };
321
322 template class TypeConverter<OutputDeviceTraits>;
323 template class TypeConverter<InputDeviceTraits>;
324 template class TypeConverter<OutputFlagTraits>;
325 template class TypeConverter<InputFlagTraits>;
326 template class TypeConverter<FormatTraits>;
327 template class TypeConverter<OutputChannelTraits>;
328 template class TypeConverter<InputChannelTraits>;
329 template class TypeConverter<ChannelIndexTraits>;
330 template class TypeConverter<GainModeTraits>;
331 template class TypeConverter<StreamTraits>;
332 template class TypeConverter<AudioModeTraits>;
333 template class TypeConverter<UsageTraits>;
334 template class TypeConverter<SourceTraits>;
335
deviceFromString(const std::string & literalDevice,audio_devices_t & device)336 bool deviceFromString(const std::string& literalDevice, audio_devices_t& device) {
337 return InputDeviceConverter::fromString(literalDevice, device) ||
338 OutputDeviceConverter::fromString(literalDevice, device);
339 }
340
deviceToString(audio_devices_t device,std::string & literalDevice)341 bool deviceToString(audio_devices_t device, std::string& literalDevice) {
342 if (device & AUDIO_DEVICE_BIT_IN) {
343 return InputDeviceConverter::toString(device, literalDevice);
344 } else {
345 return OutputDeviceConverter::toString(device, literalDevice);
346 }
347 }
348
samplingRatesFromString(const std::string & samplingRates,const char * del)349 SampleRateTraits::Collection samplingRatesFromString(
350 const std::string &samplingRates, const char *del)
351 {
352 SampleRateTraits::Collection samplingRateCollection;
353 collectionFromString<SampleRateTraits>(samplingRates, samplingRateCollection, del);
354 return samplingRateCollection;
355 }
356
formatsFromString(const std::string & formats,const char * del)357 FormatTraits::Collection formatsFromString(
358 const std::string &formats, const char *del)
359 {
360 FormatTraits::Collection formatCollection;
361 FormatConverter::collectionFromString(formats, formatCollection, del);
362 return formatCollection;
363 }
364
formatFromString(const std::string & literalFormat,audio_format_t defaultFormat)365 audio_format_t formatFromString(const std::string &literalFormat, audio_format_t defaultFormat)
366 {
367 audio_format_t format;
368 if (literalFormat.empty()) {
369 return defaultFormat;
370 }
371 FormatConverter::fromString(literalFormat, format);
372 return format;
373 }
374
channelMaskFromString(const std::string & literalChannels)375 audio_channel_mask_t channelMaskFromString(const std::string &literalChannels)
376 {
377 audio_channel_mask_t channels;
378 if (!OutputChannelConverter::fromString(literalChannels, channels) &&
379 !InputChannelConverter::fromString(literalChannels, channels)) {
380 return AUDIO_CHANNEL_INVALID;
381 }
382 return channels;
383 }
384
channelMasksFromString(const std::string & channels,const char * del)385 ChannelTraits::Collection channelMasksFromString(
386 const std::string &channels, const char *del)
387 {
388 ChannelTraits::Collection channelMaskCollection;
389 OutputChannelConverter::collectionFromString(channels, channelMaskCollection, del);
390 InputChannelConverter::collectionFromString(channels, channelMaskCollection, del);
391 ChannelIndexConverter::collectionFromString(channels, channelMaskCollection, del);
392 return channelMaskCollection;
393 }
394
inputChannelMasksFromString(const std::string & inChannels,const char * del)395 InputChannelTraits::Collection inputChannelMasksFromString(
396 const std::string &inChannels, const char *del)
397 {
398 InputChannelTraits::Collection inputChannelMaskCollection;
399 InputChannelConverter::collectionFromString(inChannels, inputChannelMaskCollection, del);
400 ChannelIndexConverter::collectionFromString(inChannels, inputChannelMaskCollection, del);
401 return inputChannelMaskCollection;
402 }
403
outputChannelMasksFromString(const std::string & outChannels,const char * del)404 OutputChannelTraits::Collection outputChannelMasksFromString(
405 const std::string &outChannels, const char *del)
406 {
407 OutputChannelTraits::Collection outputChannelMaskCollection;
408 OutputChannelConverter::collectionFromString(outChannels, outputChannelMaskCollection, del);
409 ChannelIndexConverter::collectionFromString(outChannels, outputChannelMaskCollection, del);
410 return outputChannelMaskCollection;
411 }
412
413 }; // namespace android
414