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