Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: media/base/video_frame.cc

Issue 2398463003: 16 bit capture and GPU&CPU memory buffer support.
Patch Set: fixes. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_frame.h ('k') | media/capture/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTextures( 159 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTextures(
160 VideoPixelFormat format, 160 VideoPixelFormat format,
161 const gpu::MailboxHolder (&mailbox_holders)[kMaxPlanes], 161 const gpu::MailboxHolder (&mailbox_holders)[kMaxPlanes],
162 const ReleaseMailboxCB& mailbox_holder_release_cb, 162 const ReleaseMailboxCB& mailbox_holder_release_cb,
163 const gfx::Size& coded_size, 163 const gfx::Size& coded_size,
164 const gfx::Rect& visible_rect, 164 const gfx::Rect& visible_rect,
165 const gfx::Size& natural_size, 165 const gfx::Size& natural_size,
166 base::TimeDelta timestamp) { 166 base::TimeDelta timestamp) {
167 if (format != PIXEL_FORMAT_ARGB && format != PIXEL_FORMAT_XRGB && 167 if (format != PIXEL_FORMAT_ARGB && format != PIXEL_FORMAT_XRGB &&
168 format != PIXEL_FORMAT_UYVY && format != PIXEL_FORMAT_NV12 && 168 format != PIXEL_FORMAT_UYVY && format != PIXEL_FORMAT_NV12 &&
169 format != PIXEL_FORMAT_I420) { 169 format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y16) {
170 LOG(DFATAL) << "Unsupported pixel format supported, got " 170 LOG(DFATAL) << "Unsupported pixel format supported, got "
171 << VideoPixelFormatToString(format); 171 << VideoPixelFormatToString(format);
172 return nullptr; 172 return nullptr;
173 } 173 }
174 const StorageType storage = STORAGE_OPAQUE; 174 const StorageType storage = STORAGE_OPAQUE;
175 if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) { 175 if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) {
176 LOG(DFATAL) << __func__ << " Invalid config." 176 LOG(DFATAL) << __func__ << " Invalid config."
177 << ConfigToString(format, storage, coded_size, visible_rect, 177 << ConfigToString(format, storage, coded_size, visible_rect,
178 natural_size); 178 natural_size);
179 return nullptr; 179 return nullptr;
(...skipping 27 matching lines...) Expand all
207 size_t data_size, 207 size_t data_size,
208 base::SharedMemoryHandle handle, 208 base::SharedMemoryHandle handle,
209 size_t data_offset, 209 size_t data_offset,
210 base::TimeDelta timestamp) { 210 base::TimeDelta timestamp) {
211 return WrapExternalStorage(format, STORAGE_SHMEM, coded_size, visible_rect, 211 return WrapExternalStorage(format, STORAGE_SHMEM, coded_size, visible_rect,
212 natural_size, data, data_size, timestamp, handle, 212 natural_size, data, data_size, timestamp, handle,
213 data_offset); 213 data_offset);
214 } 214 }
215 215
216 // static 216 // static
217 scoped_refptr<VideoFrame> VideoFrame::WrapExternalGpuMemoryBuffer(
218 VideoPixelFormat format,
219 const gfx::Size& coded_size,
220 const gfx::Rect& visible_rect,
221 const gfx::Size& natural_size,
222 uint8_t* data,
223 const gfx::GpuMemoryBufferHandle& handle,
224 base::TimeDelta timestamp) {
225 const StorageType storage = STORAGE_GPU_MEMORY_BUFFERS;
226 if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) {
227 LOG(DFATAL) << __func__ << " Invalid config."
228 << ConfigToString(format, storage, coded_size, visible_rect,
229 natural_size);
230 return nullptr;
231 }
232
233 scoped_refptr<VideoFrame> frame(new VideoFrame(
234 format, storage, coded_size, visible_rect, natural_size, timestamp));
235 frame->strides_[0] = coded_size.width() * BytesPerElement(format, 0);
236 frame->data_[0] = data;
237 frame->gpu_memory_buffer_handles_.push_back(handle);
238 return frame;
239 }
240
241 // static
217 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( 242 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData(
218 VideoPixelFormat format, 243 VideoPixelFormat format,
219 const gfx::Size& coded_size, 244 const gfx::Size& coded_size,
220 const gfx::Rect& visible_rect, 245 const gfx::Rect& visible_rect,
221 const gfx::Size& natural_size, 246 const gfx::Size& natural_size,
222 int32_t y_stride, 247 int32_t y_stride,
223 int32_t u_stride, 248 int32_t u_stride,
224 int32_t v_stride, 249 int32_t v_stride,
225 uint8_t* y_data, 250 uint8_t* y_data,
226 uint8_t* u_data, 251 uint8_t* u_data,
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 for (int row = 0; row < frame->rows(plane); ++row) { 641 for (int row = 0; row < frame->rows(plane); ++row) {
617 base::MD5Update( 642 base::MD5Update(
618 context, 643 context,
619 base::StringPiece(reinterpret_cast<char*>(frame->data(plane) + 644 base::StringPiece(reinterpret_cast<char*>(frame->data(plane) +
620 frame->stride(plane) * row), 645 frame->stride(plane) * row),
621 frame->row_bytes(plane))); 646 frame->row_bytes(plane)));
622 } 647 }
623 } 648 }
624 } 649 }
625 650
651 // static
652 gfx::BufferFormat VideoFrame::BufferFormat(VideoPixelFormat format) {
653 switch (format) {
654 case PIXEL_FORMAT_I420:
655 case PIXEL_FORMAT_Y8:
656 return gfx::BufferFormat::R_8;
657 case PIXEL_FORMAT_NV12:
658 return gfx::BufferFormat::YUV_420_BIPLANAR;
659 case PIXEL_FORMAT_UYVY:
660 return gfx::BufferFormat::UYVY_422;
661 case PIXEL_FORMAT_Y16:
662 return gfx::BufferFormat::RG_88;
663 default:
664 NOTREACHED();
665 return gfx::BufferFormat::BGRA_8888;
666 }
667 }
668
626 bool VideoFrame::IsMappable() const { 669 bool VideoFrame::IsMappable() const {
627 return IsStorageTypeMappable(storage_type_); 670 return IsStorageTypeMappable(storage_type_);
628 } 671 }
629 672
630 bool VideoFrame::HasTextures() const { 673 bool VideoFrame::HasTextures() const {
631 return !mailbox_holders_[0].mailbox.IsZero(); 674 return !mailbox_holders_[0].mailbox.IsZero();
632 } 675 }
633 676
634 gfx::ColorSpace VideoFrame::ColorSpace() const { 677 gfx::ColorSpace VideoFrame::ColorSpace() const {
635 if (color_space_ == gfx::ColorSpace()) { 678 if (color_space_ == gfx::ColorSpace()) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 const gfx::Size& natural_size, 854 const gfx::Size& natural_size,
812 uint8_t* data, 855 uint8_t* data,
813 size_t data_size, 856 size_t data_size,
814 base::TimeDelta timestamp, 857 base::TimeDelta timestamp,
815 base::SharedMemoryHandle handle, 858 base::SharedMemoryHandle handle,
816 size_t data_offset) { 859 size_t data_offset) {
817 DCHECK(IsStorageTypeMappable(storage_type)); 860 DCHECK(IsStorageTypeMappable(storage_type));
818 861
819 // TODO(miu): This function should support any pixel format. 862 // TODO(miu): This function should support any pixel format.
820 // http://crbug.com/555909 863 // http://crbug.com/555909
821 if (format != PIXEL_FORMAT_I420) { 864 if (format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y16) {
822 LOG(DFATAL) << "Only PIXEL_FORMAT_I420 format supported: " 865 LOG(DFATAL) << "Only PIXEL_FORMAT_I420 and PIXEL_FORMAT_Y16 formats are"
866 "supported: "
823 << VideoPixelFormatToString(format); 867 << VideoPixelFormatToString(format);
824 return nullptr; 868 return nullptr;
825 } 869 }
826 870
827 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, 871 if (!IsValidConfig(format, storage_type, coded_size, visible_rect,
828 natural_size)) { 872 natural_size)) {
829 LOG(DFATAL) << __func__ << " Invalid config." 873 LOG(DFATAL) << __func__ << " Invalid config."
830 << ConfigToString(format, storage_type, coded_size, 874 << ConfigToString(format, storage_type, coded_size,
831 visible_rect, natural_size); 875 visible_rect, natural_size);
832 return nullptr; 876 return nullptr;
833 } 877 }
834 878
835 scoped_refptr<VideoFrame> frame; 879 scoped_refptr<VideoFrame> frame;
836 if (storage_type == STORAGE_SHMEM) { 880 if (storage_type == STORAGE_SHMEM) {
837 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, 881 frame = new VideoFrame(format, storage_type, coded_size, visible_rect,
838 natural_size, timestamp, handle, data_offset); 882 natural_size, timestamp, handle, data_offset);
839 } else { 883 } else {
840 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, 884 frame = new VideoFrame(format, storage_type, coded_size, visible_rect,
841 natural_size, timestamp); 885 natural_size, timestamp);
842 } 886 }
887 if (format == PIXEL_FORMAT_Y16) {
888 DCHECK_EQ(NumPlanes(format), 1U);
889 const size_t i = 0;
890 frame->strides_[i] = coded_size.width() * BytesPerElement(format, i);
891 frame->data_[i] = data;
892 return frame;
893 }
843 frame->strides_[kYPlane] = coded_size.width(); 894 frame->strides_[kYPlane] = coded_size.width();
844 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() 895 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes()
845 // always rounds up. This inconsistency must be resolved. Perhaps a 896 // always rounds up. This inconsistency must be resolved. Perhaps a
846 // CommonAlignment() check should be made in IsValidConfig()? 897 // CommonAlignment() check should be made in IsValidConfig()?
847 // http://crbug.com/555909 898 // http://crbug.com/555909
848 frame->strides_[kUPlane] = coded_size.width() / 2; 899 frame->strides_[kUPlane] = coded_size.width() / 2;
849 frame->strides_[kVPlane] = coded_size.width() / 2; 900 frame->strides_[kVPlane] = coded_size.width() / 2;
850 frame->data_[kYPlane] = data; 901 frame->data_[kYPlane] = data;
851 frame->data_[kUPlane] = data + coded_size.GetArea(); 902 frame->data_[kUPlane] = data + coded_size.GetArea();
852 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); 903 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 case kAPlane: 1064 case kAPlane:
1014 return gfx::Size(1, 1); 1065 return gfx::Size(1, 1);
1015 1066
1016 case kUPlane: // and kUVPlane: 1067 case kUPlane: // and kUVPlane:
1017 case kVPlane: 1068 case kVPlane:
1018 switch (format) { 1069 switch (format) {
1019 case PIXEL_FORMAT_YV24: 1070 case PIXEL_FORMAT_YV24:
1020 case PIXEL_FORMAT_YUV444P9: 1071 case PIXEL_FORMAT_YUV444P9:
1021 case PIXEL_FORMAT_YUV444P10: 1072 case PIXEL_FORMAT_YUV444P10:
1022 case PIXEL_FORMAT_YUV444P12: 1073 case PIXEL_FORMAT_YUV444P12:
1074 case PIXEL_FORMAT_Y8:
1075 case PIXEL_FORMAT_Y16:
1023 return gfx::Size(1, 1); 1076 return gfx::Size(1, 1);
1024 1077
1025 case PIXEL_FORMAT_YV16: 1078 case PIXEL_FORMAT_YV16:
1026 case PIXEL_FORMAT_YUV422P9: 1079 case PIXEL_FORMAT_YUV422P9:
1027 case PIXEL_FORMAT_YUV422P10: 1080 case PIXEL_FORMAT_YUV422P10:
1028 case PIXEL_FORMAT_YUV422P12: 1081 case PIXEL_FORMAT_YUV422P12:
1029 return gfx::Size(2, 1); 1082 return gfx::Size(2, 1);
1030 1083
1031 case PIXEL_FORMAT_YV12: 1084 case PIXEL_FORMAT_YV12:
1032 case PIXEL_FORMAT_I420: 1085 case PIXEL_FORMAT_I420:
1033 case PIXEL_FORMAT_YV12A: 1086 case PIXEL_FORMAT_YV12A:
1034 case PIXEL_FORMAT_NV12: 1087 case PIXEL_FORMAT_NV12:
1035 case PIXEL_FORMAT_NV21: 1088 case PIXEL_FORMAT_NV21:
1036 case PIXEL_FORMAT_MT21: 1089 case PIXEL_FORMAT_MT21:
1037 case PIXEL_FORMAT_YUV420P9: 1090 case PIXEL_FORMAT_YUV420P9:
1038 case PIXEL_FORMAT_YUV420P10: 1091 case PIXEL_FORMAT_YUV420P10:
1039 case PIXEL_FORMAT_YUV420P12: 1092 case PIXEL_FORMAT_YUV420P12:
1040 return gfx::Size(2, 2); 1093 return gfx::Size(2, 2);
1041 1094
1042 case PIXEL_FORMAT_UNKNOWN: 1095 case PIXEL_FORMAT_UNKNOWN:
1043 case PIXEL_FORMAT_UYVY: 1096 case PIXEL_FORMAT_UYVY:
1044 case PIXEL_FORMAT_YUY2: 1097 case PIXEL_FORMAT_YUY2:
1045 case PIXEL_FORMAT_ARGB: 1098 case PIXEL_FORMAT_ARGB:
1046 case PIXEL_FORMAT_XRGB: 1099 case PIXEL_FORMAT_XRGB:
1047 case PIXEL_FORMAT_RGB24: 1100 case PIXEL_FORMAT_RGB24:
1048 case PIXEL_FORMAT_RGB32: 1101 case PIXEL_FORMAT_RGB32:
1049 case PIXEL_FORMAT_MJPEG: 1102 case PIXEL_FORMAT_MJPEG:
1050 case PIXEL_FORMAT_Y8:
1051 case PIXEL_FORMAT_Y16:
1052 break; 1103 break;
1053 } 1104 }
1054 } 1105 }
1055 NOTREACHED(); 1106 NOTREACHED();
1056 return gfx::Size(); 1107 return gfx::Size();
1057 } 1108 }
1058 1109
1059 // static 1110 // static
1060 int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) { 1111 int VideoFrame::BytesPerElement(VideoPixelFormat format, size_t plane) {
1061 DCHECK(IsValidPlane(plane, format)); 1112 DCHECK(IsValidPlane(plane, format));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 if (zero_initialize_memory) 1194 if (zero_initialize_memory)
1144 memset(data, 0, data_size); 1195 memset(data, 0, data_size);
1145 1196
1146 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 1197 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
1147 data_[plane] = data + offset[plane]; 1198 data_[plane] = data + offset[plane];
1148 1199
1149 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 1200 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
1150 } 1201 }
1151 1202
1152 } // namespace media 1203 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/capture/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698