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