Chromium Code Reviews| 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 #include <climits> | 8 #include <climits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 const gfx::Size& coded_size, | 823 const gfx::Size& coded_size, |
| 824 const gfx::Rect& visible_rect, | 824 const gfx::Rect& visible_rect, |
| 825 const gfx::Size& natural_size, | 825 const gfx::Size& natural_size, |
| 826 uint8* data, | 826 uint8* data, |
| 827 size_t data_size, | 827 size_t data_size, |
| 828 base::TimeDelta timestamp, | 828 base::TimeDelta timestamp, |
| 829 base::SharedMemoryHandle handle, | 829 base::SharedMemoryHandle handle, |
| 830 size_t data_offset) { | 830 size_t data_offset) { |
| 831 DCHECK(IsStorageTypeMappable(storage_type)); | 831 DCHECK(IsStorageTypeMappable(storage_type)); |
| 832 | 832 |
| 833 // TODO(miu): This function should support any frame format. | |
|
mcasas
2015/11/13 19:13:57
nit: bug for this? (It should be accompanied by un
miu
2015/11/14 03:43:48
Done.
| |
| 833 if (format != PIXEL_FORMAT_I420) { | 834 if (format != PIXEL_FORMAT_I420) { |
| 834 DLOG(ERROR) << "Only PIXEL_FORMAT_I420 format supported: " | 835 DLOG(ERROR) << "Only PIXEL_FORMAT_I420 format supported: " |
| 835 << VideoPixelFormatToString(format); | 836 << VideoPixelFormatToString(format); |
| 836 return nullptr; | 837 return nullptr; |
| 837 } | 838 } |
| 838 | 839 |
| 839 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, | 840 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, |
| 840 natural_size)) { | 841 natural_size)) { |
| 841 DLOG(ERROR) << __FUNCTION__ << " Invalid config." | 842 DLOG(ERROR) << __FUNCTION__ << " Invalid config." |
| 842 << ConfigToString(format, storage_type, coded_size, | 843 << ConfigToString(format, storage_type, coded_size, |
| 843 visible_rect, natural_size); | 844 visible_rect, natural_size); |
| 844 return nullptr; | 845 return nullptr; |
| 845 } | 846 } |
| 846 | 847 |
| 847 scoped_refptr<VideoFrame> frame; | 848 scoped_refptr<VideoFrame> frame; |
| 848 if (storage_type == STORAGE_SHMEM) { | 849 if (storage_type == STORAGE_SHMEM) { |
| 849 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, | 850 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, |
| 850 natural_size, timestamp, handle, data_offset); | 851 natural_size, timestamp, handle, data_offset); |
| 851 } else { | 852 } else { |
| 852 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, | 853 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, |
| 853 natural_size, timestamp); | 854 natural_size, timestamp); |
| 854 } | 855 } |
| 855 frame->strides_[kYPlane] = coded_size.width(); | 856 frame->strides_[kYPlane] = coded_size.width(); |
| 857 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() | |
| 858 // always rounds up. This inconsistency must be resolved. Perhaps a | |
| 859 // CommonAlignment() check should be made in IsValidConfig()? | |
| 856 frame->strides_[kUPlane] = coded_size.width() / 2; | 860 frame->strides_[kUPlane] = coded_size.width() / 2; |
| 857 frame->strides_[kVPlane] = coded_size.width() / 2; | 861 frame->strides_[kVPlane] = coded_size.width() / 2; |
| 858 frame->data_[kYPlane] = data; | 862 frame->data_[kYPlane] = data; |
| 859 frame->data_[kUPlane] = data + coded_size.GetArea(); | 863 frame->data_[kUPlane] = data + coded_size.GetArea(); |
| 860 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); | 864 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); |
| 861 return frame; | 865 return frame; |
| 862 } | 866 } |
| 863 | 867 |
| 864 VideoFrame::VideoFrame(VideoPixelFormat format, | 868 VideoFrame::VideoFrame(VideoPixelFormat format, |
| 865 StorageType storage_type, | 869 StorageType storage_type, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 if (zero_initialize_memory) | 1007 if (zero_initialize_memory) |
| 1004 memset(data, 0, data_size); | 1008 memset(data, 0, data_size); |
| 1005 | 1009 |
| 1006 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) | 1010 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) |
| 1007 data_[plane] = data + offset[plane]; | 1011 data_[plane] = data + offset[plane]; |
| 1008 | 1012 |
| 1009 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); | 1013 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); |
| 1010 } | 1014 } |
| 1011 | 1015 |
| 1012 } // namespace media | 1016 } // namespace media |
| OLD | NEW |