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 "DeviceDescriptor.h" 20 #include "AudioRoute.h" 21 #include <utils/RefBase.h> 22 #include <utils/String8.h> 23 #include <utils/Errors.h> 24 #include <utils/Vector.h> 25 #include <system/audio.h> 26 #include <cutils/config_utils.h> 27 #include <string> 28 29 namespace android { 30 31 class IOProfile; 32 class InputProfile; 33 class OutputProfile; 34 35 typedef Vector<sp<IOProfile> > InputProfileCollection; 36 typedef Vector<sp<IOProfile> > OutputProfileCollection; 37 typedef Vector<sp<IOProfile> > IOProfileCollection; 38 39 class HwModule : public RefBase 40 { 41 public: 42 explicit HwModule(const char *name, uint32_t halVersionMajor = 0, uint32_t halVersionMinor = 0); 43 ~HwModule(); 44 getName()45 const char *getName() const { return mName.string(); } 46 getDeclaredDevices()47 const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; } 48 void setDeclaredDevices(const DeviceVector &devices); 49 getInputProfiles()50 const InputProfileCollection &getInputProfiles() const { return mInputProfiles; } getOutputProfiles()51 const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; } 52 53 void setProfiles(const IOProfileCollection &profiles); 54 setHalVersion(uint32_t major,uint32_t minor)55 void setHalVersion(uint32_t major, uint32_t minor) { 56 mHalVersion = (major << 8) | (minor & 0xff); 57 } getHalVersionMajor()58 uint32_t getHalVersionMajor() const { return mHalVersion >> 8; } getHalVersionMinor()59 uint32_t getHalVersionMinor() const { return mHalVersion & 0xff; } 60 61 sp<DeviceDescriptor> getRouteSinkDevice(const sp<AudioRoute> &route) const; 62 DeviceVector getRouteSourceDevices(const sp<AudioRoute> &route) const; 63 void setRoutes(const AudioRouteVector &routes); 64 65 status_t addOutputProfile(const sp<IOProfile> &profile); 66 status_t addInputProfile(const sp<IOProfile> &profile); 67 status_t addProfile(const sp<IOProfile> &profile); 68 69 status_t addOutputProfile(const String8& name, const audio_config_t *config, 70 audio_devices_t device, const String8& address); 71 status_t removeOutputProfile(const String8& name); 72 status_t addInputProfile(const String8& name, const audio_config_t *config, 73 audio_devices_t device, const String8& address); 74 status_t removeInputProfile(const String8& name); 75 getHandle()76 audio_module_handle_t getHandle() const { return mHandle; } 77 void setHandle(audio_module_handle_t handle); 78 findPortByTagName(const String8 & tagName)79 sp<AudioPort> findPortByTagName(const String8 &tagName) const 80 { 81 return mPorts.findByTagName(tagName); 82 } 83 84 // TODO remove from here (split serialization) 85 void dump(int fd); 86 87 private: 88 void refreshSupportedDevices(); 89 90 const String8 mName; // base name of the audio HW module (primary, a2dp ...) 91 audio_module_handle_t mHandle; 92 OutputProfileCollection mOutputProfiles; // output profiles exposed by this module 93 InputProfileCollection mInputProfiles; // input profiles exposed by this module 94 uint32_t mHalVersion; // audio HAL API version 95 DeviceVector mDeclaredDevices; // devices declared in audio_policy configuration file. 96 AudioRouteVector mRoutes; 97 AudioPortVector mPorts; 98 }; 99 100 class HwModuleCollection : public Vector<sp<HwModule> > 101 { 102 public: 103 sp<HwModule> getModuleFromName(const char *name) const; 104 105 sp<HwModule> getModuleForDevice(audio_devices_t device) const; 106 107 sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device, 108 const char *device_address, 109 const char *device_name, 110 bool matchAdress = true) const; 111 112 status_t dump(int fd) const; 113 }; 114 115 } // namespace android 116