| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 const ReadPixelsCB& read_pixels_cb) { | 99 const ReadPixelsCB& read_pixels_cb) { |
| 100 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, | 100 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, |
| 101 coded_size, | 101 coded_size, |
| 102 visible_rect, | 102 visible_rect, |
| 103 natural_size, | 103 natural_size, |
| 104 timestamp, | 104 timestamp, |
| 105 false)); | 105 false)); |
| 106 frame->mailbox_holder_ = mailbox_holder.Pass(); | 106 frame->mailbox_holder_ = mailbox_holder.Pass(); |
| 107 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; | 107 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; |
| 108 frame->read_pixels_cb_ = read_pixels_cb; | 108 frame->read_pixels_cb_ = read_pixels_cb; |
| 109 #ifndef NDEBUG |
| 110 frame->debug_initial_sync_point_ = frame->mailbox_holder_->sync_point; |
| 111 #endif |
| 109 | 112 |
| 110 return frame; | 113 return frame; |
| 111 } | 114 } |
| 112 | 115 |
| 113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 116 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
| 114 DCHECK_EQ(format_, NATIVE_TEXTURE); | 117 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 115 if (!read_pixels_cb_.is_null()) | 118 if (!read_pixels_cb_.is_null()) |
| 116 read_pixels_cb_.Run(pixels); | 119 read_pixels_cb_.Run(this, pixels); |
| 117 } | 120 } |
| 118 | 121 |
| 119 // static | 122 // static |
| 120 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( | 123 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( |
| 121 Format format, | 124 Format format, |
| 122 const gfx::Size& coded_size, | 125 const gfx::Size& coded_size, |
| 123 const gfx::Rect& visible_rect, | 126 const gfx::Rect& visible_rect, |
| 124 const gfx::Size& natural_size, | 127 const gfx::Size& natural_size, |
| 125 uint8* data, | 128 uint8* data, |
| 126 size_t data_size, | 129 size_t data_size, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 VideoFrame::VideoFrame(VideoFrame::Format format, | 401 VideoFrame::VideoFrame(VideoFrame::Format format, |
| 399 const gfx::Size& coded_size, | 402 const gfx::Size& coded_size, |
| 400 const gfx::Rect& visible_rect, | 403 const gfx::Rect& visible_rect, |
| 401 const gfx::Size& natural_size, | 404 const gfx::Size& natural_size, |
| 402 base::TimeDelta timestamp, | 405 base::TimeDelta timestamp, |
| 403 bool end_of_stream) | 406 bool end_of_stream) |
| 404 : format_(format), | 407 : format_(format), |
| 405 coded_size_(coded_size), | 408 coded_size_(coded_size), |
| 406 visible_rect_(visible_rect), | 409 visible_rect_(visible_rect), |
| 407 natural_size_(natural_size), | 410 natural_size_(natural_size), |
| 411 #ifndef NDEBUG |
| 412 debug_initial_sync_point_(0), |
| 413 #endif |
| 408 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 414 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
| 409 timestamp_(timestamp), | 415 timestamp_(timestamp), |
| 410 end_of_stream_(end_of_stream) { | 416 end_of_stream_(end_of_stream) { |
| 411 memset(&strides_, 0, sizeof(strides_)); | 417 memset(&strides_, 0, sizeof(strides_)); |
| 412 memset(&data_, 0, sizeof(data_)); | 418 memset(&data_, 0, sizeof(data_)); |
| 413 } | 419 } |
| 414 | 420 |
| 415 VideoFrame::~VideoFrame() { | 421 VideoFrame::~VideoFrame() { |
| 416 if (!mailbox_holder_release_cb_.is_null()) { | 422 if (!mailbox_holder_release_cb_.is_null()) { |
| 423 std::vector<uint32> release_sync_points; |
| 424 { |
| 425 base::AutoLock locker(release_sync_point_lock_); |
| 426 release_sync_points_.swap(release_sync_points); |
| 427 } |
| 428 #ifndef NDEBUG |
| 429 // VideoFrame doesn't use |mailbox_holder_->sync_point| as release sync |
| 430 // point because VideoFrame can have multiple clients. i.e. the compositor, |
| 431 // webgl. So VideoFrame uses |release_sync_points_| unlike webgl. |
| 432 // mailbox_holder_->sync_point must be not changed by clients. |
| 433 DCHECK_EQ(debug_initial_sync_point_, mailbox_holder_->sync_point); |
| 434 for (size_t i = 0; i < release_sync_points.size(); i++) |
| 435 DCHECK_NE(debug_initial_sync_point_, release_sync_points[i]); |
| 436 #endif |
| 417 base::ResetAndReturn(&mailbox_holder_release_cb_) | 437 base::ResetAndReturn(&mailbox_holder_release_cb_) |
| 418 .Run(mailbox_holder_.Pass()); | 438 .Run(mailbox_holder_.Pass(), release_sync_points); |
| 419 } | 439 } |
| 420 if (!no_longer_needed_cb_.is_null()) | 440 if (!no_longer_needed_cb_.is_null()) |
| 421 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 441 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 422 } | 442 } |
| 423 | 443 |
| 424 bool VideoFrame::IsValidPlane(size_t plane) const { | 444 bool VideoFrame::IsValidPlane(size_t plane) const { |
| 425 return (plane < NumPlanes(format_)); | 445 return (plane < NumPlanes(format_)); |
| 426 } | 446 } |
| 427 | 447 |
| 428 int VideoFrame::stride(size_t plane) const { | 448 int VideoFrame::stride(size_t plane) const { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 509 |
| 490 gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 510 gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
| 491 DCHECK_EQ(format_, NATIVE_TEXTURE); | 511 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 492 return mailbox_holder_.get(); | 512 return mailbox_holder_.get(); |
| 493 } | 513 } |
| 494 | 514 |
| 495 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 515 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
| 496 return shared_memory_handle_; | 516 return shared_memory_handle_; |
| 497 } | 517 } |
| 498 | 518 |
| 519 void VideoFrame::AppendReleaseSyncPoint(uint32 sync_point) { |
| 520 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 521 base::AutoLock locker(release_sync_point_lock_); |
| 522 release_sync_points_.push_back(sync_point); |
| 523 } |
| 524 |
| 499 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 525 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
| 500 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 526 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
| 501 if (!IsValidPlane(plane)) | 527 if (!IsValidPlane(plane)) |
| 502 break; | 528 break; |
| 503 for (int row = 0; row < rows(plane); ++row) { | 529 for (int row = 0; row < rows(plane); ++row) { |
| 504 base::MD5Update(context, base::StringPiece( | 530 base::MD5Update(context, base::StringPiece( |
| 505 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 531 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 506 row_bytes(plane))); | 532 row_bytes(plane))); |
| 507 } | 533 } |
| 508 } | 534 } |
| 509 } | 535 } |
| 510 | 536 |
| 511 } // namespace media | 537 } // namespace media |
| OLD | NEW |