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_AUDIO_V2_0_DEVICE_H 18 #define ANDROID_HARDWARE_AUDIO_V2_0_DEVICE_H 19 20 #include <memory> 21 22 #include <media/AudioParameter.h> 23 #include <hardware/audio.h> 24 25 #include <android/hardware/audio/2.0/IDevice.h> 26 #include <hidl/Status.h> 27 28 #include <hidl/MQDescriptor.h> 29 30 #include "ParametersUtil.h" 31 32 namespace android { 33 namespace hardware { 34 namespace audio { 35 namespace V2_0 { 36 namespace implementation { 37 38 using ::android::hardware::audio::common::V2_0::AudioConfig; 39 using ::android::hardware::audio::common::V2_0::AudioHwSync; 40 using ::android::hardware::audio::common::V2_0::AudioInputFlag; 41 using ::android::hardware::audio::common::V2_0::AudioOutputFlag; 42 using ::android::hardware::audio::common::V2_0::AudioPatchHandle; 43 using ::android::hardware::audio::common::V2_0::AudioPort; 44 using ::android::hardware::audio::common::V2_0::AudioPortConfig; 45 using ::android::hardware::audio::common::V2_0::AudioSource; 46 using ::android::hardware::audio::V2_0::DeviceAddress; 47 using ::android::hardware::audio::V2_0::IDevice; 48 using ::android::hardware::audio::V2_0::IStreamIn; 49 using ::android::hardware::audio::V2_0::IStreamOut; 50 using ::android::hardware::audio::V2_0::ParameterValue; 51 using ::android::hardware::audio::V2_0::Result; 52 using ::android::hardware::Return; 53 using ::android::hardware::Void; 54 using ::android::hardware::hidl_vec; 55 using ::android::hardware::hidl_string; 56 using ::android::sp; 57 58 struct Device : public IDevice, public ParametersUtil { 59 explicit Device(audio_hw_device_t* device); 60 61 // Methods from ::android::hardware::audio::V2_0::IDevice follow. 62 Return<Result> initCheck() override; 63 Return<Result> setMasterVolume(float volume) override; 64 Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb) override; 65 Return<Result> setMicMute(bool mute) override; 66 Return<void> getMicMute(getMicMute_cb _hidl_cb) override; 67 Return<Result> setMasterMute(bool mute) override; 68 Return<void> getMasterMute(getMasterMute_cb _hidl_cb) override; 69 Return<void> getInputBufferSize( 70 const AudioConfig& config, getInputBufferSize_cb _hidl_cb) override; 71 Return<void> openOutputStream( 72 int32_t ioHandle, 73 const DeviceAddress& device, 74 const AudioConfig& config, 75 AudioOutputFlag flags, 76 openOutputStream_cb _hidl_cb) override; 77 Return<void> openInputStream( 78 int32_t ioHandle, 79 const DeviceAddress& device, 80 const AudioConfig& config, 81 AudioInputFlag flags, 82 AudioSource source, 83 openInputStream_cb _hidl_cb) override; 84 Return<bool> supportsAudioPatches() override; 85 Return<void> createAudioPatch( 86 const hidl_vec<AudioPortConfig>& sources, 87 const hidl_vec<AudioPortConfig>& sinks, 88 createAudioPatch_cb _hidl_cb) override; 89 Return<Result> releaseAudioPatch(int32_t patch) override; 90 Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override; 91 Return<Result> setAudioPortConfig(const AudioPortConfig& config) override; 92 Return<AudioHwSync> getHwAvSync() override; 93 Return<Result> setScreenState(bool turnedOn) override; 94 Return<void> getParameters( 95 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) override; 96 Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters) override; 97 Return<void> debugDump(const hidl_handle& fd) override; 98 99 // Utility methods for extending interfaces. 100 Result analyzeStatus(const char* funcName, int status); 101 void closeInputStream(audio_stream_in_t* stream); 102 void closeOutputStream(audio_stream_out_t* stream); deviceDevice103 audio_hw_device_t* device() const { return mDevice; } 104 105 private: 106 audio_hw_device_t *mDevice; 107 108 virtual ~Device(); 109 110 // Methods from ParametersUtil. 111 char* halGetParameters(const char* keys) override; 112 int halSetParameters(const char* keysAndValues) override; 113 versionDevice114 uint32_t version() const { return mDevice->common.version; } 115 }; 116 117 } // namespace implementation 118 } // namespace V2_0 119 } // namespace audio 120 } // namespace hardware 121 } // namespace android 122 123 #endif // ANDROID_HARDWARE_AUDIO_V2_0_DEVICE_H 124