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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 643 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
644 base::TimeDelta timestamp, | 644 base::TimeDelta timestamp, |
645 bool end_of_stream) | 645 bool end_of_stream) |
646 : format_(format), | 646 : format_(format), |
647 coded_size_(coded_size), | 647 coded_size_(coded_size), |
648 visible_rect_(visible_rect), | 648 visible_rect_(visible_rect), |
649 natural_size_(natural_size), | 649 natural_size_(natural_size), |
650 mailbox_holder_(mailbox_holder.Pass()), | 650 mailbox_holder_(mailbox_holder.Pass()), |
651 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 651 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
652 timestamp_(timestamp), | 652 timestamp_(timestamp), |
653 release_sync_point_(0), | |
653 end_of_stream_(end_of_stream) { | 654 end_of_stream_(end_of_stream) { |
654 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); | 655 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); |
655 | 656 |
656 memset(&strides_, 0, sizeof(strides_)); | 657 memset(&strides_, 0, sizeof(strides_)); |
657 memset(&data_, 0, sizeof(data_)); | 658 memset(&data_, 0, sizeof(data_)); |
658 } | 659 } |
659 | 660 |
660 VideoFrame::~VideoFrame() { | 661 VideoFrame::~VideoFrame() { |
661 if (!mailbox_holder_release_cb_.is_null()) { | 662 if (!mailbox_holder_release_cb_.is_null()) { |
662 std::vector<uint32> release_sync_points; | 663 uint32 release_sync_point; |
663 { | 664 { |
665 // To ensure |release_sync_point_| is visible on this thread. | |
664 base::AutoLock locker(release_sync_point_lock_); | 666 base::AutoLock locker(release_sync_point_lock_); |
no sievers
2014/07/10 18:52:29
Why do we need a lock in the destructor? Somebody
danakj
2014/07/10 19:15:57
Thread barrier, someone may have changed the value
dshwang
2014/07/10 19:23:11
Thank you for answer!
no sievers
2014/07/10 19:27:47
Ah thanks. I guess the comment says that already.
| |
665 release_sync_points_.swap(release_sync_points); | 667 release_sync_point = release_sync_point_; |
666 } | 668 } |
667 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_points); | 669 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); |
668 } | 670 } |
669 if (!no_longer_needed_cb_.is_null()) | 671 if (!no_longer_needed_cb_.is_null()) |
670 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 672 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
671 } | 673 } |
672 | 674 |
673 bool VideoFrame::IsValidPlane(size_t plane) const { | 675 bool VideoFrame::IsValidPlane(size_t plane) const { |
674 return (plane < NumPlanes(format_)); | 676 return (plane < NumPlanes(format_)); |
675 } | 677 } |
676 | 678 |
677 int VideoFrame::stride(size_t plane) const { | 679 int VideoFrame::stride(size_t plane) const { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 | 811 |
810 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 812 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
811 DCHECK_EQ(format_, NATIVE_TEXTURE); | 813 DCHECK_EQ(format_, NATIVE_TEXTURE); |
812 return mailbox_holder_.get(); | 814 return mailbox_holder_.get(); |
813 } | 815 } |
814 | 816 |
815 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 817 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
816 return shared_memory_handle_; | 818 return shared_memory_handle_; |
817 } | 819 } |
818 | 820 |
819 void VideoFrame::AppendReleaseSyncPoint(uint32 sync_point) { | 821 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { |
820 DCHECK_EQ(format_, NATIVE_TEXTURE); | 822 DCHECK_EQ(format_, NATIVE_TEXTURE); |
821 if (!sync_point) | |
822 return; | |
823 base::AutoLock locker(release_sync_point_lock_); | 823 base::AutoLock locker(release_sync_point_lock_); |
824 release_sync_points_.push_back(sync_point); | 824 // Must wait the previous sync point before inserting a new sync point so that |
825 // |mailbox_holder_release_cb_| guarantees the previous sync point occurred | |
826 // when it waits |release_sync_point_|. | |
827 if (release_sync_point_) | |
828 client->WaitSyncPoint(release_sync_point_); | |
829 release_sync_point_ = client->InsertSyncPoint(); | |
825 } | 830 } |
826 | 831 |
827 #if defined(OS_POSIX) | 832 #if defined(OS_POSIX) |
828 int VideoFrame::dmabuf_fd(size_t plane) const { | 833 int VideoFrame::dmabuf_fd(size_t plane) const { |
829 return dmabuf_fds_[plane].get(); | 834 return dmabuf_fds_[plane].get(); |
830 } | 835 } |
831 #endif | 836 #endif |
832 | 837 |
833 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 838 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
834 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 839 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
835 if (!IsValidPlane(plane)) | 840 if (!IsValidPlane(plane)) |
836 break; | 841 break; |
837 for (int row = 0; row < rows(plane); ++row) { | 842 for (int row = 0; row < rows(plane); ++row) { |
838 base::MD5Update(context, base::StringPiece( | 843 base::MD5Update(context, base::StringPiece( |
839 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 844 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
840 row_bytes(plane))); | 845 row_bytes(plane))); |
841 } | 846 } |
842 } | 847 } |
843 } | 848 } |
844 | 849 |
845 } // namespace media | 850 } // namespace media |
OLD | NEW |