| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 634 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 635 base::TimeDelta timestamp, | 635 base::TimeDelta timestamp, |
| 636 bool end_of_stream) | 636 bool end_of_stream) |
| 637 : format_(format), | 637 : format_(format), |
| 638 coded_size_(coded_size), | 638 coded_size_(coded_size), |
| 639 visible_rect_(visible_rect), | 639 visible_rect_(visible_rect), |
| 640 natural_size_(natural_size), | 640 natural_size_(natural_size), |
| 641 mailbox_holder_(mailbox_holder.Pass()), | 641 mailbox_holder_(mailbox_holder.Pass()), |
| 642 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 642 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
| 643 timestamp_(timestamp), | 643 timestamp_(timestamp), |
| 644 release_sync_point_(0), |
| 644 end_of_stream_(end_of_stream) { | 645 end_of_stream_(end_of_stream) { |
| 645 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); | 646 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); |
| 646 | 647 |
| 647 memset(&strides_, 0, sizeof(strides_)); | 648 memset(&strides_, 0, sizeof(strides_)); |
| 648 memset(&data_, 0, sizeof(data_)); | 649 memset(&data_, 0, sizeof(data_)); |
| 649 } | 650 } |
| 650 | 651 |
| 651 VideoFrame::~VideoFrame() { | 652 VideoFrame::~VideoFrame() { |
| 652 if (!mailbox_holder_release_cb_.is_null()) { | 653 if (!mailbox_holder_release_cb_.is_null()) { |
| 653 std::vector<uint32> release_sync_points; | 654 uint32 release_sync_point; |
| 654 { | 655 { |
| 656 // To ensure |release_sync_point_| is visible on this thread. |
| 655 base::AutoLock locker(release_sync_point_lock_); | 657 base::AutoLock locker(release_sync_point_lock_); |
| 656 release_sync_points_.swap(release_sync_points); | 658 release_sync_point = release_sync_point_; |
| 657 } | 659 } |
| 658 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_points); | 660 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); |
| 659 } | 661 } |
| 660 if (!no_longer_needed_cb_.is_null()) | 662 if (!no_longer_needed_cb_.is_null()) |
| 661 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 663 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 662 } | 664 } |
| 663 | 665 |
| 664 bool VideoFrame::IsValidPlane(size_t plane) const { | 666 bool VideoFrame::IsValidPlane(size_t plane) const { |
| 665 return (plane < NumPlanes(format_)); | 667 return (plane < NumPlanes(format_)); |
| 666 } | 668 } |
| 667 | 669 |
| 668 int VideoFrame::stride(size_t plane) const { | 670 int VideoFrame::stride(size_t plane) const { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 802 |
| 801 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 803 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
| 802 DCHECK_EQ(format_, NATIVE_TEXTURE); | 804 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 803 return mailbox_holder_.get(); | 805 return mailbox_holder_.get(); |
| 804 } | 806 } |
| 805 | 807 |
| 806 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 808 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
| 807 return shared_memory_handle_; | 809 return shared_memory_handle_; |
| 808 } | 810 } |
| 809 | 811 |
| 810 void VideoFrame::AppendReleaseSyncPoint(uint32 sync_point) { | 812 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { |
| 811 DCHECK_EQ(format_, NATIVE_TEXTURE); | 813 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 812 if (!sync_point) | |
| 813 return; | |
| 814 base::AutoLock locker(release_sync_point_lock_); | 814 base::AutoLock locker(release_sync_point_lock_); |
| 815 release_sync_points_.push_back(sync_point); | 815 // Must wait the previous sync point before inserting a new sync point so that |
| 816 // |mailbox_holder_release_cb_| guarantees the previous sync point occurred |
| 817 // when it waits |release_sync_point_|. |
| 818 if (release_sync_point_) |
| 819 client->WaitSyncPoint(release_sync_point_); |
| 820 release_sync_point_ = client->InsertSyncPoint(); |
| 816 } | 821 } |
| 817 | 822 |
| 818 #if defined(OS_POSIX) | 823 #if defined(OS_POSIX) |
| 819 int VideoFrame::dmabuf_fd(size_t plane) const { | 824 int VideoFrame::dmabuf_fd(size_t plane) const { |
| 820 return dmabuf_fds_[plane].get(); | 825 return dmabuf_fds_[plane].get(); |
| 821 } | 826 } |
| 822 #endif | 827 #endif |
| 823 | 828 |
| 824 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 829 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
| 825 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 830 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
| 826 if (!IsValidPlane(plane)) | 831 if (!IsValidPlane(plane)) |
| 827 break; | 832 break; |
| 828 for (int row = 0; row < rows(plane); ++row) { | 833 for (int row = 0; row < rows(plane); ++row) { |
| 829 base::MD5Update(context, base::StringPiece( | 834 base::MD5Update(context, base::StringPiece( |
| 830 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 835 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 831 row_bytes(plane))); | 836 row_bytes(plane))); |
| 832 } | 837 } |
| 833 } | 838 } |
| 834 } | 839 } |
| 835 | 840 |
| 836 } // namespace media | 841 } // namespace media |
| OLD | NEW |