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

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

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 8 bpp support added. R200 camera supported. Created 4 years, 5 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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 == 23,
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
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_Y8:
518 case PIXEL_FORMAT_Y16:
517 return 1; 519 return 1;
518 case PIXEL_FORMAT_NV12: 520 case PIXEL_FORMAT_NV12:
519 case PIXEL_FORMAT_NV21: 521 case PIXEL_FORMAT_NV21:
520 case PIXEL_FORMAT_MT21: 522 case PIXEL_FORMAT_MT21:
521 return 2; 523 return 2;
522 case PIXEL_FORMAT_I420: 524 case PIXEL_FORMAT_I420:
523 case PIXEL_FORMAT_YV12: 525 case PIXEL_FORMAT_YV12:
524 case PIXEL_FORMAT_YV16: 526 case PIXEL_FORMAT_YV16:
525 case PIXEL_FORMAT_YV24: 527 case PIXEL_FORMAT_YV24:
526 case PIXEL_FORMAT_YUV420P9: 528 case PIXEL_FORMAT_YUV420P9:
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 const gfx::Size& natural_size, 796 const gfx::Size& natural_size,
795 uint8_t* data, 797 uint8_t* data,
796 size_t data_size, 798 size_t data_size,
797 base::TimeDelta timestamp, 799 base::TimeDelta timestamp,
798 base::SharedMemoryHandle handle, 800 base::SharedMemoryHandle handle,
799 size_t data_offset) { 801 size_t data_offset) {
800 DCHECK(IsStorageTypeMappable(storage_type)); 802 DCHECK(IsStorageTypeMappable(storage_type));
801 803
802 // TODO(miu): This function should support any pixel format. 804 // TODO(miu): This function should support any pixel format.
803 // http://crbug.com/555909 805 // http://crbug.com/555909
804 if (format != PIXEL_FORMAT_I420) { 806 if (format != PIXEL_FORMAT_I420 && format != PIXEL_FORMAT_Y8 &&
805 LOG(DFATAL) << "Only PIXEL_FORMAT_I420 format supported: " 807 format != PIXEL_FORMAT_Y16) {
808 LOG(DFATAL) << "Only PIXEL_FORMAT_I420, PIXEL_FORMAT_Y8 and "
809 "PIXEL_FORMAT_Y16 formats are supported: "
806 << VideoPixelFormatToString(format); 810 << VideoPixelFormatToString(format);
807 return nullptr; 811 return nullptr;
808 } 812 }
809 813
810 if (!IsValidConfig(format, storage_type, coded_size, visible_rect, 814 if (!IsValidConfig(format, storage_type, coded_size, visible_rect,
811 natural_size)) { 815 natural_size)) {
812 LOG(DFATAL) << __FUNCTION__ << " Invalid config." 816 LOG(DFATAL) << __FUNCTION__ << " Invalid config."
813 << ConfigToString(format, storage_type, coded_size, 817 << ConfigToString(format, storage_type, coded_size,
814 visible_rect, natural_size); 818 visible_rect, natural_size);
815 return nullptr; 819 return nullptr;
816 } 820 }
817 821
818 scoped_refptr<VideoFrame> frame; 822 scoped_refptr<VideoFrame> frame;
819 if (storage_type == STORAGE_SHMEM) { 823 if (storage_type == STORAGE_SHMEM) {
820 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, 824 frame = new VideoFrame(format, storage_type, coded_size, visible_rect,
821 natural_size, timestamp, handle, data_offset); 825 natural_size, timestamp, handle, data_offset);
822 } else { 826 } else {
823 frame = new VideoFrame(format, storage_type, coded_size, visible_rect, 827 frame = new VideoFrame(format, storage_type, coded_size, visible_rect,
824 natural_size, timestamp); 828 natural_size, timestamp);
825 } 829 }
830 if (format == PIXEL_FORMAT_Y8 || format == PIXEL_FORMAT_Y16) {
831 // TODO(astojilj) Make this code generic for all and move format specifics
832 // to static methods.
833 DCHECK_EQ(NumPlanes(format), 1);
834 const size_t i = 0;
835 frame->strides_[i] = coded_size.width() * BytesPerElement(format, i);
836 frame->data_[i] = data;
837 return frame;
838 }
826 frame->strides_[kYPlane] = coded_size.width(); 839 frame->strides_[kYPlane] = coded_size.width();
827 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes() 840 // TODO(miu): This always rounds widths down, whereas VideoFrame::RowBytes()
828 // always rounds up. This inconsistency must be resolved. Perhaps a 841 // always rounds up. This inconsistency must be resolved. Perhaps a
829 // CommonAlignment() check should be made in IsValidConfig()? 842 // CommonAlignment() check should be made in IsValidConfig()?
830 // http://crbug.com/555909 843 // http://crbug.com/555909
831 frame->strides_[kUPlane] = coded_size.width() / 2; 844 frame->strides_[kUPlane] = coded_size.width() / 2;
832 frame->strides_[kVPlane] = coded_size.width() / 2; 845 frame->strides_[kVPlane] = coded_size.width() / 2;
833 frame->data_[kYPlane] = data; 846 frame->data_[kYPlane] = data;
834 frame->data_[kUPlane] = data + coded_size.GetArea(); 847 frame->data_[kUPlane] = data + coded_size.GetArea();
835 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); 848 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 case kYPlane: 1008 case kYPlane:
996 case kAPlane: 1009 case kAPlane:
997 return gfx::Size(1, 1); 1010 return gfx::Size(1, 1);
998 1011
999 case kUPlane: // and kUVPlane: 1012 case kUPlane: // and kUVPlane:
1000 case kVPlane: 1013 case kVPlane:
1001 switch (format) { 1014 switch (format) {
1002 case PIXEL_FORMAT_YV24: 1015 case PIXEL_FORMAT_YV24:
1003 case PIXEL_FORMAT_YUV444P9: 1016 case PIXEL_FORMAT_YUV444P9:
1004 case PIXEL_FORMAT_YUV444P10: 1017 case PIXEL_FORMAT_YUV444P10:
1018 case PIXEL_FORMAT_Y8:
1005 return gfx::Size(1, 1); 1019 return gfx::Size(1, 1);
1006 1020
1007 case PIXEL_FORMAT_YV16: 1021 case PIXEL_FORMAT_YV16:
1008 case PIXEL_FORMAT_YUV422P9: 1022 case PIXEL_FORMAT_YUV422P9:
1009 case PIXEL_FORMAT_YUV422P10: 1023 case PIXEL_FORMAT_YUV422P10:
1010 return gfx::Size(2, 1); 1024 return gfx::Size(2, 1);
1011 1025
1012 case PIXEL_FORMAT_YV12: 1026 case PIXEL_FORMAT_YV12:
1013 case PIXEL_FORMAT_I420: 1027 case PIXEL_FORMAT_I420:
1014 case PIXEL_FORMAT_YV12A: 1028 case PIXEL_FORMAT_YV12A:
(...skipping 30 matching lines...) Expand all
1045 case PIXEL_FORMAT_RGB24: 1059 case PIXEL_FORMAT_RGB24:
1046 return 3; 1060 return 3;
1047 case PIXEL_FORMAT_UYVY: 1061 case PIXEL_FORMAT_UYVY:
1048 case PIXEL_FORMAT_YUY2: 1062 case PIXEL_FORMAT_YUY2:
1049 case PIXEL_FORMAT_YUV420P9: 1063 case PIXEL_FORMAT_YUV420P9:
1050 case PIXEL_FORMAT_YUV422P9: 1064 case PIXEL_FORMAT_YUV422P9:
1051 case PIXEL_FORMAT_YUV444P9: 1065 case PIXEL_FORMAT_YUV444P9:
1052 case PIXEL_FORMAT_YUV420P10: 1066 case PIXEL_FORMAT_YUV420P10:
1053 case PIXEL_FORMAT_YUV422P10: 1067 case PIXEL_FORMAT_YUV422P10:
1054 case PIXEL_FORMAT_YUV444P10: 1068 case PIXEL_FORMAT_YUV444P10:
1069 case PIXEL_FORMAT_Y16:
1055 return 2; 1070 return 2;
1056 case PIXEL_FORMAT_NV12: 1071 case PIXEL_FORMAT_NV12:
1057 case PIXEL_FORMAT_NV21: 1072 case PIXEL_FORMAT_NV21:
1058 case PIXEL_FORMAT_MT21: { 1073 case PIXEL_FORMAT_MT21: {
1059 static const int bytes_per_element[] = {1, 2}; 1074 static const int bytes_per_element[] = {1, 2};
1060 DCHECK_LT(plane, arraysize(bytes_per_element)); 1075 DCHECK_LT(plane, arraysize(bytes_per_element));
1061 return bytes_per_element[plane]; 1076 return bytes_per_element[plane];
1062 } 1077 }
1063 case PIXEL_FORMAT_YV12: 1078 case PIXEL_FORMAT_YV12:
1064 case PIXEL_FORMAT_I420: 1079 case PIXEL_FORMAT_I420:
1065 case PIXEL_FORMAT_YV16: 1080 case PIXEL_FORMAT_YV16:
1066 case PIXEL_FORMAT_YV12A: 1081 case PIXEL_FORMAT_YV12A:
1067 case PIXEL_FORMAT_YV24: 1082 case PIXEL_FORMAT_YV24:
1083 case PIXEL_FORMAT_Y8:
1068 return 1; 1084 return 1;
1069 case PIXEL_FORMAT_MJPEG: 1085 case PIXEL_FORMAT_MJPEG:
1070 return 0; 1086 return 0;
1071 case PIXEL_FORMAT_UNKNOWN: 1087 case PIXEL_FORMAT_UNKNOWN:
1072 break; 1088 break;
1073 } 1089 }
1074 NOTREACHED(); 1090 NOTREACHED();
1075 return 0; 1091 return 0;
1076 } 1092 }
1077 1093
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 if (zero_initialize_memory) 1132 if (zero_initialize_memory)
1117 memset(data, 0, data_size); 1133 memset(data, 0, data_size);
1118 1134
1119 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 1135 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
1120 data_[plane] = data + offset[plane]; 1136 data_[plane] = data + offset[plane];
1121 1137
1122 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 1138 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
1123 } 1139 }
1124 1140
1125 } // namespace media 1141 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698