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