| OLD | NEW |
| 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 "remoting/host/video_scheduler.h" | 5 #include "remoting/host/video_scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "remoting/base/capture_data.h" | 10 #include "remoting/base/capture_data.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using ::testing::InSequence; | 27 using ::testing::InSequence; |
| 28 using ::testing::InvokeWithoutArgs; | 28 using ::testing::InvokeWithoutArgs; |
| 29 using ::testing::Return; | 29 using ::testing::Return; |
| 30 using ::testing::ReturnRef; | 30 using ::testing::ReturnRef; |
| 31 using ::testing::SaveArg; | 31 using ::testing::SaveArg; |
| 32 | 32 |
| 33 namespace remoting { | 33 namespace remoting { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 ACTION_P2(RunCallback, region, data) { | |
| 38 SkRegion& dirty_region = data->mutable_dirty_region(); | |
| 39 dirty_region.op(region, SkRegion::kUnion_Op); | |
| 40 arg0.Run(data); | |
| 41 } | |
| 42 | |
| 43 ACTION(FinishEncode) { | 37 ACTION(FinishEncode) { |
| 44 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 38 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 45 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); | 39 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); |
| 46 arg2.Run(packet.Pass()); | 40 arg2.Run(packet.Pass()); |
| 47 } | 41 } |
| 48 | 42 |
| 49 ACTION(FinishSend) { | 43 ACTION(FinishSend) { |
| 50 arg1.Run(); | 44 arg1.Run(); |
| 51 } | 45 } |
| 52 | 46 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 75 private: | 69 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); | 70 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); |
| 77 }; | 71 }; |
| 78 | 72 |
| 79 MockVideoEncoder::MockVideoEncoder() {} | 73 MockVideoEncoder::MockVideoEncoder() {} |
| 80 | 74 |
| 81 MockVideoEncoder::~MockVideoEncoder() {} | 75 MockVideoEncoder::~MockVideoEncoder() {} |
| 82 | 76 |
| 83 class VideoSchedulerTest : public testing::Test { | 77 class VideoSchedulerTest : public testing::Test { |
| 84 public: | 78 public: |
| 85 VideoSchedulerTest() { | 79 VideoSchedulerTest() : size_(SkISize::Make(0, 0)) { |
| 86 } | 80 } |
| 87 | 81 |
| 88 virtual void SetUp() OVERRIDE { | 82 virtual void SetUp() OVERRIDE { |
| 89 encoder_ = new MockVideoEncoder(); | 83 encoder_ = new MockVideoEncoder(); |
| 90 } | 84 } |
| 91 | 85 |
| 92 void StartVideoScheduler() { | 86 void StartVideoScheduler() { |
| 93 scheduler_ = new VideoScheduler( | 87 scheduler_ = new VideoScheduler( |
| 94 message_loop_.message_loop_proxy(), | 88 message_loop_.message_loop_proxy(), |
| 95 message_loop_.message_loop_proxy(), | 89 message_loop_.message_loop_proxy(), |
| 96 message_loop_.message_loop_proxy(), | 90 message_loop_.message_loop_proxy(), |
| 97 &capturer_, | 91 &capturer_, |
| 98 scoped_ptr<VideoEncoder>(encoder_), | 92 scoped_ptr<VideoEncoder>(encoder_), |
| 99 &client_stub_, | 93 &client_stub_, |
| 100 &video_stub_); | 94 &video_stub_); |
| 101 } | 95 } |
| 102 | 96 |
| 97 void GenerateOnCaptureCompleted(); |
| 98 |
| 103 protected: | 99 protected: |
| 104 MessageLoop message_loop_; | 100 MessageLoop message_loop_; |
| 105 scoped_refptr<VideoScheduler> scheduler_; | 101 scoped_refptr<VideoScheduler> scheduler_; |
| 106 | 102 |
| 107 MockClientStub client_stub_; | 103 MockClientStub client_stub_; |
| 108 MockVideoStub video_stub_; | 104 MockVideoStub video_stub_; |
| 109 MockVideoFrameCapturer capturer_; | 105 MockVideoFrameCapturer capturer_; |
| 110 | 106 |
| 111 // The following mock objects are owned by VideoScheduler. | 107 // The following mock objects are owned by VideoScheduler. |
| 112 MockVideoEncoder* encoder_; | 108 MockVideoEncoder* encoder_; |
| 113 | 109 |
| 110 SkISize size_; |
| 111 scoped_refptr<CaptureData> data_; |
| 112 |
| 114 private: | 113 private: |
| 115 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); | 114 DISALLOW_COPY_AND_ASSIGN(VideoSchedulerTest); |
| 116 }; | 115 }; |
| 117 | 116 |
| 117 void VideoSchedulerTest::GenerateOnCaptureCompleted() { |
| 118 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); |
| 119 data_->mutable_dirty_region().op(update_region, SkRegion::kUnion_Op); |
| 120 |
| 121 scheduler_->OnCaptureCompleted(data_); |
| 122 } |
| 123 |
| 118 // This test mocks capturer, encoder and network layer to simulate one capture | 124 // This test mocks capturer, encoder and network layer to simulate one capture |
| 119 // cycle. When the first encoded packet is submitted to the network | 125 // cycle. When the first encoded packet is submitted to the network |
| 120 // VideoScheduler is instructed to come to a complete stop. We expect the stop | 126 // VideoScheduler is instructed to come to a complete stop. We expect the stop |
| 121 // sequence to be executed successfully. | 127 // sequence to be executed successfully. |
| 122 TEST_F(VideoSchedulerTest, StartAndStop) { | 128 TEST_F(VideoSchedulerTest, StartAndStop) { |
| 123 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10)); | |
| 124 DataPlanes planes; | 129 DataPlanes planes; |
| 125 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { | 130 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
| 126 planes.data[i] = reinterpret_cast<uint8*>(i); | 131 planes.data[i] = reinterpret_cast<uint8*>(i); |
| 127 planes.strides[i] = kWidth * 4; | 132 planes.strides[i] = kWidth * 4; |
| 128 } | 133 } |
| 129 | 134 |
| 130 Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); | 135 Expectation capturer_start = EXPECT_CALL(capturer_, Start(_)); |
| 131 | 136 |
| 132 SkISize size(SkISize::Make(kWidth, kHeight)); | 137 size_.set(kWidth, kHeight); |
| 133 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); | 138 data_ = new CaptureData(planes, size_, kFormat); |
| 134 | 139 |
| 135 // Create a RunLoop through which to drive |message_loop_|. | 140 // Create a RunLoop through which to drive |message_loop_|. |
| 136 base::RunLoop run_loop; | 141 base::RunLoop run_loop; |
| 137 | 142 |
| 138 EXPECT_CALL(capturer_, size_most_recent()) | 143 EXPECT_CALL(capturer_, size_most_recent()) |
| 139 .WillRepeatedly(ReturnRef(size)); | 144 .WillRepeatedly(ReturnRef(size_)); |
| 140 | 145 |
| 141 // First the capturer is called. | 146 // First the capturer is called. |
| 142 Expectation capturer_capture = EXPECT_CALL(capturer_, CaptureInvalidRegion(_)) | 147 Expectation capturer_capture = EXPECT_CALL(capturer_, CaptureInvalidRegion()) |
| 143 .After(capturer_start) | 148 .After(capturer_start) |
| 144 .WillRepeatedly(RunCallback(update_region, data)); | 149 .WillRepeatedly(InvokeWithoutArgs( |
| 150 this, &VideoSchedulerTest::GenerateOnCaptureCompleted)); |
| 145 | 151 |
| 146 // Expect the encoder be called. | 152 // Expect the encoder be called. |
| 147 EXPECT_CALL(*encoder_, Encode(data, false, _)) | 153 EXPECT_CALL(*encoder_, Encode(data_, false, _)) |
| 148 .WillRepeatedly(FinishEncode()); | 154 .WillRepeatedly(FinishEncode()); |
| 149 | 155 |
| 150 // By default delete the arguments when ProcessVideoPacket is received. | 156 // By default delete the arguments when ProcessVideoPacket is received. |
| 151 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 157 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 152 .WillRepeatedly(FinishSend()); | 158 .WillRepeatedly(FinishSend()); |
| 153 | 159 |
| 154 // For the first time when ProcessVideoPacket is received we stop the | 160 // For the first time when ProcessVideoPacket is received we stop the |
| 155 // VideoScheduler. | 161 // VideoScheduler. |
| 156 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 162 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 157 .WillOnce(DoAll( | 163 .WillOnce(DoAll( |
| 158 FinishSend(), | 164 FinishSend(), |
| 159 StopVideoScheduler(&scheduler_, run_loop.QuitClosure()))) | 165 StopVideoScheduler(&scheduler_, run_loop.QuitClosure()))) |
| 160 .RetiresOnSaturation(); | 166 .RetiresOnSaturation(); |
| 161 | 167 |
| 162 EXPECT_CALL(capturer_, Stop()) | 168 EXPECT_CALL(capturer_, Stop()) |
| 163 .After(capturer_capture); | 169 .After(capturer_capture); |
| 164 | 170 |
| 165 // Start video frame capture. | 171 // Start video frame capture. |
| 166 StartVideoScheduler(); | 172 StartVideoScheduler(); |
| 167 run_loop.Run(); | 173 run_loop.Run(); |
| 168 } | 174 } |
| 169 | 175 |
| 170 } // namespace remoting | 176 } // namespace remoting |
| OLD | NEW |