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