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 | |
| 19 | #include <media/audiohal/DeviceHalInterface.h> |
| 20 | #include <media/audiohal/EffectHalInterface.h> |
| 21 | |
| 22 | #include <aidl/android/hardware/audio/core/BpModule.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | class DeviceHalAidl : public DeviceHalInterface { |
| 27 | public: |
| 28 | // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t. |
| 29 | status_t getSupportedDevices(uint32_t *devices) override; |
| 30 | |
| 31 | // Check to see if the audio hardware interface has been initialized. |
| 32 | status_t initCheck() override; |
| 33 | |
| 34 | // Set the audio volume of a voice call. Range is between 0.0 and 1.0. |
| 35 | status_t setVoiceVolume(float volume) override; |
| 36 | |
| 37 | // Set the audio volume for all audio activities other than voice call. |
| 38 | status_t setMasterVolume(float volume) override; |
| 39 | |
| 40 | // Get the current master volume value for the HAL. |
| 41 | status_t getMasterVolume(float *volume) override; |
| 42 | |
| 43 | // Called when the audio mode changes. |
| 44 | status_t setMode(audio_mode_t mode) override; |
| 45 | |
| 46 | // Muting control. |
| 47 | status_t setMicMute(bool state) override; |
| 48 | |
| 49 | status_t getMicMute(bool* state) override; |
| 50 | |
| 51 | status_t setMasterMute(bool state) override; |
| 52 | |
| 53 | status_t getMasterMute(bool *state) override; |
| 54 | |
| 55 | // Set global audio parameters. |
| 56 | status_t setParameters(const String8& kvPairs) override; |
| 57 | |
| 58 | // Get global audio parameters. |
| 59 | status_t getParameters(const String8& keys, String8 *values) override; |
| 60 | |
| 61 | // Returns audio input buffer size according to parameters passed. |
| 62 | status_t getInputBufferSize(const struct audio_config* config, size_t* size) override; |
| 63 | |
| 64 | // Creates and opens the audio hardware output stream. The stream is closed |
| 65 | // by releasing all references to the returned object. |
| 66 | status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 67 | audio_output_flags_t flags, struct audio_config* config, |
| 68 | const char* address, sp<StreamOutHalInterface>* outStream) override; |
| 69 | |
| 70 | // Creates and opens the audio hardware input stream. The stream is closed |
| 71 | // by releasing all references to the returned object. |
| 72 | status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 73 | struct audio_config* config, audio_input_flags_t flags, |
| 74 | const char* address, audio_source_t source, |
| 75 | audio_devices_t outputDevice, const char* outputDeviceAddress, |
| 76 | sp<StreamInHalInterface>* inStream) override; |
| 77 | |
| 78 | // Returns whether createAudioPatch and releaseAudioPatch operations are supported. |
| 79 | status_t supportsAudioPatches(bool* supportsPatches) override; |
| 80 | |
| 81 | // Creates an audio patch between several source and sink ports. |
| 82 | status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources, |
| 83 | unsigned int num_sinks, const struct audio_port_config* sinks, |
| 84 | audio_patch_handle_t* patch) override; |
| 85 | |
| 86 | // Releases an audio patch. |
| 87 | status_t releaseAudioPatch(audio_patch_handle_t patch) override; |
| 88 | |
| 89 | // Set audio port configuration. |
| 90 | status_t setAudioPortConfig(const struct audio_port_config* config) override; |
| 91 | |
| 92 | // List microphones |
| 93 | status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones); |
| 94 | |
| 95 | status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 96 | |
| 97 | status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 98 | |
| 99 | status_t getMmapPolicyInfos(media::audio::common::AudioMMapPolicyType policyType __unused, |
| 100 | std::vector<media::audio::common::AudioMMapPolicyInfo>* policyInfos |
| 101 | __unused) override; |
| 102 | |
| 103 | int32_t getAAudioMixerBurstCount() override; |
| 104 | |
| 105 | int32_t getAAudioHardwareBurstMinUsec() override; |
| 106 | |
| 107 | error::Result<audio_hw_sync_t> getHwAvSync() override; |
| 108 | |
| 109 | status_t dump(int __unused, const Vector<String16>& __unused) override; |
| 110 | |
| 111 | int32_t supportsBluetoothVariableLatency(bool* supports __unused) override; |
| 112 | |
| 113 | private: |
| 114 | friend class DevicesFactoryHalAidl; |
| 115 | const std::shared_ptr<::aidl::android::hardware::audio::core::IModule> mCore; |
| 116 | float mMasterVolume = 0.0f; |
| 117 | float mVoiceVolume = 0.0f; |
| 118 | bool mMasterMute = false; |
| 119 | bool mMicMute = false; |
| 120 | |
| 121 | // Can not be constructed directly by clients. |
| 122 | explicit DeviceHalAidl( |
| 123 | const std::shared_ptr<::aidl::android::hardware::audio::core::IModule>& core) |
| 124 | : mCore(core) {} |
| 125 | |
| 126 | // The destructor automatically closes the device. |
| 127 | ~DeviceHalAidl(); |
| 128 | }; |
| 129 | |
| 130 | } // namespace android |