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