dvr_buffer_queue_internal.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef ANDROID_DVR_BUFFER_QUEUE_INTERNAL_H_
  2. #define ANDROID_DVR_BUFFER_QUEUE_INTERNAL_H_
  3. #include <gui/Surface.h>
  4. #include <private/dvr/buffer_hub_queue_client.h>
  5. #include <sys/cdefs.h>
  6. #include <array>
  7. #include <memory>
  8. #include "dvr_internal.h"
  9. struct ANativeWindow;
  10. typedef struct DvrNativeBufferMetadata DvrNativeBufferMetadata;
  11. typedef struct DvrReadBuffer DvrReadBuffer;
  12. typedef struct DvrReadBufferQueue DvrReadBufferQueue;
  13. typedef struct DvrWriteBuffer DvrWriteBuffer;
  14. typedef void (*DvrReadBufferQueueBufferAvailableCallback)(void* context);
  15. typedef void (*DvrReadBufferQueueBufferRemovedCallback)(DvrReadBuffer* buffer,
  16. void* context);
  17. struct DvrWriteBufferQueue {
  18. using BufferHubQueue = android::dvr::BufferHubQueue;
  19. using ProducerQueue = android::dvr::ProducerQueue;
  20. // Create a concrete object for DvrWriteBufferQueue.
  21. //
  22. // @param producer_queue The BufferHub's ProducerQueue that is used to back
  23. // this DvrWriteBufferQueue, must not be NULL.
  24. explicit DvrWriteBufferQueue(
  25. const std::shared_ptr<ProducerQueue>& producer_queue);
  26. int id() const { return producer_queue_->id(); }
  27. uint32_t width() const { return width_; };
  28. uint32_t height() const { return height_; };
  29. uint32_t format() const { return format_; };
  30. size_t capacity() const { return producer_queue_->capacity(); }
  31. const std::shared_ptr<ProducerQueue>& producer_queue() const {
  32. return producer_queue_;
  33. }
  34. int GetNativeWindow(ANativeWindow** out_window);
  35. int CreateReadQueue(DvrReadBufferQueue** out_read_queue);
  36. int Dequeue(int timeout, DvrWriteBuffer* write_buffer, int* out_fence_fd);
  37. int GainBuffer(int timeout, DvrWriteBuffer** out_write_buffer,
  38. DvrNativeBufferMetadata* out_meta, int* out_fence_fd);
  39. int PostBuffer(DvrWriteBuffer* write_buffer,
  40. const DvrNativeBufferMetadata* meta, int ready_fence_fd);
  41. int ResizeBuffer(uint32_t width, uint32_t height);
  42. private:
  43. std::shared_ptr<ProducerQueue> producer_queue_;
  44. std::array<std::unique_ptr<DvrWriteBuffer>, BufferHubQueue::kMaxQueueCapacity>
  45. write_buffers_;
  46. int64_t next_post_index_ = 0;
  47. uint32_t width_;
  48. uint32_t height_;
  49. uint32_t format_;
  50. android::sp<android::Surface> native_window_;
  51. };
  52. struct DvrReadBufferQueue {
  53. using BufferHubQueue = android::dvr::BufferHubQueue;
  54. using ConsumerQueue = android::dvr::ConsumerQueue;
  55. explicit DvrReadBufferQueue(
  56. const std::shared_ptr<ConsumerQueue>& consumer_queue);
  57. int id() const { return consumer_queue_->id(); }
  58. int event_fd() const { return consumer_queue_->queue_fd(); }
  59. size_t capacity() const { return consumer_queue_->capacity(); }
  60. int CreateReadQueue(DvrReadBufferQueue** out_read_queue);
  61. int Dequeue(int timeout, DvrReadBuffer* read_buffer, int* out_fence_fd,
  62. void* out_meta, size_t user_metadata_size);
  63. int AcquireBuffer(int timeout, DvrReadBuffer** out_read_buffer,
  64. DvrNativeBufferMetadata* out_meta, int* out_fence_fd);
  65. int ReleaseBuffer(DvrReadBuffer* read_buffer,
  66. const DvrNativeBufferMetadata* meta, int release_fence_fd);
  67. void SetBufferAvailableCallback(
  68. DvrReadBufferQueueBufferAvailableCallback callback, void* context);
  69. void SetBufferRemovedCallback(
  70. DvrReadBufferQueueBufferRemovedCallback callback, void* context);
  71. int HandleEvents();
  72. private:
  73. std::shared_ptr<ConsumerQueue> consumer_queue_;
  74. std::array<std::unique_ptr<DvrReadBuffer>, BufferHubQueue::kMaxQueueCapacity>
  75. read_buffers_;
  76. };
  77. #endif // ANDROID_DVR_BUFFER_QUEUE_INTERNAL_H_