/* * Copyright (C) 2018 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. */ #ifndef ANDROID_HARDWARE_AUDIO_STREAMIN_H #define ANDROID_HARDWARE_AUDIO_STREAMIN_H // clang-format off #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/IStreamIn.h) // clang-format on #include "Device.h" #include "Stream.h" #include #include #include #include #include #include #include namespace android { namespace hardware { namespace audio { namespace CPP_VERSION { namespace implementation { using ::android::sp; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CPP_VERSION; struct StreamIn : public IStreamIn { typedef MessageQueue CommandMQ; typedef MessageQueue DataMQ; typedef MessageQueue StatusMQ; StreamIn(const sp& device, audio_stream_in_t* stream); // Methods from ::android::hardware::audio::CPP_VERSION::IStream follow. Return getFrameSize() override; Return getFrameCount() override; Return getBufferSize() override; #if MAJOR_VERSION <= 6 Return getSampleRate() override; #if MAJOR_VERSION == 2 Return getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override; Return getSupportedChannelMasks(getSupportedChannelMasks_cb _hidl_cb) override; #endif Return getSupportedSampleRates(AudioFormat format, getSupportedSampleRates_cb _hidl_cb); Return getSupportedChannelMasks(AudioFormat format, getSupportedChannelMasks_cb _hidl_cb); Return setSampleRate(uint32_t sampleRateHz) override; Return getChannelMask() override; Return setChannelMask(AudioChannelBitfield mask) override; Return getFormat() override; Return getSupportedFormats(getSupportedFormats_cb _hidl_cb) override; Return setFormat(AudioFormat format) override; #else Return getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override; Return setAudioProperties(const AudioConfigBaseOptional& config) override; #endif // MAJOR_VERSION <= 6 Return getAudioProperties(getAudioProperties_cb _hidl_cb) override; Return addEffect(uint64_t effectId) override; Return removeEffect(uint64_t effectId) override; Return standby() override; #if MAJOR_VERSION == 2 Return getDevice() override; Return setDevice(const DeviceAddress& address) override; Return getParameters(const hidl_vec& keys, getParameters_cb _hidl_cb) override; Return setParameters(const hidl_vec& parameters) override; Return setConnectedState(const DeviceAddress& address, bool connected) override; #elif MAJOR_VERSION >= 4 Return getDevices(getDevices_cb _hidl_cb) override; Return setDevices(const hidl_vec& devices) 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; #endif Return setHwAvSync(uint32_t hwAvSync) override; Return close() override; Return debug(const hidl_handle& fd, const hidl_vec& options) override; #if MAJOR_VERSION == 2 Return debugDump(const hidl_handle& fd) override; #endif // Methods from ::android::hardware::audio::CPP_VERSION::IStreamIn follow. Return getAudioSource(getAudioSource_cb _hidl_cb) override; Return setGain(float gain) 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 start() override; Return stop() override; Return createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override; Return getMmapPosition(getMmapPosition_cb _hidl_cb) override; #if MAJOR_VERSION >= 4 #if MAJOR_VERSION <= 6 Return updateSinkMetadata(const SinkMetadata& sinkMetadata) override; #else Return updateSinkMetadata(const SinkMetadata& sinkMetadata) override; #endif Return getActiveMicrophones(getActiveMicrophones_cb _hidl_cb) override; #endif // MAJOR_VERSION >= 4 #if MAJOR_VERSION >= 5 Return setMicrophoneDirection(MicrophoneDirection direction) override; Return setMicrophoneFieldDimension(float zoom) override; #endif static Result getCapturePositionImpl(audio_stream_in_t* stream, uint64_t* frames, uint64_t* time); private: #if MAJOR_VERSION >= 4 Result doUpdateSinkMetadata(const SinkMetadata& sinkMetadata); #if MAJOR_VERSION >= 7 Result doUpdateSinkMetadataV7(const SinkMetadata& sinkMetadata); #endif #endif // MAJOR_VERSION >= 4 const sp mDevice; audio_stream_in_t* mStream; const sp mStreamCommon; const sp> mStreamMmap; std::unique_ptr mCommandMQ; std::unique_ptr mDataMQ; std::unique_ptr mStatusMQ; EventFlag* mEfGroup; std::atomic mStopReadThread; sp mReadThread; virtual ~StreamIn(); }; } // namespace implementation } // namespace CPP_VERSION } // namespace audio } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_AUDIO_STREAMIN_H