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 #include "media/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 visible_rect.right() <= coded_size.width() && | 57 visible_rect.right() <= coded_size.width() && |
58 visible_rect.bottom() <= coded_size.height() && | 58 visible_rect.bottom() <= coded_size.height() && |
59 !natural_size.IsEmpty() && | 59 !natural_size.IsEmpty() && |
60 natural_size.GetArea() <= limits::kMaxCanvas && | 60 natural_size.GetArea() <= limits::kMaxCanvas && |
61 natural_size.width() <= limits::kMaxDimension && | 61 natural_size.width() <= limits::kMaxDimension && |
62 natural_size.height() <= limits::kMaxDimension); | 62 natural_size.height() <= limits::kMaxDimension); |
63 } | 63 } |
64 | 64 |
65 // static | 65 // static |
66 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | 66 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
67 uint32 texture_id, | 67 const scoped_refptr<MailboxHolder>& mailbox_holder, |
68 uint32 texture_target, | 68 uint32 texture_target, |
69 const gfx::Size& coded_size, | 69 const gfx::Size& coded_size, |
70 const gfx::Rect& visible_rect, | 70 const gfx::Rect& visible_rect, |
71 const gfx::Size& natural_size, | 71 const gfx::Size& natural_size, |
72 base::TimeDelta timestamp, | 72 base::TimeDelta timestamp, |
73 const ReadPixelsCB& read_pixels_cb, | 73 const ReadPixelsCB& read_pixels_cb, |
74 const base::Closure& no_longer_needed_cb) { | 74 const base::Closure& no_longer_needed_cb) { |
75 scoped_refptr<VideoFrame> frame(new VideoFrame( | 75 scoped_refptr<VideoFrame> frame(new VideoFrame( |
76 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); | 76 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); |
77 frame->texture_id_ = texture_id; | 77 frame->texture_mailbox_holder_ = mailbox_holder; |
78 frame->texture_target_ = texture_target; | 78 frame->texture_target_ = texture_target; |
79 frame->read_pixels_cb_ = read_pixels_cb; | 79 frame->read_pixels_cb_ = read_pixels_cb; |
80 frame->no_longer_needed_cb_ = no_longer_needed_cb; | 80 frame->no_longer_needed_cb_ = no_longer_needed_cb; |
| 81 |
81 return frame; | 82 return frame; |
82 } | 83 } |
83 | 84 |
84 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 85 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
85 DCHECK_EQ(format_, NATIVE_TEXTURE); | 86 DCHECK_EQ(format_, NATIVE_TEXTURE); |
86 if (!read_pixels_cb_.is_null()) | 87 if (!read_pixels_cb_.is_null()) |
87 read_pixels_cb_.Run(pixels); | 88 read_pixels_cb_.Run(pixels); |
88 } | 89 } |
89 | 90 |
90 // static | 91 // static |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 260 |
260 VideoFrame::VideoFrame(VideoFrame::Format format, | 261 VideoFrame::VideoFrame(VideoFrame::Format format, |
261 const gfx::Size& coded_size, | 262 const gfx::Size& coded_size, |
262 const gfx::Rect& visible_rect, | 263 const gfx::Rect& visible_rect, |
263 const gfx::Size& natural_size, | 264 const gfx::Size& natural_size, |
264 base::TimeDelta timestamp) | 265 base::TimeDelta timestamp) |
265 : format_(format), | 266 : format_(format), |
266 coded_size_(coded_size), | 267 coded_size_(coded_size), |
267 visible_rect_(visible_rect), | 268 visible_rect_(visible_rect), |
268 natural_size_(natural_size), | 269 natural_size_(natural_size), |
269 texture_id_(0), | |
270 texture_target_(0), | 270 texture_target_(0), |
271 timestamp_(timestamp) { | 271 timestamp_(timestamp) { |
272 memset(&strides_, 0, sizeof(strides_)); | 272 memset(&strides_, 0, sizeof(strides_)); |
273 memset(&data_, 0, sizeof(data_)); | 273 memset(&data_, 0, sizeof(data_)); |
274 } | 274 } |
275 | 275 |
276 VideoFrame::~VideoFrame() { | 276 VideoFrame::~VideoFrame() { |
277 if (!no_longer_needed_cb_.is_null()) | 277 if (!no_longer_needed_cb_.is_null()) |
278 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 278 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
279 } | 279 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Intentionally leave out non-production formats. | 333 // Intentionally leave out non-production formats. |
334 NOTREACHED() << "Unsupported video frame format: " << format_; | 334 NOTREACHED() << "Unsupported video frame format: " << format_; |
335 return 0; | 335 return 0; |
336 } | 336 } |
337 | 337 |
338 uint8* VideoFrame::data(size_t plane) const { | 338 uint8* VideoFrame::data(size_t plane) const { |
339 DCHECK(IsValidPlane(plane)); | 339 DCHECK(IsValidPlane(plane)); |
340 return data_[plane]; | 340 return data_[plane]; |
341 } | 341 } |
342 | 342 |
343 uint32 VideoFrame::texture_id() const { | 343 const scoped_refptr<VideoFrame::MailboxHolder>& VideoFrame::texture_mailbox() |
| 344 const { |
344 DCHECK_EQ(format_, NATIVE_TEXTURE); | 345 DCHECK_EQ(format_, NATIVE_TEXTURE); |
345 return texture_id_; | 346 return texture_mailbox_holder_; |
346 } | 347 } |
347 | 348 |
348 uint32 VideoFrame::texture_target() const { | 349 uint32 VideoFrame::texture_target() const { |
349 DCHECK_EQ(format_, NATIVE_TEXTURE); | 350 DCHECK_EQ(format_, NATIVE_TEXTURE); |
350 return texture_target_; | 351 return texture_target_; |
351 } | 352 } |
352 | 353 |
353 bool VideoFrame::IsEndOfStream() const { | 354 bool VideoFrame::IsEndOfStream() const { |
354 return format_ == VideoFrame::EMPTY; | 355 return format_ == VideoFrame::EMPTY; |
355 } | 356 } |
356 | 357 |
357 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 358 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
358 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 359 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
359 if (!IsValidPlane(plane)) | 360 if (!IsValidPlane(plane)) |
360 break; | 361 break; |
361 for (int row = 0; row < rows(plane); ++row) { | 362 for (int row = 0; row < rows(plane); ++row) { |
362 base::MD5Update(context, base::StringPiece( | 363 base::MD5Update(context, base::StringPiece( |
363 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 364 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
364 row_bytes(plane))); | 365 row_bytes(plane))); |
365 } | 366 } |
366 } | 367 } |
367 } | 368 } |
368 | 369 |
| 370 VideoFrame::MailboxHolder::MailboxHolder( |
| 371 const gpu::Mailbox& mailbox, |
| 372 unsigned sync_point, |
| 373 const TextureNoLongerNeededCallback& release_callback) |
| 374 : mailbox_(mailbox), |
| 375 sync_point_(sync_point), |
| 376 release_callback_(release_callback) {} |
| 377 |
| 378 VideoFrame::MailboxHolder::~MailboxHolder() { |
| 379 if (!release_callback_.is_null()) |
| 380 release_callback_.Run(sync_point_); |
| 381 } |
| 382 |
369 } // namespace media | 383 } // namespace media |
OLD | NEW |