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

Side by Side Diff: webrtc/common_video/libyuv/webrtc_libyuv.cc

Issue 2535643002: Replace some asserts with DCHECKs (Closed)
Patch Set: Don't use the enum hack Created 4 years 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 | « webrtc/common_types.h ('k') | webrtc/common_video/video_render_frames.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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
12 12
13 #include <assert.h>
14 #include <string.h> 13 #include <string.h>
15 14
15 #include "webrtc/base/checks.h"
16
16 // NOTE(ajm): Path provided by gyp. 17 // NOTE(ajm): Path provided by gyp.
17 #include "libyuv.h" // NOLINT 18 #include "libyuv.h" // NOLINT
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) { 22 VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) {
22 switch (type) { 23 switch (type) {
23 case kVideoI420: 24 case kVideoI420:
24 return kI420; 25 return kI420;
25 case kVideoIYUV: 26 case kVideoIYUV:
(...skipping 16 matching lines...) Expand all
42 return kUYVY; 43 return kUYVY;
43 case kVideoNV21: 44 case kVideoNV21:
44 return kNV21; 45 return kNV21;
45 case kVideoNV12: 46 case kVideoNV12:
46 return kNV12; 47 return kNV12;
47 case kVideoBGRA: 48 case kVideoBGRA:
48 return kBGRA; 49 return kBGRA;
49 case kVideoMJPEG: 50 case kVideoMJPEG:
50 return kMJPG; 51 return kMJPG;
51 default: 52 default:
52 assert(false); 53 RTC_NOTREACHED();
53 } 54 }
54 return kUnknown; 55 return kUnknown;
55 } 56 }
56 57
57 size_t CalcBufferSize(VideoType type, int width, int height) { 58 size_t CalcBufferSize(VideoType type, int width, int height) {
58 assert(width >= 0); 59 RTC_DCHECK_GE(width, 0);
59 assert(height >= 0); 60 RTC_DCHECK_GE(height, 0);
60 size_t buffer_size = 0; 61 size_t buffer_size = 0;
61 switch (type) { 62 switch (type) {
62 case kI420: 63 case kI420:
63 case kNV12: 64 case kNV12:
64 case kNV21: 65 case kNV21:
65 case kIYUV: 66 case kIYUV:
66 case kYV12: { 67 case kYV12: {
67 int half_width = (width + 1) >> 1; 68 int half_width = (width + 1) >> 1;
68 int half_height = (height + 1) >> 1; 69 int half_height = (height + 1) >> 1;
69 buffer_size = width * height + half_width * half_height * 2; 70 buffer_size = width * height + half_width * half_height * 2;
70 break; 71 break;
71 } 72 }
72 case kARGB4444: 73 case kARGB4444:
73 case kRGB565: 74 case kRGB565:
74 case kARGB1555: 75 case kARGB1555:
75 case kYUY2: 76 case kYUY2:
76 case kUYVY: 77 case kUYVY:
77 buffer_size = width * height * 2; 78 buffer_size = width * height * 2;
78 break; 79 break;
79 case kRGB24: 80 case kRGB24:
80 buffer_size = width * height * 3; 81 buffer_size = width * height * 3;
81 break; 82 break;
82 case kBGRA: 83 case kBGRA:
83 case kARGB: 84 case kARGB:
84 buffer_size = width * height * 4; 85 buffer_size = width * height * 4;
85 break; 86 break;
86 default: 87 default:
87 assert(false); 88 RTC_NOTREACHED();
88 break; 89 break;
89 } 90 }
90 return buffer_size; 91 return buffer_size;
91 } 92 }
92 93
93 static int PrintPlane(const uint8_t* buf, 94 static int PrintPlane(const uint8_t* buf,
94 int width, 95 int width,
95 int height, 96 int height,
96 int stride, 97 int stride,
97 FILE* file) { 98 FILE* file) {
(...skipping 30 matching lines...) Expand all
128 129
129 int PrintVideoFrame(const VideoFrame& frame, FILE* file) { 130 int PrintVideoFrame(const VideoFrame& frame, FILE* file) {
130 if (frame.IsZeroSize()) 131 if (frame.IsZeroSize())
131 return -1; 132 return -1;
132 return PrintVideoFrame(*frame.video_frame_buffer(), file); 133 return PrintVideoFrame(*frame.video_frame_buffer(), file);
133 } 134 }
134 135
135 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame, 136 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame,
136 size_t size, 137 size_t size,
137 uint8_t* buffer) { 138 uint8_t* buffer) {
138 assert(buffer); 139 RTC_DCHECK(buffer);
139 if (!input_frame) 140 if (!input_frame)
140 return -1; 141 return -1;
141 int width = input_frame->width(); 142 int width = input_frame->width();
142 int height = input_frame->height(); 143 int height = input_frame->height();
143 size_t length = CalcBufferSize(kI420, width, height); 144 size_t length = CalcBufferSize(kI420, width, height);
144 if (size < length) { 145 if (size < length) {
145 return -1; 146 return -1;
146 } 147 }
147 148
148 int chroma_width = (width + 1) / 2; 149 int chroma_width = (width + 1) / 2;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 switch (rotation) { 194 switch (rotation) {
194 case kVideoRotation_0: 195 case kVideoRotation_0:
195 return libyuv::kRotate0; 196 return libyuv::kRotate0;
196 case kVideoRotation_90: 197 case kVideoRotation_90:
197 return libyuv::kRotate90; 198 return libyuv::kRotate90;
198 case kVideoRotation_180: 199 case kVideoRotation_180:
199 return libyuv::kRotate180; 200 return libyuv::kRotate180;
200 case kVideoRotation_270: 201 case kVideoRotation_270:
201 return libyuv::kRotate270; 202 return libyuv::kRotate270;
202 } 203 }
203 assert(false); 204 RTC_NOTREACHED();
204 return libyuv::kRotate0; 205 return libyuv::kRotate0;
205 } 206 }
206 207
207 int ConvertVideoType(VideoType video_type) { 208 int ConvertVideoType(VideoType video_type) {
208 switch (video_type) { 209 switch (video_type) {
209 case kUnknown: 210 case kUnknown:
210 return libyuv::FOURCC_ANY; 211 return libyuv::FOURCC_ANY;
211 case kI420: 212 case kI420:
212 return libyuv::FOURCC_I420; 213 return libyuv::FOURCC_I420;
213 case kIYUV: // same as KYV12 214 case kIYUV: // same as KYV12
(...skipping 17 matching lines...) Expand all
231 return libyuv::FOURCC_NV12; 232 return libyuv::FOURCC_NV12;
232 case kARGB: 233 case kARGB:
233 return libyuv::FOURCC_ARGB; 234 return libyuv::FOURCC_ARGB;
234 case kBGRA: 235 case kBGRA:
235 return libyuv::FOURCC_BGRA; 236 return libyuv::FOURCC_BGRA;
236 case kARGB4444: 237 case kARGB4444:
237 return libyuv::FOURCC_R444; 238 return libyuv::FOURCC_R444;
238 case kARGB1555: 239 case kARGB1555:
239 return libyuv::FOURCC_RGBO; 240 return libyuv::FOURCC_RGBO;
240 } 241 }
241 assert(false); 242 RTC_NOTREACHED();
242 return libyuv::FOURCC_ANY; 243 return libyuv::FOURCC_ANY;
243 } 244 }
244 245
245 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. 246 // TODO(nisse): Delete this wrapper, let callers use libyuv directly.
246 int ConvertToI420(VideoType src_video_type, 247 int ConvertToI420(VideoType src_video_type,
247 const uint8_t* src_frame, 248 const uint8_t* src_frame,
248 int crop_x, 249 int crop_x,
249 int crop_y, 250 int crop_y,
250 int src_width, 251 int src_width,
251 int src_height, 252 int src_height,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 src_v, src_uv_width, 442 src_v, src_uv_width,
442 src_width, src_height, 443 src_width, src_height,
443 dst_y, dst_stride_y, 444 dst_y, dst_stride_y,
444 dst_u, dst_stride_u, 445 dst_u, dst_stride_u,
445 dst_v, dst_stride_v, 446 dst_v, dst_stride_v,
446 dst_width, dst_height, 447 dst_width, dst_height,
447 libyuv::kFilterBox); 448 libyuv::kFilterBox);
448 } 449 }
449 450
450 } // namespace webrtc 451 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_types.h ('k') | webrtc/common_video/video_render_frames.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698