AudioPolicyConfig.h revision 1d4481fb9cb1ea149f79f2a5d22110af84fbc90b
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 <AudioPort.h> 21#include <AudioPatch.h> 22#include <DeviceDescriptor.h> 23#include <IOProfile.h> 24#include <HwModule.h> 25#include <AudioInputDescriptor.h> 26#include <AudioOutputDescriptor.h> 27#include <AudioPolicyMix.h> 28#include <EffectDescriptor.h> 29#include <SoundTriggerSession.h> 30#include <StreamDescriptor.h> 31#include <SessionRoute.h> 32 33namespace android { 34 35class AudioPolicyConfig 36{ 37public: 38 AudioPolicyConfig(HwModuleCollection &hwModules, 39 DeviceVector &availableOutputDevices, 40 DeviceVector &availableInputDevices, 41 sp<DeviceDescriptor> &defaultOutputDevices, 42 bool &isSpeakerDrcEnabled) 43 : mHwModules(hwModules), 44 mAvailableOutputDevices(availableOutputDevices), 45 mAvailableInputDevices(availableInputDevices), 46 mDefaultOutputDevices(defaultOutputDevices), 47 mIsSpeakerDrcEnabled(isSpeakerDrcEnabled) 48 {} 49 50 void setHwModules(const HwModuleCollection &hwModules) 51 { 52 mHwModules = hwModules; 53 } 54 55 void addAvailableInputDevices(const DeviceVector &availableInputDevices) 56 { 57 mAvailableInputDevices.add(availableInputDevices); 58 } 59 60 void addAvailableOutputDevices(const DeviceVector &availableOutputDevices) 61 { 62 mAvailableOutputDevices.add(availableOutputDevices); 63 } 64 65 void setSpeakerDrcEnabled(bool isSpeakerDrcEnabled) 66 { 67 mIsSpeakerDrcEnabled = isSpeakerDrcEnabled; 68 } 69 70 const HwModuleCollection getHwModules() const { return mHwModules; } 71 72 const DeviceVector &getAvailableInputDevices() const 73 { 74 return mAvailableInputDevices; 75 } 76 77 const DeviceVector &getAvailableOutputDevices() const 78 { 79 return mAvailableOutputDevices; 80 } 81 82 void setDefaultOutputDevice(const sp<DeviceDescriptor> &defaultDevice) 83 { 84 mDefaultOutputDevices = defaultDevice; 85 } 86 87 const sp<DeviceDescriptor> &getDefaultOutputDevice() const { return mDefaultOutputDevices; } 88 89 void setDefault(void) 90 { 91 mDefaultOutputDevices = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER); 92 sp<HwModule> module; 93 sp<DeviceDescriptor> defaultInputDevice = new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC); 94 mAvailableOutputDevices.add(mDefaultOutputDevices); 95 mAvailableInputDevices.add(defaultInputDevice); 96 97 module = new HwModule("primary"); 98 99 sp<OutputProfile> outProfile; 100 outProfile = new OutputProfile(String8("primary")); 101 outProfile->attach(module); 102 outProfile->mSamplingRates.add(44100); 103 outProfile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT); 104 outProfile->mChannelMasks.add(AUDIO_CHANNEL_OUT_STEREO); 105 outProfile->addSupportedDevice(mDefaultOutputDevices); 106 outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY); 107 module->mOutputProfiles.add(outProfile); 108 109 sp<InputProfile> inProfile; 110 inProfile = new InputProfile(String8("primary")); 111 inProfile->attach(module); 112 inProfile->mSamplingRates.add(8000); 113 inProfile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT); 114 inProfile->mChannelMasks.add(AUDIO_CHANNEL_IN_MONO); 115 inProfile->addSupportedDevice(defaultInputDevice); 116 module->mInputProfiles.add(inProfile); 117 118 mHwModules.add(module); 119 } 120 121private: 122 HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */ 123 DeviceVector &mAvailableOutputDevices; 124 DeviceVector &mAvailableInputDevices; 125 sp<DeviceDescriptor> &mDefaultOutputDevices; 126 bool &mIsSpeakerDrcEnabled; 127}; 128 129}; // namespace android 130