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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 // thread (imply a memory barrier). | 682 // thread (imply a memory barrier). |
683 base::AutoLock locker(release_sync_point_lock_); | 683 base::AutoLock locker(release_sync_point_lock_); |
684 release_sync_point = release_sync_point_; | 684 release_sync_point = release_sync_point_; |
685 } | 685 } |
686 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); | 686 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); |
687 } | 687 } |
688 if (!no_longer_needed_cb_.is_null()) | 688 if (!no_longer_needed_cb_.is_null()) |
689 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 689 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
690 } | 690 } |
691 | 691 |
692 bool VideoFrame::IsValidPlane(size_t plane) const { | 692 // static |
693 return (plane < NumPlanes(format_)); | 693 bool VideoFrame::IsValidPlane(size_t plane, VideoFrame::Format format) { |
694 return (plane < NumPlanes(format)); | |
694 } | 695 } |
695 | 696 |
696 int VideoFrame::stride(size_t plane) const { | 697 int VideoFrame::stride(size_t plane) const { |
697 DCHECK(IsValidPlane(plane)); | 698 DCHECK(IsValidPlane(plane, format_)); |
698 return strides_[plane]; | 699 return strides_[plane]; |
699 } | 700 } |
700 | 701 |
701 int VideoFrame::row_bytes(size_t plane) const { | 702 // static |
702 DCHECK(IsValidPlane(plane)); | 703 int VideoFrame::RowBytes(size_t plane, VideoFrame::Format format, int width) { |
703 int width = coded_size_.width(); | 704 DCHECK(IsValidPlane(plane, format)); |
704 switch (format_) { | 705 switch (format) { |
705 case VideoFrame::YV24: | 706 case VideoFrame::YV24: |
706 switch (plane) { | 707 switch (plane) { |
707 case kYPlane: | 708 case kYPlane: |
708 case kUPlane: | 709 case kUPlane: |
709 case kVPlane: | 710 case kVPlane: |
710 return width; | 711 return width; |
711 default: | 712 default: |
712 break; | 713 break; |
713 } | 714 } |
714 break; | 715 break; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 break; | 748 break; |
748 } | 749 } |
749 break; | 750 break; |
750 case VideoFrame::UNKNOWN: | 751 case VideoFrame::UNKNOWN: |
751 #if defined(VIDEO_HOLE) | 752 #if defined(VIDEO_HOLE) |
752 case VideoFrame::HOLE: | 753 case VideoFrame::HOLE: |
753 #endif // defined(VIDEO_HOLE) | 754 #endif // defined(VIDEO_HOLE) |
754 case VideoFrame::NATIVE_TEXTURE: | 755 case VideoFrame::NATIVE_TEXTURE: |
755 break; | 756 break; |
756 } | 757 } |
757 NOTREACHED() << "Unsupported video frame format/plane: " | 758 NOTREACHED() << "Unsupported video frame format/plane: " << format << "/" |
Pawel Osciak
2014/08/18 07:52:03
We could do FormatToString() here while we are at
wuchengli
2014/08/18 09:09:00
If we reach here, the format is invalid and Format
| |
758 << format_ << "/" << plane; | 759 << plane; |
759 return 0; | 760 return 0; |
760 } | 761 } |
761 | 762 |
763 int VideoFrame::row_bytes(size_t plane) const { | |
764 return RowBytes(plane, format_, coded_size_.width()); | |
765 } | |
766 | |
762 int VideoFrame::rows(size_t plane) const { | 767 int VideoFrame::rows(size_t plane) const { |
henryhsu
2014/08/18 08:18:57
Can we make rows function as static also?
wuchengli
2014/08/18 09:09:00
That is not related to this CL. You'll need to cre
| |
763 DCHECK(IsValidPlane(plane)); | 768 DCHECK(IsValidPlane(plane, format_)); |
764 int height = coded_size_.height(); | 769 int height = coded_size_.height(); |
765 switch (format_) { | 770 switch (format_) { |
766 case VideoFrame::YV24: | 771 case VideoFrame::YV24: |
767 case VideoFrame::YV16: | 772 case VideoFrame::YV16: |
768 switch (plane) { | 773 switch (plane) { |
769 case kYPlane: | 774 case kYPlane: |
770 case kUPlane: | 775 case kUPlane: |
771 case kVPlane: | 776 case kVPlane: |
772 return height; | 777 return height; |
773 default: | 778 default: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 #endif // defined(VIDEO_HOLE) | 820 #endif // defined(VIDEO_HOLE) |
816 case VideoFrame::NATIVE_TEXTURE: | 821 case VideoFrame::NATIVE_TEXTURE: |
817 break; | 822 break; |
818 } | 823 } |
819 NOTREACHED() << "Unsupported video frame format/plane: " | 824 NOTREACHED() << "Unsupported video frame format/plane: " |
820 << format_ << "/" << plane; | 825 << format_ << "/" << plane; |
821 return 0; | 826 return 0; |
822 } | 827 } |
823 | 828 |
824 uint8* VideoFrame::data(size_t plane) const { | 829 uint8* VideoFrame::data(size_t plane) const { |
825 DCHECK(IsValidPlane(plane)); | 830 DCHECK(IsValidPlane(plane, format_)); |
826 return data_[plane]; | 831 return data_[plane]; |
827 } | 832 } |
828 | 833 |
829 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 834 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
830 DCHECK_EQ(format_, NATIVE_TEXTURE); | 835 DCHECK_EQ(format_, NATIVE_TEXTURE); |
831 return mailbox_holder_.get(); | 836 return mailbox_holder_.get(); |
832 } | 837 } |
833 | 838 |
834 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 839 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
835 return shared_memory_handle_; | 840 return shared_memory_handle_; |
(...skipping 11 matching lines...) Expand all Loading... | |
847 } | 852 } |
848 | 853 |
849 #if defined(OS_POSIX) | 854 #if defined(OS_POSIX) |
850 int VideoFrame::dmabuf_fd(size_t plane) const { | 855 int VideoFrame::dmabuf_fd(size_t plane) const { |
851 return dmabuf_fds_[plane].get(); | 856 return dmabuf_fds_[plane].get(); |
852 } | 857 } |
853 #endif | 858 #endif |
854 | 859 |
855 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 860 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
856 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 861 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
857 if (!IsValidPlane(plane)) | 862 if (!IsValidPlane(plane, format_)) |
858 break; | 863 break; |
859 for (int row = 0; row < rows(plane); ++row) { | 864 for (int row = 0; row < rows(plane); ++row) { |
860 base::MD5Update(context, base::StringPiece( | 865 base::MD5Update(context, base::StringPiece( |
861 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 866 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
862 row_bytes(plane))); | 867 row_bytes(plane))); |
863 } | 868 } |
864 } | 869 } |
865 } | 870 } |
866 | 871 |
867 } // namespace media | 872 } // namespace media |
OLD | NEW |