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