xref: /aosp_15_r20/frameworks/av/media/libaudiohal/include/media/audiohal/DeviceHalInterface.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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_INTERFACE_H
18 #define ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
19 
20 #include <android/media/audio/common/AudioMMapPolicyInfo.h>
21 #include <android/media/audio/common/AudioMMapPolicyType.h>
22 #include <android/media/audio/common/AudioMode.h>
23 #include <android/media/audio/common/AudioPort.h>
24 #include <android/media/AudioRoute.h>
25 #include <error/Result.h>
26 #include <media/audiohal/EffectHalInterface.h>
27 #include <system/audio.h>
28 #include <utils/Errors.h>
29 #include <utils/RefBase.h>
30 #include <utils/String8.h>
31 
32 namespace ndk {
33 class SpAIBinder;
34 }
35 
36 namespace android {
37 
38 class StreamInHalInterface;
39 class StreamOutHalInterface;
40 
41 class DeviceHalInterface : public virtual RefBase
42 {
43   public:
44     virtual status_t getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) = 0;
45 
46     virtual status_t getAudioRoutes(std::vector<media::AudioRoute> *routes) = 0;
47 
48     virtual status_t getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) = 0;
49 
50     // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
51     virtual status_t getSupportedDevices(uint32_t *devices) = 0;
52 
53     // Check to see if the audio hardware interface has been initialized.
54     virtual status_t initCheck() = 0;
55 
56     // Set the audio volume of a voice call. Range is between 0.0 and 1.0.
57     virtual status_t setVoiceVolume(float volume) = 0;
58 
59     // Set the audio volume for all audio activities other than voice call.
60     virtual status_t setMasterVolume(float volume) = 0;
61 
62     // Get the current master volume value for the HAL.
63     virtual status_t getMasterVolume(float *volume) = 0;
64 
65     // Called when the audio mode changes.
66     virtual status_t setMode(audio_mode_t mode) = 0;
67 
68     // Muting control.
69     virtual status_t setMicMute(bool state) = 0;
70     virtual status_t getMicMute(bool *state) = 0;
71     virtual status_t setMasterMute(bool state) = 0;
72     virtual status_t getMasterMute(bool *state) = 0;
73 
74     // Set global audio parameters.
75     virtual status_t setParameters(const String8& kvPairs) = 0;
76 
77     // Get global audio parameters.
78     virtual status_t getParameters(const String8& keys, String8 *values) = 0;
79 
80     // Returns audio input buffer size according to parameters passed.
81     // If there is no possibility for the HAL to open an input with the provided
82     // parameters, the method will return BAD_VALUE and modify the provided `config`.
83     virtual status_t getInputBufferSize(struct audio_config *config, size_t *size) = 0;
84 
85     // Creates and opens the audio hardware output stream. The stream is closed
86     // by releasing all references to the returned object.
87     virtual status_t openOutputStream(
88             audio_io_handle_t handle,
89             audio_devices_t deviceType,
90             audio_output_flags_t flags,
91             struct audio_config *config,
92             const char *address,
93             sp<StreamOutHalInterface> *outStream,
94             const std::vector<playback_track_metadata_v7_t>& sourceMetadata = {}) = 0;
95 
96     // Creates and opens the audio hardware input stream. The stream is closed
97     // by releasing all references to the returned object.
98     virtual status_t openInputStream(
99             audio_io_handle_t handle,
100             audio_devices_t devices,
101             struct audio_config *config,
102             audio_input_flags_t flags,
103             const char *address,
104             audio_source_t source,
105             audio_devices_t outputDevice,
106             const char *outputDeviceAddress,
107             sp<StreamInHalInterface> *inStream) = 0;
108 
109     // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
110     virtual status_t supportsAudioPatches(bool *supportsPatches) = 0;
111 
112     // Creates an audio patch between several source and sink ports.
113     virtual status_t createAudioPatch(
114             unsigned int num_sources,
115             const struct audio_port_config *sources,
116             unsigned int num_sinks,
117             const struct audio_port_config *sinks,
118             audio_patch_handle_t *patch) = 0;
119 
120     // Releases an audio patch.
121     virtual status_t releaseAudioPatch(audio_patch_handle_t patch) = 0;
122 
123     // Fills the list of supported attributes for a given audio port.
124     virtual status_t getAudioPort(struct audio_port* port) = 0;
125 
126     // Fills the list of supported attributes for a given audio port.
127     virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
128 
129     // Set audio port configuration.
130     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
131 
132     // List microphones
133     virtual status_t getMicrophones(
134             std::vector<audio_microphone_characteristic_t>* microphones) = 0;
135 
136     virtual status_t addDeviceEffect(
137             const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
138     virtual status_t removeDeviceEffect(
139             const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
140 
141     virtual status_t getMmapPolicyInfos(
142             media::audio::common::AudioMMapPolicyType policyType,
143             std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) = 0;
144     virtual int32_t getAAudioMixerBurstCount() = 0;
145     virtual int32_t getAAudioHardwareBurstMinUsec() = 0;
146 
147     virtual status_t supportsBluetoothVariableLatency(bool* supports) = 0;
148 
149     // Update the connection status of an external device.
150     virtual status_t setConnectedState(const struct audio_port_v7* port, bool connected) = 0;
151 
152     // Enable simulation of external devices connection at the HAL level.
153     virtual status_t setSimulateDeviceConnections(bool enabled) = 0;
154 
155     virtual error::Result<audio_hw_sync_t> getHwAvSync() = 0;
156 
157     virtual status_t dump(int fd, const Vector<String16>& args) = 0;
158 
159     // Returns the sound dose binder interface if it is supported by the HAL, nullptr otherwise
160     virtual status_t getSoundDoseInterface(const std::string& module,
161                                            ::ndk::SpAIBinder* soundDoseBinder) = 0;
162 
163     virtual status_t prepareToDisconnectExternalDevice(const struct audio_port_v7* port) = 0;
164 
165     virtual status_t getAudioMixPort(const struct audio_port_v7* devicePort,
166                                      struct audio_port_v7* mixPort) = 0;
167 
168   protected:
169     // Subclasses can not be constructed directly by clients.
DeviceHalInterface()170     DeviceHalInterface() {}
171 
172     // The destructor automatically closes the device.
~DeviceHalInterface()173     virtual ~DeviceHalInterface() {}
174 };
175 
176 } // namespace android
177 
178 #endif // ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
179