OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 MEDIA_BASE_VIDEO_FRAME_H_ | 5 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ |
6 #define MEDIA_BASE_VIDEO_FRAME_H_ | 6 #define MEDIA_BASE_VIDEO_FRAME_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/md5.h" | 11 #include "base/md5.h" |
10 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
| 13 #include "base/synchronization/lock.h" |
11 #include "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
12 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
13 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
14 | 17 |
15 class SkBitmap; | 18 class SkBitmap; |
16 | 19 |
17 namespace gpu { | 20 namespace gpu { |
18 struct MailboxHolder; | 21 struct MailboxHolder; |
19 } // namespace gpu | 22 } // namespace gpu |
20 | 23 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 76 static bool IsValidConfig(Format format, const gfx::Size& coded_size, |
74 const gfx::Rect& visible_rect, | 77 const gfx::Rect& visible_rect, |
75 const gfx::Size& natural_size); | 78 const gfx::Size& natural_size); |
76 | 79 |
77 // CB to write pixels from the texture backing this frame into the | 80 // CB to write pixels from the texture backing this frame into the |
78 // |const SkBitmap&| parameter. | 81 // |const SkBitmap&| parameter. |
79 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; | 82 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; |
80 | 83 |
81 // CB to be called on the mailbox backing this frame when the frame is | 84 // CB to be called on the mailbox backing this frame when the frame is |
82 // destroyed. | 85 // destroyed. |
83 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; | 86 typedef base::Callback<void(const std::vector<uint32>&)> ReleaseMailboxCB; |
84 | 87 |
85 // Wraps a native texture of the given parameters with a VideoFrame. The | 88 // Wraps a native texture of the given parameters with a VideoFrame. The |
86 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, | 89 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, |
87 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the | 90 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the |
88 // argument when the VideoFrame is to be destroyed. | 91 // argument when the VideoFrame is to be destroyed. |
89 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 92 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
90 // texture to main memory. | 93 // texture to main memory. |
91 static scoped_refptr<VideoFrame> WrapNativeTexture( | 94 static scoped_refptr<VideoFrame> WrapNativeTexture( |
92 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 95 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
93 const ReleaseMailboxCB& mailbox_holder_release_cb, | 96 const ReleaseMailboxCB& mailbox_holder_release_cb, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 int row_bytes(size_t plane) const; | 200 int row_bytes(size_t plane) const; |
198 int rows(size_t plane) const; | 201 int rows(size_t plane) const; |
199 | 202 |
200 // Returns pointer to the buffer for a given plane. The memory is owned by | 203 // Returns pointer to the buffer for a given plane. The memory is owned by |
201 // VideoFrame object and must not be freed by the caller. | 204 // VideoFrame object and must not be freed by the caller. |
202 uint8* data(size_t plane) const; | 205 uint8* data(size_t plane) const; |
203 | 206 |
204 // Returns the mailbox holder of the native texture wrapped by this frame. | 207 // Returns the mailbox holder of the native texture wrapped by this frame. |
205 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the | 208 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the |
206 // mailbox, the caller must wait for the included sync point. | 209 // mailbox, the caller must wait for the included sync point. |
207 gpu::MailboxHolder* mailbox_holder() const; | 210 const gpu::MailboxHolder* mailbox_holder() const; |
208 | 211 |
209 // Returns the shared-memory handle, if present | 212 // Returns the shared-memory handle, if present |
210 base::SharedMemoryHandle shared_memory_handle() const; | 213 base::SharedMemoryHandle shared_memory_handle() const; |
211 | 214 |
212 // Returns true if this VideoFrame represents the end of the stream. | 215 // Returns true if this VideoFrame represents the end of the stream. |
213 bool end_of_stream() const { return end_of_stream_; } | 216 bool end_of_stream() const { return end_of_stream_; } |
214 | 217 |
215 base::TimeDelta timestamp() const { | 218 base::TimeDelta timestamp() const { |
216 return timestamp_; | 219 return timestamp_; |
217 } | 220 } |
218 void set_timestamp(const base::TimeDelta& timestamp) { | 221 void set_timestamp(const base::TimeDelta& timestamp) { |
219 timestamp_ = timestamp; | 222 timestamp_ = timestamp; |
220 } | 223 } |
221 | 224 |
| 225 // Append |sync_point| into |release_sync_points_| which will be passed to |
| 226 // the video decoder when |mailbox_holder_release_cb_| is called so that |
| 227 // the video decoder waits for the sync points before reusing the mailbox. |
| 228 // Multiple clients can append multiple sync points on one frame. |
| 229 // This method is thread safe. Both blink and compositor threads can call it. |
| 230 void AppendReleaseSyncPoint(uint32 sync_point); |
| 231 |
222 // Used to keep a running hash of seen frames. Expects an initialized MD5 | 232 // Used to keep a running hash of seen frames. Expects an initialized MD5 |
223 // context. Calls MD5Update with the context and the contents of the frame. | 233 // context. Calls MD5Update with the context and the contents of the frame. |
224 void HashFrameForTesting(base::MD5Context* context); | 234 void HashFrameForTesting(base::MD5Context* context); |
225 | 235 |
226 private: | 236 private: |
227 friend class base::RefCountedThreadSafe<VideoFrame>; | 237 friend class base::RefCountedThreadSafe<VideoFrame>; |
228 // Clients must use the static CreateFrame() method to create a new frame. | 238 // Clients must use the static CreateFrame() method to create a new frame. |
229 VideoFrame(Format format, | 239 VideoFrame(Format format, |
230 const gfx::Size& coded_size, | 240 const gfx::Size& coded_size, |
231 const gfx::Rect& visible_rect, | 241 const gfx::Rect& visible_rect, |
232 const gfx::Size& natural_size, | 242 const gfx::Size& natural_size, |
| 243 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
233 base::TimeDelta timestamp, | 244 base::TimeDelta timestamp, |
234 bool end_of_stream); | 245 bool end_of_stream); |
235 virtual ~VideoFrame(); | 246 virtual ~VideoFrame(); |
236 | 247 |
237 void AllocateYUV(); | 248 void AllocateYUV(); |
238 | 249 |
239 // Used to DCHECK() plane parameters. | 250 // Used to DCHECK() plane parameters. |
240 bool IsValidPlane(size_t plane) const; | 251 bool IsValidPlane(size_t plane) const; |
241 | 252 |
242 // Frame format. | 253 // Frame format. |
(...skipping 17 matching lines...) Expand all Loading... |
260 | 271 |
261 // Array of strides for each plane, typically greater or equal to the width | 272 // Array of strides for each plane, typically greater or equal to the width |
262 // of the surface divided by the horizontal sampling period. Note that | 273 // of the surface divided by the horizontal sampling period. Note that |
263 // strides can be negative. | 274 // strides can be negative. |
264 int32 strides_[kMaxPlanes]; | 275 int32 strides_[kMaxPlanes]; |
265 | 276 |
266 // Array of data pointers to each plane. | 277 // Array of data pointers to each plane. |
267 uint8* data_[kMaxPlanes]; | 278 uint8* data_[kMaxPlanes]; |
268 | 279 |
269 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. | 280 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
270 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; | 281 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_; |
271 ReleaseMailboxCB mailbox_holder_release_cb_; | 282 ReleaseMailboxCB mailbox_holder_release_cb_; |
272 ReadPixelsCB read_pixels_cb_; | 283 ReadPixelsCB read_pixels_cb_; |
273 | 284 |
274 // Shared memory handle, if this frame was allocated from shared memory. | 285 // Shared memory handle, if this frame was allocated from shared memory. |
275 base::SharedMemoryHandle shared_memory_handle_; | 286 base::SharedMemoryHandle shared_memory_handle_; |
276 | 287 |
277 base::Closure no_longer_needed_cb_; | 288 base::Closure no_longer_needed_cb_; |
278 | 289 |
279 base::TimeDelta timestamp_; | 290 base::TimeDelta timestamp_; |
280 | 291 |
| 292 base::Lock release_sync_point_lock_; |
| 293 std::vector<uint32> release_sync_points_; |
| 294 |
281 const bool end_of_stream_; | 295 const bool end_of_stream_; |
282 | 296 |
283 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 297 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
284 }; | 298 }; |
285 | 299 |
286 } // namespace media | 300 } // namespace media |
287 | 301 |
288 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 302 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |