Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame^] | 19 | #include <map> |
| 20 | #include <set> |
| 21 | #include <vector> |
| 22 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 23 | #include <aidl/android/hardware/audio/core/BpModule.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 24 | #include <media/audiohal/DeviceHalInterface.h> |
| 25 | #include <media/audiohal/EffectHalInterface.h> |
| 26 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 27 | #include "ConversionHelperAidl.h" |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 31 | class DeviceHalAidl : public DeviceHalInterface, public ConversionHelperAidl { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 32 | public: |
| 33 | // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t. |
| 34 | status_t getSupportedDevices(uint32_t *devices) override; |
| 35 | |
| 36 | // Check to see if the audio hardware interface has been initialized. |
| 37 | status_t initCheck() override; |
| 38 | |
| 39 | // Set the audio volume of a voice call. Range is between 0.0 and 1.0. |
| 40 | status_t setVoiceVolume(float volume) override; |
| 41 | |
| 42 | // Set the audio volume for all audio activities other than voice call. |
| 43 | status_t setMasterVolume(float volume) override; |
| 44 | |
| 45 | // Get the current master volume value for the HAL. |
| 46 | status_t getMasterVolume(float *volume) override; |
| 47 | |
| 48 | // Called when the audio mode changes. |
| 49 | status_t setMode(audio_mode_t mode) override; |
| 50 | |
| 51 | // Muting control. |
| 52 | status_t setMicMute(bool state) override; |
| 53 | |
| 54 | status_t getMicMute(bool* state) override; |
| 55 | |
| 56 | status_t setMasterMute(bool state) override; |
| 57 | |
| 58 | status_t getMasterMute(bool *state) override; |
| 59 | |
| 60 | // Set global audio parameters. |
| 61 | status_t setParameters(const String8& kvPairs) override; |
| 62 | |
| 63 | // Get global audio parameters. |
| 64 | status_t getParameters(const String8& keys, String8 *values) override; |
| 65 | |
| 66 | // Returns audio input buffer size according to parameters passed. |
| 67 | status_t getInputBufferSize(const struct audio_config* config, size_t* size) override; |
| 68 | |
| 69 | // Creates and opens the audio hardware output stream. The stream is closed |
| 70 | // by releasing all references to the returned object. |
| 71 | status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 72 | audio_output_flags_t flags, struct audio_config* config, |
| 73 | const char* address, sp<StreamOutHalInterface>* outStream) override; |
| 74 | |
| 75 | // Creates and opens the audio hardware input stream. The stream is closed |
| 76 | // by releasing all references to the returned object. |
| 77 | status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 78 | struct audio_config* config, audio_input_flags_t flags, |
| 79 | const char* address, audio_source_t source, |
| 80 | audio_devices_t outputDevice, const char* outputDeviceAddress, |
| 81 | sp<StreamInHalInterface>* inStream) override; |
| 82 | |
| 83 | // Returns whether createAudioPatch and releaseAudioPatch operations are supported. |
| 84 | status_t supportsAudioPatches(bool* supportsPatches) override; |
| 85 | |
| 86 | // Creates an audio patch between several source and sink ports. |
| 87 | status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources, |
| 88 | unsigned int num_sinks, const struct audio_port_config* sinks, |
| 89 | audio_patch_handle_t* patch) override; |
| 90 | |
| 91 | // Releases an audio patch. |
| 92 | status_t releaseAudioPatch(audio_patch_handle_t patch) override; |
| 93 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 94 | // Fills the list of supported attributes for a given audio port. |
| 95 | status_t getAudioPort(struct audio_port* port) override; |
| 96 | |
| 97 | // Fills the list of supported attributes for a given audio port. |
| 98 | status_t getAudioPort(struct audio_port_v7 *port) override; |
| 99 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 100 | // Set audio port configuration. |
| 101 | status_t setAudioPortConfig(const struct audio_port_config* config) override; |
| 102 | |
| 103 | // List microphones |
| 104 | status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones); |
| 105 | |
| 106 | status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 107 | |
| 108 | status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 109 | |
| 110 | status_t getMmapPolicyInfos(media::audio::common::AudioMMapPolicyType policyType __unused, |
| 111 | std::vector<media::audio::common::AudioMMapPolicyInfo>* policyInfos |
| 112 | __unused) override; |
| 113 | |
| 114 | int32_t getAAudioMixerBurstCount() override; |
| 115 | |
| 116 | int32_t getAAudioHardwareBurstMinUsec() override; |
| 117 | |
| 118 | error::Result<audio_hw_sync_t> getHwAvSync() override; |
| 119 | |
| 120 | status_t dump(int __unused, const Vector<String16>& __unused) override; |
| 121 | |
| 122 | int32_t supportsBluetoothVariableLatency(bool* supports __unused) override; |
| 123 | |
| 124 | private: |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 125 | friend class sp<DeviceHalAidl>; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame^] | 126 | using Patches = std::map<int32_t /*patch ID*/, |
| 127 | ::aidl::android::hardware::audio::core::AudioPatch>; |
| 128 | using PortConfigs = std::map<int32_t /*port config ID*/, |
| 129 | ::aidl::android::media::audio::common::AudioPortConfig>; |
| 130 | using Ports = std::map<int32_t /*port ID*/, ::aidl::android::media::audio::common::AudioPort>; |
| 131 | class Cleanups; |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 132 | |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame^] | 133 | // Must not be constructed directly by clients. |
| 134 | DeviceHalAidl( |
| 135 | const std::string& instance, |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 136 | const std::shared_ptr<::aidl::android::hardware::audio::core::IModule>& module) |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame^] | 137 | : ConversionHelperAidl("DeviceHalAidl"), mInstance(instance), mModule(module) {} |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 138 | |
Mikhail Naganov | 31d4665 | 2023-01-10 18:29:25 +0000 | [diff] [blame] | 139 | ~DeviceHalAidl() override = default; |
Mikhail Naganov | 5b1eed1 | 2023-01-25 11:29:11 -0800 | [diff] [blame^] | 140 | |
| 141 | status_t createPortConfig( |
| 142 | const ::aidl::android::media::audio::common::AudioPortConfig& requestedPortConfig, |
| 143 | ::aidl::android::media::audio::common::AudioPortConfig* appliedPortConfig); |
| 144 | status_t findOrCreatePatch( |
| 145 | const std::set<int32_t>& sourcePortConfigIds, |
| 146 | const std::set<int32_t>& sinkPortConfigIds, |
| 147 | ::aidl::android::hardware::audio::core::AudioPatch* patch, bool* created); |
| 148 | status_t findOrCreatePatch( |
| 149 | const ::aidl::android::hardware::audio::core::AudioPatch& requestedPatch, |
| 150 | ::aidl::android::hardware::audio::core::AudioPatch* patch, bool* created); |
| 151 | status_t findOrCreatePortConfig( |
| 152 | const ::aidl::android::media::audio::common::AudioDevice& device, |
| 153 | ::aidl::android::media::audio::common::AudioPortConfig* portConfig, |
| 154 | bool* created); |
| 155 | status_t findOrCreatePortConfig( |
| 156 | const ::aidl::android::media::audio::common::AudioConfig& config, |
| 157 | const ::aidl::android::media::audio::common::AudioIoFlags& flags, |
| 158 | int32_t ioHandle, |
| 159 | ::aidl::android::media::audio::common::AudioPortConfig* portConfig, bool* created); |
| 160 | status_t findOrCreatePortConfig( |
| 161 | const ::aidl::android::media::audio::common::AudioPortConfig& requestedPortConfig, |
| 162 | ::aidl::android::media::audio::common::AudioPortConfig* portConfig, bool* created); |
| 163 | Patches::iterator findPatch(const std::set<int32_t>& sourcePortConfigIds, |
| 164 | const std::set<int32_t>& sinkPortConfigIds); |
| 165 | Ports::iterator findPort(const ::aidl::android::media::audio::common::AudioDevice& device); |
| 166 | Ports::iterator findPort( |
| 167 | const ::aidl::android::media::audio::common::AudioConfig& config, |
| 168 | const ::aidl::android::media::audio::common::AudioIoFlags& flags); |
| 169 | PortConfigs::iterator findPortConfig( |
| 170 | const ::aidl::android::media::audio::common::AudioDevice& device); |
| 171 | PortConfigs::iterator findPortConfig( |
| 172 | const ::aidl::android::media::audio::common::AudioConfig& config, |
| 173 | const ::aidl::android::media::audio::common::AudioIoFlags& flags, |
| 174 | int32_t ioHandle); |
| 175 | // Currently unused but may be useful for implementing setAudioPortConfig |
| 176 | // PortConfigs::iterator findPortConfig( |
| 177 | // const ::aidl::android::media::audio::common::AudioPortConfig& portConfig); |
| 178 | status_t prepareToOpenStream( |
| 179 | int32_t aidlHandle, |
| 180 | const ::aidl::android::media::audio::common::AudioDevice& aidlDevice, |
| 181 | const ::aidl::android::media::audio::common::AudioIoFlags& aidlFlags, |
| 182 | struct audio_config* config, |
| 183 | Cleanups* cleanups, |
| 184 | ::aidl::android::media::audio::common::AudioConfig* aidlConfig, |
| 185 | ::aidl::android::media::audio::common::AudioPortConfig* mixPortConfig); |
| 186 | void resetPatch(int32_t patchId); |
| 187 | void resetPortConfig(int32_t portConfigId); |
| 188 | |
| 189 | const std::string mInstance; |
| 190 | const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mModule; |
| 191 | Ports mPorts; |
| 192 | PortConfigs mPortConfigs; |
| 193 | Patches mPatches; |
| 194 | std::map<audio_patch_handle_t, int32_t /* patch ID */> mFwkHandles; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | } // namespace android |