• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
2 #define ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
3 
4 #include "buffer_hub.h"
5 
6 #include <pdx/rpc/buffer_wrapper.h>
7 #include <private/dvr/bufferhub_rpc.h>
8 
9 namespace android {
10 namespace dvr {
11 
12 // Consumer channels are attached to a Producer channel
13 class ConsumerChannel : public BufferHubChannel {
14  public:
15   using BorrowedHandle = pdx::BorrowedHandle;
16   using Channel = pdx::Channel;
17   using Message = pdx::Message;
18 
19   ConsumerChannel(BufferHubService* service, int buffer_id, int channel_id,
20                   uint64_t consumer_state_bit,
21                   const std::shared_ptr<Channel> producer);
22   ~ConsumerChannel() override;
23 
24   bool HandleMessage(Message& message) override;
25   void HandleImpulse(Message& message) override;
26 
consumer_state_bit()27   uint64_t consumer_state_bit() const { return consumer_state_bit_; }
28   BufferInfo GetBufferInfo() const override;
29 
30   bool 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   pdx::Status<void> OnConsumerSetIgnore(Message& message, bool ignore);
42 
43   uint64_t consumer_state_bit_{0};
44   bool acquired_{false};
45   bool released_{true};
46   bool ignored_{false};  // True if we are ignoring events.
47   std::weak_ptr<Channel> producer_;
48 
49   ConsumerChannel(const ConsumerChannel&) = delete;
50   void operator=(const ConsumerChannel&) = delete;
51 };
52 
53 }  // namespace dvr
54 }  // namespace android
55 
56 #endif  // ANDROID_DVR_BUFFERHUBD_CONSUMER_CHANNEL_H_
57