• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/BnOutputStream.h>
18 #include <fmq/AidlMessageQueue.h>
19 #include <fmq/EventFlag.h>
20 #include <utils/Thread.h>
21 
22 using aidl::android::hardware::common::fmq::MQDescriptor;
23 using aidl::android::hardware::common::fmq::SynchronizedReadWrite;
24 using android::AidlMessageQueue;
25 using android::sp;
26 using android::Thread;
27 using android::hardware::EventFlag;
28 
29 using aidl::device::google::atv::audio_proxy::AudioDrain;
30 using aidl::device::google::atv::audio_proxy::BnOutputStream;
31 using aidl::device::google::atv::audio_proxy::WriteStatus;
32 
33 namespace audio_proxy {
34 class AudioProxyStreamOut;
35 
36 class OutputStreamImpl : public BnOutputStream {
37  public:
38   using DataMQ = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
39   using DataMQDesc = MQDescriptor<int8_t, SynchronizedReadWrite>;
40   using StatusMQ = AidlMessageQueue<WriteStatus, SynchronizedReadWrite>;
41   using StatusMQDesc = MQDescriptor<WriteStatus, SynchronizedReadWrite>;
42 
43   explicit OutputStreamImpl(std::unique_ptr<AudioProxyStreamOut> stream);
44   ~OutputStreamImpl() override;
45 
46   ndk::ScopedAStatus prepareForWriting(int32_t frameSize, int32_t framesCount,
47                                        DataMQDesc* dataMQDesc,
48                                        StatusMQDesc* statusMQDesc) override;
49 
50   ndk::ScopedAStatus standby() override;
51   ndk::ScopedAStatus close() override;
52   ndk::ScopedAStatus pause() override;
53   ndk::ScopedAStatus resume() override;
54   ndk::ScopedAStatus drain(AudioDrain type) override;
55   ndk::ScopedAStatus flush() override;
56 
57   ndk::ScopedAStatus setVolume(float left, float right) override;
58 
59  private:
60   typedef void (*EventFlagDeleter)(EventFlag*);
61 
62   ndk::ScopedAStatus closeImpl();
63 
64   std::unique_ptr<AudioProxyStreamOut> mStream;
65 
66   std::unique_ptr<DataMQ> mDataMQ;
67   std::unique_ptr<StatusMQ> mStatusMQ;
68   std::unique_ptr<EventFlag, EventFlagDeleter> mEventFlag;
69   std::atomic<bool> mStopWriteThread = false;
70   sp<Thread> mWriteThread;
71 };
72 
73 }  // namespace audio_proxy