OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // | 77 // |
78 // If successful, the reserved buffer remains reserved (and writable by the | 78 // If successful, the reserved buffer remains reserved (and writable by the |
79 // producer) until ownership is transferred either to the consumer via | 79 // producer) until ownership is transferred either to the consumer via |
80 // HoldForConsumers(), or back to the pool with | 80 // HoldForConsumers(), or back to the pool with |
81 // RelinquishProducerReservation(). | 81 // RelinquishProducerReservation(). |
82 // | 82 // |
83 // On occasion, this call will decide to free an old buffer to make room for a | 83 // On occasion, this call will decide to free an old buffer to make room for a |
84 // new allocation at a larger size. If so, the ID of the destroyed buffer is | 84 // new allocation at a larger size. If so, the ID of the destroyed buffer is |
85 // returned via |buffer_id_to_drop|. | 85 // returned via |buffer_id_to_drop|. |
86 int ReserveForProducer(media::VideoPixelFormat format, | 86 int ReserveForProducer(media::VideoPixelFormat format, |
| 87 media::VideoPixelStorage storage, |
87 const gfx::Size& dimensions, | 88 const gfx::Size& dimensions, |
88 int* buffer_id_to_drop); | 89 int* buffer_id_to_drop); |
89 | 90 |
90 // Indicate that a buffer held for the producer should be returned back to the | 91 // Indicate that a buffer held for the producer should be returned back to the |
91 // pool without passing on to the consumer. This effectively is the opposite | 92 // pool without passing on to the consumer. This effectively is the opposite |
92 // of ReserveForProducer(). | 93 // of ReserveForProducer(). |
93 void RelinquishProducerReservation(int buffer_id); | 94 void RelinquishProducerReservation(int buffer_id); |
94 | 95 |
95 // Transfer a buffer from producer to consumer ownership. | 96 // Transfer a buffer from producer to consumer ownership. |
96 // |buffer_id| must be a buffer index previously returned by | 97 // |buffer_id| must be a buffer index previously returned by |
(...skipping 13 matching lines...) Expand all Loading... |
110 class GpuMemoryBufferTracker; | 111 class GpuMemoryBufferTracker; |
111 class SharedMemTracker; | 112 class SharedMemTracker; |
112 // Generic class to keep track of the state of a given mappable resource. Each | 113 // Generic class to keep track of the state of a given mappable resource. Each |
113 // Tracker carries indication of pixel format and storage type. | 114 // Tracker carries indication of pixel format and storage type. |
114 class Tracker { | 115 class Tracker { |
115 public: | 116 public: |
116 static scoped_ptr<Tracker> CreateTracker(bool use_gmb); | 117 static scoped_ptr<Tracker> CreateTracker(bool use_gmb); |
117 | 118 |
118 Tracker() | 119 Tracker() |
119 : pixel_count_(0), held_by_producer_(false), consumer_hold_count_(0) {} | 120 : pixel_count_(0), held_by_producer_(false), consumer_hold_count_(0) {} |
120 virtual bool Init(media::VideoFrame::Format format, | 121 virtual bool Init(media::VideoPixelFormat format, |
121 media::VideoFrame::StorageType storage_type, | 122 media::VideoPixelStorage storage_type, |
122 const gfx::Size& dimensions) = 0; | 123 const gfx::Size& dimensions) = 0; |
123 virtual ~Tracker(); | 124 virtual ~Tracker(); |
124 | 125 |
125 size_t pixel_count() const { return pixel_count_; } | 126 size_t pixel_count() const { return pixel_count_; } |
126 void set_pixel_count(size_t count) { pixel_count_ = count; } | 127 void set_pixel_count(size_t count) { pixel_count_ = count; } |
127 media::VideoFrame::Format pixel_format() const { return pixel_format_; } | 128 media::VideoPixelFormat pixel_format() const { return pixel_format_; } |
128 void set_pixel_format(media::VideoFrame::Format format) { | 129 void set_pixel_format(media::VideoPixelFormat format) { |
129 pixel_format_ = format; | 130 pixel_format_ = format; |
130 } | 131 } |
131 media::VideoFrame::StorageType storage_type() const { | 132 media::VideoPixelStorage storage_type() const { return storage_type_; } |
132 return storage_type_; | 133 void set_storage_type(media::VideoPixelStorage storage_type) { |
133 } | |
134 void set_storage_type(media::VideoFrame::StorageType storage_type) { | |
135 storage_type_ = storage_type; | 134 storage_type_ = storage_type; |
136 } | 135 } |
137 bool held_by_producer() const { return held_by_producer_; } | 136 bool held_by_producer() const { return held_by_producer_; } |
138 void set_held_by_producer(bool value) { held_by_producer_ = value; } | 137 void set_held_by_producer(bool value) { held_by_producer_ = value; } |
139 int consumer_hold_count() const { return consumer_hold_count_; } | 138 int consumer_hold_count() const { return consumer_hold_count_; } |
140 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } | 139 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } |
141 | 140 |
142 // Returns a handle to the underlying storage, be that a block of Shared | 141 // Returns a handle to the underlying storage, be that a block of Shared |
143 // Memory, or a GpuMemoryBuffer. | 142 // Memory, or a GpuMemoryBuffer. |
144 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; | 143 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; |
145 // The actual size of the underlying backing resource. | 144 // The actual size of the underlying backing resource. |
146 virtual size_t mapped_size() const = 0; | 145 virtual size_t mapped_size() const = 0; |
147 | 146 |
148 virtual bool ShareToProcess(base::ProcessHandle process_handle, | 147 virtual bool ShareToProcess(base::ProcessHandle process_handle, |
149 base::SharedMemoryHandle* new_handle) = 0; | 148 base::SharedMemoryHandle* new_handle) = 0; |
150 | 149 |
151 private: | 150 private: |
152 size_t pixel_count_; | 151 size_t pixel_count_; |
153 media::VideoFrame::Format pixel_format_; | 152 media::VideoPixelFormat pixel_format_; |
154 media::VideoFrame::StorageType storage_type_; | 153 media::VideoPixelStorage storage_type_; |
155 // Indicates whether this Tracker is currently referenced by the producer. | 154 // Indicates whether this Tracker is currently referenced by the producer. |
156 bool held_by_producer_; | 155 bool held_by_producer_; |
157 // Number of consumer processes which hold this Tracker. | 156 // Number of consumer processes which hold this Tracker. |
158 int consumer_hold_count_; | 157 int consumer_hold_count_; |
159 }; | 158 }; |
160 | 159 |
161 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; | 160 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; |
162 virtual ~VideoCaptureBufferPool(); | 161 virtual ~VideoCaptureBufferPool(); |
163 | 162 |
164 int ReserveForProducerInternal(media::VideoPixelFormat format, | 163 int ReserveForProducerInternal(media::VideoPixelFormat format, |
| 164 media::VideoPixelStorage storage, |
165 const gfx::Size& dimensions, | 165 const gfx::Size& dimensions, |
166 int* tracker_id_to_drop); | 166 int* tracker_id_to_drop); |
167 | 167 |
168 Tracker* GetTracker(int buffer_id); | 168 Tracker* GetTracker(int buffer_id); |
169 | 169 |
170 // The max number of buffers that the pool is allowed to have at any moment. | 170 // The max number of buffers that the pool is allowed to have at any moment. |
171 const int count_; | 171 const int count_; |
172 | 172 |
173 // Protects everything below it. | 173 // Protects everything below it. |
174 mutable base::Lock lock_; | 174 mutable base::Lock lock_; |
175 | 175 |
176 // The ID of the next buffer. | 176 // The ID of the next buffer. |
177 int next_buffer_id_; | 177 int next_buffer_id_; |
178 | 178 |
179 // The buffers, indexed by the first parameter, a buffer id. | 179 // The buffers, indexed by the first parameter, a buffer id. |
180 using TrackerMap = std::map<int, Tracker*>; | 180 using TrackerMap = std::map<int, Tracker*>; |
181 TrackerMap trackers_; | 181 TrackerMap trackers_; |
182 | 182 |
183 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); | 183 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); |
184 }; | 184 }; |
185 | 185 |
186 } // namespace content | 186 } // namespace content |
187 | 187 |
188 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 188 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
OLD | NEW |