Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef ANDROID_HARDWARE_DEVICE_HAL_HIDL_H |
| 18 | #define ANDROID_HARDWARE_DEVICE_HAL_HIDL_H |
| 19 | |
Kevin Rocard | 95213bf | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 20 | #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) |
| 21 | #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 22 | #include <media/audiohal/DeviceHalInterface.h> |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 23 | #include <media/audiohal/EffectHalInterface.h> |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 24 | |
Mikhail Naganov | 288a343 | 2022-03-25 00:29:56 +0000 | [diff] [blame] | 25 | #include "CoreConversionHelperHidl.h" |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 26 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
Mikhail Naganov | 288a343 | 2022-03-25 00:29:56 +0000 | [diff] [blame] | 29 | class DeviceHalHidl : public DeviceHalInterface, public CoreConversionHelperHidl |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 30 | { |
| 31 | public: |
| 32 | // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 33 | status_t getSupportedDevices(uint32_t *devices) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 34 | |
| 35 | // Check to see if the audio hardware interface has been initialized. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 36 | status_t initCheck() override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 37 | |
| 38 | // Set the audio volume of a voice call. Range is between 0.0 and 1.0. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 39 | status_t setVoiceVolume(float volume) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 40 | |
| 41 | // Set the audio volume for all audio activities other than voice call. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 42 | status_t setMasterVolume(float volume) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 43 | |
| 44 | // Get the current master volume value for the HAL. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 45 | status_t getMasterVolume(float *volume) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 46 | |
| 47 | // Called when the audio mode changes. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 48 | status_t setMode(audio_mode_t mode) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 49 | |
| 50 | // Muting control. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 51 | status_t setMicMute(bool state) override; |
| 52 | status_t getMicMute(bool *state) override; |
| 53 | status_t setMasterMute(bool state) override; |
| 54 | status_t getMasterMute(bool *state) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 55 | |
| 56 | // Set global audio parameters. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 57 | status_t setParameters(const String8& kvPairs) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 58 | |
| 59 | // Get global audio parameters. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 60 | status_t getParameters(const String8& keys, String8 *values) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 61 | |
| 62 | // Returns audio input buffer size according to parameters passed. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 63 | status_t getInputBufferSize(const struct audio_config* config, size_t* size) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 64 | |
| 65 | // Creates and opens the audio hardware output stream. The stream is closed |
| 66 | // by releasing all references to the returned object. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 67 | status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 68 | audio_output_flags_t flags, struct audio_config* config, |
| 69 | const char* address, sp<StreamOutHalInterface>* outStream) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 70 | |
| 71 | // Creates and opens the audio hardware input stream. The stream is closed |
| 72 | // by releasing all references to the returned object. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 73 | status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices, |
| 74 | struct audio_config* config, audio_input_flags_t flags, |
| 75 | const char* address, audio_source_t source, |
| 76 | audio_devices_t outputDevice, const char* outputDeviceAddress, |
| 77 | sp<StreamInHalInterface>* inStream) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 78 | |
| 79 | // Returns whether createAudioPatch and releaseAudioPatch operations are supported. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 80 | status_t supportsAudioPatches(bool* supportsPatches) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 81 | |
| 82 | // Creates an audio patch between several source and sink ports. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 83 | status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources, |
| 84 | unsigned int num_sinks, const struct audio_port_config* sinks, |
| 85 | audio_patch_handle_t* patch) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 86 | |
| 87 | // Releases an audio patch. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 88 | status_t releaseAudioPatch(audio_patch_handle_t patch) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 89 | |
| 90 | // Fills the list of supported attributes for a given audio port. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 91 | status_t getAudioPort(struct audio_port *port) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 92 | |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 93 | // Fills the list of supported attributes for a given audio port. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 94 | status_t getAudioPort(struct audio_port_v7 *port) override; |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 95 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 96 | // Set audio port configuration. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 97 | status_t setAudioPortConfig(const struct audio_port_config *config) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 98 | |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 99 | // List microphones |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame^] | 100 | status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override; |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 101 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 102 | status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 103 | status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override; |
| 104 | |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 105 | status_t getMmapPolicyInfos( |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 106 | media::audio::common::AudioMMapPolicyType policyType __unused, |
| 107 | std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos __unused) override { |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 108 | // TODO: Implement the HAL query when moving to AIDL HAL. |
| 109 | return INVALID_OPERATION; |
| 110 | } |
| 111 | |
jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 112 | int32_t getAAudioMixerBurstCount() override { |
| 113 | // TODO: Implement the HAL query when moving to AIDL HAL. |
| 114 | return INVALID_OPERATION; |
| 115 | } |
| 116 | |
| 117 | int32_t getAAudioHardwareBurstMinUsec() override { |
| 118 | // TODO: Implement the HAL query when moving to AIDL HAL. |
| 119 | return INVALID_OPERATION; |
| 120 | } |
| 121 | |
Eric Laurent | 49879b7 | 2022-12-20 20:20:23 +0100 | [diff] [blame] | 122 | int32_t supportsBluetoothVariableLatency(bool* supports __unused) override { |
Eric Laurent | 01eb164 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 123 | // TODO: Implement the HAL query when moving to AIDL HAL. |
| 124 | return INVALID_OPERATION; |
| 125 | } |
| 126 | |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 127 | status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override; |
| 128 | |
Ytai Ben-Tsvi | 48287b5 | 2021-12-01 15:07:11 -0800 | [diff] [blame] | 129 | error::Result<audio_hw_sync_t> getHwAvSync() override; |
| 130 | |
Andy Hung | 61589a4 | 2021-06-16 09:37:53 -0700 | [diff] [blame] | 131 | status_t dump(int fd, const Vector<String16>& args) override; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 132 | |
| 133 | private: |
| 134 | friend class DevicesFactoryHalHidl; |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 135 | sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice; |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 136 | // Null if it's not a primary device. |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 137 | sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice; |
| 138 | bool supportsSetConnectedState7_1 = true; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 139 | |
| 140 | // Can not be constructed directly by clients. |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 141 | explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device); |
| 142 | explicit DeviceHalHidl( |
| 143 | const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 144 | |
| 145 | // The destructor automatically closes the device. |
| 146 | virtual ~DeviceHalHidl(); |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 147 | |
| 148 | template <typename HalPort> status_t getAudioPortImpl(HalPort *port); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 151 | } // namespace android |
| 152 | |
| 153 | #endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H |