1 #ifndef ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
2 #define ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
3 
4 #include <pdx/rpc/buffer_wrapper.h>
5 #include <private/dvr/bufferhub_rpc.h>
6 #include <private/dvr/buffer_hub.h>
7 
8 namespace android {
9 namespace dvr {
10 
11 // Consumer channels are attached to a Producer channel
12 class ConsumerChannel : public BufferHubChannel {
13  public:
14   using BorrowedHandle = pdx::BorrowedHandle;
15   using Channel = pdx::Channel;
16   using Message = pdx::Message;
17 
18   ConsumerChannel(BufferHubService* service, int buffer_id, int channel_id,
19                   uint32_t client_state_mask,
20                   const std::shared_ptr<Channel> producer);
21   ~ConsumerChannel() override;
22 
23   bool HandleMessage(Message& message) override;
24   void HandleImpulse(Message& message) override;
25 
client_state_mask()26   uint32_t client_state_mask() const { return client_state_mask_; }
27   BufferInfo GetBufferInfo() const override;
28 
29   void OnProducerGained();
30   void OnProducerPosted();
31   void OnProducerClosed();
32 
33  private:
34   std::shared_ptr<ProducerChannel> GetProducer() const;
35 
36   pdx::Status<BufferDescription<BorrowedHandle>> OnGetBuffer(Message& message);
37 
38   pdx::Status<LocalFence> OnConsumerAcquire(Message& message);
39   pdx::Status<void> OnConsumerRelease(Message& message,
40                                       LocalFence release_fence);
41 
42   uint32_t client_state_mask_{0U};
43   bool acquired_{false};
44   bool released_{true};
45   std::weak_ptr<Channel> producer_;
46 
47   ConsumerChannel(const ConsumerChannel&) = delete;
48   void operator=(const ConsumerChannel&) = delete;
49 };
50 
51 }  // namespace dvr
52 }  // namespace android
53 
54 #endif  // ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
55