Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame^] | 17 | #pragma once |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 18 | |
François Gaffie | ad3183e | 2015-03-18 16:55:35 +0100 | [diff] [blame^] | 19 | #include "Ports.h" |
| 20 | #include <utils/Errors.h> |
| 21 | #include <utils/String8.h> |
| 22 | #include <utils/SortedVector.h> |
| 23 | #include <cutils/config_utils.h> |
| 24 | #include <system/audio.h> |
| 25 | |
| 26 | namespace android { |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 27 | |
| 28 | class DeviceDescriptor: public AudioPort, public AudioPortConfig |
| 29 | { |
| 30 | public: |
| 31 | DeviceDescriptor(const String8& name, audio_devices_t type); |
| 32 | |
| 33 | virtual ~DeviceDescriptor() {} |
| 34 | |
| 35 | bool equals(const sp<DeviceDescriptor>& other) const; |
| 36 | |
| 37 | // AudioPortConfig |
| 38 | virtual sp<AudioPort> getAudioPort() const { return (AudioPort*) this; } |
| 39 | virtual void toAudioPortConfig(struct audio_port_config *dstConfig, |
| 40 | const struct audio_port_config *srcConfig = NULL) const; |
| 41 | |
| 42 | // AudioPort |
| 43 | virtual void loadGains(cnode *root); |
| 44 | virtual void toAudioPort(struct audio_port *port) const; |
| 45 | |
| 46 | status_t dump(int fd, int spaces, int index) const; |
| 47 | |
| 48 | audio_devices_t mDeviceType; |
| 49 | String8 mAddress; |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 50 | |
| 51 | static String8 emptyNameStr; |
| 52 | }; |
| 53 | |
| 54 | class DeviceVector : public SortedVector< sp<DeviceDescriptor> > |
| 55 | { |
| 56 | public: |
| 57 | DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {} |
| 58 | |
| 59 | ssize_t add(const sp<DeviceDescriptor>& item); |
| 60 | ssize_t remove(const sp<DeviceDescriptor>& item); |
| 61 | ssize_t indexOf(const sp<DeviceDescriptor>& item) const; |
| 62 | |
| 63 | audio_devices_t types() const { return mDeviceTypes; } |
| 64 | |
| 65 | void loadDevicesFromType(audio_devices_t types); |
| 66 | void loadDevicesFromName(char *name, const DeviceVector& declaredDevices); |
| 67 | |
| 68 | sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const; |
| 69 | DeviceVector getDevicesFromType(audio_devices_t types) const; |
| 70 | sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const; |
| 71 | sp<DeviceDescriptor> getDeviceFromName(const String8& name) const; |
| 72 | DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) |
| 73 | const; |
| 74 | |
| 75 | private: |
| 76 | void refreshTypes(); |
| 77 | audio_devices_t mDeviceTypes; |
| 78 | }; |
| 79 | |
| 80 | }; // namespace android |