blob: f6e0e933023848bd39a736546e5e554c629fb9fc [file] [log] [blame]
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -08001/*
2 * Copyright (C) 2015 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
17namespace android {
18
19class HwModule;
20
21class AudioPort: public virtual RefBase
22{
23public:
24 AudioPort(const String8& name, audio_port_type_t type,
25 audio_port_role_t role, const sp<HwModule>& module);
26 virtual ~AudioPort() {}
27
28 audio_port_handle_t getHandle() { return mId; }
29
30 void attach(const sp<HwModule>& module);
31 bool isAttached() { return mId != 0; }
32
33 virtual void toAudioPort(struct audio_port *port) const;
34
35 void importAudioPort(const sp<AudioPort> port);
36 void clearCapabilities();
37
38 void loadSamplingRates(char *name);
39 void loadFormats(char *name);
40 void loadOutChannels(char *name);
41 void loadInChannels(char *name);
42
43 audio_gain_mode_t loadGainMode(char *name);
44 void loadGain(cnode *root, int index);
45 virtual void loadGains(cnode *root);
46
47 // searches for an exact match
48 status_t checkExactSamplingRate(uint32_t samplingRate) const;
49 // searches for a compatible match, and returns the best match via updatedSamplingRate
50 status_t checkCompatibleSamplingRate(uint32_t samplingRate,
51 uint32_t *updatedSamplingRate) const;
52 // searches for an exact match
53 status_t checkExactChannelMask(audio_channel_mask_t channelMask) const;
54 // searches for a compatible match, currently implemented for input channel masks only
55 status_t checkCompatibleChannelMask(audio_channel_mask_t channelMask) const;
56 status_t checkFormat(audio_format_t format) const;
57 status_t checkGain(const struct audio_gain_config *gainConfig, int index) const;
58
59 uint32_t pickSamplingRate() const;
60 audio_channel_mask_t pickChannelMask() const;
61 audio_format_t pickFormat() const;
62
63 static const audio_format_t sPcmFormatCompareTable[];
64 static int compareFormats(audio_format_t format1, audio_format_t format2);
65
66 void dump(int fd, int spaces) const;
67
68 String8 mName;
69 audio_port_type_t mType;
70 audio_port_role_t mRole;
71 bool mUseInChannelMask;
72 // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
73 // indicates the supported parameters should be read from the output stream
74 // after it is opened for the first time
75 Vector <uint32_t> mSamplingRates; // supported sampling rates
76 Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
77 Vector <audio_format_t> mFormats; // supported audio formats
78 Vector < sp<AudioGain> > mGains; // gain controllers
79 sp<HwModule> mModule; // audio HW module exposing this I/O stream
80 uint32_t mFlags; // attribute flags (e.g primary output,
81 // direct output...).
82
83
84protected:
85 //TODO - clarify the role of mId in this case, both an "attached" indicator
86 // and a unique ID for identifying a port to the (upcoming) selection API,
87 // and its relationship to the mId in AudioOutputDescriptor and AudioInputDescriptor.
88 audio_port_handle_t mId;
89};
90
91class AudioPortConfig: public virtual RefBase
92{
93public:
94 AudioPortConfig();
95 virtual ~AudioPortConfig() {}
96
97 status_t applyAudioPortConfig(const struct audio_port_config *config,
98 struct audio_port_config *backupConfig = NULL);
99 virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
100 const struct audio_port_config *srcConfig = NULL) const = 0;
101 virtual sp<AudioPort> getAudioPort() const = 0;
102 uint32_t mSamplingRate;
103 audio_format_t mFormat;
104 audio_channel_mask_t mChannelMask;
105 struct audio_gain_config mGain;
106};
107
108
109class AudioPatch: public RefBase
110{
111public:
112 AudioPatch(audio_patch_handle_t handle, const struct audio_patch *patch, uid_t uid);
113
114 status_t dump(int fd, int spaces, int index) const;
115
116 audio_patch_handle_t mHandle;
117 struct audio_patch mPatch;
118 uid_t mUid;
119 audio_patch_handle_t mAfPatchHandle;
120};
121
122}; // namespace android