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

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

Issue 2765243002: Delete RawVideoType enum, use the VideoType enum instead. (Closed)
Patch Set: Define constant webrtc::kI420, for backwards compatibility. Created 3 years, 7 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 /* 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 <string.h> 13 #include <string.h>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 // TODO(nisse): Only needed for the deprecated ConvertToI420. 16 // TODO(nisse): Only needed for the deprecated ConvertToI420.
17 #include "webrtc/api/video/i420_buffer.h" 17 #include "webrtc/api/video/i420_buffer.h"
18 18
19 // NOTE(ajm): Path provided by gn. 19 // NOTE(ajm): Path provided by gn.
20 #include "libyuv.h" // NOLINT 20 #include "libyuv.h" // NOLINT
21 21
22 namespace webrtc { 22 namespace webrtc {
23 23
24 VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) {
25 switch (type) {
26 case kVideoI420:
27 return kI420;
28 case kVideoIYUV:
29 return kIYUV;
30 case kVideoRGB24:
31 return kRGB24;
32 case kVideoARGB:
33 return kARGB;
34 case kVideoARGB4444:
35 return kARGB4444;
36 case kVideoRGB565:
37 return kRGB565;
38 case kVideoARGB1555:
39 return kARGB1555;
40 case kVideoYUY2:
41 return kYUY2;
42 case kVideoYV12:
43 return kYV12;
44 case kVideoUYVY:
45 return kUYVY;
46 case kVideoNV21:
47 return kNV21;
48 case kVideoNV12:
49 return kNV12;
50 case kVideoBGRA:
51 return kBGRA;
52 case kVideoMJPEG:
53 return kMJPG;
54 default:
55 RTC_NOTREACHED();
56 }
57 return kUnknown;
58 }
59
60 size_t CalcBufferSize(VideoType type, int width, int height) { 24 size_t CalcBufferSize(VideoType type, int width, int height) {
61 RTC_DCHECK_GE(width, 0); 25 RTC_DCHECK_GE(width, 0);
62 RTC_DCHECK_GE(height, 0); 26 RTC_DCHECK_GE(height, 0);
63 size_t buffer_size = 0; 27 size_t buffer_size = 0;
64 switch (type) { 28 switch (type) {
65 case kI420: 29 case VideoType::kI420:
66 case kNV12: 30 case VideoType::kNV12:
67 case kNV21: 31 case VideoType::kNV21:
68 case kIYUV: 32 case VideoType::kIYUV:
69 case kYV12: { 33 case VideoType::kYV12: {
70 int half_width = (width + 1) >> 1; 34 int half_width = (width + 1) >> 1;
71 int half_height = (height + 1) >> 1; 35 int half_height = (height + 1) >> 1;
72 buffer_size = width * height + half_width * half_height * 2; 36 buffer_size = width * height + half_width * half_height * 2;
73 break; 37 break;
74 } 38 }
75 case kARGB4444: 39 case VideoType::kARGB4444:
76 case kRGB565: 40 case VideoType::kRGB565:
77 case kARGB1555: 41 case VideoType::kARGB1555:
78 case kYUY2: 42 case VideoType::kYUY2:
79 case kUYVY: 43 case VideoType::kUYVY:
80 buffer_size = width * height * 2; 44 buffer_size = width * height * 2;
81 break; 45 break;
82 case kRGB24: 46 case VideoType::kRGB24:
83 buffer_size = width * height * 3; 47 buffer_size = width * height * 3;
84 break; 48 break;
85 case kBGRA: 49 case VideoType::kBGRA:
86 case kARGB: 50 case VideoType::kARGB:
87 buffer_size = width * height * 4; 51 buffer_size = width * height * 4;
88 break; 52 break;
89 default: 53 default:
90 RTC_NOTREACHED(); 54 RTC_NOTREACHED();
91 break; 55 break;
92 } 56 }
93 return buffer_size; 57 return buffer_size;
94 } 58 }
95 59
96 static int PrintPlane(const uint8_t* buf, 60 static int PrintPlane(const uint8_t* buf,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 98 }
135 99
136 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame, 100 int ExtractBuffer(const rtc::scoped_refptr<VideoFrameBuffer>& input_frame,
137 size_t size, 101 size_t size,
138 uint8_t* buffer) { 102 uint8_t* buffer) {
139 RTC_DCHECK(buffer); 103 RTC_DCHECK(buffer);
140 if (!input_frame) 104 if (!input_frame)
141 return -1; 105 return -1;
142 int width = input_frame->width(); 106 int width = input_frame->width();
143 int height = input_frame->height(); 107 int height = input_frame->height();
144 size_t length = CalcBufferSize(kI420, width, height); 108 size_t length = CalcBufferSize(VideoType::kI420, width, height);
145 if (size < length) { 109 if (size < length) {
146 return -1; 110 return -1;
147 } 111 }
148 112
149 int chroma_width = (width + 1) / 2; 113 int chroma_width = (width + 1) / 2;
150 int chroma_height = (height + 1) / 2; 114 int chroma_height = (height + 1) / 2;
151 115
152 libyuv::I420Copy(input_frame->DataY(), 116 libyuv::I420Copy(input_frame->DataY(),
153 input_frame->StrideY(), 117 input_frame->StrideY(),
154 input_frame->DataU(), 118 input_frame->DataU(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 return libyuv::kRotate180; 164 return libyuv::kRotate180;
201 case kVideoRotation_270: 165 case kVideoRotation_270:
202 return libyuv::kRotate270; 166 return libyuv::kRotate270;
203 } 167 }
204 RTC_NOTREACHED(); 168 RTC_NOTREACHED();
205 return libyuv::kRotate0; 169 return libyuv::kRotate0;
206 } 170 }
207 171
208 int ConvertVideoType(VideoType video_type) { 172 int ConvertVideoType(VideoType video_type) {
209 switch (video_type) { 173 switch (video_type) {
210 case kUnknown: 174 case VideoType::kUnknown:
211 return libyuv::FOURCC_ANY; 175 return libyuv::FOURCC_ANY;
212 case kI420: 176 case VideoType::kI420:
213 return libyuv::FOURCC_I420; 177 return libyuv::FOURCC_I420;
214 case kIYUV: // same as KYV12 178 case VideoType::kIYUV: // same as VideoType::kYV12
215 case kYV12: 179 case VideoType::kYV12:
216 return libyuv::FOURCC_YV12; 180 return libyuv::FOURCC_YV12;
217 case kRGB24: 181 case VideoType::kRGB24:
218 return libyuv::FOURCC_24BG; 182 return libyuv::FOURCC_24BG;
219 case kABGR: 183 case VideoType::kABGR:
220 return libyuv::FOURCC_ABGR; 184 return libyuv::FOURCC_ABGR;
221 case kRGB565: 185 case VideoType::kRGB565:
222 return libyuv::FOURCC_RGBP; 186 return libyuv::FOURCC_RGBP;
223 case kYUY2: 187 case VideoType::kYUY2:
224 return libyuv::FOURCC_YUY2; 188 return libyuv::FOURCC_YUY2;
225 case kUYVY: 189 case VideoType::kUYVY:
226 return libyuv::FOURCC_UYVY; 190 return libyuv::FOURCC_UYVY;
227 case kMJPG: 191 case VideoType::kMJPEG:
228 return libyuv::FOURCC_MJPG; 192 return libyuv::FOURCC_MJPG;
229 case kNV21: 193 case VideoType::kNV21:
230 return libyuv::FOURCC_NV21; 194 return libyuv::FOURCC_NV21;
231 case kNV12: 195 case VideoType::kNV12:
232 return libyuv::FOURCC_NV12; 196 return libyuv::FOURCC_NV12;
233 case kARGB: 197 case VideoType::kARGB:
234 return libyuv::FOURCC_ARGB; 198 return libyuv::FOURCC_ARGB;
235 case kBGRA: 199 case VideoType::kBGRA:
236 return libyuv::FOURCC_BGRA; 200 return libyuv::FOURCC_BGRA;
237 case kARGB4444: 201 case VideoType::kARGB4444:
238 return libyuv::FOURCC_R444; 202 return libyuv::FOURCC_R444;
239 case kARGB1555: 203 case VideoType::kARGB1555:
240 return libyuv::FOURCC_RGBO; 204 return libyuv::FOURCC_RGBO;
241 } 205 }
242 RTC_NOTREACHED(); 206 RTC_NOTREACHED();
243 return libyuv::FOURCC_ANY; 207 return libyuv::FOURCC_ANY;
244 } 208 }
245 209
246 // TODO(nisse): Delete this wrapper, let callers use libyuv directly. 210 // TODO(nisse): Delete this wrapper, let callers use libyuv directly.
247 int ConvertToI420(VideoType src_video_type, 211 int ConvertToI420(VideoType src_video_type,
248 const uint8_t* src_frame, 212 const uint8_t* src_frame,
249 int crop_x, 213 int crop_x,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 src_v, src_uv_width, 410 src_v, src_uv_width,
447 src_width, src_height, 411 src_width, src_height,
448 dst_y, dst_stride_y, 412 dst_y, dst_stride_y,
449 dst_u, dst_stride_u, 413 dst_u, dst_stride_u,
450 dst_v, dst_stride_v, 414 dst_v, dst_stride_v,
451 dst_width, dst_height, 415 dst_width, dst_height,
452 libyuv::kFilterBox); 416 libyuv::kFilterBox);
453 } 417 }
454 418
455 } // namespace webrtc 419 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/libyuv/libyuv_unittest.cc ('k') | webrtc/media/engine/webrtcvideocapturer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698