 Chromium Code Reviews
 Chromium Code Reviews Issue 872433005:
  Move capture scheduling logic from VideoScheduler to CaptureScheduler.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 872433005:
  Move capture scheduling logic from VideoScheduler to CaptureScheduler.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "remoting/host/capture_scheduler.h" | 5 #include "remoting/host/capture_scheduler.h" | 
| 6 | |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "base/test/simple_test_tick_clock.h" | |
| 9 #include "base/timer/mock_timer.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" | 
| 7 | 11 | 
| 8 namespace remoting { | 12 namespace remoting { | 
| 9 | 13 | 
| 10 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 }; | 14 static const int kTestInputs[] = { 100, 50, 30, 20, 10, 30, 60, 80 }; | 
| 11 static const int kMinumumFrameIntervalMs = 50; | |
| 12 | 15 | 
| 13 TEST(CaptureSchedulerTest, SingleSampleSameTimes) { | 16 class CaptureSchedulerTest : public testing::Test { | 
| 17 public: | |
| 18 CaptureSchedulerTest() : capture_called_(false) {} | |
| 19 | |
| 20 void InitScheduler() { | |
| 21 scheduler_.reset(new CaptureScheduler( | |
| 22 base::Bind(&CaptureSchedulerTest::DoCapture, base::Unretained(this)))); | |
| 23 tick_clock_ = new base::SimpleTestTickClock(); | |
| 24 scheduler_->SetTickClockForTest(make_scoped_ptr(tick_clock_)); | |
| 25 capture_timer_ = new base::MockTimer(false, false); | |
| 26 scheduler_->SetTimerForTest(make_scoped_ptr(capture_timer_)); | |
| 27 scheduler_->Start(); | |
| 28 } | |
| 29 | |
| 30 void DoCapture() { | |
| 31 capture_called_ = true; | |
| 32 } | |
| 33 | |
| 34 void CheckCaptureCalled() { | |
| 35 EXPECT_TRUE(capture_called_); | |
| 36 capture_called_ = false; | |
| 37 } | |
| 38 | |
| 39 void SimulateSingleFrameCapture( | |
| 40 base::TimeDelta capture_delay, | |
| 41 base::TimeDelta encode_delay, | |
| 42 base::TimeDelta expected_delay_between_frames) { | |
| 
Wez
2015/02/05 02:40:25
I don't see a test for the expected delay?
 
Sergey Ulanov
2015/02/05 19:13:27
Removed it by mistake somehow
 | |
| 43 capture_timer_->Fire(); | |
| 44 CheckCaptureCalled(); | |
| 45 tick_clock_->Advance(capture_delay); | |
| 46 scheduler_->OnCaptureCompleted(); | |
| 47 scheduler_->OnFrameEncoded(encode_delay); | |
| 48 scheduler_->OnFrameSent(); | |
| 49 | |
| 50 EXPECT_TRUE(capture_timer_->IsRunning()); | |
| 51 } | |
| 52 | |
| 53 protected: | |
| 54 base::MessageLoop message_loop_; | |
| 55 | |
| 56 scoped_ptr<CaptureScheduler> scheduler_; | |
| 57 | |
| 58 // Owned by |scheduler_|. | |
| 59 base::SimpleTestTickClock* tick_clock_; | |
| 60 base::MockTimer* capture_timer_; | |
| 61 | |
| 62 bool capture_called_; | |
| 63 }; | |
| 64 | |
| 65 TEST_F(CaptureSchedulerTest, SingleSampleSameTimes) { | |
| 14 const int kTestResults[][arraysize(kTestInputs)] = { | 66 const int kTestResults[][arraysize(kTestInputs)] = { | 
| 15 { 400, 200, 120, 80, 50, 120, 240, 320 }, // One core. | 67 { 400, 200, 120, 80, 50, 120, 240, 320 }, // One core. | 
| 16 { 200, 100, 60, 50, 50, 60, 120, 160 }, // Two cores. | 68 { 200, 100, 60, 50, 50, 60, 120, 160 }, // Two cores. | 
| 17 { 100, 50, 50, 50, 50, 50, 60, 80 }, // Four cores. | 69 { 100, 50, 50, 50, 50, 50, 60, 80 }, // Four cores. | 
| 18 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 70 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 
| 19 }; | 71 }; | 
| 20 | 72 | 
| 21 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 73 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 
| 22 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 74 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 
| 23 CaptureScheduler scheduler; | 75 InitScheduler(); | 
| 24 scheduler.SetNumOfProcessorsForTest(1 << i); | 76 scheduler_->SetNumOfProcessorsForTest(1 << i); | 
| 25 scheduler.set_minimum_interval( | 77 | 
| 26 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); | 78 SimulateSingleFrameCapture( | 
| 27 scheduler.RecordCaptureTime( | 79 base::TimeDelta::FromMilliseconds(kTestInputs[j]), | 
| 28 base::TimeDelta::FromMilliseconds(kTestInputs[j])); | 80 base::TimeDelta::FromMilliseconds(kTestInputs[j]), | 
| 29 scheduler.RecordEncodeTime( | 81 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); | 
| 30 base::TimeDelta::FromMilliseconds(kTestInputs[j])); | |
| 31 EXPECT_EQ(kTestResults[i][j], | |
| 32 scheduler.NextCaptureDelay().InMilliseconds()) << i << " "<< j; | |
| 33 } | 82 } | 
| 34 } | 83 } | 
| 35 } | 84 } | 
| 36 | 85 | 
| 37 TEST(CaptureSchedulerTest, SingleSampleDifferentTimes) { | 86 TEST_F(CaptureSchedulerTest, SingleSampleDifferentTimes) { | 
| 38 const int kTestResults[][arraysize(kTestInputs)] = { | 87 const int kTestResults[][arraysize(kTestInputs)] = { | 
| 39 { 360, 220, 120, 60, 60, 120, 220, 360 }, // One core. | 88 { 360, 220, 120, 60, 60, 120, 220, 360 }, // One core. | 
| 40 { 180, 110, 60, 50, 50, 60, 110, 180 }, // Two cores. | 89 { 180, 110, 60, 50, 50, 60, 110, 180 }, // Two cores. | 
| 41 { 90, 55, 50, 50, 50, 50, 55, 90 }, // Four cores. | 90 { 90, 55, 50, 50, 50, 50, 55, 90 }, // Four cores. | 
| 42 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 91 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 
| 43 }; | 92 }; | 
| 44 | 93 | 
| 45 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 94 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 
| 46 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 95 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 
| 47 CaptureScheduler scheduler; | 96 InitScheduler(); | 
| 48 scheduler.SetNumOfProcessorsForTest(1 << i); | 97 scheduler_->SetNumOfProcessorsForTest(1 << i); | 
| 49 scheduler.set_minimum_interval( | 98 | 
| 50 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); | 99 SimulateSingleFrameCapture( | 
| 51 scheduler.RecordCaptureTime( | 100 base::TimeDelta::FromMilliseconds(kTestInputs[j]), | 
| 52 base::TimeDelta::FromMilliseconds(kTestInputs[j])); | |
| 53 scheduler.RecordEncodeTime( | |
| 54 base::TimeDelta::FromMilliseconds( | 101 base::TimeDelta::FromMilliseconds( | 
| 55 kTestInputs[arraysize(kTestInputs) - 1 - j])); | 102 kTestInputs[arraysize(kTestInputs) - 1 - j]), | 
| 56 EXPECT_EQ(kTestResults[i][j], | 103 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); | 
| 57 scheduler.NextCaptureDelay().InMilliseconds()); | |
| 58 } | 104 } | 
| 59 } | 105 } | 
| 60 } | 106 } | 
| 61 | 107 | 
| 62 TEST(CaptureSchedulerTest, RollingAverageDifferentTimes) { | 108 TEST_F(CaptureSchedulerTest, RollingAverageDifferentTimes) { | 
| 63 const int kTestResults[][arraysize(kTestInputs)] = { | 109 const int kTestResults[][arraysize(kTestInputs)] = { | 
| 64 { 360, 290, 233, 133, 80, 80, 133, 233 }, // One core. | 110 { 360, 290, 233, 133, 80, 80, 133, 233 }, // One core. | 
| 65 { 180, 145, 116, 66, 50, 50, 66, 116 }, // Two cores. | 111 { 180, 145, 116, 66, 50, 50, 66, 116 }, // Two cores. | 
| 66 { 90, 72, 58, 50, 50, 50, 50, 58 }, // Four cores. | 112 { 90, 72, 58, 50, 50, 50, 50, 58 }, // Four cores. | 
| 67 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 113 { 50, 50, 50, 50, 50, 50, 50, 50 } // Eight cores. | 
| 68 }; | 114 }; | 
| 69 | 115 | 
| 70 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 116 for (size_t i = 0; i < arraysize(kTestResults); ++i) { | 
| 71 CaptureScheduler scheduler; | 117 InitScheduler(); | 
| 72 scheduler.SetNumOfProcessorsForTest(1 << i); | 118 scheduler_->SetNumOfProcessorsForTest(1 << i); | 
| 73 scheduler.set_minimum_interval( | |
| 74 base::TimeDelta::FromMilliseconds(kMinumumFrameIntervalMs)); | |
| 75 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 119 for (size_t j = 0; j < arraysize(kTestInputs); ++j) { | 
| 76 scheduler.RecordCaptureTime( | 120 SimulateSingleFrameCapture( | 
| 77 base::TimeDelta::FromMilliseconds(kTestInputs[j])); | 121 base::TimeDelta::FromMilliseconds(kTestInputs[j]), | 
| 78 scheduler.RecordEncodeTime( | |
| 79 base::TimeDelta::FromMilliseconds( | 122 base::TimeDelta::FromMilliseconds( | 
| 80 kTestInputs[arraysize(kTestInputs) - 1 - j])); | 123 kTestInputs[arraysize(kTestInputs) - 1 - j]), | 
| 81 EXPECT_EQ(kTestResults[i][j], | 124 base::TimeDelta::FromMilliseconds(kTestResults[i][j])); | 
| 82 scheduler.NextCaptureDelay().InMilliseconds()); | |
| 83 } | 125 } | 
| 84 } | 126 } | 
| 85 } | 127 } | 
| 86 | 128 | 
| 129 // Verify that we never have more than 2 pending frames. | |
| 130 TEST_F(CaptureSchedulerTest, MaximumPendingFrames) { | |
| 131 InitScheduler(); | |
| 132 | |
| 133 capture_timer_->Fire(); | |
| 134 CheckCaptureCalled(); | |
| 135 scheduler_->OnCaptureCompleted(); | |
| 136 | |
| 137 capture_timer_->Fire(); | |
| 138 CheckCaptureCalled(); | |
| 139 scheduler_->OnCaptureCompleted(); | |
| 140 | |
| 141 EXPECT_FALSE(capture_timer_->IsRunning()); | |
| 142 | |
| 143 scheduler_->OnFrameEncoded(base::TimeDelta()); | |
| 144 scheduler_->OnFrameSent(); | |
| 145 | |
| 146 EXPECT_TRUE(capture_timer_->IsRunning()); | |
| 147 } | |
| 148 | |
| 87 } // namespace remoting | 149 } // namespace remoting | 
| OLD | NEW |