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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 visible_rect.right() <= coded_size.width() && | 84 visible_rect.right() <= coded_size.width() && |
85 visible_rect.bottom() <= coded_size.height() && | 85 visible_rect.bottom() <= coded_size.height() && |
86 !natural_size.IsEmpty() && | 86 !natural_size.IsEmpty() && |
87 natural_size.GetArea() <= limits::kMaxCanvas && | 87 natural_size.GetArea() <= limits::kMaxCanvas && |
88 natural_size.width() <= limits::kMaxDimension && | 88 natural_size.width() <= limits::kMaxDimension && |
89 natural_size.height() <= limits::kMaxDimension); | 89 natural_size.height() <= limits::kMaxDimension); |
90 } | 90 } |
91 | 91 |
92 // static | 92 // static |
93 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | 93 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
94 scoped_ptr<MailboxHolder> mailbox_holder, | 94 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
95 uint32 texture_target, | 95 const gpu::MailboxHolder::ReleaseCallback& mailbox_holder_release_cb, |
96 const gfx::Size& coded_size, | 96 const gfx::Size& coded_size, |
97 const gfx::Rect& visible_rect, | 97 const gfx::Rect& visible_rect, |
98 const gfx::Size& natural_size, | 98 const gfx::Size& natural_size, |
99 base::TimeDelta timestamp, | 99 base::TimeDelta timestamp, |
100 const ReadPixelsCB& read_pixels_cb, | 100 const ReadPixelsCB& read_pixels_cb) { |
101 const base::Closure& no_longer_needed_cb) { | |
102 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, | 101 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, |
103 coded_size, | 102 coded_size, |
104 visible_rect, | 103 visible_rect, |
105 natural_size, | 104 natural_size, |
106 timestamp, | 105 timestamp, |
107 false)); | 106 false)); |
108 frame->texture_mailbox_holder_ = mailbox_holder.Pass(); | 107 frame->mailbox_holder_ = mailbox_holder.Pass(); |
109 frame->texture_target_ = texture_target; | 108 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; |
110 frame->read_pixels_cb_ = read_pixels_cb; | 109 frame->read_pixels_cb_ = read_pixels_cb; |
111 frame->no_longer_needed_cb_ = no_longer_needed_cb; | |
112 | 110 |
113 return frame; | 111 return frame; |
114 } | 112 } |
115 | 113 |
116 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 114 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
117 DCHECK_EQ(format_, NATIVE_TEXTURE); | 115 DCHECK_EQ(format_, NATIVE_TEXTURE); |
118 if (!read_pixels_cb_.is_null()) | 116 if (!read_pixels_cb_.is_null()) |
119 read_pixels_cb_.Run(pixels); | 117 read_pixels_cb_.Run(pixels); |
120 } | 118 } |
121 | 119 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 VideoFrame::VideoFrame(VideoFrame::Format format, | 382 VideoFrame::VideoFrame(VideoFrame::Format format, |
385 const gfx::Size& coded_size, | 383 const gfx::Size& coded_size, |
386 const gfx::Rect& visible_rect, | 384 const gfx::Rect& visible_rect, |
387 const gfx::Size& natural_size, | 385 const gfx::Size& natural_size, |
388 base::TimeDelta timestamp, | 386 base::TimeDelta timestamp, |
389 bool end_of_stream) | 387 bool end_of_stream) |
390 : format_(format), | 388 : format_(format), |
391 coded_size_(coded_size), | 389 coded_size_(coded_size), |
392 visible_rect_(visible_rect), | 390 visible_rect_(visible_rect), |
393 natural_size_(natural_size), | 391 natural_size_(natural_size), |
394 texture_target_(0), | |
395 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 392 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
396 timestamp_(timestamp), | 393 timestamp_(timestamp), |
397 end_of_stream_(end_of_stream) { | 394 end_of_stream_(end_of_stream) { |
398 memset(&strides_, 0, sizeof(strides_)); | 395 memset(&strides_, 0, sizeof(strides_)); |
399 memset(&data_, 0, sizeof(data_)); | 396 memset(&data_, 0, sizeof(data_)); |
400 } | 397 } |
401 | 398 |
402 VideoFrame::~VideoFrame() { | 399 VideoFrame::~VideoFrame() { |
| 400 if (!mailbox_holder_release_cb_.is_null()) { |
| 401 base::ResetAndReturn(&mailbox_holder_release_cb_) |
| 402 .Run(mailbox_holder_.Pass()); |
| 403 } |
403 if (!no_longer_needed_cb_.is_null()) | 404 if (!no_longer_needed_cb_.is_null()) |
404 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 405 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
405 } | 406 } |
406 | 407 |
407 bool VideoFrame::IsValidPlane(size_t plane) const { | 408 bool VideoFrame::IsValidPlane(size_t plane) const { |
408 return (plane < NumPlanes(format_)); | 409 return (plane < NumPlanes(format_)); |
409 } | 410 } |
410 | 411 |
411 int VideoFrame::stride(size_t plane) const { | 412 int VideoFrame::stride(size_t plane) const { |
412 DCHECK(IsValidPlane(plane)); | 413 DCHECK(IsValidPlane(plane)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Intentionally leave out non-production formats. | 464 // Intentionally leave out non-production formats. |
464 NOTREACHED() << "Unsupported video frame format: " << format_; | 465 NOTREACHED() << "Unsupported video frame format: " << format_; |
465 return 0; | 466 return 0; |
466 } | 467 } |
467 | 468 |
468 uint8* VideoFrame::data(size_t plane) const { | 469 uint8* VideoFrame::data(size_t plane) const { |
469 DCHECK(IsValidPlane(plane)); | 470 DCHECK(IsValidPlane(plane)); |
470 return data_[plane]; | 471 return data_[plane]; |
471 } | 472 } |
472 | 473 |
473 VideoFrame::MailboxHolder* VideoFrame::texture_mailbox() const { | 474 gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
474 DCHECK_EQ(format_, NATIVE_TEXTURE); | 475 DCHECK_EQ(format_, NATIVE_TEXTURE); |
475 return texture_mailbox_holder_.get(); | 476 return mailbox_holder_.get(); |
476 } | |
477 | |
478 uint32 VideoFrame::texture_target() const { | |
479 DCHECK_EQ(format_, NATIVE_TEXTURE); | |
480 return texture_target_; | |
481 } | 477 } |
482 | 478 |
483 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 479 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
484 return shared_memory_handle_; | 480 return shared_memory_handle_; |
485 } | 481 } |
486 | 482 |
487 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 483 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
488 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 484 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
489 if (!IsValidPlane(plane)) | 485 if (!IsValidPlane(plane)) |
490 break; | 486 break; |
491 for (int row = 0; row < rows(plane); ++row) { | 487 for (int row = 0; row < rows(plane); ++row) { |
492 base::MD5Update(context, base::StringPiece( | 488 base::MD5Update(context, base::StringPiece( |
493 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 489 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
494 row_bytes(plane))); | 490 row_bytes(plane))); |
495 } | 491 } |
496 } | 492 } |
497 } | 493 } |
498 | 494 |
499 VideoFrame::MailboxHolder::MailboxHolder( | |
500 const gpu::Mailbox& mailbox, | |
501 unsigned sync_point, | |
502 const TextureNoLongerNeededCallback& release_callback) | |
503 : mailbox_(mailbox), | |
504 sync_point_(sync_point), | |
505 release_callback_(release_callback) {} | |
506 | |
507 VideoFrame::MailboxHolder::~MailboxHolder() { | |
508 if (!release_callback_.is_null()) | |
509 release_callback_.Run(sync_point_); | |
510 } | |
511 | |
512 } // namespace media | 495 } // namespace media |
OLD | NEW |