blob: e82f20af82503f09bc24fceecdbec609822561d8 [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>
Mikhail Naganovf558e022016-11-14 17:45:17 -080024
Mikhail Naganov288a3432022-03-25 00:29:56 +000025#include "CoreConversionHelperHidl.h"
Mikhail Naganovf558e022016-11-14 17:45:17 -080026
Mikhail Naganovf558e022016-11-14 17:45:17 -080027namespace android {
28
Mikhail Naganov288a3432022-03-25 00:29:56 +000029class DeviceHalHidl : public DeviceHalInterface, public CoreConversionHelperHidl
Mikhail Naganovf558e022016-11-14 17:45:17 -080030{
31 public:
Mikhail Naganovf83b9742023-04-24 13:06:04 -070032 status_t getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) override;
33
34 status_t getAudioRoutes(std::vector<media::AudioRoute> *routes) override;
35
Mikhail Naganov1fba38c2023-05-03 17:45:36 -070036 status_t getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) override;
37
Mikhail Naganovf558e022016-11-14 17:45:17 -080038 // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
Shunkai Yao51202502022-12-12 06:11:46 +000039 status_t getSupportedDevices(uint32_t *devices) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080040
41 // Check to see if the audio hardware interface has been initialized.
Shunkai Yao51202502022-12-12 06:11:46 +000042 status_t initCheck() override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080043
44 // Set the audio volume of a voice call. Range is between 0.0 and 1.0.
Shunkai Yao51202502022-12-12 06:11:46 +000045 status_t setVoiceVolume(float volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080046
47 // Set the audio volume for all audio activities other than voice call.
Shunkai Yao51202502022-12-12 06:11:46 +000048 status_t setMasterVolume(float volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080049
50 // Get the current master volume value for the HAL.
Shunkai Yao51202502022-12-12 06:11:46 +000051 status_t getMasterVolume(float *volume) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080052
53 // Called when the audio mode changes.
Shunkai Yao51202502022-12-12 06:11:46 +000054 status_t setMode(audio_mode_t mode) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080055
56 // Muting control.
Shunkai Yao51202502022-12-12 06:11:46 +000057 status_t setMicMute(bool state) override;
58 status_t getMicMute(bool *state) override;
59 status_t setMasterMute(bool state) override;
60 status_t getMasterMute(bool *state) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080061
62 // Set global audio parameters.
Shunkai Yao51202502022-12-12 06:11:46 +000063 status_t setParameters(const String8& kvPairs) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080064
65 // Get global audio parameters.
Shunkai Yao51202502022-12-12 06:11:46 +000066 status_t getParameters(const String8& keys, String8 *values) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080067
68 // Returns audio input buffer size according to parameters passed.
Shunkai Yao51202502022-12-12 06:11:46 +000069 status_t getInputBufferSize(const struct audio_config* config, size_t* size) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080070
71 // Creates and opens the audio hardware output stream. The stream is closed
72 // by releasing all references to the returned object.
Shunkai Yao51202502022-12-12 06:11:46 +000073 status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices,
74 audio_output_flags_t flags, struct audio_config* config,
75 const char* address, sp<StreamOutHalInterface>* outStream) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080076
77 // Creates and opens the audio hardware input stream. The stream is closed
78 // by releasing all references to the returned object.
Shunkai Yao51202502022-12-12 06:11:46 +000079 status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices,
80 struct audio_config* config, audio_input_flags_t flags,
81 const char* address, audio_source_t source,
82 audio_devices_t outputDevice, const char* outputDeviceAddress,
83 sp<StreamInHalInterface>* inStream) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080084
85 // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
Shunkai Yao51202502022-12-12 06:11:46 +000086 status_t supportsAudioPatches(bool* supportsPatches) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080087
88 // Creates an audio patch between several source and sink ports.
Shunkai Yao51202502022-12-12 06:11:46 +000089 status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources,
90 unsigned int num_sinks, const struct audio_port_config* sinks,
91 audio_patch_handle_t* patch) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080092
93 // Releases an audio patch.
Shunkai Yao51202502022-12-12 06:11:46 +000094 status_t releaseAudioPatch(audio_patch_handle_t patch) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080095
96 // Fills the list of supported attributes for a given audio port.
Shunkai Yao51202502022-12-12 06:11:46 +000097 status_t getAudioPort(struct audio_port *port) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -080098
jiabinb4fed192020-09-22 14:45:40 -070099 // Fills the list of supported attributes for a given audio port.
Shunkai Yao51202502022-12-12 06:11:46 +0000100 status_t getAudioPort(struct audio_port_v7 *port) override;
jiabinb4fed192020-09-22 14:45:40 -0700101
Mikhail Naganovf558e022016-11-14 17:45:17 -0800102 // Set audio port configuration.
Shunkai Yao51202502022-12-12 06:11:46 +0000103 status_t setAudioPortConfig(const struct audio_port_config *config) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800104
jiabin9ff780e2018-03-19 18:19:52 -0700105 // List microphones
Shunkai Yao51202502022-12-12 06:11:46 +0000106 status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override;
jiabin9ff780e2018-03-19 18:19:52 -0700107
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700108 status_t addDeviceEffect(
109 const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
110 status_t removeDeviceEffect(
111 const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800112
Jiabin Huangebe64102021-09-07 20:01:07 +0000113 status_t getMmapPolicyInfos(
jiabine99d0882021-09-17 05:21:25 +0000114 media::audio::common::AudioMMapPolicyType policyType __unused,
115 std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos __unused) override {
Jiabin Huangebe64102021-09-07 20:01:07 +0000116 // TODO: Implement the HAL query when moving to AIDL HAL.
117 return INVALID_OPERATION;
118 }
119
jiabine504e7b2021-09-18 00:27:08 +0000120 int32_t getAAudioMixerBurstCount() override {
121 // TODO: Implement the HAL query when moving to AIDL HAL.
122 return INVALID_OPERATION;
123 }
124
125 int32_t getAAudioHardwareBurstMinUsec() override {
126 // TODO: Implement the HAL query when moving to AIDL HAL.
127 return INVALID_OPERATION;
128 }
129
Eric Laurent49879b72022-12-20 20:20:23 +0100130 int32_t supportsBluetoothVariableLatency(bool* supports __unused) override {
Eric Laurent01eb1642022-12-16 11:45:07 +0100131 // TODO: Implement the HAL query when moving to AIDL HAL.
132 return INVALID_OPERATION;
133 }
134
Mikhail Naganov516d3982022-02-01 23:53:59 +0000135 status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override;
136
Mikhail Naganove93a0862023-03-15 17:06:59 -0700137 status_t setSimulateDeviceConnections(bool enabled __unused) override {
138 // Only supported by AIDL HALs.
139 return INVALID_OPERATION;
140 }
141
Ytai Ben-Tsvi48287b52021-12-01 15:07:11 -0800142 error::Result<audio_hw_sync_t> getHwAvSync() override;
143
Andy Hung61589a42021-06-16 09:37:53 -0700144 status_t dump(int fd, const Vector<String16>& args) override;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800145
jiabin872de702023-04-27 22:04:31 +0000146 status_t prepareToDisconnectExternalDevice(const struct audio_port_v7* port) override;
147
Mikhail Naganovf558e022016-11-14 17:45:17 -0800148 private:
149 friend class DevicesFactoryHalHidl;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000150 sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000151 // Null if it's not a primary device.
Mikhail Naganov516d3982022-02-01 23:53:59 +0000152 sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
153 bool supportsSetConnectedState7_1 = true;
jiabin872de702023-04-27 22:04:31 +0000154 std::set<audio_port_handle_t> mDeviceDisconnectionNotified;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800155
156 // Can not be constructed directly by clients.
Mikhail Naganov6718c392022-01-27 22:17:21 +0000157 explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device);
158 explicit DeviceHalHidl(
159 const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device);
Mikhail Naganovf558e022016-11-14 17:45:17 -0800160
161 // The destructor automatically closes the device.
162 virtual ~DeviceHalHidl();
Mikhail Naganov720cc432021-03-24 20:42:49 -0700163
164 template <typename HalPort> status_t getAudioPortImpl(HalPort *port);
Mikhail Naganovf558e022016-11-14 17:45:17 -0800165};
166
Mikhail Naganovf558e022016-11-14 17:45:17 -0800167} // namespace android
168
169#endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H