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

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

Issue 2481343002: VideoFrame::AllocationSize test against odd values. (Closed)
Patch Set: #10 fix. Thanks DaleCurtis@. Created 4 years, 1 month 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 | « no previous file | media/base/video_frame_unittest.cc » ('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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 VideoPixelFormat target_format) { 85 VideoPixelFormat target_format) {
86 if (source_format == target_format) 86 if (source_format == target_format)
87 return true; 87 return true;
88 88
89 // It is possible to add other planar to planar format conversions here if the 89 // It is possible to add other planar to planar format conversions here if the
90 // use case is there. 90 // use case is there.
91 return source_format == PIXEL_FORMAT_YV12A && 91 return source_format == PIXEL_FORMAT_YV12A &&
92 target_format == PIXEL_FORMAT_I420; 92 target_format == PIXEL_FORMAT_I420;
93 } 93 }
94 94
95 // If it is required to allocate aligned to multiple-of-two size overall for the
96 // frame of pixel |format|.
97 bool RequiresEvenSizeAllocation(VideoPixelFormat format) {
98 switch (format) {
99 case PIXEL_FORMAT_ARGB:
100 case PIXEL_FORMAT_XRGB:
101 case PIXEL_FORMAT_RGB24:
102 case PIXEL_FORMAT_RGB32:
103 case PIXEL_FORMAT_Y8:
104 case PIXEL_FORMAT_Y16:
105 return false;
106 case PIXEL_FORMAT_NV12:
107 case PIXEL_FORMAT_NV21:
108 case PIXEL_FORMAT_MT21:
109 case PIXEL_FORMAT_I420:
110 case PIXEL_FORMAT_MJPEG:
111 case PIXEL_FORMAT_YUY2:
112 case PIXEL_FORMAT_YV12:
113 case PIXEL_FORMAT_YV16:
114 case PIXEL_FORMAT_YV24:
115 case PIXEL_FORMAT_YUV420P9:
116 case PIXEL_FORMAT_YUV422P9:
117 case PIXEL_FORMAT_YUV444P9:
118 case PIXEL_FORMAT_YUV420P10:
119 case PIXEL_FORMAT_YUV422P10:
120 case PIXEL_FORMAT_YUV444P10:
121 case PIXEL_FORMAT_YUV420P12:
122 case PIXEL_FORMAT_YUV422P12:
123 case PIXEL_FORMAT_YUV444P12:
124 case PIXEL_FORMAT_YV12A:
125 case PIXEL_FORMAT_UYVY:
126 return true;
127 case PIXEL_FORMAT_UNKNOWN:
128 break;
129 }
130 NOTREACHED() << "Unsupported video frame format: " << format;
131 return false;
132 }
133
95 // static 134 // static
96 bool VideoFrame::IsValidConfig(VideoPixelFormat format, 135 bool VideoFrame::IsValidConfig(VideoPixelFormat format,
97 StorageType storage_type, 136 StorageType storage_type,
98 const gfx::Size& coded_size, 137 const gfx::Size& coded_size,
99 const gfx::Rect& visible_rect, 138 const gfx::Rect& visible_rect,
100 const gfx::Size& natural_size) { 139 const gfx::Size& natural_size) {
101 // Check maximum limits for all formats. 140 // Check maximum limits for all formats.
102 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); 141 int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX);
103 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); 142 int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX);
104 static_assert(limits::kMaxCanvas < INT_MAX, ""); 143 static_assert(limits::kMaxCanvas < INT_MAX, "");
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 547 }
509 548
510 // static 549 // static
511 gfx::Size VideoFrame::PlaneSize(VideoPixelFormat format, 550 gfx::Size VideoFrame::PlaneSize(VideoPixelFormat format,
512 size_t plane, 551 size_t plane,
513 const gfx::Size& coded_size) { 552 const gfx::Size& coded_size) {
514 DCHECK(IsValidPlane(plane, format)); 553 DCHECK(IsValidPlane(plane, format));
515 554
516 int width = coded_size.width(); 555 int width = coded_size.width();
517 int height = coded_size.height(); 556 int height = coded_size.height();
518 if (format != PIXEL_FORMAT_ARGB) { 557 if (RequiresEvenSizeAllocation(format)) {
519 // Align to multiple-of-two size overall. This ensures that non-subsampled 558 // Align to multiple-of-two size overall. This ensures that non-subsampled
520 // planes can be addressed by pixel with the same scaling as the subsampled 559 // planes can be addressed by pixel with the same scaling as the subsampled
521 // planes. 560 // planes.
522 width = RoundUp(width, 2); 561 width = RoundUp(width, 2);
523 height = RoundUp(height, 2); 562 height = RoundUp(height, 2);
524 } 563 }
525 564
526 const gfx::Size subsample = SampleSize(format, plane); 565 const gfx::Size subsample = SampleSize(format, plane);
527 DCHECK(width % subsample.width() == 0); 566 DCHECK(width % subsample.width() == 0);
528 DCHECK(height % subsample.height() == 0); 567 DCHECK(height % subsample.height() == 0);
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 if (zero_initialize_memory) 1148 if (zero_initialize_memory)
1110 memset(data, 0, data_size); 1149 memset(data, 0, data_size);
1111 1150
1112 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) 1151 for (size_t plane = 0; plane < NumPlanes(format_); ++plane)
1113 data_[plane] = data + offset[plane]; 1152 data_[plane] = data + offset[plane];
1114 1153
1115 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); 1154 AddDestructionObserver(base::Bind(&base::AlignedFree, data));
1116 } 1155 }
1117 1156
1118 } // namespace media 1157 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698