1 /* 2 * Copyright (C) 2018 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_AUDIO_DEVICE_H 18 #define ANDROID_HARDWARE_AUDIO_DEVICE_H 19 20 #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) 21 22 #include "ParametersUtil.h" 23 24 #include <memory> 25 26 #include <hardware/audio.h> 27 #include <media/AudioParameter.h> 28 29 #include <hidl/Status.h> 30 31 #include <hidl/MQDescriptor.h> 32 33 #include <VersionUtils.h> 34 35 namespace android { 36 namespace hardware { 37 namespace audio { 38 namespace CPP_VERSION { 39 namespace implementation { 40 41 using ::android::sp; 42 using ::android::hardware::hidl_string; 43 using ::android::hardware::hidl_vec; 44 using ::android::hardware::Return; 45 using ::android::hardware::Void; 46 using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield; 47 using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield; 48 using namespace ::android::hardware::audio::common::CPP_VERSION; 49 using namespace ::android::hardware::audio::CPP_VERSION; 50 51 struct Device : public IDevice, public ParametersUtil { 52 explicit Device(audio_hw_device_t* device); 53 54 // Methods from ::android::hardware::audio::CPP_VERSION::IDevice follow. 55 Return<Result> initCheck() override; 56 Return<Result> setMasterVolume(float volume) override; 57 Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb) override; 58 Return<Result> setMicMute(bool mute) override; 59 Return<void> getMicMute(getMicMute_cb _hidl_cb) override; 60 Return<Result> setMasterMute(bool mute) override; 61 Return<void> getMasterMute(getMasterMute_cb _hidl_cb) override; 62 Return<void> getInputBufferSize(const AudioConfig& config, 63 getInputBufferSize_cb _hidl_cb) override; 64 65 std::tuple<Result, sp<IStreamOut>> openOutputStreamImpl(int32_t ioHandle, 66 const DeviceAddress& device, 67 const AudioConfig& config, 68 AudioOutputFlagBitfield flags, 69 AudioConfig* suggestedConfig); 70 std::tuple<Result, sp<IStreamIn>> openInputStreamImpl( 71 int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, 72 AudioInputFlagBitfield flags, AudioSource source, AudioConfig* suggestedConfig); 73 #if MAJOR_VERSION == 2 74 Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device, 75 const AudioConfig& config, AudioOutputFlagBitfield flags, 76 openOutputStream_cb _hidl_cb) override; 77 Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device, 78 const AudioConfig& config, AudioInputFlagBitfield flags, 79 AudioSource source, openInputStream_cb _hidl_cb) override; 80 #elif MAJOR_VERSION >= 4 81 Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device, 82 const AudioConfig& config, AudioOutputFlagBitfield flags, 83 const SourceMetadata& sourceMetadata, 84 openOutputStream_cb _hidl_cb) override; 85 Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device, 86 const AudioConfig& config, AudioInputFlagBitfield flags, 87 const SinkMetadata& sinkMetadata, 88 openInputStream_cb _hidl_cb) override; 89 #endif 90 91 Return<bool> supportsAudioPatches() override; 92 Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources, 93 const hidl_vec<AudioPortConfig>& sinks, 94 createAudioPatch_cb _hidl_cb) override; 95 Return<Result> releaseAudioPatch(int32_t patch) override; 96 Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override; 97 Return<Result> setAudioPortConfig(const AudioPortConfig& config) override; 98 99 Return<Result> setScreenState(bool turnedOn) override; 100 101 #if MAJOR_VERSION == 2 102 Return<AudioHwSync> getHwAvSync() override; 103 Return<void> getParameters(const hidl_vec<hidl_string>& keys, 104 getParameters_cb _hidl_cb) override; 105 Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters) override; 106 Return<void> debugDump(const hidl_handle& fd) override; 107 #elif MAJOR_VERSION >= 4 108 Return<void> getHwAvSync(getHwAvSync_cb _hidl_cb) override; 109 Return<void> getParameters(const hidl_vec<ParameterValue>& context, 110 const hidl_vec<hidl_string>& keys, 111 getParameters_cb _hidl_cb) override; 112 Return<Result> setParameters(const hidl_vec<ParameterValue>& context, 113 const hidl_vec<ParameterValue>& parameters) override; 114 Return<void> getMicrophones(getMicrophones_cb _hidl_cb) override; 115 Return<Result> setConnectedState(const DeviceAddress& address, bool connected) override; 116 #endif 117 118 Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override; 119 120 // Utility methods for extending interfaces. 121 Result analyzeStatus(const char* funcName, int status, 122 const std::vector<int>& ignoreErrors = {}); 123 void closeInputStream(audio_stream_in_t* stream); 124 void closeOutputStream(audio_stream_out_t* stream); deviceDevice125 audio_hw_device_t* device() const { return mDevice; } 126 127 private: 128 audio_hw_device_t* mDevice; 129 130 virtual ~Device(); 131 132 // Methods from ParametersUtil. 133 char* halGetParameters(const char* keys) override; 134 int halSetParameters(const char* keysAndValues) override; 135 versionDevice136 uint32_t version() const { return mDevice->common.version; } 137 }; 138 139 } // namespace implementation 140 } // namespace CPP_VERSION 141 } // namespace audio 142 } // namespace hardware 143 } // namespace android 144 145 #endif // ANDROID_HARDWARE_AUDIO_DEVICE_H 146