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