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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 77 |
75 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 78 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
76 // automatically by VideoDecoderConfig::IsValidConfig(). | 79 // automatically by VideoDecoderConfig::IsValidConfig(). |
77 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 80 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
78 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 81 static bool IsValidConfig(Format format, const gfx::Size& coded_size, |
79 const gfx::Rect& visible_rect, | 82 const gfx::Rect& visible_rect, |
80 const gfx::Size& natural_size); | 83 const gfx::Size& natural_size); |
81 | 84 |
82 // CB to write pixels from the texture backing this frame into the | 85 // CB to write pixels from the texture backing this frame into the |
83 // |const SkBitmap&| parameter. | 86 // |const SkBitmap&| parameter. |
84 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; | 87 typedef base::Callback< |
| 88 void(const scoped_refptr<VideoFrame>&, const SkBitmap&)> ReadPixelsCB; |
85 | 89 |
86 // CB to be called on the mailbox backing this frame when the frame is | 90 // CB to be called on the mailbox backing this frame when the frame is |
87 // destroyed. | 91 // destroyed. |
88 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; | 92 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>, |
| 93 const std::vector<uint32>&)> ReleaseMailboxCB; |
89 | 94 |
90 // Wraps a native texture of the given parameters with a VideoFrame. The | 95 // 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|, | 96 // 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 | 97 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the |
93 // argument when the VideoFrame is to be destroyed. | 98 // argument when the VideoFrame is to be destroyed. |
94 // |coded_size| is the width and height of the frame data in pixels. | 99 // |coded_size| is the width and height of the frame data in pixels. |
95 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | 100 // |visible_rect| is the visible portion of |coded_size|, after cropping (if |
96 // any) is applied. | 101 // any) is applied. |
97 // |natural_size| is the width and height of the frame when the frame's aspect | 102 // |natural_size| is the width and height of the frame when the frame's aspect |
98 // ratio is applied to |visible_rect|. | 103 // ratio is applied to |visible_rect|. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Returns true if this VideoFrame represents the end of the stream. | 220 // Returns true if this VideoFrame represents the end of the stream. |
216 bool end_of_stream() const { return end_of_stream_; } | 221 bool end_of_stream() const { return end_of_stream_; } |
217 | 222 |
218 base::TimeDelta GetTimestamp() const { | 223 base::TimeDelta GetTimestamp() const { |
219 return timestamp_; | 224 return timestamp_; |
220 } | 225 } |
221 void SetTimestamp(const base::TimeDelta& timestamp) { | 226 void SetTimestamp(const base::TimeDelta& timestamp) { |
222 timestamp_ = timestamp; | 227 timestamp_ = timestamp; |
223 } | 228 } |
224 | 229 |
| 230 // Append |sync_point| into |release_sync_points_| which will be passed to |
| 231 // the video decoder when |mailbox_holder_release_cb_| is called so that |
| 232 // the video decoder waits for the sync points before reusing the mailbox. |
| 233 // Multiple clients can append multiple sync points in one frame. |
| 234 // This method is thread safe. Both blink and compositor threads can call it. |
| 235 void AppendReleaseSyncPoint(uint32 sync_point); |
| 236 |
225 // Used to keep a running hash of seen frames. Expects an initialized MD5 | 237 // Used to keep a running hash of seen frames. Expects an initialized MD5 |
226 // context. Calls MD5Update with the context and the contents of the frame. | 238 // context. Calls MD5Update with the context and the contents of the frame. |
227 void HashFrameForTesting(base::MD5Context* context); | 239 void HashFrameForTesting(base::MD5Context* context); |
228 | 240 |
229 private: | 241 private: |
230 friend class base::RefCountedThreadSafe<VideoFrame>; | 242 friend class base::RefCountedThreadSafe<VideoFrame>; |
231 // Clients must use the static CreateFrame() method to create a new frame. | 243 // Clients must use the static CreateFrame() method to create a new frame. |
232 VideoFrame(Format format, | 244 VideoFrame(Format format, |
233 const gfx::Size& coded_size, | 245 const gfx::Size& coded_size, |
234 const gfx::Rect& visible_rect, | 246 const gfx::Rect& visible_rect, |
(...skipping 23 matching lines...) Expand all Loading... |
258 // Array of strides for each plane, typically greater or equal to the width | 270 // Array of strides for each plane, typically greater or equal to the width |
259 // of the surface divided by the horizontal sampling period. Note that | 271 // of the surface divided by the horizontal sampling period. Note that |
260 // strides can be negative. | 272 // strides can be negative. |
261 int32 strides_[kMaxPlanes]; | 273 int32 strides_[kMaxPlanes]; |
262 | 274 |
263 // Array of data pointers to each plane. | 275 // Array of data pointers to each plane. |
264 uint8* data_[kMaxPlanes]; | 276 uint8* data_[kMaxPlanes]; |
265 | 277 |
266 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. | 278 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
267 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; | 279 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; |
| 280 #ifndef NDEBUG |
| 281 uint32 debug_initial_sync_point_; |
| 282 #endif |
268 ReleaseMailboxCB mailbox_holder_release_cb_; | 283 ReleaseMailboxCB mailbox_holder_release_cb_; |
269 ReadPixelsCB read_pixels_cb_; | 284 ReadPixelsCB read_pixels_cb_; |
270 | 285 |
271 // Shared memory handle, if this frame was allocated from shared memory. | 286 // Shared memory handle, if this frame was allocated from shared memory. |
272 base::SharedMemoryHandle shared_memory_handle_; | 287 base::SharedMemoryHandle shared_memory_handle_; |
273 | 288 |
274 base::Closure no_longer_needed_cb_; | 289 base::Closure no_longer_needed_cb_; |
275 | 290 |
276 base::TimeDelta timestamp_; | 291 base::TimeDelta timestamp_; |
277 | 292 |
| 293 base::Lock release_sync_point_lock_; |
| 294 std::vector<uint32> release_sync_points_; |
| 295 |
278 const bool end_of_stream_; | 296 const bool end_of_stream_; |
279 | 297 |
280 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 298 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
281 }; | 299 }; |
282 | 300 |
283 } // namespace media | 301 } // namespace media |
284 | 302 |
285 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 303 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |