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