// Copyright (C) 2021 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 #include using aidl::android::hardware::common::fmq::MQDescriptor; using aidl::android::hardware::common::fmq::SynchronizedReadWrite; using android::AidlMessageQueue; using android::sp; using android::Thread; using android::hardware::EventFlag; using aidl::device::google::atv::audio_proxy::AudioDrain; using aidl::device::google::atv::audio_proxy::BnOutputStream; using aidl::device::google::atv::audio_proxy::MmapBufferInfo; using aidl::device::google::atv::audio_proxy::PresentationPosition; using aidl::device::google::atv::audio_proxy::WriteStatus; namespace audio_proxy { class AudioProxyStreamOut; class OutputStreamImpl : public BnOutputStream { public: using DataMQ = AidlMessageQueue; using DataMQDesc = MQDescriptor; using StatusMQ = AidlMessageQueue; using StatusMQDesc = MQDescriptor; explicit OutputStreamImpl(std::unique_ptr stream); ~OutputStreamImpl() override; ndk::ScopedAStatus prepareForWriting(int32_t frameSize, int32_t framesCount, DataMQDesc* dataMQDesc, StatusMQDesc* statusMQDesc) override; ndk::ScopedAStatus standby() override; ndk::ScopedAStatus close() override; ndk::ScopedAStatus pause() override; ndk::ScopedAStatus resume() override; ndk::ScopedAStatus drain(AudioDrain type) override; ndk::ScopedAStatus flush() override; ndk::ScopedAStatus setVolume(float left, float right) override; ndk::ScopedAStatus getBufferSizeBytes(int64_t* bufferSizeBytes) override; ndk::ScopedAStatus getLatencyMs(int32_t* latencyMs) override; ndk::ScopedAStatus start() override; ndk::ScopedAStatus stop() override; ndk::ScopedAStatus createMmapBuffer(int32_t minBufferSizeFrames, MmapBufferInfo* info) override; ndk::ScopedAStatus getMmapPosition(PresentationPosition* position) override; private: typedef void (*EventFlagDeleter)(EventFlag*); ndk::ScopedAStatus closeImpl(); std::unique_ptr mStream; std::unique_ptr mDataMQ; std::unique_ptr mStatusMQ; std::unique_ptr mEventFlag; std::atomic mStopWriteThread = false; sp mWriteThread; }; } // namespace audio_proxy