blob: 1362dab4e2fc1b17c4c1bc23dc43fa24bf603d0e [file] [log] [blame]
Mikhail Naganovf558e022016-11-14 17:45:17 -08001/*
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 Rocard95213bf2018-11-08 17:16:57 -080020#include PATH(android/hardware/audio/FILE_VERSION/IDevice.h)
21#include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h)
Mikhail Naganovf558e022016-11-14 17:45:17 -080022#include <media/audiohal/DeviceHalInterface.h>
Mikhail Naganov6718c392022-01-27 22:17:21 +000023#include <media/audiohal/EffectHalInterface.h>
jiabin12537fc2023-10-12 17:56:08 +000024#include <media/audiohal/StreamHalInterface.h>
Mikhail Naganovf558e022016-11-14 17:45:17 -080025
Mikhail Naganov288a3432022-03-25 00:29:56 +000026#include "CoreConversionHelperHidl.h"
Mikhail Naganovf558e022016-11-14 17:45:17 -080027
Mikhail Naganovf558e022016-11-14 17:45:17 -080028namespace android {
29
Mikhail Naganov288a3432022-03-25 00:29:56 +000030class DeviceHalHidl : public DeviceHalInterface, public CoreConversionHelperHidl
Mikhail Naganovf558e022016-11-14 17:45:17 -080031{
32 public:
Mikhail Naganov2d814892023-04-24 13:06:04 -070033 status_t getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) override;
34
35 status_t getAudioRoutes(std::vector<media::AudioRoute> *routes) override;
36
Mikhail Naganovffd97712023-05-03 17:45:36 -070037 status_t getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) override;
38
Mikhail Naganovf558e022016-11-14 17:45:17 -080039 // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
Shunkai Yaoed624a72022-12-12 06:11:46 +000040 status_t getSupportedDevices(uint32_t *devices) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080041
42 // Check to see if the audio hardware interface has been initialized.
Shunkai Yaoed624a72022-12-12 06:11:46 +000043 status_t initCheck() override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080044
45 // Set the audio volume of a voice call. Range is between 0.0 and 1.0.
Shunkai Yaoed624a72022-12-12 06:11:46 +000046 status_t setVoiceVolume(float volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080047
48 // Set the audio volume for all audio activities other than voice call.
Shunkai Yaoed624a72022-12-12 06:11:46 +000049 status_t setMasterVolume(float volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080050
51 // Get the current master volume value for the HAL.
Shunkai Yaoed624a72022-12-12 06:11:46 +000052 status_t getMasterVolume(float *volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080053
54 // Called when the audio mode changes.
Shunkai Yaoed624a72022-12-12 06:11:46 +000055 status_t setMode(audio_mode_t mode) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080056
57 // Muting control.
Shunkai Yaoed624a72022-12-12 06:11:46 +000058 status_t setMicMute(bool state) override;
59 status_t getMicMute(bool *state) override;
60 status_t setMasterMute(bool state) override;
61 status_t getMasterMute(bool *state) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080062
63 // Set global audio parameters.
Shunkai Yaoed624a72022-12-12 06:11:46 +000064 status_t setParameters(const String8& kvPairs) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080065
66 // Get global audio parameters.
Shunkai Yaoed624a72022-12-12 06:11:46 +000067 status_t getParameters(const String8& keys, String8 *values) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080068
69 // Returns audio input buffer size according to parameters passed.
Mikhail Naganovd5b643f2024-02-15 11:51:26 -080070 status_t getInputBufferSize(struct audio_config* config, size_t* size) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080071
72 // Creates and opens the audio hardware output stream. The stream is closed
73 // by releasing all references to the returned object.
Shunkai Yaoed624a72022-12-12 06:11:46 +000074 status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices,
75 audio_output_flags_t flags, struct audio_config* config,
76 const char* address, sp<StreamOutHalInterface>* outStream) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080077
78 // Creates and opens the audio hardware input stream. The stream is closed
79 // by releasing all references to the returned object.
Shunkai Yaoed624a72022-12-12 06:11:46 +000080 status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices,
81 struct audio_config* config, audio_input_flags_t flags,
82 const char* address, audio_source_t source,
83 audio_devices_t outputDevice, const char* outputDeviceAddress,
84 sp<StreamInHalInterface>* inStream) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080085
86 // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
Shunkai Yaoed624a72022-12-12 06:11:46 +000087 status_t supportsAudioPatches(bool* supportsPatches) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080088
89 // Creates an audio patch between several source and sink ports.
Shunkai Yaoed624a72022-12-12 06:11:46 +000090 status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources,
91 unsigned int num_sinks, const struct audio_port_config* sinks,
92 audio_patch_handle_t* patch) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080093
94 // Releases an audio patch.
Shunkai Yaoed624a72022-12-12 06:11:46 +000095 status_t releaseAudioPatch(audio_patch_handle_t patch) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080096
97 // Fills the list of supported attributes for a given audio port.
Shunkai Yaoed624a72022-12-12 06:11:46 +000098 status_t getAudioPort(struct audio_port *port) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080099
jiabinb4fed192020-09-22 14:45:40 -0700100 // Fills the list of supported attributes for a given audio port.
Shunkai Yaoed624a72022-12-12 06:11:46 +0000101 status_t getAudioPort(struct audio_port_v7 *port) override;
jiabinb4fed192020-09-22 14:45:40 -0700102
Mikhail Naganovf558e022016-11-14 17:45:17 -0800103 // Set audio port configuration.
Shunkai Yaoed624a72022-12-12 06:11:46 +0000104 status_t setAudioPortConfig(const struct audio_port_config *config) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800105
jiabin9ff780e2018-03-19 18:19:52 -0700106 // List microphones
Shunkai Yaoed624a72022-12-12 06:11:46 +0000107 status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override;
jiabin9ff780e2018-03-19 18:19:52 -0700108
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700109 status_t addDeviceEffect(
110 const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
111 status_t removeDeviceEffect(
112 const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800113
Jiabin Huangebe64102021-09-07 20:01:07 +0000114 status_t getMmapPolicyInfos(
jiabine99d0882021-09-17 05:21:25 +0000115 media::audio::common::AudioMMapPolicyType policyType __unused,
116 std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos __unused) override {
Jiabin Huangebe64102021-09-07 20:01:07 +0000117 // TODO: Implement the HAL query when moving to AIDL HAL.
118 return INVALID_OPERATION;
119 }
120
jiabine504e7b2021-09-18 00:27:08 +0000121 int32_t getAAudioMixerBurstCount() override {
122 // TODO: Implement the HAL query when moving to AIDL HAL.
123 return INVALID_OPERATION;
124 }
125
126 int32_t getAAudioHardwareBurstMinUsec() override {
127 // TODO: Implement the HAL query when moving to AIDL HAL.
128 return INVALID_OPERATION;
129 }
130
Eric Laurent7af6ee72023-06-29 11:44:54 +0200131 status_t supportsBluetoothVariableLatency(bool* supports) override;
Eric Laurent52057642022-12-16 11:45:07 +0100132
Mikhail Naganov516d3982022-02-01 23:53:59 +0000133 status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override;
134
Mikhail Naganovb1ddbb02023-03-15 17:06:59 -0700135 status_t setSimulateDeviceConnections(bool enabled __unused) override {
136 // Only supported by AIDL HALs.
137 return INVALID_OPERATION;
138 }
139
Ytai Ben-Tsvi48287b52021-12-01 15:07:11 -0800140 error::Result<audio_hw_sync_t> getHwAvSync() override;
141
Andy Hung61589a42021-06-16 09:37:53 -0700142 status_t dump(int fd, const Vector<String16>& args) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800143
Vlad Popa03bd5bc2023-01-17 16:16:51 +0100144 status_t getSoundDoseInterface(const std::string& module,
145 ::ndk::SpAIBinder* soundDoseBinder) override;
146
jiabinc0048632023-04-27 22:04:31 +0000147 status_t prepareToDisconnectExternalDevice(const struct audio_port_v7* port) override;
148
jiabin12537fc2023-10-12 17:56:08 +0000149 status_t getAudioMixPort(const struct audio_port_v7* devicePort,
150 struct audio_port_v7* mixPort) override;
151
Mikhail Naganovf558e022016-11-14 17:45:17 -0800152 private:
153 friend class DevicesFactoryHalHidl;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000154 sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000155 // Null if it's not a primary device.
Mikhail Naganov516d3982022-02-01 23:53:59 +0000156 sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
157 bool supportsSetConnectedState7_1 = true;
Vlad Popa03bd5bc2023-01-17 16:16:51 +0100158 class SoundDoseWrapper;
159 const std::unique_ptr<SoundDoseWrapper> mSoundDoseWrapper;
jiabinc0048632023-04-27 22:04:31 +0000160 std::set<audio_port_handle_t> mDeviceDisconnectionNotified;
jiabin12537fc2023-10-12 17:56:08 +0000161 std::map<audio_io_handle_t, wp<StreamHalInterface>> mStreams;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800162
163 // Can not be constructed directly by clients.
Mikhail Naganov6718c392022-01-27 22:17:21 +0000164 explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device);
165 explicit DeviceHalHidl(
166 const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device);
Mikhail Naganovf558e022016-11-14 17:45:17 -0800167
jiabin12537fc2023-10-12 17:56:08 +0000168 void cleanupStreams();
169
Mikhail Naganovf558e022016-11-14 17:45:17 -0800170 // The destructor automatically closes the device.
171 virtual ~DeviceHalHidl();
Mikhail Naganov720cc432021-03-24 20:42:49 -0700172
173 template <typename HalPort> status_t getAudioPortImpl(HalPort *port);
Mikhail Naganovf558e022016-11-14 17:45:17 -0800174};
175
Mikhail Naganovf558e022016-11-14 17:45:17 -0800176} // namespace android
177
178#endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H