/* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include "stream_common.h" #include "io_thread.h" #include "primary_device.h" namespace android { namespace hardware { namespace audio { namespace V6_0 { namespace implementation { using ::android::sp; using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using namespace ::android::hardware::audio::common::V6_0; using namespace ::android::hardware::audio::V6_0; struct StreamIn : public IStreamIn { StreamIn(sp dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, hidl_bitfield flags, const SinkMetadata& sinkMetadata); ~StreamIn(); // IStream Return getFrameSize() override; Return getFrameCount() override; Return getBufferSize() override; Return getSampleRate() override; Return getSupportedSampleRates(AudioFormat format, getSupportedSampleRates_cb _hidl_cb) override; Return setSampleRate(uint32_t sampleRateHz) override; Return> getChannelMask() override; Return getSupportedChannelMasks(AudioFormat format, getSupportedChannelMasks_cb _hidl_cb) override; Return setChannelMask(hidl_bitfield mask) override; Return getFormat() override; Return getSupportedFormats(getSupportedFormats_cb _hidl_cb) override; Return setFormat(AudioFormat format) override; Return getAudioProperties(getAudioProperties_cb _hidl_cb) override; Return addEffect(uint64_t effectId) override; Return removeEffect(uint64_t effectId) override; Return standby() override; Return getDevices(getDevices_cb _hidl_cb) override; Return setDevices(const hidl_vec& devices) override; Return setHwAvSync(uint32_t hwAvSync) override; Return getParameters(const hidl_vec& context, const hidl_vec& keys, getParameters_cb _hidl_cb) override; Return setParameters(const hidl_vec& context, const hidl_vec& parameters) override; Return start() override; Return stop() override; Return createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override; Return getMmapPosition(getMmapPosition_cb _hidl_cb) override; Return close() override; // IStreamIn Return getAudioSource(getAudioSource_cb _hidl_cb) override; Return setGain(float gain) override; Return updateSinkMetadata(const SinkMetadata& sinkMetadata) override; Return prepareForReading(uint32_t frameSize, uint32_t framesCount, prepareForReading_cb _hidl_cb) override; Return getInputFramesLost() override; Return getCapturePosition(getCapturePosition_cb _hidl_cb) override; Return getActiveMicrophones(getActiveMicrophones_cb _hidl_cb) override; Return setMicrophoneDirection(MicrophoneDirection direction) override; Return setMicrophoneFieldDimension(float zoom) override; const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; } const AudioConfig &getAudioConfig() const { return mCommon.m_config; } const hidl_bitfield &getAudioOutputFlags() const { return mCommon.m_flags; } uint64_t &getFrameCounter() { return mFrames; } void setMicMute(bool mute); void addInputFramesLost(size_t n) { mInputFramesLost += n; } float getEffectiveVolume() const { return mEffectiveVolume; } private: Result closeImpl(bool fromDctor); sp mDev; const StreamCommon mCommon; const SinkMetadata mSinkMetadata; std::unique_ptr mReadThread; // The count is not reset to zero when output enters standby. uint64_t mFrames = 0; std::atomic mInputFramesLost = 0; std::atomic mEffectiveVolume = 1.0f; }; } // namespace implementation } // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android