blob: 65e14164cdecbe451e89c3f72091b63a1e2c4abd [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 AudioPort;
20class AudioPortConfig;
21
22class DeviceDescriptor: public AudioPort, public AudioPortConfig
23{
24public:
25 DeviceDescriptor(const String8& name, audio_devices_t type);
26
27 virtual ~DeviceDescriptor() {}
28
29 bool equals(const sp<DeviceDescriptor>& other) const;
30
31 // AudioPortConfig
32 virtual sp<AudioPort> getAudioPort() const { return (AudioPort*) this; }
33 virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
34 const struct audio_port_config *srcConfig = NULL) const;
35
36 // AudioPort
37 virtual void loadGains(cnode *root);
38 virtual void toAudioPort(struct audio_port *port) const;
39
40 status_t dump(int fd, int spaces, int index) const;
41
42 audio_devices_t mDeviceType;
43 String8 mAddress;
44 audio_port_handle_t mId;
45
46 static String8 emptyNameStr;
47};
48
49class DeviceVector : public SortedVector< sp<DeviceDescriptor> >
50{
51public:
52 DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {}
53
54 ssize_t add(const sp<DeviceDescriptor>& item);
55 ssize_t remove(const sp<DeviceDescriptor>& item);
56 ssize_t indexOf(const sp<DeviceDescriptor>& item) const;
57
58 audio_devices_t types() const { return mDeviceTypes; }
59
60 void loadDevicesFromType(audio_devices_t types);
61 void loadDevicesFromName(char *name, const DeviceVector& declaredDevices);
62
63 sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
64 DeviceVector getDevicesFromType(audio_devices_t types) const;
65 sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
66 sp<DeviceDescriptor> getDeviceFromName(const String8& name) const;
67 DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address)
68 const;
69
70private:
71 void refreshTypes();
72 audio_devices_t mDeviceTypes;
73};
74
75}; // namespace android