1 /* 2 * Copyright (C) 2020 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 #pragma once 18 #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/IStreamIn.h) 19 #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) 20 #include "stream_common.h" 21 #include "io_thread.h" 22 #include "primary_device.h" 23 24 namespace android { 25 namespace hardware { 26 namespace audio { 27 namespace CPP_VERSION { 28 namespace implementation { 29 30 using ::android::sp; 31 using ::android::hardware::hidl_bitfield; 32 using ::android::hardware::hidl_string; 33 using ::android::hardware::hidl_vec; 34 using ::android::hardware::Return; 35 using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; 36 using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; 37 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStreamIn; 38 39 struct StreamIn : public IStreamIn { 40 StreamIn(sp<Device> dev, 41 int32_t ioHandle, 42 const DeviceAddress& device, 43 const AudioConfig& config, 44 hidl_vec<AudioInOutFlag> flags, 45 const SinkMetadata& sinkMetadata); 46 ~StreamIn(); 47 48 // IStream 49 Return<uint64_t> getFrameSize() override; 50 Return<uint64_t> getFrameCount() override; 51 Return<uint64_t> getBufferSize() override; 52 Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override; 53 Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override; 54 Return<Result> setAudioProperties(const AudioConfigBaseOptional& config) override; 55 Return<Result> addEffect(uint64_t effectId) override; 56 Return<Result> removeEffect(uint64_t effectId) override; 57 Return<Result> standby() override; 58 Return<void> getDevices(getDevices_cb _hidl_cb) override; 59 Return<Result> setDevices(const hidl_vec<DeviceAddress>& devices) override; 60 Return<Result> setHwAvSync(uint32_t hwAvSync) override; 61 Return<void> getParameters(const hidl_vec<ParameterValue>& context, 62 const hidl_vec<hidl_string>& keys, 63 getParameters_cb _hidl_cb) override; 64 Return<Result> setParameters(const hidl_vec<ParameterValue>& context, 65 const hidl_vec<ParameterValue>& parameters) override; 66 Return<Result> start() override; 67 Return<Result> stop() override; 68 Return<void> createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override; 69 Return<void> getMmapPosition(getMmapPosition_cb _hidl_cb) override; 70 Return<Result> close() override; 71 72 // IStreamIn 73 Return<void> getAudioSource(getAudioSource_cb _hidl_cb) override; 74 Return<Result> setGain(float gain) override; 75 Return<Result> updateSinkMetadata(const SinkMetadata& sinkMetadata) override; 76 Return<void> prepareForReading(uint32_t frameSize, uint32_t framesCount, 77 prepareForReading_cb _hidl_cb) override; 78 Return<uint32_t> getInputFramesLost() override; 79 Return<void> getCapturePosition(getCapturePosition_cb _hidl_cb) override; 80 Return<void> getActiveMicrophones(getActiveMicrophones_cb _hidl_cb) override; 81 Return<Result> setMicrophoneDirection(MicrophoneDirection direction) override; 82 Return<Result> setMicrophoneFieldDimension(float zoom) override; 83 getDeviceAddressStreamIn84 const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; } getAudioConfigStreamIn85 const AudioConfig &getAudioConfig() const { return mCommon.m_config; } getAudioOutputFlagsStreamIn86 const hidl_vec<AudioInOutFlag> &getAudioOutputFlags() const { return mCommon.m_flags; } 87 getFrameCounterStreamIn88 uint64_t &getFrameCounter() { return mFrames; } 89 void setMicMute(bool mute); addInputFramesLostStreamIn90 void addInputFramesLost(size_t n) { mInputFramesLost += n; } getEffectiveVolumeStreamIn91 float getEffectiveVolume() const { return mEffectiveVolume; } 92 93 static bool validateDeviceAddress(const DeviceAddress& device); 94 static bool validateFlags(const hidl_vec<AudioInOutFlag>& flags); 95 static bool validateSinkMetadata(const SinkMetadata& sinkMetadata); 96 97 private: 98 Result closeImpl(bool fromDctor); 99 100 sp<Device> mDev; 101 const StreamCommon mCommon; 102 const SinkMetadata mSinkMetadata; 103 std::unique_ptr<IOThread> mReadThread; 104 105 // The count is not reset to zero when output enters standby. 106 uint64_t mFrames = 0; 107 108 std::atomic<uint32_t> mInputFramesLost = 0; 109 std::atomic<float> mEffectiveVolume = 1.0f; 110 }; 111 112 } // namespace implementation 113 } // namespace CPP_VERSION 114 } // namespace audio 115 } // namespace hardware 116 } // namespace android 117