Index: content/browser/renderer_host/media/video_capture_buffer_pool.h |
diff --git a/content/browser/renderer_host/media/video_capture_buffer_pool.h b/content/browser/renderer_host/media/video_capture_buffer_pool.h |
index ba92d4d4f867a60938c4fa1498cefe12bd8d66aa..8104fa43732f4a5f5319d4e6a2b21f6414476777 100644 |
--- a/content/browser/renderer_host/media/video_capture_buffer_pool.h |
+++ b/content/browser/renderer_host/media/video_capture_buffer_pool.h |
@@ -24,59 +24,36 @@ |
namespace content { |
-// A thread-safe class that does the bookkeeping and lifetime management for a |
-// pool of pixel buffers cycled between an in-process producer (e.g. a |
-// VideoCaptureDevice) and a set of out-of-process consumers. The pool is |
-// intended to be orchestrated by a VideoCaptureDevice::Client, but is designed |
-// to outlive the controller if necessary. The pixel buffers may be backed by a |
-// SharedMemory, but this is not compulsory. |
-// |
-// Producers get a buffer by calling ReserveForProducer(), and may pass on their |
-// ownership to the consumer by calling HoldForConsumers(), or drop the buffer |
-// (without further processing) by calling RelinquishProducerReservation(). |
-// Consumers signal that they are done with the buffer by calling |
-// RelinquishConsumerHold(). |
-// |
-// Buffers are allocated on demand, but there will never be more than |count| |
-// buffers in existence at any time. Buffers are identified by an int value |
-// called |buffer_id|. -1 (kInvalidId) is never a valid ID, and is returned by |
-// some methods to indicate failure. The active set of buffer ids may change |
-// over the lifetime of the buffer pool, as existing buffers are freed and |
-// reallocated at larger size. When reallocation occurs, new buffer IDs will |
-// circulate. |
-class CONTENT_EXPORT VideoCaptureBufferPool |
- : public base::RefCountedThreadSafe<VideoCaptureBufferPool> { |
+class VideoCaptureBufferPoolBufferHandle { |
public: |
- static const int kInvalidId; |
- |
- // Abstraction of a pool's buffer data buffer and size for clients. |
- // TODO(emircan): See https://crbug.com/521059, refactor this class. |
- class BufferHandle { |
- public: |
- virtual ~BufferHandle() {} |
- virtual gfx::Size dimensions() const = 0; |
- virtual size_t mapped_size() const = 0; |
- virtual void* data(int plane) = 0; |
- virtual ClientBuffer AsClientBuffer(int plane) = 0; |
+ virtual ~VideoCaptureBufferPoolBufferHandle() {} |
+ virtual gfx::Size dimensions() const = 0; |
+ virtual size_t mapped_size() const = 0; |
+ virtual void* data(int plane) = 0; |
+ virtual ClientBuffer AsClientBuffer(int plane) = 0; |
#if defined(OS_POSIX) && !defined(OS_MACOSX) |
- virtual base::FileDescriptor AsPlatformFile() = 0; |
+ virtual base::FileDescriptor AsPlatformFile() = 0; |
#endif |
- }; |
+}; |
- explicit VideoCaptureBufferPool(int count); |
+class CONTENT_EXPORT VideoCaptureBufferPool |
+ : public base::RefCountedThreadSafe<VideoCaptureBufferPool> { |
+ public: |
+ static constexpr int kInvalidId = -1; |
// One-time (per client/per-buffer) initialization to share a particular |
// buffer to a process. The shared handle is returned as |new_handle|. |
- bool ShareToProcess(int buffer_id, |
- base::ProcessHandle process_handle, |
- base::SharedMemoryHandle* new_handle); |
- bool ShareToProcess2(int buffer_id, |
- int plane, |
- base::ProcessHandle process_handle, |
- gfx::GpuMemoryBufferHandle* new_handle); |
+ virtual bool ShareToProcess(int buffer_id, |
+ base::ProcessHandle process_handle, |
+ base::SharedMemoryHandle* new_handle) = 0; |
+ virtual bool ShareToProcess2(int buffer_id, |
+ int plane, |
+ base::ProcessHandle process_handle, |
+ gfx::GpuMemoryBufferHandle* new_handle) = 0; |
// Try and obtain a BufferHandle for |buffer_id|. |
- std::unique_ptr<BufferHandle> GetBufferHandle(int buffer_id); |
+ virtual std::unique_ptr<VideoCaptureBufferPoolBufferHandle> GetBufferHandle( |
+ int buffer_id) = 0; |
// Reserve or allocate a buffer to support a packed frame of |dimensions| of |
// pixel |format| and return its id. This will fail (returning kInvalidId) if |
@@ -91,25 +68,15 @@ class CONTENT_EXPORT VideoCaptureBufferPool |
// On occasion, this call will decide to free an old buffer to make room for a |
// new allocation at a larger size. If so, the ID of the destroyed buffer is |
// returned via |buffer_id_to_drop|. |
- int ReserveForProducer(const gfx::Size& dimensions, |
- media::VideoPixelFormat format, |
- media::VideoPixelStorage storage, |
- int* buffer_id_to_drop); |
+ virtual int ReserveForProducer(const gfx::Size& dimensions, |
+ media::VideoPixelFormat format, |
+ media::VideoPixelStorage storage, |
+ int* buffer_id_to_drop) = 0; |
// Indicate that a buffer held for the producer should be returned back to the |
// pool without passing on to the consumer. This effectively is the opposite |
// of ReserveForProducer(). |
- void RelinquishProducerReservation(int buffer_id); |
- |
- // Transfer a buffer from producer to consumer ownership. |
- // |buffer_id| must be a buffer index previously returned by |
- // ReserveForProducer(), and not already passed to HoldForConsumers(). |
- void HoldForConsumers(int buffer_id, int num_clients); |
- |
- // Indicate that one or more consumers are done with a particular buffer. This |
- // effectively is the opposite of HoldForConsumers(). Once the consumers are |
- // done, a buffer is returned to the pool for reuse. |
- void RelinquishConsumerHold(int buffer_id, int num_clients); |
+ virtual void RelinquishProducerReservation(int buffer_id) = 0; |
// Attempt to reserve the same buffer that was relinquished in the last call |
// to RelinquishProducerReservation(). If the buffer is not still being |
@@ -119,13 +86,78 @@ class CONTENT_EXPORT VideoCaptureBufferPool |
// |
// A producer may assume the content of the buffer has been preserved and may |
// also make modifications. |
- int ResurrectLastForProducer(const gfx::Size& dimensions, |
- media::VideoPixelFormat format, |
- media::VideoPixelStorage storage); |
+ virtual int ResurrectLastForProducer(const gfx::Size& dimensions, |
+ media::VideoPixelFormat format, |
+ media::VideoPixelStorage storage) = 0; |
// Returns a snapshot of the current number of buffers in-use divided by the |
// maximum |count_|. |
- double GetBufferPoolUtilization() const; |
+ virtual double GetBufferPoolUtilization() const = 0; |
+ |
+ // Transfer a buffer from producer to consumer ownership. |
+ // |buffer_id| must be a buffer index previously returned by |
+ // ReserveForProducer(), and not already passed to HoldForConsumers(). |
+ virtual void HoldForConsumers(int buffer_id, int num_clients) = 0; |
+ |
+ // Indicate that one or more consumers are done with a particular buffer. This |
+ // effectively is the opposite of HoldForConsumers(). Once the consumers are |
+ // done, a buffer is returned to the pool for reuse. |
+ virtual void RelinquishConsumerHold(int buffer_id, int num_clients) = 0; |
+ |
+ protected: |
+ virtual ~VideoCaptureBufferPool() {} |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; |
+}; |
+ |
+// A thread-safe class that does the bookkeeping and lifetime management for a |
+// pool of pixel buffers cycled between an in-process producer (e.g. a |
+// VideoCaptureDevice) and a set of out-of-process consumers. The pool is |
+// intended to be orchestrated by a VideoCaptureDevice::Client, but is designed |
+// to outlive the controller if necessary. The pixel buffers may be backed by a |
+// SharedMemory, but this is not compulsory. |
+// |
+// Producers get a buffer by calling ReserveForProducer(), and may pass on their |
+// ownership to the consumer by calling HoldForConsumers(), or drop the buffer |
+// (without further processing) by calling RelinquishProducerReservation(). |
+// Consumers signal that they are done with the buffer by calling |
+// RelinquishConsumerHold(). |
+// |
+// Buffers are allocated on demand, but there will never be more than |count| |
+// buffers in existence at any time. Buffers are identified by an int value |
+// called |buffer_id|. -1 (kInvalidId) is never a valid ID, and is returned by |
+// some methods to indicate failure. The active set of buffer ids may change |
+// over the lifetime of the buffer pool, as existing buffers are freed and |
+// reallocated at larger size. When reallocation occurs, new buffer IDs will |
+// circulate. |
+class CONTENT_EXPORT VideoCaptureBufferPoolImpl |
+ : public VideoCaptureBufferPool { |
+ public: |
+ using BufferHandle = VideoCaptureBufferPoolBufferHandle; |
+ |
+ explicit VideoCaptureBufferPoolImpl(int count); |
+ |
+ // Implementation of VideoCaptureBufferPool interface: |
+ bool ShareToProcess(int buffer_id, |
+ base::ProcessHandle process_handle, |
+ base::SharedMemoryHandle* new_handle) override; |
+ bool ShareToProcess2(int buffer_id, |
+ int plane, |
+ base::ProcessHandle process_handle, |
+ gfx::GpuMemoryBufferHandle* new_handle) override; |
+ std::unique_ptr<BufferHandle> GetBufferHandle(int buffer_id) override; |
+ int ReserveForProducer(const gfx::Size& dimensions, |
+ media::VideoPixelFormat format, |
+ media::VideoPixelStorage storage, |
+ int* buffer_id_to_drop) override; |
+ void RelinquishProducerReservation(int buffer_id) override; |
+ int ResurrectLastForProducer(const gfx::Size& dimensions, |
+ media::VideoPixelFormat format, |
+ media::VideoPixelStorage storage) override; |
+ double GetBufferPoolUtilization() const override; |
+ void HoldForConsumers(int buffer_id, int num_clients) override; |
+ void RelinquishConsumerHold(int buffer_id, int num_clients) override; |
private: |
class GpuMemoryBufferTracker; |
@@ -192,8 +224,8 @@ class CONTENT_EXPORT VideoCaptureBufferPool |
int consumer_hold_count_; |
}; |
- friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; |
- virtual ~VideoCaptureBufferPool(); |
+ friend class base::RefCountedThreadSafe<VideoCaptureBufferPoolImpl>; |
+ ~VideoCaptureBufferPoolImpl() override; |
int ReserveForProducerInternal(const gfx::Size& dimensions, |
media::VideoPixelFormat format, |
@@ -219,7 +251,7 @@ class CONTENT_EXPORT VideoCaptureBufferPool |
using TrackerMap = std::map<int, Tracker*>; |
TrackerMap trackers_; |
- DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl); |
}; |
} // namespace content |