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