Home | History | Annotate | Download | only in include
      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      // Note that empty name refers by convention to a generic device.
     33     DeviceDescriptor(audio_devices_t type, const String8 &tagName = String8(""));
     34 
     35     virtual ~DeviceDescriptor() {}
     36 
     37     virtual const String8 getTagName() const { return mTagName; }
     38 
     39     audio_devices_t type() const { return mDeviceType; }
     40 
     41     bool equals(const sp<DeviceDescriptor>& other) const;
     42 
     43     // AudioPortConfig
     44     virtual sp<AudioPort> getAudioPort() const { return (AudioPort*) this; }
     45     virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
     46             const struct audio_port_config *srcConfig = NULL) const;
     47 
     48     // AudioPort
     49     virtual void attach(const sp<HwModule>& module);
     50     virtual void toAudioPort(struct audio_port *port) const;
     51     virtual void importAudioPort(const sp<AudioPort> port);
     52 
     53     audio_port_handle_t getId() const;
     54     status_t dump(int fd, int spaces, int index, bool verbose = true) const;
     55     void log() const;
     56 
     57     String8 mAddress;
     58 
     59 private:
     60     String8 mTagName; // Unique human readable identifier for a device port found in conf file.
     61     audio_devices_t     mDeviceType;
     62     audio_port_handle_t mId;
     63 
     64 friend class DeviceVector;
     65 };
     66 
     67 class DeviceVector : public SortedVector<sp<DeviceDescriptor> >
     68 {
     69 public:
     70     DeviceVector() : SortedVector(), mDeviceTypes(AUDIO_DEVICE_NONE) {}
     71 
     72     ssize_t add(const sp<DeviceDescriptor>& item);
     73     void add(const DeviceVector &devices);
     74     ssize_t remove(const sp<DeviceDescriptor>& item);
     75     ssize_t indexOf(const sp<DeviceDescriptor>& item) const;
     76 
     77     audio_devices_t types() const { return mDeviceTypes; }
     78 
     79     sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
     80     DeviceVector getDevicesFromType(audio_devices_t types) const;
     81     sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
     82     sp<DeviceDescriptor> getDeviceFromTagName(const String8 &tagName) const;
     83     DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) const;
     84 
     85     audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
     86 
     87     status_t dump(int fd, const String8 &tag, int spaces = 0, bool verbose = true) const;
     88 
     89 private:
     90     void refreshTypes();
     91     audio_devices_t mDeviceTypes;
     92 };
     93 
     94 }; // namespace android
     95