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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "remoting/base/auto_thread_task_runner.h" | 10 #include "remoting/base/auto_thread_task_runner.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using ::testing::ReturnRef; | 31 using ::testing::ReturnRef; |
32 using ::testing::SaveArg; | 32 using ::testing::SaveArg; |
33 | 33 |
34 namespace remoting { | 34 namespace remoting { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 ACTION(FinishEncode) { | 38 ACTION(FinishEncode) { |
39 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 39 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
40 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); | 40 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); |
41 arg1.Run(packet.Pass()); | 41 return packet.release(); |
42 } | 42 } |
43 | 43 |
44 ACTION(FinishSend) { | 44 ACTION(FinishSend) { |
45 arg1.Run(); | 45 arg1.Run(); |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 static const int kWidth = 640; | 50 static const int kWidth = 640; |
51 static const int kHeight = 480; | 51 static const int kHeight = 480; |
52 | 52 |
53 class MockVideoEncoder : public VideoEncoder { | 53 class MockVideoEncoder : public VideoEncoder { |
54 public: | 54 public: |
55 MockVideoEncoder(); | 55 MockVideoEncoder(); |
56 virtual ~MockVideoEncoder(); | 56 virtual ~MockVideoEncoder(); |
57 | 57 |
58 MOCK_METHOD2(Encode, void( | 58 scoped_ptr<VideoPacket> Encode( |
59 const webrtc::DesktopFrame* frame, | 59 const webrtc::DesktopFrame& frame) { |
60 const DataAvailableCallback& data_available_callback)); | 60 return scoped_ptr<VideoPacket>(EncodePtr(frame)); |
| 61 } |
| 62 MOCK_METHOD1(EncodePtr, VideoPacket*(const webrtc::DesktopFrame& frame)); |
61 | 63 |
62 private: | 64 private: |
63 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); | 65 DISALLOW_COPY_AND_ASSIGN(MockVideoEncoder); |
64 }; | 66 }; |
65 | 67 |
66 MockVideoEncoder::MockVideoEncoder() {} | 68 MockVideoEncoder::MockVideoEncoder() {} |
67 | 69 |
68 MockVideoEncoder::~MockVideoEncoder() {} | 70 MockVideoEncoder::~MockVideoEncoder() {} |
69 | 71 |
70 class VideoSchedulerTest : public testing::Test { | 72 class VideoSchedulerTest : public testing::Test { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // sequence to be executed successfully. | 153 // sequence to be executed successfully. |
152 TEST_F(VideoSchedulerTest, StartAndStop) { | 154 TEST_F(VideoSchedulerTest, StartAndStop) { |
153 scoped_ptr<webrtc::MockScreenCapturer> capturer( | 155 scoped_ptr<webrtc::MockScreenCapturer> capturer( |
154 new webrtc::MockScreenCapturer()); | 156 new webrtc::MockScreenCapturer()); |
155 Expectation capturer_start = | 157 Expectation capturer_start = |
156 EXPECT_CALL(*capturer, Start(_)) | 158 EXPECT_CALL(*capturer, Start(_)) |
157 .WillOnce(Invoke(this, &VideoSchedulerTest::OnCapturerStart)); | 159 .WillOnce(Invoke(this, &VideoSchedulerTest::OnCapturerStart)); |
158 | 160 |
159 frame_.reset(new webrtc::BasicDesktopFrame( | 161 frame_.reset(new webrtc::BasicDesktopFrame( |
160 webrtc::DesktopSize(kWidth, kHeight))); | 162 webrtc::DesktopSize(kWidth, kHeight))); |
161 webrtc::DesktopFrame* frame_ptr = frame_.get(); | |
162 | 163 |
163 // First the capturer is called. | 164 // First the capturer is called. |
164 Expectation capturer_capture = EXPECT_CALL(*capturer, Capture(_)) | 165 Expectation capturer_capture = EXPECT_CALL(*capturer, Capture(_)) |
165 .After(capturer_start) | 166 .After(capturer_start) |
166 .WillRepeatedly(Invoke(this, &VideoSchedulerTest::OnCaptureFrame)); | 167 .WillRepeatedly(Invoke(this, &VideoSchedulerTest::OnCaptureFrame)); |
167 | 168 |
168 // Expect the encoder be called. | 169 // Expect the encoder be called. |
169 EXPECT_CALL(*encoder_, Encode(frame_ptr, _)) | 170 EXPECT_CALL(*encoder_, EncodePtr(_)) |
170 .WillRepeatedly(FinishEncode()); | 171 .WillRepeatedly(FinishEncode()); |
171 | 172 |
172 // By default delete the arguments when ProcessVideoPacket is received. | 173 // By default delete the arguments when ProcessVideoPacket is received. |
173 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 174 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
174 .WillRepeatedly(FinishSend()); | 175 .WillRepeatedly(FinishSend()); |
175 | 176 |
176 // For the first time when ProcessVideoPacket is received we stop the | 177 // For the first time when ProcessVideoPacket is received we stop the |
177 // VideoScheduler. | 178 // VideoScheduler. |
178 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 179 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
179 .WillOnce(DoAll( | 180 .WillOnce(DoAll( |
180 FinishSend(), | 181 FinishSend(), |
181 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) | 182 InvokeWithoutArgs(this, &VideoSchedulerTest::StopVideoScheduler))) |
182 .RetiresOnSaturation(); | 183 .RetiresOnSaturation(); |
183 | 184 |
184 // Start video frame capture. | 185 // Start video frame capture. |
185 StartVideoScheduler(capturer.PassAs<webrtc::ScreenCapturer>()); | 186 StartVideoScheduler(capturer.PassAs<webrtc::ScreenCapturer>()); |
186 | 187 |
187 task_runner_ = NULL; | 188 task_runner_ = NULL; |
188 run_loop_.Run(); | 189 run_loop_.Run(); |
189 } | 190 } |
190 | 191 |
191 } // namespace remoting | 192 } // namespace remoting |
OLD | NEW |