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> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/md5.h" | 11 #include "base/md5.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 | 17 |
18 class SkBitmap; | 18 class SkBitmap; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 78 static bool IsValidConfig(Format format, const gfx::Size& coded_size, |
79 const gfx::Rect& visible_rect, | 79 const gfx::Rect& visible_rect, |
80 const gfx::Size& natural_size); | 80 const gfx::Size& natural_size); |
81 | 81 |
82 // CB to write pixels from the texture backing this frame into the | 82 // CB to write pixels from the texture backing this frame into the |
83 // |const SkBitmap&| parameter. | 83 // |const SkBitmap&| parameter. |
84 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; | 84 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; |
85 | 85 |
86 // CB to be called on the mailbox backing this frame when the frame is | 86 // CB to be called on the mailbox backing this frame when the frame is |
87 // destroyed. | 87 // destroyed. |
88 typedef base::Callback<void(const std::vector<uint32>&)> ReleaseMailboxCB; | 88 typedef base::Callback<void(const std::map<std::string, uint32>&)> |
| 89 ReleaseMailboxCB; |
89 | 90 |
90 // Wraps a native texture of the given parameters with a VideoFrame. The | 91 // Wraps a native texture of the given parameters with a VideoFrame. The |
91 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, | 92 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, |
92 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the | 93 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the |
93 // argument when the VideoFrame is to be destroyed. | 94 // argument when the VideoFrame is to be destroyed. |
94 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 95 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
95 // texture to main memory. | 96 // texture to main memory. |
96 static scoped_refptr<VideoFrame> WrapNativeTexture( | 97 static scoped_refptr<VideoFrame> WrapNativeTexture( |
97 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 98 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
98 const ReleaseMailboxCB& mailbox_holder_release_cb, | 99 const ReleaseMailboxCB& mailbox_holder_release_cb, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // Returns true if this VideoFrame represents the end of the stream. | 247 // Returns true if this VideoFrame represents the end of the stream. |
247 bool end_of_stream() const { return end_of_stream_; } | 248 bool end_of_stream() const { return end_of_stream_; } |
248 | 249 |
249 base::TimeDelta timestamp() const { | 250 base::TimeDelta timestamp() const { |
250 return timestamp_; | 251 return timestamp_; |
251 } | 252 } |
252 void set_timestamp(const base::TimeDelta& timestamp) { | 253 void set_timestamp(const base::TimeDelta& timestamp) { |
253 timestamp_ = timestamp; | 254 timestamp_ = timestamp; |
254 } | 255 } |
255 | 256 |
256 // Append |sync_point| into |release_sync_points_| which will be passed to | 257 // Append |sync_point| into |release_sync_point_map_| which will be passed to |
257 // the video decoder when |mailbox_holder_release_cb_| is called so that | 258 // the video decoder when |mailbox_holder_release_cb_| is called so that |
258 // the video decoder waits for the sync points before reusing the mailbox. | 259 // the video decoder waits for the sync points before reusing the mailbox. |
259 // Multiple clients can append multiple sync points on one frame. | 260 // This keeps only the latest sync point for each client. If a client appends |
| 261 // two sync points, the previous sync point is overridden. |
| 262 // e.g. WebGL can insert multiple sync points on one frame. |
260 // This method is thread safe. Both blink and compositor threads can call it. | 263 // This method is thread safe. Both blink and compositor threads can call it. |
261 void AppendReleaseSyncPoint(uint32 sync_point); | 264 void AppendReleaseSyncPoint(std::string client, uint32 sync_point); |
262 | 265 |
263 // Used to keep a running hash of seen frames. Expects an initialized MD5 | 266 // Used to keep a running hash of seen frames. Expects an initialized MD5 |
264 // context. Calls MD5Update with the context and the contents of the frame. | 267 // context. Calls MD5Update with the context and the contents of the frame. |
265 void HashFrameForTesting(base::MD5Context* context); | 268 void HashFrameForTesting(base::MD5Context* context); |
266 | 269 |
267 private: | 270 private: |
268 friend class base::RefCountedThreadSafe<VideoFrame>; | 271 friend class base::RefCountedThreadSafe<VideoFrame>; |
269 // Clients must use the static CreateFrame() method to create a new frame. | 272 // Clients must use the static CreateFrame() method to create a new frame. |
270 VideoFrame(Format format, | 273 VideoFrame(Format format, |
271 const gfx::Size& coded_size, | 274 const gfx::Size& coded_size, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 // Dmabufs for each plane, if this frame is wrapping memory | 323 // Dmabufs for each plane, if this frame is wrapping memory |
321 // acquired via dmabuf. | 324 // acquired via dmabuf. |
322 base::ScopedFD dmabuf_fds_[kMaxPlanes]; | 325 base::ScopedFD dmabuf_fds_[kMaxPlanes]; |
323 #endif | 326 #endif |
324 | 327 |
325 base::Closure no_longer_needed_cb_; | 328 base::Closure no_longer_needed_cb_; |
326 | 329 |
327 base::TimeDelta timestamp_; | 330 base::TimeDelta timestamp_; |
328 | 331 |
329 base::Lock release_sync_point_lock_; | 332 base::Lock release_sync_point_lock_; |
330 std::vector<uint32> release_sync_points_; | 333 std::map<std::string, uint32> release_sync_point_map_; |
331 | 334 |
332 const bool end_of_stream_; | 335 const bool end_of_stream_; |
333 | 336 |
334 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 337 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
335 }; | 338 }; |
336 | 339 |
337 } // namespace media | 340 } // namespace media |
338 | 341 |
339 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 342 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |