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

Side by Side Diff: webrtc/common_video/i420_video_frame_unittest.cc

Issue 2477233004: Update VideoFrameBuffer-related methods to not use references to scoped_refptr. (Closed)
Patch Set: Fix memory leak. 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 | webrtc/common_video/include/video_frame_buffer.h » ('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
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 const int kSizeY = 400; 144 const int kSizeY = 400;
145 const int kSizeU = 100; 145 const int kSizeU = 100;
146 const int kSizeV = 100; 146 const int kSizeV = 100;
147 const VideoRotation kRotation = kVideoRotation_270; 147 const VideoRotation kRotation = kVideoRotation_270;
148 uint8_t buffer_y[kSizeY]; 148 uint8_t buffer_y[kSizeY];
149 uint8_t buffer_u[kSizeU]; 149 uint8_t buffer_u[kSizeU];
150 uint8_t buffer_v[kSizeV]; 150 uint8_t buffer_v[kSizeV];
151 memset(buffer_y, 16, kSizeY); 151 memset(buffer_y, 16, kSizeY);
152 memset(buffer_u, 8, kSizeU); 152 memset(buffer_u, 8, kSizeU);
153 memset(buffer_v, 4, kSizeV); 153 memset(buffer_v, 4, kSizeV);
154 // TODO(nisse): This new + Copy looks quite awkward. Consider adding
155 // an alternative I420Buffer::Create method.
154 VideoFrame frame1( 156 VideoFrame frame1(
155 I420Buffer::Copy(new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( 157 I420Buffer::Copy(*rtc::scoped_refptr<VideoFrameBuffer>(
nisse-webrtc 2016/11/10 15:19:54 This was a bit subtle. Just creating a temporary R
156 width, height, 158 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
157 buffer_y, stride_y, 159 width, height,
158 buffer_u, stride_u, 160 buffer_y, stride_y,
159 buffer_v, stride_v, 161 buffer_u, stride_u,
160 rtc::Callback0<void>([](){}))), 162 buffer_v, stride_v,
163 rtc::Callback0<void>([](){})))),
161 kRotation, 0); 164 kRotation, 0);
162 frame1.set_timestamp(timestamp); 165 frame1.set_timestamp(timestamp);
163 frame1.set_ntp_time_ms(ntp_time_ms); 166 frame1.set_ntp_time_ms(ntp_time_ms);
164 frame1.set_render_time_ms(render_time_ms); 167 frame1.set_render_time_ms(render_time_ms);
165 VideoFrame frame2(frame1); 168 VideoFrame frame2(frame1);
166 169
167 EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer()); 170 EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer());
168 EXPECT_EQ(frame1.video_frame_buffer()->DataY(), 171 EXPECT_EQ(frame1.video_frame_buffer()->DataY(),
169 frame2.video_frame_buffer()->DataY()); 172 frame2.video_frame_buffer()->DataY());
170 EXPECT_EQ(frame1.video_frame_buffer()->DataU(), 173 EXPECT_EQ(frame1.video_frame_buffer()->DataU(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 frame.set_render_time_ms(20); 207 frame.set_render_time_ms(20);
205 EXPECT_EQ(20, frame.render_time_ms()); 208 EXPECT_EQ(20, frame.render_time_ms());
206 } 209 }
207 210
208 TEST(TestI420FrameBuffer, Copy) { 211 TEST(TestI420FrameBuffer, Copy) {
209 rtc::scoped_refptr<I420Buffer> buf1( 212 rtc::scoped_refptr<I420Buffer> buf1(
210 I420Buffer::Create(20, 10)); 213 I420Buffer::Create(20, 10));
211 memset(buf1->MutableDataY(), 1, 200); 214 memset(buf1->MutableDataY(), 1, 200);
212 memset(buf1->MutableDataU(), 2, 50); 215 memset(buf1->MutableDataU(), 2, 50);
213 memset(buf1->MutableDataV(), 3, 50); 216 memset(buf1->MutableDataV(), 3, 50);
214 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 217 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(*buf1);
215 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 218 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
216 } 219 }
217 220
218 TEST(TestI420FrameBuffer, Scale) { 221 TEST(TestI420FrameBuffer, Scale) {
219 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 222 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
220 223
221 // Pure scaling, no cropping. 224 // Pure scaling, no cropping.
222 rtc::scoped_refptr<I420Buffer> scaled_buffer( 225 rtc::scoped_refptr<I420Buffer> scaled_buffer(
223 I420Buffer::Create(150, 75)); 226 I420Buffer::Create(150, 75));
224 227
225 scaled_buffer->ScaleFrom(buf); 228 scaled_buffer->ScaleFrom(*buf);
226 CheckCrop(*scaled_buffer, 0.0, 0.0, 1.0, 1.0); 229 CheckCrop(*scaled_buffer, 0.0, 0.0, 1.0, 1.0);
227 } 230 }
228 231
229 TEST(TestI420FrameBuffer, CropXCenter) { 232 TEST(TestI420FrameBuffer, CropXCenter) {
230 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 233 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
231 234
232 // Pure center cropping, no scaling. 235 // Pure center cropping, no scaling.
233 rtc::scoped_refptr<I420Buffer> scaled_buffer( 236 rtc::scoped_refptr<I420Buffer> scaled_buffer(
234 I420Buffer::Create(100, 100)); 237 I420Buffer::Create(100, 100));
235 238
236 scaled_buffer->CropAndScaleFrom(buf, 50, 0, 100, 100); 239 scaled_buffer->CropAndScaleFrom(*buf, 50, 0, 100, 100);
237 CheckCrop(*scaled_buffer, 0.25, 0.0, 0.5, 1.0); 240 CheckCrop(*scaled_buffer, 0.25, 0.0, 0.5, 1.0);
238 } 241 }
239 242
240 TEST(TestI420FrameBuffer, CropXNotCenter) { 243 TEST(TestI420FrameBuffer, CropXNotCenter) {
241 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 244 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
242 245
243 // Non-center cropping, no scaling. 246 // Non-center cropping, no scaling.
244 rtc::scoped_refptr<I420Buffer> scaled_buffer( 247 rtc::scoped_refptr<I420Buffer> scaled_buffer(
245 I420Buffer::Create(100, 100)); 248 I420Buffer::Create(100, 100));
246 249
247 scaled_buffer->CropAndScaleFrom(buf, 25, 0, 100, 100); 250 scaled_buffer->CropAndScaleFrom(*buf, 25, 0, 100, 100);
248 CheckCrop(*scaled_buffer, 0.125, 0.0, 0.5, 1.0); 251 CheckCrop(*scaled_buffer, 0.125, 0.0, 0.5, 1.0);
249 } 252 }
250 253
251 TEST(TestI420FrameBuffer, CropYCenter) { 254 TEST(TestI420FrameBuffer, CropYCenter) {
252 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 255 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
253 256
254 // Pure center cropping, no scaling. 257 // Pure center cropping, no scaling.
255 rtc::scoped_refptr<I420Buffer> scaled_buffer( 258 rtc::scoped_refptr<I420Buffer> scaled_buffer(
256 I420Buffer::Create(100, 100)); 259 I420Buffer::Create(100, 100));
257 260
258 scaled_buffer->CropAndScaleFrom(buf, 0, 50, 100, 100); 261 scaled_buffer->CropAndScaleFrom(*buf, 0, 50, 100, 100);
259 CheckCrop(*scaled_buffer, 0.0, 0.25, 1.0, 0.5); 262 CheckCrop(*scaled_buffer, 0.0, 0.25, 1.0, 0.5);
260 } 263 }
261 264
262 TEST(TestI420FrameBuffer, CropYNotCenter) { 265 TEST(TestI420FrameBuffer, CropYNotCenter) {
263 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 266 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
264 267
265 // Non-center cropping, no scaling. 268 // Non-center cropping, no scaling.
266 rtc::scoped_refptr<I420Buffer> scaled_buffer( 269 rtc::scoped_refptr<I420Buffer> scaled_buffer(
267 I420Buffer::Create(100, 100)); 270 I420Buffer::Create(100, 100));
268 271
269 scaled_buffer->CropAndScaleFrom(buf, 0, 25, 100, 100); 272 scaled_buffer->CropAndScaleFrom(*buf, 0, 25, 100, 100);
270 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.5); 273 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.5);
271 } 274 }
272 275
273 TEST(TestI420FrameBuffer, CropAndScale16x9) { 276 TEST(TestI420FrameBuffer, CropAndScale16x9) {
274 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480); 277 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480);
275 278
276 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. 279 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2.
277 rtc::scoped_refptr<I420Buffer> scaled_buffer( 280 rtc::scoped_refptr<I420Buffer> scaled_buffer(
278 I420Buffer::Create(320, 180)); 281 I420Buffer::Create(320, 180));
279 282
280 scaled_buffer->CropAndScaleFrom(buf); 283 scaled_buffer->CropAndScaleFrom(*buf);
281 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75); 284 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75);
282 } 285 }
283 286
284 class TestI420BufferRotate 287 class TestI420BufferRotate
285 : public ::testing::TestWithParam<webrtc::VideoRotation> {}; 288 : public ::testing::TestWithParam<webrtc::VideoRotation> {};
286 289
287 TEST_P(TestI420BufferRotate, Rotates) { 290 TEST_P(TestI420BufferRotate, Rotates) {
288 rtc::scoped_refptr<VideoFrameBuffer> buffer = CreateGradient(640, 480); 291 rtc::scoped_refptr<VideoFrameBuffer> buffer = CreateGradient(640, 480);
289 rtc::scoped_refptr<VideoFrameBuffer> rotated_buffer = 292 rtc::scoped_refptr<VideoFrameBuffer> rotated_buffer =
290 I420Buffer::Rotate(buffer, GetParam()); 293 I420Buffer::Rotate(buffer, GetParam());
291 CheckRotate(640, 480, GetParam(), *rotated_buffer); 294 CheckRotate(640, 480, GetParam(), *rotated_buffer);
292 } 295 }
293 296
294 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate, 297 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate,
295 ::testing::Values(kVideoRotation_0, 298 ::testing::Values(kVideoRotation_0,
296 kVideoRotation_90, 299 kVideoRotation_90,
297 kVideoRotation_180, 300 kVideoRotation_180,
298 kVideoRotation_270)); 301 kVideoRotation_270));
299 302
300 } // namespace webrtc 303 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/common_video/include/video_frame_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698