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

Side by Side Diff: content/browser/media/capture/desktop_capture_device_unittest.cc

Issue 1983193002: Decouple capture timestamp and reference time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/media/capture/desktop_capture_device.h" 5 #include "content/browser/media/capture/desktop_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // Use a special value for frame pixels to tell pixel bytes apart from the 53 // Use a special value for frame pixels to tell pixel bytes apart from the
54 // padding bytes in the unpacked frame test. 54 // padding bytes in the unpacked frame test.
55 const uint8_t kFakePixelValue = 1; 55 const uint8_t kFakePixelValue = 1;
56 56
57 // Use a special value for the first pixel to verify the result in the inverted 57 // Use a special value for the first pixel to verify the result in the inverted
58 // frame test. 58 // frame test.
59 const uint8_t kFakePixelValueFirst = 2; 59 const uint8_t kFakePixelValueFirst = 2;
60 60
61 class MockDeviceClient : public media::VideoCaptureDevice::Client { 61 class MockDeviceClient : public media::VideoCaptureDevice::Client {
62 public: 62 public:
63 MOCK_METHOD5(OnIncomingCapturedData, 63 MOCK_METHOD6(OnIncomingCapturedData,
64 void(const uint8_t* data, 64 void(const uint8_t* data,
65 int length, 65 int length,
66 const media::VideoCaptureFormat& frame_format, 66 const media::VideoCaptureFormat& frame_format,
67 int rotation, 67 int rotation,
68 const base::TimeTicks& timestamp)); 68 base::TimeTicks reference_time,
69 MOCK_METHOD9(OnIncomingCapturedYuvData, 69 base::TimeDelta timestamp));
70 void(const uint8_t* y_data,
71 const uint8_t* u_data,
72 const uint8_t* v_data,
73 size_t y_stride,
74 size_t u_stride,
75 size_t v_stride,
76 const media::VideoCaptureFormat& frame_format,
77 int clockwise_rotation,
78 const base::TimeTicks& timestamp));
79 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); 70 MOCK_METHOD0(DoReserveOutputBuffer, void(void));
80 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 71 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
81 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); 72 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void));
82 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); 73 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void));
83 MOCK_METHOD2(OnError, 74 MOCK_METHOD2(OnError,
84 void(const tracked_objects::Location& from_here, 75 void(const tracked_objects::Location& from_here,
85 const std::string& reason)); 76 const std::string& reason));
86 77
87 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. 78 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>.
88 std::unique_ptr<Buffer> ReserveOutputBuffer( 79 std::unique_ptr<Buffer> ReserveOutputBuffer(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } // namespace 253 } // namespace
263 254
264 class DesktopCaptureDeviceTest : public testing::Test { 255 class DesktopCaptureDeviceTest : public testing::Test {
265 public: 256 public:
266 void CreateScreenCaptureDevice( 257 void CreateScreenCaptureDevice(
267 std::unique_ptr<webrtc::DesktopCapturer> capturer) { 258 std::unique_ptr<webrtc::DesktopCapturer> capturer) {
268 capture_device_.reset(new DesktopCaptureDevice( 259 capture_device_.reset(new DesktopCaptureDevice(
269 std::move(capturer), DesktopMediaID::TYPE_SCREEN)); 260 std::move(capturer), DesktopMediaID::TYPE_SCREEN));
270 } 261 }
271 262
272 void CopyFrame(const uint8_t* frame, int size, 263 void CopyFrame(const uint8_t* frame,
273 const media::VideoCaptureFormat&, int, base::TimeTicks) { 264 int size,
265 const media::VideoCaptureFormat&,
266 int,
267 base::TimeTicks,
268 base::TimeDelta) {
274 ASSERT_TRUE(output_frame_); 269 ASSERT_TRUE(output_frame_);
275 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size); 270 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size);
276 memcpy(output_frame_->data(), frame, size); 271 memcpy(output_frame_->data(), frame, size);
277 } 272 }
278 273
279 protected: 274 protected:
280 std::unique_ptr<DesktopCaptureDevice> capture_device_; 275 std::unique_ptr<DesktopCaptureDevice> capture_device_;
281 std::unique_ptr<webrtc::DesktopFrame> output_frame_; 276 std::unique_ptr<webrtc::DesktopFrame> output_frame_;
282 }; 277 };
283 278
(...skipping 10 matching lines...) Expand all
294 webrtc::ScreenCapturer::Create( 289 webrtc::ScreenCapturer::Create(
295 webrtc::DesktopCaptureOptions::CreateDefault())); 290 webrtc::DesktopCaptureOptions::CreateDefault()));
296 CreateScreenCaptureDevice(std::move(capturer)); 291 CreateScreenCaptureDevice(std::move(capturer));
297 292
298 media::VideoCaptureFormat format; 293 media::VideoCaptureFormat format;
299 base::WaitableEvent done_event(false, false); 294 base::WaitableEvent done_event(false, false);
300 int frame_size; 295 int frame_size;
301 296
302 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 297 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
303 EXPECT_CALL(*client, OnError(_, _)).Times(0); 298 EXPECT_CALL(*client, OnError(_, _)).Times(0);
304 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 299 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
305 DoAll(SaveArg<1>(&frame_size), 300 .WillRepeatedly(
306 SaveArg<2>(&format), 301 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format),
307 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 302 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
308 303
309 media::VideoCaptureParams capture_params; 304 media::VideoCaptureParams capture_params;
310 capture_params.requested_format.frame_size.SetSize(640, 480); 305 capture_params.requested_format.frame_size.SetSize(640, 480);
311 capture_params.requested_format.frame_rate = kFrameRate; 306 capture_params.requested_format.frame_rate = kFrameRate;
312 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 307 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
313 capture_device_->AllocateAndStart(capture_params, std::move(client)); 308 capture_device_->AllocateAndStart(capture_params, std::move(client));
314 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 309 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
315 capture_device_->StopAndDeAllocate(); 310 capture_device_->StopAndDeAllocate();
316 311
317 EXPECT_GT(format.frame_size.width(), 0); 312 EXPECT_GT(format.frame_size.width(), 0);
(...skipping 11 matching lines...) Expand all
329 324
330 CreateScreenCaptureDevice( 325 CreateScreenCaptureDevice(
331 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 326 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
332 327
333 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), 328 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1),
334 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); 329 gfx::Size(kTestFrameWidth1, kTestFrameHeight1));
335 base::WaitableEvent done_event(false, false); 330 base::WaitableEvent done_event(false, false);
336 331
337 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 332 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
338 EXPECT_CALL(*client, OnError(_, _)).Times(0); 333 EXPECT_CALL(*client, OnError(_, _)).Times(0);
339 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 334 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
340 DoAll(WithArg<2>(Invoke(&format_checker, 335 .WillRepeatedly(
341 &FormatChecker::ExpectAcceptableSize)), 336 DoAll(WithArg<2>(Invoke(&format_checker,
342 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 337 &FormatChecker::ExpectAcceptableSize)),
338 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
343 339
344 media::VideoCaptureParams capture_params; 340 media::VideoCaptureParams capture_params;
345 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 341 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
346 kTestFrameHeight1); 342 kTestFrameHeight1);
347 capture_params.requested_format.frame_rate = kFrameRate; 343 capture_params.requested_format.frame_rate = kFrameRate;
348 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 344 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
349 capture_params.resolution_change_policy = 345 capture_params.resolution_change_policy =
350 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 346 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
351 347
352 capture_device_->AllocateAndStart(capture_params, std::move(client)); 348 capture_device_->AllocateAndStart(capture_params, std::move(client));
(...skipping 17 matching lines...) Expand all
370 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 366 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
371 367
372 CreateScreenCaptureDevice( 368 CreateScreenCaptureDevice(
373 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 369 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
374 370
375 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); 371 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300));
376 base::WaitableEvent done_event(false, false); 372 base::WaitableEvent done_event(false, false);
377 373
378 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 374 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
379 EXPECT_CALL(*client, OnError(_,_)).Times(0); 375 EXPECT_CALL(*client, OnError(_,_)).Times(0);
380 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 376 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
381 DoAll(WithArg<2>(Invoke(&format_checker, 377 .WillRepeatedly(
382 &FormatChecker::ExpectAcceptableSize)), 378 DoAll(WithArg<2>(Invoke(&format_checker,
383 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 379 &FormatChecker::ExpectAcceptableSize)),
380 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
384 381
385 media::VideoCaptureParams capture_params; 382 media::VideoCaptureParams capture_params;
386 const gfx::Size high_def_16_by_9(1920, 1080); 383 const gfx::Size high_def_16_by_9(1920, 1080);
387 ASSERT_GE(high_def_16_by_9.width(), 384 ASSERT_GE(high_def_16_by_9.width(),
388 std::max(kTestFrameWidth1, kTestFrameWidth2)); 385 std::max(kTestFrameWidth1, kTestFrameWidth2));
389 ASSERT_GE(high_def_16_by_9.height(), 386 ASSERT_GE(high_def_16_by_9.height(),
390 std::max(kTestFrameHeight1, kTestFrameHeight2)); 387 std::max(kTestFrameHeight1, kTestFrameHeight2));
391 capture_params.requested_format.frame_size = high_def_16_by_9; 388 capture_params.requested_format.frame_size = high_def_16_by_9;
392 capture_params.requested_format.frame_rate = kFrameRate; 389 capture_params.requested_format.frame_rate = kFrameRate;
393 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 390 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
(...skipping 21 matching lines...) Expand all
415 412
416 CreateScreenCaptureDevice( 413 CreateScreenCaptureDevice(
417 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 414 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
418 415
419 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), 416 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1),
420 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); 417 gfx::Size(kTestFrameWidth2, kTestFrameHeight2));
421 base::WaitableEvent done_event(false, false); 418 base::WaitableEvent done_event(false, false);
422 419
423 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 420 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
424 EXPECT_CALL(*client, OnError(_,_)).Times(0); 421 EXPECT_CALL(*client, OnError(_,_)).Times(0);
425 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 422 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
426 DoAll(WithArg<2>(Invoke(&format_checker, 423 .WillRepeatedly(
427 &FormatChecker::ExpectAcceptableSize)), 424 DoAll(WithArg<2>(Invoke(&format_checker,
428 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 425 &FormatChecker::ExpectAcceptableSize)),
426 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
429 427
430 media::VideoCaptureParams capture_params; 428 media::VideoCaptureParams capture_params;
431 const gfx::Size high_def_16_by_9(1920, 1080); 429 const gfx::Size high_def_16_by_9(1920, 1080);
432 ASSERT_GE(high_def_16_by_9.width(), 430 ASSERT_GE(high_def_16_by_9.width(),
433 std::max(kTestFrameWidth1, kTestFrameWidth2)); 431 std::max(kTestFrameWidth1, kTestFrameWidth2));
434 ASSERT_GE(high_def_16_by_9.height(), 432 ASSERT_GE(high_def_16_by_9.height(),
435 std::max(kTestFrameHeight1, kTestFrameHeight2)); 433 std::max(kTestFrameHeight1, kTestFrameHeight2));
436 capture_params.requested_format.frame_size = high_def_16_by_9; 434 capture_params.requested_format.frame_size = high_def_16_by_9;
437 capture_params.requested_format.frame_rate = kFrameRate; 435 capture_params.requested_format.frame_rate = kFrameRate;
438 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 436 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
(...skipping 23 matching lines...) Expand all
462 460
463 media::VideoCaptureFormat format; 461 media::VideoCaptureFormat format;
464 base::WaitableEvent done_event(false, false); 462 base::WaitableEvent done_event(false, false);
465 463
466 int frame_size = 0; 464 int frame_size = 0;
467 output_frame_.reset(new webrtc::BasicDesktopFrame( 465 output_frame_.reset(new webrtc::BasicDesktopFrame(
468 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 466 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)));
469 467
470 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 468 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
471 EXPECT_CALL(*client, OnError(_,_)).Times(0); 469 EXPECT_CALL(*client, OnError(_,_)).Times(0);
472 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 470 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
473 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), 471 .WillRepeatedly(
474 SaveArg<1>(&frame_size), 472 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame),
475 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 473 SaveArg<1>(&frame_size),
474 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
476 475
477 media::VideoCaptureParams capture_params; 476 media::VideoCaptureParams capture_params;
478 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 477 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
479 kTestFrameHeight1); 478 kTestFrameHeight1);
480 capture_params.requested_format.frame_rate = kFrameRate; 479 capture_params.requested_format.frame_rate = kFrameRate;
481 capture_params.requested_format.pixel_format = 480 capture_params.requested_format.pixel_format =
482 media::PIXEL_FORMAT_I420; 481 media::PIXEL_FORMAT_I420;
483 482
484 capture_device_->AllocateAndStart(capture_params, std::move(client)); 483 capture_device_->AllocateAndStart(capture_params, std::move(client));
485 484
(...skipping 20 matching lines...) Expand all
506 505
507 media::VideoCaptureFormat format; 506 media::VideoCaptureFormat format;
508 base::WaitableEvent done_event(false, false); 507 base::WaitableEvent done_event(false, false);
509 508
510 int frame_size = 0; 509 int frame_size = 0;
511 output_frame_.reset(new webrtc::BasicDesktopFrame( 510 output_frame_.reset(new webrtc::BasicDesktopFrame(
512 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 511 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)));
513 512
514 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 513 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
515 EXPECT_CALL(*client, OnError(_,_)).Times(0); 514 EXPECT_CALL(*client, OnError(_,_)).Times(0);
516 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 515 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _))
517 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), 516 .WillRepeatedly(
518 SaveArg<1>(&frame_size), 517 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame),
519 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 518 SaveArg<1>(&frame_size),
519 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
520 520
521 media::VideoCaptureParams capture_params; 521 media::VideoCaptureParams capture_params;
522 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 522 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
523 kTestFrameHeight1); 523 kTestFrameHeight1);
524 capture_params.requested_format.frame_rate = kFrameRate; 524 capture_params.requested_format.frame_rate = kFrameRate;
525 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 525 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
526 526
527 capture_device_->AllocateAndStart(capture_params, std::move(client)); 527 capture_device_->AllocateAndStart(capture_params, std::move(client));
528 528
529 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 529 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
530 done_event.Reset(); 530 done_event.Reset();
531 capture_device_->StopAndDeAllocate(); 531 capture_device_->StopAndDeAllocate();
532 532
533 // Verifies that |output_frame_| has the same pixel values as the inverted 533 // Verifies that |output_frame_| has the same pixel values as the inverted
534 // frame. 534 // frame.
535 std::unique_ptr<webrtc::DesktopFrame> inverted_frame( 535 std::unique_ptr<webrtc::DesktopFrame> inverted_frame(
536 new InvertedDesktopFrame(CreateBasicFrame( 536 new InvertedDesktopFrame(CreateBasicFrame(
537 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)))); 537 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))));
538 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), 538 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(),
539 frame_size); 539 frame_size);
540 for (int i = 0; i < output_frame_->size().height(); ++i) { 540 for (int i = 0; i < output_frame_->size().height(); ++i) {
541 EXPECT_EQ(0, 541 EXPECT_EQ(0,
542 memcmp(inverted_frame->data() + i * inverted_frame->stride(), 542 memcmp(inverted_frame->data() + i * inverted_frame->stride(),
543 output_frame_->data() + i * output_frame_->stride(), 543 output_frame_->data() + i * output_frame_->stride(),
544 output_frame_->stride())); 544 output_frame_->stride()));
545 } 545 }
546 } 546 }
547 547
548 } // namespace content 548 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698