• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_DVR_BUFFERHUBD_PRODUCER_QUEUE_CHANNEL_H_
2 #define ANDROID_DVR_BUFFERHUBD_PRODUCER_QUEUE_CHANNEL_H_
3 
4 #include <pdx/status.h>
5 #include <private/dvr/bufferhub_rpc.h>
6 #include <private/dvr/buffer_hub.h>
7 
8 namespace android {
9 namespace dvr {
10 
11 class ProducerQueueChannel : public BufferHubChannel {
12  public:
13   static pdx::Status<std::shared_ptr<ProducerQueueChannel>> Create(
14       BufferHubService* service, int channel_id,
15       const ProducerQueueConfig& config, const UsagePolicy& usage_policy);
16   ~ProducerQueueChannel() override;
17 
18   bool HandleMessage(pdx::Message& message) override;
19   void HandleImpulse(pdx::Message& message) override;
20 
21   BufferInfo GetBufferInfo() const override;
22 
23   // Handles client request to create a new consumer queue attached to current
24   // producer queue.
25   // Returns a handle for the service channel, as well as the size of the
26   // metadata associated with the queue.
27   pdx::Status<pdx::RemoteChannelHandle> OnCreateConsumerQueue(
28       pdx::Message& message, bool silent);
29 
30   pdx::Status<QueueInfo> OnGetQueueInfo(pdx::Message& message);
31 
32   // Allocate a new BufferHubProducer according to the input spec. Client may
33   // handle this as if a new producer is created through kOpCreateBuffer.
34   pdx::Status<std::vector<std::pair<pdx::RemoteChannelHandle, size_t>>>
35   OnProducerQueueAllocateBuffers(pdx::Message& message, uint32_t width,
36                                  uint32_t height, uint32_t layer_count,
37                                  uint32_t format, uint64_t usage,
38                                  size_t buffer_count);
39 
40   // Inserts a ProducerBuffer into the queue. Note that the buffer must be in
41   // Gain'ed state for the operation to succeed.
42   pdx::Status<size_t> OnProducerQueueInsertBuffer(pdx::Message& message, int buffer_cid);
43 
44   // Removes a ProducerBuffer indicated by |slot|. Note that the buffer must be
45   // in Gain'ed state for the operation to succeed.
46   pdx::Status<void> OnProducerQueueRemoveBuffer(pdx::Message& message,
47                                                 size_t slot);
48 
49   void AddConsumer(ConsumerQueueChannel* channel);
50   void RemoveConsumer(ConsumerQueueChannel* channel);
51 
52  private:
53   ProducerQueueChannel(BufferHubService* service, int channel_id,
54                        const ProducerQueueConfig& config,
55                        const UsagePolicy& usage_policy, int* error);
56 
57   // Allocate one single producer buffer by |OnProducerQueueAllocateBuffers|.
58   // Note that the newly created buffer's file handle will be pushed to client
59   // and our return type is a RemoteChannelHandle.
60   // Returns the remote channel handle and the slot number for the newly
61   // allocated buffer.
62   pdx::Status<std::pair<pdx::RemoteChannelHandle, size_t>> AllocateBuffer(
63       pdx::Message& message, uint32_t width, uint32_t height,
64       uint32_t layer_count, uint32_t format, uint64_t usage);
65 
66   // The producer queue's configuration. Now we assume the configuration is
67   // immutable once the queue is created.
68   ProducerQueueConfig config_;
69 
70   // A set of variables to control what |usage| bits can this ProducerQueue
71   // allocate.
72   UsagePolicy usage_policy_;
73 
74   // Provides access to the |channel_id| of all consumer channels associated
75   // with this producer.
76   std::vector<ConsumerQueueChannel*> consumer_channels_;
77 
78   // Tracks how many buffers have this queue allocated.
79   size_t capacity_;
80 
81   // Tracks of all buffer producer allocated through this buffer queue. Once
82   // a buffer get allocated, it will take a logical slot in the |buffers_| array
83   // and the slot number will stay unchanged during the entire life cycle of the
84   // queue.
85   std::weak_ptr<ProducerChannel> buffers_[BufferHubRPC::kMaxQueueCapacity];
86 
87   ProducerQueueChannel(const ProducerQueueChannel&) = delete;
88   void operator=(const ProducerQueueChannel&) = delete;
89 };
90 
91 }  // namespace dvr
92 }  // namespace android
93 
94 #endif  // ANDROID_DVR_BUFFERHUBD_PRODUCER_QUEUE_CHANNEL_H_
95