blob: 727e92fc3a3ab68cd8be43d95645452344430e09 [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:
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 Naganovb4e037e2019-01-14 15:56:33 -080085 audio_devices_t outputDevice,
86 const char *outputDeviceAddress,
Mikhail Naganovf558e022016-11-14 17:45:17 -080087 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
jiabinb4fed192020-09-22 14:45:40 -0700106 // Fills the list of supported attributes for a given audio port.
107 virtual status_t getAudioPort(struct audio_port_v7 *port);
108
Mikhail Naganovf558e022016-11-14 17:45:17 -0800109 // Set audio port configuration.
110 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
111
jiabin9ff780e2018-03-19 18:19:52 -0700112 // List microphones
113 virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones);
114
Eric Laurentb82e6b72019-11-22 17:25:04 -0800115 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 Huangebe64102021-09-07 20:01:07 +0000118 status_t getMmapPolicyInfos(
jiabine99d0882021-09-17 05:21:25 +0000119 media::audio::common::AudioMMapPolicyType policyType __unused,
120 std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos __unused) override {
Jiabin Huangebe64102021-09-07 20:01:07 +0000121 // TODO: Implement the HAL query when moving to AIDL HAL.
122 return INVALID_OPERATION;
123 }
124
jiabine504e7b2021-09-18 00:27:08 +0000125 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 Laurent52057642022-12-16 11:45:07 +0100135 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 Naganov516d3982022-02-01 23:53:59 +0000140 status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override;
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
146 private:
147 friend class DevicesFactoryHalHidl;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000148 sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000149 // Null if it's not a primary device.
Mikhail Naganov516d3982022-02-01 23:53:59 +0000150 sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice;
151 bool supportsSetConnectedState7_1 = true;
Mikhail Naganovf558e022016-11-14 17:45:17 -0800152
153 // Can not be constructed directly by clients.
Mikhail Naganov6718c392022-01-27 22:17:21 +0000154 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 Naganovf558e022016-11-14 17:45:17 -0800157
158 // The destructor automatically closes the device.
159 virtual ~DeviceHalHidl();
Mikhail Naganov720cc432021-03-24 20:42:49 -0700160
161 template <typename HalPort> status_t getAudioPortImpl(HalPort *port);
Mikhail Naganovf558e022016-11-14 17:45:17 -0800162};
163
Mikhail Naganovf558e022016-11-14 17:45:17 -0800164} // namespace android
165
166#endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H