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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 natural_size.width() > limits::kMaxDimension || | 118 natural_size.width() > limits::kMaxDimension || |
119 natural_size.height() > limits::kMaxDimension) | 119 natural_size.height() > limits::kMaxDimension) |
120 return false; | 120 return false; |
121 | 121 |
122 // TODO(mcasas): Remove parameter |storage_type| when the opaque storage types | 122 // TODO(mcasas): Remove parameter |storage_type| when the opaque storage types |
123 // comply with the checks below. Right now we skip them. | 123 // comply with the checks below. Right now we skip them. |
124 if (!IsStorageTypeMappable(storage_type)) | 124 if (!IsStorageTypeMappable(storage_type)) |
125 return true; | 125 return true; |
126 | 126 |
127 // Make sure new formats are properly accounted for in the method. | 127 // Make sure new formats are properly accounted for in the method. |
128 static_assert(PIXEL_FORMAT_MAX == 21, | 128 static_assert(PIXEL_FORMAT_MAX == 22, |
129 "Added pixel format, please review IsValidConfig()"); | 129 "Added pixel format, please review IsValidConfig()"); |
130 | 130 |
131 if (format == PIXEL_FORMAT_UNKNOWN) { | 131 if (format == PIXEL_FORMAT_UNKNOWN) { |
132 return coded_size.IsEmpty() && visible_rect.IsEmpty() && | 132 return coded_size.IsEmpty() && visible_rect.IsEmpty() && |
133 natural_size.IsEmpty(); | 133 natural_size.IsEmpty(); |
134 } | 134 } |
135 | 135 |
136 // Check that software-allocated buffer formats are not empty. | 136 // Check that software-allocated buffer formats are not empty. |
137 return !coded_size.IsEmpty() && !visible_rect.IsEmpty() && | 137 return !coded_size.IsEmpty() && !visible_rect.IsEmpty() && |
138 !natural_size.IsEmpty(); | 138 !natural_size.IsEmpty(); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // static | 507 // static |
508 size_t VideoFrame::NumPlanes(VideoPixelFormat format) { | 508 size_t VideoFrame::NumPlanes(VideoPixelFormat format) { |
509 switch (format) { | 509 switch (format) { |
510 case PIXEL_FORMAT_UYVY: | 510 case PIXEL_FORMAT_UYVY: |
511 case PIXEL_FORMAT_YUY2: | 511 case PIXEL_FORMAT_YUY2: |
512 case PIXEL_FORMAT_ARGB: | 512 case PIXEL_FORMAT_ARGB: |
513 case PIXEL_FORMAT_XRGB: | 513 case PIXEL_FORMAT_XRGB: |
514 case PIXEL_FORMAT_RGB24: | 514 case PIXEL_FORMAT_RGB24: |
515 case PIXEL_FORMAT_RGB32: | 515 case PIXEL_FORMAT_RGB32: |
516 case PIXEL_FORMAT_MJPEG: | 516 case PIXEL_FORMAT_MJPEG: |
| 517 case PIXEL_FORMAT_Y16: |
517 return 1; | 518 return 1; |
518 case PIXEL_FORMAT_NV12: | 519 case PIXEL_FORMAT_NV12: |
519 case PIXEL_FORMAT_NV21: | 520 case PIXEL_FORMAT_NV21: |
520 case PIXEL_FORMAT_MT21: | 521 case PIXEL_FORMAT_MT21: |
521 return 2; | 522 return 2; |
522 case PIXEL_FORMAT_I420: | 523 case PIXEL_FORMAT_I420: |
523 case PIXEL_FORMAT_YV12: | 524 case PIXEL_FORMAT_YV12: |
524 case PIXEL_FORMAT_YV16: | 525 case PIXEL_FORMAT_YV16: |
525 case PIXEL_FORMAT_YV24: | 526 case PIXEL_FORMAT_YV24: |
526 case PIXEL_FORMAT_YUV420P9: | 527 case PIXEL_FORMAT_YUV420P9: |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 const gfx::Size& natural_size, | 795 const gfx::Size& natural_size, |
795 uint8_t* data, | 796 uint8_t* data, |
796 size_t data_size, | 797 size_t data_size, |
797 base::TimeDelta timestamp, | 798 base::TimeDelta timestamp, |
798 base::SharedMemoryHandle handle, | 799 base::SharedMemoryHandle handle, |
799 size_t data_offset) { | 800 size_t data_offset) { |
800 DCHECK(IsStorageTypeMappable(storage_type)); | 801 DCHECK(IsStorageTypeMappable(storage_type)); |
801 | 802 |
802 // TODO(miu): This function should support any pixel format. | 803 // TODO(miu): This function should support any pixel format. |
803 // http://crbug.com/555909 | 804 // http://crbug.com/555909 |
804 if (format != PIXEL_FORMAT_I420) { | 805 if (format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y16) { |
805 LOG(DFATAL) << "Only PIXEL_FORMAT_I420 format supported: " | 806 LOG(DFATAL) << "Only PIXEL_FORMAT_I420 and PIXEL_FORMAT_Y16 formats are " |
| 807 "supported: " |
806 << VideoPixelFormatToString(format); | 808 << VideoPixelFormatToString(format); |
807 return nullptr; | 809 return nullptr; |
808 } | 810 } |
809 | 811 |
810 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, | 812 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, |
811 natural_size)) { | 813 natural_size)) { |
812 LOG(DFATAL) << __FUNCTION__ << " Invalid config." | 814 LOG(DFATAL) << __FUNCTION__ << " Invalid config." |
813 << ConfigToString(format, storage_type, coded_size, | 815 << ConfigToString(format, storage_type, coded_size, |
814 visible_rect, natural_size); | 816 visible_rect, natural_size); |
815 return nullptr; | 817 return nullptr; |
816 } | 818 } |
817 | 819 |
818 scoped_refptr<VideoFrame> frame; | 820 scoped_refptr<VideoFrame> frame; |
819 if (storage_type == STORAGE_SHMEM) { | 821 if (storage_type == STORAGE_SHMEM) { |
820 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, | 822 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, |
821 natural_size, timestamp, handle, data_offset); | 823 natural_size, timestamp, handle, data_offset); |
822 } else { | 824 } else { |
823 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, | 825 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, |
824 natural_size, timestamp); | 826 natural_size, timestamp); |
825 } | 827 } |
| 828 if (format == PIXEL_FORMAT_Y16) { |
| 829 // TODO(astojilj) Make this code generic for all and move format specifics |
| 830 // to static methods. |
| 831 DCHECK_EQ(NumPlanes(format), 1); |
| 832 const size_t i = 0; |
| 833 frame->strides_[i] = coded_size.width() * BytesPerElement(format, i); |
| 834 frame->data_[i] = data; |
| 835 return frame; |
| 836 } |
826 frame->strides_[kYPlane] = coded_size.width(); | 837 frame->strides_[kYPlane] = coded_size.width(); |
827 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() | 838 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() |
828 // always rounds up. This inconsistency must be resolved. Perhaps a | 839 // always rounds up. This inconsistency must be resolved. Perhaps a |
829 // CommonAlignment() check should be made in IsValidConfig()? | 840 // CommonAlignment() check should be made in IsValidConfig()? |
830 // http://crbug.com/555909 | 841 // http://crbug.com/555909 |
831 frame->strides_[kUPlane] = coded_size.width() / 2; | 842 frame->strides_[kUPlane] = coded_size.width() / 2; |
832 frame->strides_[kVPlane] = coded_size.width() / 2; | 843 frame->strides_[kVPlane] = coded_size.width() / 2; |
833 frame->data_[kYPlane] = data; | 844 frame->data_[kYPlane] = data; |
834 frame->data_[kUPlane] = data + coded_size.GetArea(); | 845 frame->data_[kUPlane] = data + coded_size.GetArea(); |
835 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); | 846 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 // static | 1048 // static |
1038 int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) { | 1049 int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) { |
1039 DCHECK(IsValidPlane(plane, format)); | 1050 DCHECK(IsValidPlane(plane, format)); |
1040 switch (format) { | 1051 switch (format) { |
1041 case PIXEL_FORMAT_ARGB: | 1052 case PIXEL_FORMAT_ARGB: |
1042 case PIXEL_FORMAT_XRGB: | 1053 case PIXEL_FORMAT_XRGB: |
1043 case PIXEL_FORMAT_RGB32: | 1054 case PIXEL_FORMAT_RGB32: |
1044 return 4; | 1055 return 4; |
1045 case PIXEL_FORMAT_RGB24: | 1056 case PIXEL_FORMAT_RGB24: |
1046 return 3; | 1057 return 3; |
| 1058 case PIXEL_FORMAT_Y16: |
1047 case PIXEL_FORMAT_UYVY: | 1059 case PIXEL_FORMAT_UYVY: |
1048 case PIXEL_FORMAT_YUY2: | 1060 case PIXEL_FORMAT_YUY2: |
1049 case PIXEL_FORMAT_YUV420P9: | 1061 case PIXEL_FORMAT_YUV420P9: |
1050 case PIXEL_FORMAT_YUV422P9: | 1062 case PIXEL_FORMAT_YUV422P9: |
1051 case PIXEL_FORMAT_YUV444P9: | 1063 case PIXEL_FORMAT_YUV444P9: |
1052 case PIXEL_FORMAT_YUV420P10: | 1064 case PIXEL_FORMAT_YUV420P10: |
1053 case PIXEL_FORMAT_YUV422P10: | 1065 case PIXEL_FORMAT_YUV422P10: |
1054 case PIXEL_FORMAT_YUV444P10: | 1066 case PIXEL_FORMAT_YUV444P10: |
1055 return 2; | 1067 return 2; |
1056 case PIXEL_FORMAT_NV12: | 1068 case PIXEL_FORMAT_NV12: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 if (zero_initialize_memory) | 1128 if (zero_initialize_memory) |
1117 memset(data, 0, data_size); | 1129 memset(data, 0, data_size); |
1118 | 1130 |
1119 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) | 1131 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) |
1120 data_[plane] = data + offset[plane]; | 1132 data_[plane] = data + offset[plane]; |
1121 | 1133 |
1122 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); | 1134 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); |
1123 } | 1135 } |
1124 | 1136 |
1125 } // namespace media | 1137 } // namespace media |
OLD | NEW |