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