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

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

Issue 2364413002: Screen Video Capture: Implement suspend optimization. (Closed)
Patch Set: Unwind ScreenCaptureMachineAndroid changes. Created 4 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/web_contents_video_capture_device.h" 5 #include "content/browser/media/capture/web_contents_video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 base::Callback<void(SkColor, const gfx::Size&)> report_callback_; 458 base::Callback<void(SkColor, const gfx::Size&)> report_callback_;
459 base::Closure error_callback_; 459 base::Closure error_callback_;
460 460
461 DISALLOW_COPY_AND_ASSIGN(StubClient); 461 DISALLOW_COPY_AND_ASSIGN(StubClient);
462 }; 462 };
463 463
464 class StubClientObserver { 464 class StubClientObserver {
465 public: 465 public:
466 StubClientObserver() 466 StubClientObserver()
467 : error_encountered_(false), 467 : error_encountered_(false),
468 wait_color_yuv_(0xcafe1950) { 468 wait_color_yuv_(0xcafe1950),
469 expecting_frames_(true) {
469 client_.reset(new StubClient( 470 client_.reset(new StubClient(
470 base::Bind(&StubClientObserver::DidDeliverFrame, 471 base::Bind(&StubClientObserver::DidDeliverFrame,
471 base::Unretained(this)), 472 base::Unretained(this)),
472 base::Bind(&StubClientObserver::OnError, base::Unretained(this)))); 473 base::Bind(&StubClientObserver::OnError, base::Unretained(this))));
473 } 474 }
474 475
475 virtual ~StubClientObserver() {} 476 virtual ~StubClientObserver() {}
476 477
477 std::unique_ptr<media::VideoCaptureDevice::Client> PassClient() { 478 std::unique_ptr<media::VideoCaptureDevice::Client> PassClient() {
478 return std::move(client_); 479 return std::move(client_);
479 } 480 }
480 481
482 void SetIsExpectingFrames(bool expecting_frames) {
483 base::AutoLock guard(lock_);
484 expecting_frames_ = expecting_frames;
485 }
486
481 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) { 487 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) {
482 base::AutoLock guard(lock_); 488 base::AutoLock guard(lock_);
489 EXPECT_TRUE(expecting_frames_);
483 if (error_encountered_ || wait_color_yuv_ == kNotInterested || 490 if (error_encountered_ || wait_color_yuv_ == kNotInterested ||
484 wait_color_yuv_ == color) { 491 wait_color_yuv_ == color) {
485 last_frame_color_yuv_ = color; 492 last_frame_color_yuv_ = color;
486 last_frame_size_ = size; 493 last_frame_size_ = size;
487 base::MessageLoop::current()->QuitWhenIdle(); 494 base::MessageLoop::current()->QuitWhenIdle();
488 } 495 }
489 } 496 }
490 497
491 // Run the current loop until the next frame is delivered. Returns the YUV 498 // Run the current loop until the next frame is delivered. Returns the YUV
492 // color and frame size. 499 // color and frame size.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 size)); 563 size));
557 } 564 }
558 565
559 private: 566 private:
560 base::Lock lock_; 567 base::Lock lock_;
561 bool error_encountered_; 568 bool error_encountered_;
562 SkColor wait_color_yuv_; 569 SkColor wait_color_yuv_;
563 SkColor last_frame_color_yuv_; 570 SkColor last_frame_color_yuv_;
564 gfx::Size last_frame_size_; 571 gfx::Size last_frame_size_;
565 std::unique_ptr<StubClient> client_; 572 std::unique_ptr<StubClient> client_;
573 bool expecting_frames_;
566 574
567 DISALLOW_COPY_AND_ASSIGN(StubClientObserver); 575 DISALLOW_COPY_AND_ASSIGN(StubClientObserver);
568 }; 576 };
569 577
570 // crbug.com/159234 578 // crbug.com/159234
571 #if defined(OS_ANDROID) 579 #if defined(OS_ANDROID)
572 #define MAYBE_WebContentsVideoCaptureDeviceTest \ 580 #define MAYBE_WebContentsVideoCaptureDeviceTest \
573 DISABLED_WebContentsVideoCaptureDeviceTest 581 DISABLED_WebContentsVideoCaptureDeviceTest
574 #else 582 #else
575 #define MAYBE_WebContentsVideoCaptureDeviceTest \ 583 #define MAYBE_WebContentsVideoCaptureDeviceTest \
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 // adjustment made. 1184 // adjustment made.
1177 RunTestForPreferredSize( 1185 RunTestForPreferredSize(
1178 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); 1186 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000));
1179 RunTestForPreferredSize( 1187 RunTestForPreferredSize(
1180 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); 1188 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000));
1181 RunTestForPreferredSize( 1189 RunTestForPreferredSize(
1182 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); 1190 policies[i], gfx::Size(837, 999), gfx::Size(837, 999));
1183 } 1191 }
1184 } 1192 }
1185 1193
1194 // Tests the Suspend/Resume() functionality.
1195 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, SuspendsAndResumes) {
1196 media::VideoCaptureParams capture_params;
1197 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
1198 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
1199 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
1200 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
1201
1202 for (int i = 0; i < 3; ++i) {
1203 // Draw a RED frame and wait for a normal frame capture to occur.
1204 source()->SetSolidColor(SK_ColorRED);
1205 SimulateDrawEvent();
1206 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
1207
1208 // Suspend capture and then draw a GREEN frame. No frame capture should
1209 // occur.
1210 device()->MaybeSuspend();
1211 base::RunLoop().RunUntilIdle();
1212 client_observer()->SetIsExpectingFrames(false);
1213 source()->SetSolidColor(SK_ColorGREEN);
1214 SimulateDrawEvent();
1215 base::RunLoop().RunUntilIdle();
1216
1217 // Resume capture and then draw a BLUE frame and wait for it to be captured.
1218 device()->Resume();
1219 base::RunLoop().RunUntilIdle();
1220 client_observer()->SetIsExpectingFrames(true);
1221 source()->SetSolidColor(SK_ColorBLUE);
1222 SimulateDrawEvent();
1223 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE));
1224 }
1225
1226 device()->StopAndDeAllocate();
1227 }
1228
1186 // Tests the RequestRefreshFrame() functionality. 1229 // Tests the RequestRefreshFrame() functionality.
1187 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) { 1230 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) {
1188 media::VideoCaptureParams capture_params; 1231 media::VideoCaptureParams capture_params;
1189 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 1232 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
1190 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 1233 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
1191 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 1234 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
1192 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 1235 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
1193 1236
1194 // Request a refresh frame before the first frame has been drawn. This forces 1237 // Request a refresh frame before the first frame has been drawn. This forces
1195 // a capture. 1238 // a capture.
(...skipping 13 matching lines...) Expand all
1209 for (int i = 0; i < 3; ++i) { 1252 for (int i = 0; i < 3; ++i) {
1210 SimulateRefreshFrameRequest(); 1253 SimulateRefreshFrameRequest();
1211 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 1254 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
1212 } 1255 }
1213 1256
1214 device()->StopAndDeAllocate(); 1257 device()->StopAndDeAllocate();
1215 } 1258 }
1216 1259
1217 } // namespace 1260 } // namespace
1218 } // namespace content 1261 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/capture/web_contents_video_capture_device.cc ('k') | media/capture/content/screen_capture_device_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698