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