• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008-2011 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 #ifndef ANDROID_AUDIOPARAMETER_H_
18 #define ANDROID_AUDIOPARAMETER_H_
19 
20 #include <utils/Errors.h>
21 #include <utils/KeyedVector.h>
22 #include <utils/String8.h>
23 
24 namespace android {
25 
26 class AudioParameter {
27 
28 public:
AudioParameter()29     AudioParameter() {}
30     AudioParameter(const String8& keyValuePairs);
31     virtual ~AudioParameter();
32 
33     // reserved parameter keys for changing standard parameters with setParameters() function.
34     // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
35     // configuration changes and act accordingly.
36     //  keyRouting: to change audio routing, value is an int in audio_devices_t
37     //  keySamplingRate: to change sampling rate routing, value is an int
38     //  keyFormat: to change audio format, value is an int in audio_format_t
39     //  keyChannels: to change audio channel configuration, value is an int in audio_channels_t
40     //  keyFrameCount: to change audio output frame count, value is an int
41     //  keyInputSource: to change audio input source, value is an int in audio_source_t
42     //     (defined in media/mediarecorder.h)
43     //  keyScreenState: either "on" or "off"
44     //  keyScreenRotation: one of: 0, 90, 180, 270
45     static const char * const keyRouting;
46     static const char * const keySamplingRate;
47     static const char * const keyFormat;
48     static const char * const keyChannels;
49     static const char * const keyFrameCount;
50     static const char * const keyInputSource;
51     static const char * const keyScreenState;
52     static const char * const keyScreenRotation;
53 
54     // keyClosing: "true" on AudioFlinger Thread preExit.  Used by A2DP HAL.
55     // keyExiting: "1" on AudioFlinger Thread preExit.  Used by remote_submix and A2DP HAL.
56     static const char * const keyClosing;
57     static const char * const keyExiting;
58 
59     //  keyBtSco: Whether BT SCO is 'on' or 'off'
60     //  keyBtScoHeadsetName: BT SCO headset name (for debugging)
61     //  keyBtNrec: BT SCO Noise Reduction + Echo Cancellation parameters
62     //  keyBtScoWb: BT SCO NR wideband mode
63     //  keyHfp...: Parameters of the Hands-Free Profile
64     static const char * const keyBtSco;
65     static const char * const keyBtScoHeadsetName;
66     static const char * const keyBtNrec;
67     static const char * const keyBtScoWb;
68     static const char * const keyBtHfpEnable;
69     static const char * const keyBtHfpSamplingRate;
70     static const char * const keyBtHfpVolume;
71 
72 #ifndef __ANDROID_VNDK__
73     // These static fields are not used by vendor code, they were added to make
74     // the framework code consistent. There is no plan to expose them to vendors
75     // because they were used by HIDL get/setParameters interface which does not
76     // exist in the AIDL HAL interface.
77     static const char * const keyTtyMode;
78     static const char * const valueTtyModeOff;
79     static const char * const valueTtyModeFull;
80     static const char * const valueTtyModeHco;
81     static const char * const valueTtyModeVco;
82 
83     static const char * const keyHacSetting;
84     static const char * const valueHacOff;
85     static const char * const valueHacOn;
86 #endif  // __ANDROID_VNDK__
87 
88     //  keyHwAvSync: get HW synchronization source identifier from a device
89     //  keyMonoOutput: Enable mono audio playback
90     //  keyStreamHwAvSync: set HW synchronization source identifier on a stream
91     static const char * const keyHwAvSync;
92     static const char * const keyMonoOutput;
93     static const char * const keyStreamHwAvSync;
94 
95     //  keys for presentation selection
96     //  keyPresentationId: Audio presentation identifier
97     //  keyProgramId: Audio presentation program identifier
98     static const char * const keyPresentationId;
99     static const char * const keyProgramId;
100 
101     //  keyAudioLanguagePreferred: Preferred audio language
102     static const char * const keyAudioLanguagePreferred;
103 
104     //  keyDeviceConnect / Disconnect: value is an int in audio_devices_t
105     static const char * const keyDeviceConnect;
106     static const char * const keyDeviceDisconnect;
107     //  Need to be here because vendors still use them.
108     static const char * const keyStreamConnect;  // Deprecated: DO NOT USE.
109     static const char * const keyStreamDisconnect;  // Deprecated: DO NOT USE.
110 
111     // For querying stream capabilities. All the returned values are lists.
112     //   keyStreamSupportedFormats: audio_format_t
113     //   keyStreamSupportedChannels: audio_channel_mask_t
114     //   keyStreamSupportedSamplingRates: sampling rate values
115     static const char * const keyStreamSupportedFormats;
116     static const char * const keyStreamSupportedChannels;
117     static const char * const keyStreamSupportedSamplingRates;
118 
119     static const char * const valueOn;
120     static const char * const valueOff;
121     static const char * const valueTrue;
122     static const char * const valueFalse;
123 
124     static const char * const valueListSeparator;
125 
126     // keyBtA2dpSuspended: 'true' or 'false'
127     // keyReconfigA2dp: Ask HwModule to reconfigure A2DP offloaded codec
128     // keyReconfigA2dpSupported: Query if HwModule supports A2DP offload codec config
129     // keyBtLeSuspended: 'true' or 'false'
130     static const char * const keyBtA2dpSuspended;
131     static const char * const keyReconfigA2dp;
132     static const char * const keyReconfigA2dpSupported;
133     static const char * const keyBtLeSuspended;
134 
135     // For querying device supported encapsulation capabilities. All returned values are integer,
136     // which are bit fields composed from using encapsulation capability values as position bits.
137     // Encapsulation capability values are defined in audio_encapsulation_mode_t and
138     // audio_encapsulation_metadata_type_t. For instance, if the supported encapsulation mode is
139     // AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM, the returned value is
140     // "supEncapsulationModes=1 << AUDIO_ENCAPSULATION_MODE_HANDLE".
141     // When querying device supported encapsulation capabilities, the key should use with device
142     // type and address so that it is able to identify the device. The device will be a key. The
143     // device type will be the value of key AUDIO_PARAMETER_STREAM_ROUTING.
144     // static const char * const keyDeviceSupportedEncapsulationModes;
145     // static const char * const keyDeviceSupportedEncapsulationMetadataTypes;
146 
147     static const char * const keyAdditionalOutputDeviceDelay;
148     static const char * const keyMaxAdditionalOutputDeviceDelay;
149 
150     static const char * const keyOffloadCodecAverageBitRate;
151     static const char * const keyOffloadCodecSampleRate;
152     static const char * const keyOffloadCodecChannels;
153     static const char * const keyOffloadCodecDelaySamples;
154     static const char * const keyOffloadCodecPaddingSamples;
155 
toString()156     String8 toString() const { return toStringImpl(true); }
keysToString()157     String8 keysToString() const { return toStringImpl(false); }
158 
159     status_t add(const String8& key, const String8& value);
160     status_t addInt(const String8& key, const int value);
161     status_t addKey(const String8& key);
162     status_t addFloat(const String8& key, const float value);
163 
164     status_t remove(const String8& key);
165 
get(const String8 & key,int & value)166     status_t get(const String8& key, int& value) const {
167         return getInt(key, value);
168     }
get(const String8 & key,float & value)169     status_t get(const String8& key, float& value) const {
170         return getFloat(key, value);
171     }
172     status_t get(const String8& key, String8& value) const;
173     status_t getInt(const String8& key, int& value) const;
174     status_t getFloat(const String8& key, float& value) const;
175     status_t getAt(size_t index, String8& key) const;
176     status_t getAt(size_t index, String8& key, String8& value) const;
177 
size()178     size_t size() const { return mParameters.size(); }
179 
180     bool containsKey(const String8& key) const;
181 private:
182     String8 mKeyValuePairs;
183     KeyedVector <String8, String8> mParameters;
184 
185     String8 toStringImpl(bool useValues) const;
186 };
187 
188 };  // namespace android
189 
190 #endif  /*ANDROID_AUDIOPARAMETER_H_*/
191