• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #pragma once
18 
19 #include "AudioPort.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 #include <system/audio_policy.h>
26 
27 namespace android {
28 
29 class DeviceDescriptor : public AudioPort, public AudioPortConfig
30 {
31 public:
32     DeviceDescriptor(audio_devices_t type);
33 
~DeviceDescriptor()34     virtual ~DeviceDescriptor() {}
35 
36     bool equals(const sp<DeviceDescriptor>& other) const;
37 
38     // AudioPortConfig
getAudioPort()39     virtual sp<AudioPort> getAudioPort() const { return (AudioPort*) this; }
40     virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
41             const struct audio_port_config *srcConfig = NULL) const;
42 
43     // AudioPort
44     virtual void attach(const sp<HwModule>& module);
45     virtual void loadGains(cnode *root);
46     virtual void toAudioPort(struct audio_port *port) const;
47     virtual void importAudioPort(const sp<AudioPort> port);
48 
49     audio_port_handle_t getId() const;
type()50     audio_devices_t type() const { return mDeviceType; }
51     status_t dump(int fd, int spaces, int index) const;
52     void log() const;
53 
54     String8 mTag;
55     String8 mAddress;
56 
57 private:
58     audio_devices_t     mDeviceType;
59     audio_port_handle_t mId;
60 
61 friend class DeviceVector;
62 };
63 
64 class DeviceVector : public SortedVector< sp<DeviceDescriptor> >
65 {
66 public:
DeviceVector()67     DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {}
68 
69     ssize_t add(const sp<DeviceDescriptor>& item);
70     ssize_t remove(const sp<DeviceDescriptor>& item);
71     ssize_t indexOf(const sp<DeviceDescriptor>& item) const;
72 
types()73     audio_devices_t types() const { return mDeviceTypes; }
74 
75     void loadDevicesFromType(audio_devices_t types);
76     void loadDevicesFromTag(char *tag, const DeviceVector& declaredDevices);
77 
78     sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
79     DeviceVector getDevicesFromType(audio_devices_t types) const;
80     sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
81     sp<DeviceDescriptor> getDeviceFromTag(const String8& tag) const;
82     DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) const;
83 
84     audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
85 
86     audio_policy_dev_state_t getDeviceConnectionState(const sp<DeviceDescriptor> &devDesc) const;
87 
88     status_t dump(int fd, const String8 &direction) const;
89 
90 private:
91     void refreshTypes();
92     audio_devices_t mDeviceTypes;
93 };
94 
95 }; // namespace android
96