1 // Copyright (C) 2021 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <aidl/device/google/atv/audio_proxy/IOutputStream.h> 18 #include <fmq/AidlMessageQueue.h> 19 #include <fmq/EventFlag.h> 20 21 #include "BusOutputStream.h" 22 23 namespace audio_proxy { 24 namespace service { 25 26 using aidl::android::hardware::common::fmq::MQDescriptor; 27 using aidl::android::hardware::common::fmq::SynchronizedReadWrite; 28 using aidl::device::google::atv::audio_proxy::IOutputStream; 29 using android::AidlMessageQueue; 30 using android::hardware::EventFlag; 31 32 class RemoteBusOutputStream : public BusOutputStream { 33 public: 34 RemoteBusOutputStream(std::shared_ptr<IOutputStream> stream, 35 const std::string& address, 36 const AidlAudioConfig& config, int32_t flags); 37 ~RemoteBusOutputStream() override; 38 39 bool standby() override; 40 bool pause() override; 41 bool resume() override; 42 bool drain(AidlAudioDrain drain) override; 43 bool flush() override; 44 bool close() override; 45 bool setVolume(float left, float right) override; 46 47 size_t availableToWrite() override; 48 AidlWriteStatus writeRingBuffer(const uint8_t* firstMem, size_t firstLength, 49 const uint8_t* secondMem, 50 size_t secondLength) override; 51 52 bool start() override; 53 bool stop() override; 54 AidlMmapBufferInfo createMmapBuffer(int32_t minBufferSizeFrames) override; 55 AidlPresentationPosition getMmapPosition() override; 56 57 protected: 58 bool prepareForWritingImpl(uint32_t frameSize, uint32_t frameCount) override; 59 60 private: 61 using DataMQ = AidlMessageQueue<int8_t, SynchronizedReadWrite>; 62 using DataMQDesc = MQDescriptor<int8_t, SynchronizedReadWrite>; 63 using StatusMQ = AidlMessageQueue<AidlWriteStatus, SynchronizedReadWrite>; 64 using StatusMQDesc = MQDescriptor<AidlWriteStatus, SynchronizedReadWrite>; 65 66 typedef void (*EventFlagDeleter)(EventFlag*); 67 68 std::shared_ptr<IOutputStream> mStream; 69 70 std::unique_ptr<DataMQ> mDataMQ; 71 std::unique_ptr<StatusMQ> mStatusMQ; 72 std::unique_ptr<EventFlag, EventFlagDeleter> mEventFlag; 73 }; 74 75 } // namespace service 76 } // namespace audio_proxy