HwModule.h revision cbb3044d6bfa9ab30c83b67874f40344e29805e1
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 <hardware/audio.h>
22#include <utils/RefBase.h>
23#include <utils/String8.h>
24#include <utils/Errors.h>
25#include <utils/Vector.h>
26#include <system/audio.h>
27#include <cutils/config_utils.h>
28#include <string>
29
30namespace android {
31
32class IOProfile;
33class InputProfile;
34class OutputProfile;
35
36typedef Vector<sp<IOProfile> > InputProfileCollection;
37typedef Vector<sp<IOProfile> > OutputProfileCollection;
38typedef Vector<sp<IOProfile> > IOProfileCollection;
39
40class HwModule : public RefBase
41{
42public:
43    HwModule(const char *name, uint32_t halVersion = AUDIO_DEVICE_API_VERSION_MIN);
44    ~HwModule();
45
46    const char *getName() const { return mName.string(); }
47
48
49    const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; }
50    void setDeclaredDevices(const DeviceVector &devices);
51
52    const InputProfileCollection &getInputProfiles() const { return mInputProfiles; }
53
54    const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; }
55
56    void setProfiles(const IOProfileCollection &profiles);
57
58    void setHalVersion(uint32_t halVersion) { mHalVersion = halVersion; }
59    uint32_t getHalVersion() const { return mHalVersion; }
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(String8 name, const audio_config_t *config,
70            audio_devices_t device, String8 address);
71    status_t removeOutputProfile(String8 name);
72    status_t addInputProfile(String8 name, const audio_config_t *config,
73            audio_devices_t device, String8 address);
74    status_t removeInputProfile(String8 name);
75
76    audio_module_handle_t getHandle() const { return mHandle; }
77
78    sp<AudioPort> findPortByTagName(const String8 &tagName) const
79    {
80        return mPorts.findByTagName(tagName);
81    }
82
83    // TODO remove from here (split serialization)
84    void dump(int fd);
85
86    const String8 mName; // base name of the audio HW module (primary, a2dp ...)
87    audio_module_handle_t mHandle;
88    OutputProfileCollection mOutputProfiles; // output profiles exposed by this module
89    InputProfileCollection mInputProfiles;  // input profiles exposed by this module
90
91private:
92    void refreshSupportedDevices();
93
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
100class HwModuleCollection : public Vector<sp<HwModule> >
101{
102public:
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) const;
110
111    status_t dump(int fd) const;
112};
113
114}; // namespace android
115