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