| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/protocol/video_frame_pump.h" | 5 #include "remoting/protocol/video_frame_pump.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 "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 base::RunLoop run_loop; | 169 base::RunLoop run_loop; |
| 170 | 170 |
| 171 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 171 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 172 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 172 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 173 .WillOnce(DoAll(FinishSend(), | 173 .WillOnce(DoAll(FinishSend(), |
| 174 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | 174 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 175 .RetiresOnSaturation(); | 175 .RetiresOnSaturation(); |
| 176 | 176 |
| 177 // Start video frame capture. | 177 // Start video frame capture. |
| 178 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), | 178 pump_.reset(new VideoFramePump(encode_task_runner_, std::move(capturer), |
| 179 encoder.Pass(), &video_stub_)); | 179 std::move(encoder), &video_stub_)); |
| 180 | 180 |
| 181 // Run MessageLoop until the first frame is received. | 181 // Run MessageLoop until the first frame is received. |
| 182 run_loop.Run(); | 182 run_loop.Run(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Tests that the pump handles null frames returned by the capturer. | 185 // Tests that the pump handles null frames returned by the capturer. |
| 186 TEST_F(VideoFramePumpTest, NullFrame) { | 186 TEST_F(VideoFramePumpTest, NullFrame) { |
| 187 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); | 187 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); |
| 188 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); | 188 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); |
| 189 | 189 |
| 190 base::RunLoop run_loop; | 190 base::RunLoop run_loop; |
| 191 | 191 |
| 192 // Set up the capturer to return null frames. | 192 // Set up the capturer to return null frames. |
| 193 capturer->set_frame_generator(base::Bind(&CreateNullFrame)); | 193 capturer->set_frame_generator(base::Bind(&CreateNullFrame)); |
| 194 | 194 |
| 195 // Expect that the VideoEncoder::Encode() method is never called. | 195 // Expect that the VideoEncoder::Encode() method is never called. |
| 196 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0); | 196 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0); |
| 197 | 197 |
| 198 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 198 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 199 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 199 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 200 .WillOnce(DoAll(FinishSend(), | 200 .WillOnce(DoAll(FinishSend(), |
| 201 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | 201 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 202 .RetiresOnSaturation(); | 202 .RetiresOnSaturation(); |
| 203 | 203 |
| 204 // Start video frame capture. | 204 // Start video frame capture. |
| 205 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), | 205 pump_.reset(new VideoFramePump(encode_task_runner_, std::move(capturer), |
| 206 encoder.Pass(), &video_stub_)); | 206 std::move(encoder), &video_stub_)); |
| 207 | 207 |
| 208 // Run MessageLoop until the first frame is received.. | 208 // Run MessageLoop until the first frame is received.. |
| 209 run_loop.Run(); | 209 run_loop.Run(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Tests how the pump handles unchanged frames returned by the capturer. | 212 // Tests how the pump handles unchanged frames returned by the capturer. |
| 213 TEST_F(VideoFramePumpTest, UnchangedFrame) { | 213 TEST_F(VideoFramePumpTest, UnchangedFrame) { |
| 214 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); | 214 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); |
| 215 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); | 215 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); |
| 216 | 216 |
| 217 base::RunLoop run_loop; | 217 base::RunLoop run_loop; |
| 218 | 218 |
| 219 // Set up the capturer to return unchanged frames. | 219 // Set up the capturer to return unchanged frames. |
| 220 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame)); | 220 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame)); |
| 221 | 221 |
| 222 // Expect that the VideoEncoder::Encode() method is called. | 222 // Expect that the VideoEncoder::Encode() method is called. |
| 223 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr)); | 223 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr)); |
| 224 | 224 |
| 225 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 225 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 226 // TODO(wez): Verify that the generated packet has no content here. | 226 // TODO(wez): Verify that the generated packet has no content here. |
| 227 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 227 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 228 .WillOnce(DoAll(FinishSend(), | 228 .WillOnce(DoAll(FinishSend(), |
| 229 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | 229 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 230 .RetiresOnSaturation(); | 230 .RetiresOnSaturation(); |
| 231 | 231 |
| 232 // Start video frame capture. | 232 // Start video frame capture. |
| 233 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), | 233 pump_.reset(new VideoFramePump(encode_task_runner_, std::move(capturer), |
| 234 encoder.Pass(), &video_stub_)); | 234 std::move(encoder), &video_stub_)); |
| 235 | 235 |
| 236 // Run MessageLoop until the first frame is received. | 236 // Run MessageLoop until the first frame is received. |
| 237 run_loop.Run(); | 237 run_loop.Run(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace protocol | 240 } // namespace protocol |
| 241 } // namespace remoting | 241 } // namespace remoting |
| OLD | NEW |