| 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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 659 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 660 base::TimeDelta timestamp, | 660 base::TimeDelta timestamp, |
| 661 bool end_of_stream) | 661 bool end_of_stream) |
| 662 : format_(format), | 662 : format_(format), |
| 663 coded_size_(coded_size), | 663 coded_size_(coded_size), |
| 664 visible_rect_(visible_rect), | 664 visible_rect_(visible_rect), |
| 665 natural_size_(natural_size), | 665 natural_size_(natural_size), |
| 666 mailbox_holder_(mailbox_holder.Pass()), | 666 mailbox_holder_(mailbox_holder.Pass()), |
| 667 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 667 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
| 668 timestamp_(timestamp), | 668 timestamp_(timestamp), |
| 669 release_sync_point_(0), |
| 669 end_of_stream_(end_of_stream) { | 670 end_of_stream_(end_of_stream) { |
| 670 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); | 671 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); |
| 671 | 672 |
| 672 memset(&strides_, 0, sizeof(strides_)); | 673 memset(&strides_, 0, sizeof(strides_)); |
| 673 memset(&data_, 0, sizeof(data_)); | 674 memset(&data_, 0, sizeof(data_)); |
| 674 } | 675 } |
| 675 | 676 |
| 676 VideoFrame::~VideoFrame() { | 677 VideoFrame::~VideoFrame() { |
| 677 if (!mailbox_holder_release_cb_.is_null()) { | 678 if (!mailbox_holder_release_cb_.is_null()) { |
| 678 std::vector<uint32> release_sync_points; | 679 uint32 release_sync_point; |
| 679 { | 680 { |
| 681 // To ensure that changes to |release_sync_point_| are visible on this |
| 682 // thread (imply a memory barrier). |
| 680 base::AutoLock locker(release_sync_point_lock_); | 683 base::AutoLock locker(release_sync_point_lock_); |
| 681 release_sync_points_.swap(release_sync_points); | 684 release_sync_point = release_sync_point_; |
| 682 } | 685 } |
| 683 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_points); | 686 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); |
| 684 } | 687 } |
| 685 if (!no_longer_needed_cb_.is_null()) | 688 if (!no_longer_needed_cb_.is_null()) |
| 686 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 689 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 687 } | 690 } |
| 688 | 691 |
| 689 bool VideoFrame::IsValidPlane(size_t plane) const { | 692 bool VideoFrame::IsValidPlane(size_t plane) const { |
| 690 return (plane < NumPlanes(format_)); | 693 return (plane < NumPlanes(format_)); |
| 691 } | 694 } |
| 692 | 695 |
| 693 int VideoFrame::stride(size_t plane) const { | 696 int VideoFrame::stride(size_t plane) const { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 828 |
| 826 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 829 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
| 827 DCHECK_EQ(format_, NATIVE_TEXTURE); | 830 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 828 return mailbox_holder_.get(); | 831 return mailbox_holder_.get(); |
| 829 } | 832 } |
| 830 | 833 |
| 831 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 834 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
| 832 return shared_memory_handle_; | 835 return shared_memory_handle_; |
| 833 } | 836 } |
| 834 | 837 |
| 835 void VideoFrame::AppendReleaseSyncPoint(uint32 sync_point) { | 838 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { |
| 836 DCHECK_EQ(format_, NATIVE_TEXTURE); | 839 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 837 if (!sync_point) | |
| 838 return; | |
| 839 base::AutoLock locker(release_sync_point_lock_); | 840 base::AutoLock locker(release_sync_point_lock_); |
| 840 release_sync_points_.push_back(sync_point); | 841 // Must wait on the previous sync point before inserting a new sync point so |
| 842 // that |mailbox_holder_release_cb_| guarantees the previous sync point |
| 843 // occurred when it waits on |release_sync_point_|. |
| 844 if (release_sync_point_) |
| 845 client->WaitSyncPoint(release_sync_point_); |
| 846 release_sync_point_ = client->InsertSyncPoint(); |
| 841 } | 847 } |
| 842 | 848 |
| 843 #if defined(OS_POSIX) | 849 #if defined(OS_POSIX) |
| 844 int VideoFrame::dmabuf_fd(size_t plane) const { | 850 int VideoFrame::dmabuf_fd(size_t plane) const { |
| 845 return dmabuf_fds_[plane].get(); | 851 return dmabuf_fds_[plane].get(); |
| 846 } | 852 } |
| 847 #endif | 853 #endif |
| 848 | 854 |
| 849 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 855 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
| 850 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 856 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
| 851 if (!IsValidPlane(plane)) | 857 if (!IsValidPlane(plane)) |
| 852 break; | 858 break; |
| 853 for (int row = 0; row < rows(plane); ++row) { | 859 for (int row = 0; row < rows(plane); ++row) { |
| 854 base::MD5Update(context, base::StringPiece( | 860 base::MD5Update(context, base::StringPiece( |
| 855 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 861 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 856 row_bytes(plane))); | 862 row_bytes(plane))); |
| 857 } | 863 } |
| 858 } | 864 } |
| 859 } | 865 } |
| 860 | 866 |
| 861 } // namespace media | 867 } // namespace media |
| OLD | NEW |