TypeConverter.cpp revision fdb3c07db5d44535eb8c3ec46dc78ad8446c01eb
1a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie/*
2a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * Copyright (C) 2015 The Android Open Source Project
3a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie *
4a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * Licensed under the Apache License, Version 2.0 (the "License");
5a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * you may not use this file except in compliance with the License.
6a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * You may obtain a copy of the License at
7a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie *
8a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie *      http://www.apache.org/licenses/LICENSE-2.0
9a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie *
10a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * Unless required by applicable law or agreed to in writing, software
11a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * distributed under the License is distributed on an "AS IS" BASIS,
12a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * See the License for the specific language governing permissions and
14a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie * limitations under the License.
15a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie */
16a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
17a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie#include "TypeConverter.h"
18a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
19a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffienamespace android {
20a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
21a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie#define MAKE_STRING_FROM_ENUM(string) { #string, string }
22a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
23a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
24a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst DeviceConverter::Table DeviceConverter::mTable[] = {
25a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_EARPIECE),
26a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPEAKER),
27a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPEAKER_SAFE),
28a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_WIRED_HEADSET),
29a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_WIRED_HEADPHONE),
30a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO),
31a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET),
32a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
33a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_SCO),
34a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP),
35a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES),
36a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
37a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_A2DP),
38a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_AUX_DIGITAL),
39a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_HDMI),
40a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET),
41a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
42a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_ACCESSORY),
43a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_DEVICE),
44a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_USB),
45a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_REMOTE_SUBMIX),
46a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_TELEPHONY_TX),
47a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_LINE),
48a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_HDMI_ARC),
49a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_SPDIF),
50a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_FM),
51a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_AUX_LINE),
52a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_IP),
53a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
54a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
55a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
56a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ALL_SCO),
57a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
58a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
59a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
60a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TELEPHONY_RX),
61a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_VOICE_CALL),
62a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BACK_MIC),
63a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_REMOTE_SUBMIX),
64a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
65a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
66a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
67a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
68a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
69a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
70a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
71a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_SPDIF),
72a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
73a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
74a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_IP),
75a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
76a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
77a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
78a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t DeviceConverter::mSize = sizeof(DeviceConverter::mTable) /
79a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(DeviceConverter::mTable[0]);
80a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
81a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
82a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
83a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst OutputFlagConverter::Table OutputFlagConverter::mTable[] = {
84a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
85a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
86a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_FAST),
87a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
88a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
89a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
90a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
91a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_TTS),
92a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_RAW),
93a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_OUTPUT_FLAG_SYNC),
94a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
95a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
96a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t OutputFlagConverter::mSize = sizeof(OutputFlagConverter::mTable) /
97a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(OutputFlagConverter::mTable[0]);
98a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
99a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
100a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
101a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst InputFlagConverter::Table InputFlagConverter::mTable[] = {
102a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_FAST),
103a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
104a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_RAW),
105a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_INPUT_FLAG_SYNC),
106a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
107a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
108a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t InputFlagConverter::mSize = sizeof(InputFlagConverter::mTable) /
109a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(InputFlagConverter::mTable[0]);
110a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
111a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
112a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
113a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst FormatConverter::Table FormatConverter::mTable[] = {
114a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_16_BIT),
115a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_BIT),
116a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_32_BIT),
117a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
118a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_FLOAT),
119a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
120a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MP3),
121a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC),
122a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_MAIN),
123a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LC),
124a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SSR),
125a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LTP),
126a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V1),
127a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SCALABLE),
128a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ERLC),
129a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LD),
130a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V2),
131a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ELD),
132a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_VORBIS),
133a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V1),
134a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V2),
135a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_OPUS),
136a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AC3),
137a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_E_AC3),
138a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS),
139a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS_HD),
140fdb3c07db5d44535eb8c3ec46dc78ad8446c01ebPhil Burk    MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_IEC61937),
141a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
142a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
143a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t FormatConverter::mSize = sizeof(FormatConverter::mTable) /
144a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(FormatConverter::mTable[0]);
145a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
146a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
147a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
148a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst OutputChannelConverter::Table OutputChannelConverter::mTable[] = {
149a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_MONO),
150a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_STEREO),
151a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_QUAD),
152a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
153a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
154a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
155a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
156a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t OutputChannelConverter::mSize = sizeof(OutputChannelConverter::mTable) /
157a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(OutputChannelConverter::mTable[0]);
158a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
159a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
160a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
161a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst InputChannelConverter::Table InputChannelConverter::mTable[] = {
162a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_MONO),
163a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_STEREO),
164a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_CHANNEL_IN_FRONT_BACK),
165a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
166a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
167a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t InputChannelConverter::mSize = sizeof(InputChannelConverter::mTable) /
168a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(InputChannelConverter::mTable[0]);
169a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
170a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
171a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst ChannelIndexConverter::Table ChannelIndexConverter::mTable[] = {
1727b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_1", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_1)},
1737b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_2", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_2)},
1747b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_3", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_3)},
1757b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_4", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_4)},
1767b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_5", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_5)},
1777b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_6", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_6)},
1787b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_7", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_7)},
1797b279bbc24139ee1e01b58055ca94926ec18e2e9Eric Laurent    {"AUDIO_CHANNEL_INDEX_MASK_8", static_cast<audio_channel_mask_t>(AUDIO_CHANNEL_INDEX_MASK_8)},
180a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
181a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
182a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t ChannelIndexConverter::mSize = sizeof(ChannelIndexConverter::mTable) /
183a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(ChannelIndexConverter::mTable[0]);
184a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
185a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
186a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate <>
187a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst GainModeConverter::Table GainModeConverter::mTable[] = {
188a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_JOINT),
189a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_CHANNELS),
190a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_GAIN_MODE_RAMP),
191a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie};
192a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
193a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffietemplate<>
194a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffieconst size_t GainModeConverter::mSize = sizeof(GainModeConverter::mTable) /
195a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        sizeof(GainModeConverter::mTable[0]);
196a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
1975fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <>
1985fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffieconst DeviceCategoryConverter::Table DeviceCategoryConverter::mTable[] = {
1995fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(DEVICE_CATEGORY_HEADSET),
2005fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(DEVICE_CATEGORY_SPEAKER),
2015fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(DEVICE_CATEGORY_EARPIECE),
2025fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(DEVICE_CATEGORY_EXT_MEDIA)
2035fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie};
2045fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie
2055fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate<>
2065fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffieconst size_t DeviceCategoryConverter::mSize = sizeof(DeviceCategoryConverter::mTable) /
2075fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie        sizeof(DeviceCategoryConverter::mTable[0]);
2085fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie
2095fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <>
2105fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffieconst StreamTypeConverter::Table StreamTypeConverter::mTable[] = {
2115fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_VOICE_CALL),
2125fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_SYSTEM),
2135fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_RING),
2145fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_MUSIC),
2155fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ALARM),
2165fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_NOTIFICATION),
2175fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_BLUETOOTH_SCO ),
2185fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ENFORCED_AUDIBLE),
2195fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_DTMF),
2205fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_TTS),
2215fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_ACCESSIBILITY),
2225fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_REROUTING),
223d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie    MAKE_STRING_FROM_ENUM(AUDIO_STREAM_PATCH),
2245fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie};
2255fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie
2265fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate<>
2275fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffieconst size_t StreamTypeConverter::mSize = sizeof(StreamTypeConverter::mTable) /
2285fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie        sizeof(StreamTypeConverter::mTable[0]);
229a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2305fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <class Traits>
2315fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffiebool TypeConverter<Traits>::toString(const typename Traits::Type &value, std::string &str)
232a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie{
233a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    for (size_t i = 0; i < mSize; i++) {
234a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        if (mTable[i].value == value) {
235a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            str = mTable[i].literal;
236a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            return true;
237a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        }
238a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    }
239a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    return false;
240a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie}
241a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2425fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <class Traits>
2435fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffiebool TypeConverter<Traits>::fromString(const std::string &str, typename Traits::Type &result)
244a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie{
245a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    for (size_t i = 0; i < mSize; i++) {
246a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        if (strcmp(mTable[i].literal, str.c_str()) == 0) {
247a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            ALOGV("stringToEnum() found %s", mTable[i].literal);
248a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            result = mTable[i].value;
249a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            return true;
250a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        }
251a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    }
252a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    return false;
253a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie}
254a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2555fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <class Traits>
2565fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffievoid TypeConverter<Traits>::collectionFromString(const std::string &str,
2575fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie                                                 typename Traits::Collection &collection,
2585fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie                                                 const char *del)
259a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie{
260a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    char *literal = strdup(str.c_str());
261a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2625fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    for (const char *cstr = strtok(literal, del); cstr != NULL; cstr = strtok(NULL, del)) {
2635fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie        typename Traits::Type value;
264a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        if (fromString(cstr, value)) {
265a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            collection.add(value);
266a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        }
267a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    }
268a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    free(literal);
269a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie}
270a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2715fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate <class Traits>
2725fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffieuint32_t TypeConverter<Traits>::maskFromString(const std::string &str, const char *del)
273a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie{
274a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    char *literal = strdup(str.c_str());
275a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    uint32_t value = 0;
2765fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie    for (const char *cstr = strtok(literal, del); cstr != NULL; cstr = strtok(NULL, del)) {
2775fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffie        typename Traits::Type type;
278a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        if (fromString(cstr, type)) {
279a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie            value |= static_cast<uint32_t>(type);
280a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie        }
281a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    }
282a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    free(literal);
283a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie    return value;
284a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie}
285a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
2865fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<DeviceTraits>;
2875fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<OutputFlagTraits>;
2885fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<InputFlagTraits>;
2895fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<FormatTraits>;
2905fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<OutputChannelTraits>;
2915fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<InputChannelTraits>;
2925fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<ChannelIndexTraits>;
2935fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<GainModeTraits>;
2945fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<StreamTraits>;
2955fcd6f99944d8722c57d2b2963814a1964ecfeddFrançois Gaffietemplate class TypeConverter<DeviceCategoryTraits>;
296a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
297a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie}; // namespace android
298a8ecc2c72ca26389bd6b0162181d60aaeaca8149François Gaffie
299