• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     virtual status_t getInputBufferSize(const struct audio_config *config,
82             size_t *size) = 0;
83 
84     // Creates and opens the audio hardware output stream. The stream is closed
85     // by releasing all references to the returned object.
86     virtual status_t openOutputStream(
87             audio_io_handle_t handle,
88             audio_devices_t deviceType,
89             audio_output_flags_t flags,
90             struct audio_config *config,
91             const char *address,
92             sp<StreamOutHalInterface> *outStream) = 0;
93 
94     // Creates and opens the audio hardware input stream. The stream is closed
95     // by releasing all references to the returned object.
96     virtual status_t openInputStream(
97             audio_io_handle_t handle,
98             audio_devices_t devices,
99             struct audio_config *config,
100             audio_input_flags_t flags,
101             const char *address,
102             audio_source_t source,
103             audio_devices_t outputDevice,
104             const char *outputDeviceAddress,
105             sp<StreamInHalInterface> *inStream) = 0;
106 
107     // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
108     virtual status_t supportsAudioPatches(bool *supportsPatches) = 0;
109 
110     // Creates an audio patch between several source and sink ports.
111     virtual status_t createAudioPatch(
112             unsigned int num_sources,
113             const struct audio_port_config *sources,
114             unsigned int num_sinks,
115             const struct audio_port_config *sinks,
116             audio_patch_handle_t *patch) = 0;
117 
118     // Releases an audio patch.
119     virtual status_t releaseAudioPatch(audio_patch_handle_t patch) = 0;
120 
121     // Fills the list of supported attributes for a given audio port.
122     virtual status_t getAudioPort(struct audio_port* port) = 0;
123 
124     // Fills the list of supported attributes for a given audio port.
125     virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
126 
127     // Set audio port configuration.
128     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
129 
130     // List microphones
131     virtual status_t getMicrophones(
132             std::vector<audio_microphone_characteristic_t>* microphones) = 0;
133 
134     virtual status_t addDeviceEffect(
135             const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
136     virtual status_t removeDeviceEffect(
137             const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
138 
139     virtual status_t getMmapPolicyInfos(
140             media::audio::common::AudioMMapPolicyType policyType,
141             std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) = 0;
142     virtual int32_t getAAudioMixerBurstCount() = 0;
143     virtual int32_t getAAudioHardwareBurstMinUsec() = 0;
144 
145     virtual status_t supportsBluetoothVariableLatency(bool* supports) = 0;
146 
147     // Update the connection status of an external device.
148     virtual status_t setConnectedState(const struct audio_port_v7* port, bool connected) = 0;
149 
150     // Enable simulation of external devices connection at the HAL level.
151     virtual status_t setSimulateDeviceConnections(bool enabled) = 0;
152 
153     virtual error::Result<audio_hw_sync_t> getHwAvSync() = 0;
154 
155     virtual status_t dump(int fd, const Vector<String16>& args) = 0;
156 
157     // Returns the sound dose binder interface if it is supported by the HAL, nullptr otherwise
158     virtual status_t getSoundDoseInterface(const std::string& module,
159                                            ::ndk::SpAIBinder* soundDoseBinder) = 0;
160 
161     virtual status_t prepareToDisconnectExternalDevice(const struct audio_port_v7* port) = 0;
162 
163   protected:
164     // Subclasses can not be constructed directly by clients.
DeviceHalInterface()165     DeviceHalInterface() {}
166 
167     // The destructor automatically closes the device.
~DeviceHalInterface()168     virtual ~DeviceHalInterface() {}
169 };
170 
171 } // namespace android
172 
173 #endif // ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
174