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_HIDL_H 18 #define ANDROID_HARDWARE_DEVICE_HAL_HIDL_H 19 20 #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) 21 #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) 22 #include <media/audiohal/DeviceHalInterface.h> 23 #include <media/audiohal/EffectHalInterface.h> 24 25 #include "CoreConversionHelperHidl.h" 26 27 namespace android { 28 29 class DeviceHalHidl : public DeviceHalInterface, public CoreConversionHelperHidl 30 { 31 public: 32 status_t getAudioPorts(std::vector<media::audio::common::AudioPort> *ports) override; 33 34 status_t getAudioRoutes(std::vector<media::AudioRoute> *routes) override; 35 36 status_t getSupportedModes(std::vector<media::audio::common::AudioMode> *modes) override; 37 38 // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t. 39 status_t getSupportedDevices(uint32_t *devices) override; 40 41 // Check to see if the audio hardware interface has been initialized. 42 status_t initCheck() override; 43 44 // Set the audio volume of a voice call. Range is between 0.0 and 1.0. 45 status_t setVoiceVolume(float volume) override; 46 47 // Set the audio volume for all audio activities other than voice call. 48 status_t setMasterVolume(float volume) override; 49 50 // Get the current master volume value for the HAL. 51 status_t getMasterVolume(float *volume) override; 52 53 // Called when the audio mode changes. 54 status_t setMode(audio_mode_t mode) override; 55 56 // Muting control. 57 status_t setMicMute(bool state) override; 58 status_t getMicMute(bool *state) override; 59 status_t setMasterMute(bool state) override; 60 status_t getMasterMute(bool *state) override; 61 62 // Set global audio parameters. 63 status_t setParameters(const String8& kvPairs) override; 64 65 // Get global audio parameters. 66 status_t getParameters(const String8& keys, String8 *values) override; 67 68 // Returns audio input buffer size according to parameters passed. 69 status_t getInputBufferSize(const struct audio_config* config, size_t* size) override; 70 71 // Creates and opens the audio hardware output stream. The stream is closed 72 // by releasing all references to the returned object. 73 status_t openOutputStream(audio_io_handle_t handle, audio_devices_t devices, 74 audio_output_flags_t flags, struct audio_config* config, 75 const char* address, sp<StreamOutHalInterface>* outStream) override; 76 77 // Creates and opens the audio hardware input stream. The stream is closed 78 // by releasing all references to the returned object. 79 status_t openInputStream(audio_io_handle_t handle, audio_devices_t devices, 80 struct audio_config* config, audio_input_flags_t flags, 81 const char* address, audio_source_t source, 82 audio_devices_t outputDevice, const char* outputDeviceAddress, 83 sp<StreamInHalInterface>* inStream) override; 84 85 // Returns whether createAudioPatch and releaseAudioPatch operations are supported. 86 status_t supportsAudioPatches(bool* supportsPatches) override; 87 88 // Creates an audio patch between several source and sink ports. 89 status_t createAudioPatch(unsigned int num_sources, const struct audio_port_config* sources, 90 unsigned int num_sinks, const struct audio_port_config* sinks, 91 audio_patch_handle_t* patch) override; 92 93 // Releases an audio patch. 94 status_t releaseAudioPatch(audio_patch_handle_t patch) override; 95 96 // Fills the list of supported attributes for a given audio port. 97 status_t getAudioPort(struct audio_port *port) override; 98 99 // Fills the list of supported attributes for a given audio port. 100 status_t getAudioPort(struct audio_port_v7 *port) override; 101 102 // Set audio port configuration. 103 status_t setAudioPortConfig(const struct audio_port_config *config) override; 104 105 // List microphones 106 status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override; 107 108 status_t addDeviceEffect( 109 const struct audio_port_config *device, sp<EffectHalInterface> effect) override; 110 status_t removeDeviceEffect( 111 const struct audio_port_config *device, sp<EffectHalInterface> effect) override; 112 getMmapPolicyInfos(media::audio::common::AudioMMapPolicyType policyType __unused,std::vector<media::audio::common::AudioMMapPolicyInfo> * policyInfos __unused)113 status_t getMmapPolicyInfos( 114 media::audio::common::AudioMMapPolicyType policyType __unused, 115 std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos __unused) override { 116 // TODO: Implement the HAL query when moving to AIDL HAL. 117 return INVALID_OPERATION; 118 } 119 getAAudioMixerBurstCount()120 int32_t getAAudioMixerBurstCount() override { 121 // TODO: Implement the HAL query when moving to AIDL HAL. 122 return INVALID_OPERATION; 123 } 124 getAAudioHardwareBurstMinUsec()125 int32_t getAAudioHardwareBurstMinUsec() override { 126 // TODO: Implement the HAL query when moving to AIDL HAL. 127 return INVALID_OPERATION; 128 } 129 130 status_t supportsBluetoothVariableLatency(bool* supports) override; 131 132 status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override; 133 setSimulateDeviceConnections(bool enabled __unused)134 status_t setSimulateDeviceConnections(bool enabled __unused) override { 135 // Only supported by AIDL HALs. 136 return INVALID_OPERATION; 137 } 138 139 error::Result<audio_hw_sync_t> getHwAvSync() override; 140 141 status_t dump(int fd, const Vector<String16>& args) override; 142 143 status_t getSoundDoseInterface(const std::string& module, 144 ::ndk::SpAIBinder* soundDoseBinder) override; 145 146 status_t prepareToDisconnectExternalDevice(const struct audio_port_v7* port) override; 147 148 private: 149 friend class DevicesFactoryHalHidl; 150 sp<::android::hardware::audio::CPP_VERSION::IDevice> mDevice; 151 // Null if it's not a primary device. 152 sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice> mPrimaryDevice; 153 bool supportsSetConnectedState7_1 = true; 154 class SoundDoseWrapper; 155 const std::unique_ptr<SoundDoseWrapper> mSoundDoseWrapper; 156 std::set<audio_port_handle_t> mDeviceDisconnectionNotified; 157 158 // Can not be constructed directly by clients. 159 explicit DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device); 160 explicit DeviceHalHidl( 161 const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device); 162 163 // The destructor automatically closes the device. 164 virtual ~DeviceHalHidl(); 165 166 template <typename HalPort> status_t getAudioPortImpl(HalPort *port); 167 }; 168 169 } // namespace android 170 171 #endif // ANDROID_HARDWARE_DEVICE_HAL_HIDL_H 172