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(enumval) { #enumval, enumval }
22 #define TERMINATOR { .literal = nullptr }
23
24 template<>
25 const AudioModeConverter::Table AudioModeConverter::mTable[] = {
26 MAKE_STRING_FROM_ENUM(AUDIO_MODE_INVALID),
27 MAKE_STRING_FROM_ENUM(AUDIO_MODE_CURRENT),
28 MAKE_STRING_FROM_ENUM(AUDIO_MODE_NORMAL),
29 MAKE_STRING_FROM_ENUM(AUDIO_MODE_RINGTONE),
30 MAKE_STRING_FROM_ENUM(AUDIO_MODE_IN_CALL),
31 MAKE_STRING_FROM_ENUM(AUDIO_MODE_IN_COMMUNICATION),
32 MAKE_STRING_FROM_ENUM(AUDIO_MODE_CALL_SCREEN),
33 TERMINATOR
34 };
35
36 template <>
37 const AudioFlagConverter::Table AudioFlagConverter::mTable[] = {
38 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_NONE),
39 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_AUDIBILITY_ENFORCED),
40 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_SECURE),
41 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_SCO),
42 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BEACON),
43 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_HW_AV_SYNC),
44 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_HW_HOTWORD),
45 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY),
46 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_BYPASS_MUTE),
47 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_LOW_LATENCY),
48 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_DEEP_BUFFER),
49 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_NO_MEDIA_PROJECTION),
50 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_MUTE_HAPTIC),
51 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_NO_SYSTEM_CAPTURE),
52 MAKE_STRING_FROM_ENUM(AUDIO_FLAG_CAPTURE_PRIVATE),
53 TERMINATOR
54 };
55
56 template class TypeConverter<OutputDeviceTraits>;
57 template class TypeConverter<InputDeviceTraits>;
58 template class TypeConverter<DeviceTraits>;
59 template class TypeConverter<OutputFlagTraits>;
60 template class TypeConverter<InputFlagTraits>;
61 template class TypeConverter<FormatTraits>;
62 template class TypeConverter<OutputChannelTraits>;
63 template class TypeConverter<InputChannelTraits>;
64 template class TypeConverter<ChannelIndexTraits>;
65 template class TypeConverter<GainModeTraits>;
66 template class TypeConverter<StreamTraits>;
67 template class TypeConverter<AudioModeTraits>;
68 template class TypeConverter<UsageTraits>;
69 template class TypeConverter<SourceTraits>;
70 template class TypeConverter<AudioFlagTraits>;
71
samplingRatesFromString(const std::string & samplingRates,const char * del)72 SampleRateTraits::Collection samplingRatesFromString(
73 const std::string &samplingRates, const char *del)
74 {
75 SampleRateTraits::Collection samplingRateCollection;
76 collectionFromString<SampleRateTraits>(samplingRates, samplingRateCollection, del);
77 return samplingRateCollection;
78 }
79
formatsFromString(const std::string & formats,const char * del)80 FormatTraits::Collection formatsFromString(
81 const std::string &formats, const char *del)
82 {
83 FormatTraits::Collection formatCollection;
84 FormatConverter::collectionFromString(formats, formatCollection, del);
85 return formatCollection;
86 }
87
formatFromString(const std::string & literalFormat,audio_format_t defaultFormat)88 audio_format_t formatFromString(const std::string &literalFormat, audio_format_t defaultFormat)
89 {
90 audio_format_t format;
91 if (!literalFormat.empty() && FormatConverter::fromString(literalFormat, format)) {
92 return format;
93 }
94 return defaultFormat;
95 }
96
channelMaskFromString(const std::string & literalChannels)97 audio_channel_mask_t channelMaskFromString(const std::string &literalChannels)
98 {
99 audio_channel_mask_t channels;
100 if (!literalChannels.empty() &&
101 audio_channel_mask_from_string(literalChannels.c_str(), &channels)) {
102 return channels;
103 }
104 return AUDIO_CHANNEL_INVALID;
105 }
106
channelMasksFromString(const std::string & channels,const char * del)107 ChannelTraits::Collection channelMasksFromString(
108 const std::string &channels, const char *del)
109 {
110 ChannelTraits::Collection channelMaskCollection;
111 OutputChannelConverter::collectionFromString(channels, channelMaskCollection, del);
112 InputChannelConverter::collectionFromString(channels, channelMaskCollection, del);
113 ChannelIndexConverter::collectionFromString(channels, channelMaskCollection, del);
114 return channelMaskCollection;
115 }
116
inputChannelMasksFromString(const std::string & inChannels,const char * del)117 InputChannelTraits::Collection inputChannelMasksFromString(
118 const std::string &inChannels, const char *del)
119 {
120 InputChannelTraits::Collection inputChannelMaskCollection;
121 InputChannelConverter::collectionFromString(inChannels, inputChannelMaskCollection, del);
122 ChannelIndexConverter::collectionFromString(inChannels, inputChannelMaskCollection, del);
123 return inputChannelMaskCollection;
124 }
125
outputChannelMasksFromString(const std::string & outChannels,const char * del)126 OutputChannelTraits::Collection outputChannelMasksFromString(
127 const std::string &outChannels, const char *del)
128 {
129 OutputChannelTraits::Collection outputChannelMaskCollection;
130 OutputChannelConverter::collectionFromString(outChannels, outputChannelMaskCollection, del);
131 ChannelIndexConverter::collectionFromString(outChannels, outputChannelMaskCollection, del);
132 return outputChannelMaskCollection;
133 }
134
135 }; // namespace android
136