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 ReleaseMailboxCB& 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 VideoFrame::VideoFrame(VideoFrame::Format format, | 399 VideoFrame::VideoFrame(VideoFrame::Format format, |
402 const gfx::Size& coded_size, | 400 const gfx::Size& coded_size, |
403 const gfx::Rect& visible_rect, | 401 const gfx::Rect& visible_rect, |
404 const gfx::Size& natural_size, | 402 const gfx::Size& natural_size, |
405 base::TimeDelta timestamp, | 403 base::TimeDelta timestamp, |
406 bool end_of_stream) | 404 bool end_of_stream) |
407 : format_(format), | 405 : format_(format), |
408 coded_size_(coded_size), | 406 coded_size_(coded_size), |
409 visible_rect_(visible_rect), | 407 visible_rect_(visible_rect), |
410 natural_size_(natural_size), | 408 natural_size_(natural_size), |
411 texture_target_(0), | |
412 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 409 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
413 timestamp_(timestamp), | 410 timestamp_(timestamp), |
414 end_of_stream_(end_of_stream) { | 411 end_of_stream_(end_of_stream) { |
415 memset(&strides_, 0, sizeof(strides_)); | 412 memset(&strides_, 0, sizeof(strides_)); |
416 memset(&data_, 0, sizeof(data_)); | 413 memset(&data_, 0, sizeof(data_)); |
417 } | 414 } |
418 | 415 |
419 VideoFrame::~VideoFrame() { | 416 VideoFrame::~VideoFrame() { |
| 417 if (!mailbox_holder_release_cb_.is_null()) { |
| 418 base::ResetAndReturn(&mailbox_holder_release_cb_) |
| 419 .Run(mailbox_holder_.Pass()); |
| 420 } |
420 if (!no_longer_needed_cb_.is_null()) | 421 if (!no_longer_needed_cb_.is_null()) |
421 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 422 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
422 } | 423 } |
423 | 424 |
424 bool VideoFrame::IsValidPlane(size_t plane) const { | 425 bool VideoFrame::IsValidPlane(size_t plane) const { |
425 return (plane < NumPlanes(format_)); | 426 return (plane < NumPlanes(format_)); |
426 } | 427 } |
427 | 428 |
428 int VideoFrame::stride(size_t plane) const { | 429 int VideoFrame::stride(size_t plane) const { |
429 DCHECK(IsValidPlane(plane)); | 430 DCHECK(IsValidPlane(plane)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // Intentionally leave out non-production formats. | 481 // Intentionally leave out non-production formats. |
481 NOTREACHED() << "Unsupported video frame format: " << format_; | 482 NOTREACHED() << "Unsupported video frame format: " << format_; |
482 return 0; | 483 return 0; |
483 } | 484 } |
484 | 485 |
485 uint8* VideoFrame::data(size_t plane) const { | 486 uint8* VideoFrame::data(size_t plane) const { |
486 DCHECK(IsValidPlane(plane)); | 487 DCHECK(IsValidPlane(plane)); |
487 return data_[plane]; | 488 return data_[plane]; |
488 } | 489 } |
489 | 490 |
490 VideoFrame::MailboxHolder* VideoFrame::texture_mailbox() const { | 491 gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
491 DCHECK_EQ(format_, NATIVE_TEXTURE); | 492 DCHECK_EQ(format_, NATIVE_TEXTURE); |
492 return texture_mailbox_holder_.get(); | 493 return mailbox_holder_.get(); |
493 } | |
494 | |
495 uint32 VideoFrame::texture_target() const { | |
496 DCHECK_EQ(format_, NATIVE_TEXTURE); | |
497 return texture_target_; | |
498 } | 494 } |
499 | 495 |
500 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 496 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
501 return shared_memory_handle_; | 497 return shared_memory_handle_; |
502 } | 498 } |
503 | 499 |
504 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 500 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
505 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 501 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
506 if (!IsValidPlane(plane)) | 502 if (!IsValidPlane(plane)) |
507 break; | 503 break; |
508 for (int row = 0; row < rows(plane); ++row) { | 504 for (int row = 0; row < rows(plane); ++row) { |
509 base::MD5Update(context, base::StringPiece( | 505 base::MD5Update(context, base::StringPiece( |
510 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 506 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
511 row_bytes(plane))); | 507 row_bytes(plane))); |
512 } | 508 } |
513 } | 509 } |
514 } | 510 } |
515 | 511 |
516 VideoFrame::MailboxHolder::MailboxHolder( | |
517 const gpu::Mailbox& mailbox, | |
518 unsigned sync_point, | |
519 const TextureNoLongerNeededCallback& release_callback) | |
520 : mailbox_(mailbox), | |
521 sync_point_(sync_point), | |
522 release_callback_(release_callback) {} | |
523 | |
524 VideoFrame::MailboxHolder::~MailboxHolder() { | |
525 if (!release_callback_.is_null()) | |
526 release_callback_.Run(sync_point_); | |
527 } | |
528 | |
529 } // namespace media | 512 } // namespace media |
OLD | NEW |