Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: media/capture/video/video_capture_buffer_pool.h

Issue 2361173002: Move classses VideoCaptureDeviceClient and VideoCaptureBufferPool to media/capture/video (Closed)
Patch Set: mcasas@ comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ 5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ 6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_H_
7 7
8 #include <stddef.h>
9
10 #include <map>
11
12 #include "base/files/file.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
15 #include "base/memory/shared_memory.h"
16 #include "base/process/process.h"
17 #include "base/synchronization/lock.h"
18 #include "build/build_config.h"
19 #include "content/common/content_export.h"
20 #include "media/base/video_capture_types.h" 9 #include "media/base/video_capture_types.h"
21 #include "media/base/video_frame.h" 10 #include "media/capture/capture_export.h"
22 #include "ui/gfx/geometry/size.h" 11 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/gpu_memory_buffer.h" 12 #include "ui/gfx/gpu_memory_buffer.h"
24 13
25 namespace content { 14 namespace media {
26 15
27 class VideoCaptureBufferHandle; 16 class VideoCaptureBufferHandle;
28 class VideoCaptureBufferTracker;
29 17
30 class CONTENT_EXPORT VideoCaptureBufferPool 18 // A thread-safe class that does the bookkeeping and lifetime management for a
19 // pool of pixel buffers cycled between an in-process producer (e.g. a
20 // VideoCaptureDevice) and a set of out-of-process consumers. The pool is
21 // intended to be orchestrated by a VideoCaptureDevice::Client, but is designed
22 // to outlive the controller if necessary. The pixel buffers may be backed by a
23 // SharedMemory, but this is not compulsory.
24 //
25 // Producers get a buffer by calling ReserveForProducer(), and may pass on their
26 // ownership to the consumer by calling HoldForConsumers(), or drop the buffer
27 // (without further processing) by calling RelinquishProducerReservation().
28 // Consumers signal that they are done with the buffer by calling
29 // RelinquishConsumerHold().
30 //
31 // Buffers are allocated on demand, but there will never be more than |count|
32 // buffers in existence at any time. Buffers are identified by an int value
33 // called |buffer_id|. -1 (kInvalidId) is never a valid ID, and is returned by
34 // some methods to indicate failure. The active set of buffer ids may change
35 // over the lifetime of the buffer pool, as existing buffers are freed and
36 // reallocated at larger size. When reallocation occurs, new buffer IDs will
37 // circulate.
38 class CAPTURE_EXPORT VideoCaptureBufferPool
31 : public base::RefCountedThreadSafe<VideoCaptureBufferPool> { 39 : public base::RefCountedThreadSafe<VideoCaptureBufferPool> {
32 public: 40 public:
33 static constexpr int kInvalidId = -1; 41 static constexpr int kInvalidId = -1;
34 42
35 // One-time (per client/per-buffer) initialization to share a particular 43 // One-time (per client/per-buffer) initialization to share a particular
36 // buffer to a process. The shared handle is returned as |new_handle|. 44 // buffer to a process. The shared handle is returned as |new_handle|.
37 virtual bool ShareToProcess(int buffer_id, 45 virtual bool ShareToProcess(int buffer_id,
38 base::ProcessHandle process_handle, 46 base::ProcessHandle process_handle,
39 base::SharedMemoryHandle* new_handle) = 0; 47 base::SharedMemoryHandle* new_handle) = 0;
40 virtual bool ShareToProcess2(int buffer_id, 48 virtual bool ShareToProcess2(int buffer_id,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // done, a buffer is returned to the pool for reuse. 103 // done, a buffer is returned to the pool for reuse.
96 virtual void RelinquishConsumerHold(int buffer_id, int num_clients) = 0; 104 virtual void RelinquishConsumerHold(int buffer_id, int num_clients) = 0;
97 105
98 protected: 106 protected:
99 virtual ~VideoCaptureBufferPool() {} 107 virtual ~VideoCaptureBufferPool() {}
100 108
101 private: 109 private:
102 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; 110 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>;
103 }; 111 };
104 112
105 // A thread-safe class that does the bookkeeping and lifetime management for a 113 } // namespace media
106 // pool of pixel buffers cycled between an in-process producer (e.g. a
107 // VideoCaptureDevice) and a set of out-of-process consumers. The pool is
108 // intended to be orchestrated by a VideoCaptureDevice::Client, but is designed
109 // to outlive the controller if necessary. The pixel buffers may be backed by a
110 // SharedMemory, but this is not compulsory.
111 //
112 // Producers get a buffer by calling ReserveForProducer(), and may pass on their
113 // ownership to the consumer by calling HoldForConsumers(), or drop the buffer
114 // (without further processing) by calling RelinquishProducerReservation().
115 // Consumers signal that they are done with the buffer by calling
116 // RelinquishConsumerHold().
117 //
118 // Buffers are allocated on demand, but there will never be more than |count|
119 // buffers in existence at any time. Buffers are identified by an int value
120 // called |buffer_id|. -1 (kInvalidId) is never a valid ID, and is returned by
121 // some methods to indicate failure. The active set of buffer ids may change
122 // over the lifetime of the buffer pool, as existing buffers are freed and
123 // reallocated at larger size. When reallocation occurs, new buffer IDs will
124 // circulate.
125 class CONTENT_EXPORT VideoCaptureBufferPoolImpl
126 : public VideoCaptureBufferPool {
127 public:
128 explicit VideoCaptureBufferPoolImpl(int count);
129 114
130 // Implementation of VideoCaptureBufferPool interface: 115 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_H_
131 bool ShareToProcess(int buffer_id,
132 base::ProcessHandle process_handle,
133 base::SharedMemoryHandle* new_handle) override;
134 bool ShareToProcess2(int buffer_id,
135 int plane,
136 base::ProcessHandle process_handle,
137 gfx::GpuMemoryBufferHandle* new_handle) override;
138 std::unique_ptr<VideoCaptureBufferHandle> GetBufferHandle(
139 int buffer_id) override;
140 int ReserveForProducer(const gfx::Size& dimensions,
141 media::VideoPixelFormat format,
142 media::VideoPixelStorage storage,
143 int* buffer_id_to_drop) override;
144 void RelinquishProducerReservation(int buffer_id) override;
145 int ResurrectLastForProducer(const gfx::Size& dimensions,
146 media::VideoPixelFormat format,
147 media::VideoPixelStorage storage) override;
148 double GetBufferPoolUtilization() const override;
149 void HoldForConsumers(int buffer_id, int num_clients) override;
150 void RelinquishConsumerHold(int buffer_id, int num_clients) override;
151
152 private:
153 friend class base::RefCountedThreadSafe<VideoCaptureBufferPoolImpl>;
154 ~VideoCaptureBufferPoolImpl() override;
155
156 int ReserveForProducerInternal(const gfx::Size& dimensions,
157 media::VideoPixelFormat format,
158 media::VideoPixelStorage storage,
159 int* tracker_id_to_drop);
160
161 VideoCaptureBufferTracker* GetTracker(int buffer_id);
162
163 // The max number of buffers that the pool is allowed to have at any moment.
164 const int count_;
165
166 // Protects everything below it.
167 mutable base::Lock lock_;
168
169 // The ID of the next buffer.
170 int next_buffer_id_;
171
172 // The ID of the buffer last relinquished by the producer (a candidate for
173 // resurrection).
174 int last_relinquished_buffer_id_;
175
176 // The buffers, indexed by the first parameter, a buffer id.
177 using TrackerMap = std::map<int, VideoCaptureBufferTracker*>;
178 TrackerMap trackers_;
179
180 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl);
181 };
182
183 } // namespace content
184
185 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_
OLDNEW
« no previous file with comments | « media/capture/video/video_capture_buffer_handle.h ('k') | media/capture/video/video_capture_buffer_pool_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698