AudioPolicyConfig.h revision a8ecc2c72ca26389bd6b0162181d60aaeaca8149
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 =
94                        new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC);
95        mAvailableOutputDevices.add(mDefaultOutputDevices);
96        mAvailableInputDevices.add(defaultInputDevice);
97
98        module = new HwModule("primary");
99
100        sp<OutputProfile> outProfile;
101        outProfile = new OutputProfile(String8("primary"));
102        outProfile->attach(module);
103        outProfile->mSamplingRates.add(44100);
104        outProfile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT);
105        outProfile->mChannelMasks.add(AUDIO_CHANNEL_OUT_STEREO);
106        outProfile->addSupportedDevice(mDefaultOutputDevices);
107        outProfile->setFlags(AUDIO_OUTPUT_FLAG_PRIMARY);
108        module->mOutputProfiles.add(outProfile);
109
110        sp<InputProfile> inProfile;
111        inProfile = new InputProfile(String8("primary"));
112        inProfile->attach(module);
113        inProfile->mSamplingRates.add(8000);
114        inProfile->mFormats.add(AUDIO_FORMAT_PCM_16_BIT);
115        inProfile->mChannelMasks.add(AUDIO_CHANNEL_IN_MONO);
116        inProfile->addSupportedDevice(defaultInputDevice);
117        module->mInputProfiles.add(inProfile);
118
119        mHwModules.add(module);
120    }
121
122private:
123    HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */
124    DeviceVector &mAvailableOutputDevices;
125    DeviceVector &mAvailableInputDevices;
126    sp<DeviceDescriptor> &mDefaultOutputDevices;
127    bool &mIsSpeakerDrcEnabled;
128};
129
130}; // namespace android
131