• 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 <error/Result.h>
23 #include <media/audiohal/EffectHalInterface.h>
24 #include <media/MicrophoneInfo.h>
25 #include <system/audio.h>
26 #include <utils/Errors.h>
27 #include <utils/RefBase.h>
28 #include <utils/String8.h>
29 
30 namespace android {
31 
32 class StreamInHalInterface;
33 class StreamOutHalInterface;
34 
35 class DeviceHalInterface : public RefBase
36 {
37   public:
38     // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
39     virtual status_t getSupportedDevices(uint32_t *devices) = 0;
40 
41     // Check to see if the audio hardware interface has been initialized.
42     virtual status_t initCheck() = 0;
43 
44     // Set the audio volume of a voice call. Range is between 0.0 and 1.0.
45     virtual status_t setVoiceVolume(float volume) = 0;
46 
47     // Set the audio volume for all audio activities other than voice call.
48     virtual status_t setMasterVolume(float volume) = 0;
49 
50     // Get the current master volume value for the HAL.
51     virtual status_t getMasterVolume(float *volume) = 0;
52 
53     // Called when the audio mode changes.
54     virtual status_t setMode(audio_mode_t mode) = 0;
55 
56     // Muting control.
57     virtual status_t setMicMute(bool state) = 0;
58     virtual status_t getMicMute(bool *state) = 0;
59     virtual status_t setMasterMute(bool state) = 0;
60     virtual status_t getMasterMute(bool *state) = 0;
61 
62     // Set global audio parameters.
63     virtual status_t setParameters(const String8& kvPairs) = 0;
64 
65     // Get global audio parameters.
66     virtual status_t getParameters(const String8& keys, String8 *values) = 0;
67 
68     // Returns audio input buffer size according to parameters passed.
69     virtual status_t getInputBufferSize(const struct audio_config *config,
70             size_t *size) = 0;
71 
72     // Creates and opens the audio hardware output stream. The stream is closed
73     // by releasing all references to the returned object.
74     virtual status_t openOutputStream(
75             audio_io_handle_t handle,
76             audio_devices_t deviceType,
77             audio_output_flags_t flags,
78             struct audio_config *config,
79             const char *address,
80             sp<StreamOutHalInterface> *outStream) = 0;
81 
82     // Creates and opens the audio hardware input stream. The stream is closed
83     // by releasing all references to the returned object.
84     virtual status_t openInputStream(
85             audio_io_handle_t handle,
86             audio_devices_t devices,
87             struct audio_config *config,
88             audio_input_flags_t flags,
89             const char *address,
90             audio_source_t source,
91             audio_devices_t outputDevice,
92             const char *outputDeviceAddress,
93             sp<StreamInHalInterface> *inStream) = 0;
94 
95     // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
96     virtual status_t supportsAudioPatches(bool *supportsPatches) = 0;
97 
98     // Creates an audio patch between several source and sink ports.
99     virtual status_t createAudioPatch(
100             unsigned int num_sources,
101             const struct audio_port_config *sources,
102             unsigned int num_sinks,
103             const struct audio_port_config *sinks,
104             audio_patch_handle_t *patch) = 0;
105 
106     // Releases an audio patch.
107     virtual status_t releaseAudioPatch(audio_patch_handle_t patch) = 0;
108 
109     // Fills the list of supported attributes for a given audio port.
110     virtual status_t getAudioPort(struct audio_port *port) = 0;
111 
112     // Fills the list of supported attributes for a given audio port.
113     virtual status_t getAudioPort(struct audio_port_v7 *port) = 0;
114 
115     // Set audio port configuration.
116     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
117 
118     // List microphones
119     virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones) = 0;
120 
121     virtual status_t addDeviceEffect(
122             audio_port_handle_t device, sp<EffectHalInterface> effect) = 0;
123     virtual status_t removeDeviceEffect(
124             audio_port_handle_t device, sp<EffectHalInterface> effect) = 0;
125 
126     virtual status_t getMmapPolicyInfos(
127             media::audio::common::AudioMMapPolicyType policyType,
128             std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos)  = 0;
129     virtual int32_t getAAudioMixerBurstCount() = 0;
130     virtual int32_t getAAudioHardwareBurstMinUsec() = 0;
131 
132     // Update the connection status of an external device.
133     virtual status_t setConnectedState(const struct audio_port_v7 *port, bool connected) = 0;
134 
135     virtual error::Result<audio_hw_sync_t> getHwAvSync() = 0;
136 
137     virtual status_t dump(int fd, const Vector<String16>& args) = 0;
138 
139   protected:
140     // Subclasses can not be constructed directly by clients.
DeviceHalInterface()141     DeviceHalInterface() {}
142 
143     // The destructor automatically closes the device.
~DeviceHalInterface()144     virtual ~DeviceHalInterface() {}
145 };
146 
147 } // namespace android
148 
149 #endif // ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
150