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

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

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fixes for failing bots 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
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_METHOD6(OnIncomingCapturedData, 63 MOCK_METHOD7(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 base::TimeTicks reference_time, 68 base::TimeTicks reference_time,
69 base::TimeDelta timestamp)); 69 base::TimeDelta timestamp,
70 int frame_id));
70 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); 71 MOCK_METHOD0(DoReserveOutputBuffer, void(void));
71 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 72 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
72 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); 73 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void));
73 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); 74 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void));
74 MOCK_METHOD2(OnError, 75 MOCK_METHOD2(OnError,
75 void(const tracked_objects::Location& from_here, 76 void(const tracked_objects::Location& from_here,
76 const std::string& reason)); 77 const std::string& reason));
77 78
78 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. 79 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>.
79 std::unique_ptr<Buffer> ReserveOutputBuffer( 80 std::unique_ptr<Buffer> ReserveOutputBuffer(
80 const gfx::Size& dimensions, 81 const gfx::Size& dimensions,
81 media::VideoPixelFormat format, 82 media::VideoPixelFormat format,
82 media::VideoPixelStorage storage) override { 83 media::VideoPixelStorage storage) override {
83 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 && 84 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 &&
84 storage == media::PIXEL_STORAGE_CPU); 85 storage == media::PIXEL_STORAGE_CPU);
85 DoReserveOutputBuffer(); 86 DoReserveOutputBuffer();
86 return std::unique_ptr<Buffer>(); 87 return std::unique_ptr<Buffer>();
87 } 88 }
88 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, 89 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
89 const media::VideoCaptureFormat& frame_format, 90 const media::VideoCaptureFormat& format,
90 base::TimeTicks reference_time, 91 base::TimeTicks reference_time,
91 base::TimeDelta timestamp) override { 92 base::TimeDelta timestamp,
93 int frame_id) override {
92 DoOnIncomingCapturedBuffer(); 94 DoOnIncomingCapturedBuffer();
93 } 95 }
94 void OnIncomingCapturedVideoFrame( 96 void OnIncomingCapturedVideoFrame(
95 std::unique_ptr<Buffer> buffer, 97 std::unique_ptr<Buffer> buffer,
96 scoped_refptr<media::VideoFrame> frame) override { 98 scoped_refptr<media::VideoFrame> frame,
99 int frame_id) override {
97 DoOnIncomingCapturedVideoFrame(); 100 DoOnIncomingCapturedVideoFrame();
98 } 101 }
99 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( 102 std::unique_ptr<Buffer> ResurrectLastOutputBuffer(
100 const gfx::Size& dimensions, 103 const gfx::Size& dimensions,
101 media::VideoPixelFormat format, 104 media::VideoPixelFormat format,
102 media::VideoPixelStorage storage) override { 105 media::VideoPixelStorage storage) override {
103 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 && 106 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 &&
104 storage == media::PIXEL_STORAGE_CPU); 107 storage == media::PIXEL_STORAGE_CPU);
105 DoResurrectLastOutputBuffer(); 108 DoResurrectLastOutputBuffer();
106 return std::unique_ptr<Buffer>(); 109 return std::unique_ptr<Buffer>();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 std::unique_ptr<webrtc::DesktopCapturer> capturer) { 260 std::unique_ptr<webrtc::DesktopCapturer> capturer) {
258 capture_device_.reset(new DesktopCaptureDevice( 261 capture_device_.reset(new DesktopCaptureDevice(
259 std::move(capturer), DesktopMediaID::TYPE_SCREEN)); 262 std::move(capturer), DesktopMediaID::TYPE_SCREEN));
260 } 263 }
261 264
262 void CopyFrame(const uint8_t* frame, 265 void CopyFrame(const uint8_t* frame,
263 int size, 266 int size,
264 const media::VideoCaptureFormat&, 267 const media::VideoCaptureFormat&,
265 int, 268 int,
266 base::TimeTicks, 269 base::TimeTicks,
267 base::TimeDelta) { 270 base::TimeDelta,
271 int) {
268 ASSERT_TRUE(output_frame_); 272 ASSERT_TRUE(output_frame_);
269 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size); 273 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size);
270 memcpy(output_frame_->data(), frame, size); 274 memcpy(output_frame_->data(), frame, size);
271 } 275 }
272 276
273 protected: 277 protected:
274 std::unique_ptr<DesktopCaptureDevice> capture_device_; 278 std::unique_ptr<DesktopCaptureDevice> capture_device_;
275 std::unique_ptr<webrtc::DesktopFrame> output_frame_; 279 std::unique_ptr<webrtc::DesktopFrame> output_frame_;
276 }; 280 };
277 281
(...skipping 12 matching lines...) Expand all
290 CreateScreenCaptureDevice(std::move(capturer)); 294 CreateScreenCaptureDevice(std::move(capturer));
291 295
292 media::VideoCaptureFormat format; 296 media::VideoCaptureFormat format;
293 base::WaitableEvent done_event( 297 base::WaitableEvent done_event(
294 base::WaitableEvent::ResetPolicy::AUTOMATIC, 298 base::WaitableEvent::ResetPolicy::AUTOMATIC,
295 base::WaitableEvent::InitialState::NOT_SIGNALED); 299 base::WaitableEvent::InitialState::NOT_SIGNALED);
296 int frame_size; 300 int frame_size;
297 301
298 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 302 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
299 EXPECT_CALL(*client, OnError(_, _)).Times(0); 303 EXPECT_CALL(*client, OnError(_, _)).Times(0);
300 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 304 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
301 .WillRepeatedly( 305 .WillRepeatedly(
302 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format), 306 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format),
303 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 307 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
304 308
305 media::VideoCaptureParams capture_params; 309 media::VideoCaptureParams capture_params;
306 capture_params.requested_format.frame_size.SetSize(640, 480); 310 capture_params.requested_format.frame_size.SetSize(640, 480);
307 capture_params.requested_format.frame_rate = kFrameRate; 311 capture_params.requested_format.frame_rate = kFrameRate;
308 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 312 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
309 capture_device_->AllocateAndStart(capture_params, std::move(client)); 313 capture_device_->AllocateAndStart(capture_params, std::move(client));
310 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 314 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
(...skipping 16 matching lines...) Expand all
327 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 331 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
328 332
329 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), 333 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1),
330 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); 334 gfx::Size(kTestFrameWidth1, kTestFrameHeight1));
331 base::WaitableEvent done_event( 335 base::WaitableEvent done_event(
332 base::WaitableEvent::ResetPolicy::AUTOMATIC, 336 base::WaitableEvent::ResetPolicy::AUTOMATIC,
333 base::WaitableEvent::InitialState::NOT_SIGNALED); 337 base::WaitableEvent::InitialState::NOT_SIGNALED);
334 338
335 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 339 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
336 EXPECT_CALL(*client, OnError(_, _)).Times(0); 340 EXPECT_CALL(*client, OnError(_, _)).Times(0);
337 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 341 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
338 .WillRepeatedly( 342 .WillRepeatedly(
339 DoAll(WithArg<2>(Invoke(&format_checker, 343 DoAll(WithArg<2>(Invoke(&format_checker,
340 &FormatChecker::ExpectAcceptableSize)), 344 &FormatChecker::ExpectAcceptableSize)),
341 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 345 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
342 346
343 media::VideoCaptureParams capture_params; 347 media::VideoCaptureParams capture_params;
344 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 348 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
345 kTestFrameHeight1); 349 kTestFrameHeight1);
346 capture_params.requested_format.frame_rate = kFrameRate; 350 capture_params.requested_format.frame_rate = kFrameRate;
347 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 351 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
(...skipping 23 matching lines...) Expand all
371 CreateScreenCaptureDevice( 375 CreateScreenCaptureDevice(
372 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 376 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
373 377
374 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); 378 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300));
375 base::WaitableEvent done_event( 379 base::WaitableEvent done_event(
376 base::WaitableEvent::ResetPolicy::AUTOMATIC, 380 base::WaitableEvent::ResetPolicy::AUTOMATIC,
377 base::WaitableEvent::InitialState::NOT_SIGNALED); 381 base::WaitableEvent::InitialState::NOT_SIGNALED);
378 382
379 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 383 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
380 EXPECT_CALL(*client, OnError(_,_)).Times(0); 384 EXPECT_CALL(*client, OnError(_,_)).Times(0);
381 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 385 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
382 .WillRepeatedly( 386 .WillRepeatedly(
383 DoAll(WithArg<2>(Invoke(&format_checker, 387 DoAll(WithArg<2>(Invoke(&format_checker,
384 &FormatChecker::ExpectAcceptableSize)), 388 &FormatChecker::ExpectAcceptableSize)),
385 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 389 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
386 390
387 media::VideoCaptureParams capture_params; 391 media::VideoCaptureParams capture_params;
388 const gfx::Size high_def_16_by_9(1920, 1080); 392 const gfx::Size high_def_16_by_9(1920, 1080);
389 ASSERT_GE(high_def_16_by_9.width(), 393 ASSERT_GE(high_def_16_by_9.width(),
390 std::max(kTestFrameWidth1, kTestFrameWidth2)); 394 std::max(kTestFrameWidth1, kTestFrameWidth2));
391 ASSERT_GE(high_def_16_by_9.height(), 395 ASSERT_GE(high_def_16_by_9.height(),
(...skipping 27 matching lines...) Expand all
419 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); 423 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer));
420 424
421 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), 425 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1),
422 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); 426 gfx::Size(kTestFrameWidth2, kTestFrameHeight2));
423 base::WaitableEvent done_event( 427 base::WaitableEvent done_event(
424 base::WaitableEvent::ResetPolicy::AUTOMATIC, 428 base::WaitableEvent::ResetPolicy::AUTOMATIC,
425 base::WaitableEvent::InitialState::NOT_SIGNALED); 429 base::WaitableEvent::InitialState::NOT_SIGNALED);
426 430
427 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 431 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
428 EXPECT_CALL(*client, OnError(_,_)).Times(0); 432 EXPECT_CALL(*client, OnError(_,_)).Times(0);
429 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 433 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
430 .WillRepeatedly( 434 .WillRepeatedly(
431 DoAll(WithArg<2>(Invoke(&format_checker, 435 DoAll(WithArg<2>(Invoke(&format_checker,
432 &FormatChecker::ExpectAcceptableSize)), 436 &FormatChecker::ExpectAcceptableSize)),
433 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 437 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
434 438
435 media::VideoCaptureParams capture_params; 439 media::VideoCaptureParams capture_params;
436 const gfx::Size high_def_16_by_9(1920, 1080); 440 const gfx::Size high_def_16_by_9(1920, 1080);
437 ASSERT_GE(high_def_16_by_9.width(), 441 ASSERT_GE(high_def_16_by_9.width(),
438 std::max(kTestFrameWidth1, kTestFrameWidth2)); 442 std::max(kTestFrameWidth1, kTestFrameWidth2));
439 ASSERT_GE(high_def_16_by_9.height(), 443 ASSERT_GE(high_def_16_by_9.height(),
(...skipping 29 matching lines...) Expand all
469 base::WaitableEvent done_event( 473 base::WaitableEvent done_event(
470 base::WaitableEvent::ResetPolicy::AUTOMATIC, 474 base::WaitableEvent::ResetPolicy::AUTOMATIC,
471 base::WaitableEvent::InitialState::NOT_SIGNALED); 475 base::WaitableEvent::InitialState::NOT_SIGNALED);
472 476
473 int frame_size = 0; 477 int frame_size = 0;
474 output_frame_.reset(new webrtc::BasicDesktopFrame( 478 output_frame_.reset(new webrtc::BasicDesktopFrame(
475 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 479 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)));
476 480
477 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 481 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
478 EXPECT_CALL(*client, OnError(_,_)).Times(0); 482 EXPECT_CALL(*client, OnError(_,_)).Times(0);
479 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 483 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
480 .WillRepeatedly( 484 .WillRepeatedly(
481 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), 485 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame),
482 SaveArg<1>(&frame_size), 486 SaveArg<1>(&frame_size),
483 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 487 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
484 488
485 media::VideoCaptureParams capture_params; 489 media::VideoCaptureParams capture_params;
486 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 490 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
487 kTestFrameHeight1); 491 kTestFrameHeight1);
488 capture_params.requested_format.frame_rate = kFrameRate; 492 capture_params.requested_format.frame_rate = kFrameRate;
489 capture_params.requested_format.pixel_format = 493 capture_params.requested_format.pixel_format =
(...skipping 26 matching lines...) Expand all
516 base::WaitableEvent done_event( 520 base::WaitableEvent done_event(
517 base::WaitableEvent::ResetPolicy::AUTOMATIC, 521 base::WaitableEvent::ResetPolicy::AUTOMATIC,
518 base::WaitableEvent::InitialState::NOT_SIGNALED); 522 base::WaitableEvent::InitialState::NOT_SIGNALED);
519 523
520 int frame_size = 0; 524 int frame_size = 0;
521 output_frame_.reset(new webrtc::BasicDesktopFrame( 525 output_frame_.reset(new webrtc::BasicDesktopFrame(
522 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 526 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)));
523 527
524 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); 528 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient());
525 EXPECT_CALL(*client, OnError(_,_)).Times(0); 529 EXPECT_CALL(*client, OnError(_,_)).Times(0);
526 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) 530 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
527 .WillRepeatedly( 531 .WillRepeatedly(
528 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), 532 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame),
529 SaveArg<1>(&frame_size), 533 SaveArg<1>(&frame_size),
530 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 534 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
531 535
532 media::VideoCaptureParams capture_params; 536 media::VideoCaptureParams capture_params;
533 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 537 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
534 kTestFrameHeight1); 538 kTestFrameHeight1);
535 capture_params.requested_format.frame_rate = kFrameRate; 539 capture_params.requested_format.frame_rate = kFrameRate;
536 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 540 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
(...skipping 13 matching lines...) Expand all
550 frame_size); 554 frame_size);
551 for (int i = 0; i < output_frame_->size().height(); ++i) { 555 for (int i = 0; i < output_frame_->size().height(); ++i) {
552 EXPECT_EQ(0, 556 EXPECT_EQ(0,
553 memcmp(inverted_frame->data() + i * inverted_frame->stride(), 557 memcmp(inverted_frame->data() + i * inverted_frame->stride(),
554 output_frame_->data() + i * output_frame_->stride(), 558 output_frame_->data() + i * output_frame_->stride(),
555 output_frame_->stride())); 559 output_frame_->stride()));
556 } 560 }
557 } 561 }
558 562
559 } // namespace content 563 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698