1 /* 2 * Copyright (C) 2009 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 <AudioGain.h> 20 #include <VolumeCurve.h> 21 #include <AudioPort.h> 22 #include <AudioPatch.h> 23 #include <DeviceDescriptor.h> 24 #include <IOProfile.h> 25 #include <HwModule.h> 26 #include <AudioInputDescriptor.h> 27 #include <AudioOutputDescriptor.h> 28 #include <AudioPolicyMix.h> 29 #include <EffectDescriptor.h> 30 #include <SoundTriggerSession.h> 31 #include <SessionRoute.h> 32 33 namespace android { 34 35 class AudioPolicyConfig 36 { 37 public: 38 AudioPolicyConfig(HwModuleCollection &hwModules, 39 DeviceVector &availableOutputDevices, 40 DeviceVector &availableInputDevices, 41 sp<DeviceDescriptor> &defaultOutputDevices, 42 VolumeCurvesCollection *volumes = nullptr) mHwModules(hwModules)43 : mHwModules(hwModules), 44 mAvailableOutputDevices(availableOutputDevices), 45 mAvailableInputDevices(availableInputDevices), 46 mDefaultOutputDevices(defaultOutputDevices), 47 mVolumeCurves(volumes), 48 mIsSpeakerDrcEnabled(false) 49 {} 50 setVolumes(const VolumeCurvesCollection & volumes)51 void setVolumes(const VolumeCurvesCollection &volumes) 52 { 53 if (mVolumeCurves != nullptr) { 54 *mVolumeCurves = volumes; 55 } 56 } 57 setHwModules(const HwModuleCollection & hwModules)58 void setHwModules(const HwModuleCollection &hwModules) 59 { 60 mHwModules = hwModules; 61 } 62 addAvailableDevice(const sp<DeviceDescriptor> & availableDevice)63 void addAvailableDevice(const sp<DeviceDescriptor> &availableDevice) 64 { 65 if (audio_is_output_device(availableDevice->type())) { 66 mAvailableOutputDevices.add(availableDevice); 67 } else if (audio_is_input_device(availableDevice->type())) { 68 mAvailableInputDevices.add(availableDevice); 69 } 70 } 71 addAvailableInputDevices(const DeviceVector & availableInputDevices)72 void addAvailableInputDevices(const DeviceVector &availableInputDevices) 73 { 74 mAvailableInputDevices.add(availableInputDevices); 75 } 76 addAvailableOutputDevices(const DeviceVector & availableOutputDevices)77 void addAvailableOutputDevices(const DeviceVector &availableOutputDevices) 78 { 79 mAvailableOutputDevices.add(availableOutputDevices); 80 } 81 isSpeakerDrcEnabled()82 bool isSpeakerDrcEnabled() const { return mIsSpeakerDrcEnabled; } 83 setSpeakerDrcEnabled(bool isSpeakerDrcEnabled)84 void setSpeakerDrcEnabled(bool isSpeakerDrcEnabled) 85 { 86 mIsSpeakerDrcEnabled = isSpeakerDrcEnabled; 87 } 88 getHwModules()89 const HwModuleCollection getHwModules() const { return mHwModules; } 90 getAvailableInputDevices()91 const DeviceVector &getAvailableInputDevices() const 92 { 93 return mAvailableInputDevices; 94 } 95 getAvailableOutputDevices()96 const DeviceVector &getAvailableOutputDevices() const 97 { 98 return mAvailableOutputDevices; 99 } 100 setDefaultOutputDevice(const sp<DeviceDescriptor> & defaultDevice)101 void setDefaultOutputDevice(const sp<DeviceDescriptor> &defaultDevice) 102 { 103 mDefaultOutputDevices = defaultDevice; 104 } 105 getDefaultOutputDevice()106 const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevices; } 107 setDefault(void)108 void setDefault(void) 109 { 110 mDefaultOutputDevices = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); 111 sp<HwModule> module; 112 sp<DeviceDescriptor> defaultInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC); 113 mAvailableOutputDevices.add(mDefaultOutputDevices); 114 mAvailableInputDevices.add(defaultInputDevice); 115 116 module = new HwModule(AUDIO_HARDWARE_MODULE_ID_PRIMARY); 117 118 sp<OutputProfile> outProfile; 119 outProfile = new OutputProfile(String8("primary")); 120 outProfile->attach(module); 121 outProfile->addAudioProfile( 122 new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO, 44100)); 123 outProfile->addSupportedDevice(mDefaultOutputDevices); 124 outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY); 125 module->addOutputProfile(outProfile); 126 127 sp<InputProfile> inProfile; 128 inProfile = new InputProfile(String8("primary")); 129 inProfile->attach(module); 130 inProfile->addAudioProfile( 131 new AudioProfile(AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_IN_MONO, 8000)); 132 inProfile->addSupportedDevice(defaultInputDevice); 133 module->addInputProfile(inProfile); 134 135 mHwModules.add(module); 136 } 137 138 private: 139 HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */ 140 DeviceVector &mAvailableOutputDevices; 141 DeviceVector &mAvailableInputDevices; 142 sp<DeviceDescriptor> &mDefaultOutputDevices; 143 VolumeCurvesCollection *mVolumeCurves; 144 // TODO: remove when legacy conf file is removed. true on devices that use DRC on the 145 // DEVICE_CATEGORY_SPEAKER path to boost soft sounds, used to adjust volume curves accordingly. 146 // Note: remove also speaker_drc_enabled from global configuration of XML config file. 147 bool mIsSpeakerDrcEnabled; 148 }; 149 150 } // namespace android 151