| 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/host/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" |
| 11 #include "remoting/base/auto_thread.h" | 11 #include "remoting/base/auto_thread.h" |
| 12 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
| 13 #include "remoting/codec/video_encoder.h" | 13 #include "remoting/codec/video_encoder.h" |
| 14 #include "remoting/codec/video_encoder_verbatim.h" | 14 #include "remoting/codec/video_encoder_verbatim.h" |
| 15 #include "remoting/host/desktop_capturer_proxy.h" | |
| 16 #include "remoting/host/fake_desktop_capturer.h" | |
| 17 #include "remoting/host/host_mock_objects.h" | |
| 18 #include "remoting/proto/control.pb.h" | 15 #include "remoting/proto/control.pb.h" |
| 19 #include "remoting/proto/video.pb.h" | 16 #include "remoting/proto/video.pb.h" |
| 17 #include "remoting/protocol/fake_desktop_capturer.h" |
| 20 #include "remoting/protocol/protocol_mock_objects.h" | 18 #include "remoting/protocol/protocol_mock_objects.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 24 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" | 22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object
s.h" |
| 25 | 23 |
| 26 using ::remoting::protocol::MockVideoStub; | |
| 27 | |
| 28 using ::testing::_; | 24 using ::testing::_; |
| 29 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
| 30 using ::testing::DoAll; | 26 using ::testing::DoAll; |
| 31 using ::testing::Expectation; | 27 using ::testing::Expectation; |
| 32 using ::testing::InvokeWithoutArgs; | 28 using ::testing::InvokeWithoutArgs; |
| 33 using ::testing::Return; | 29 using ::testing::Return; |
| 34 | 30 |
| 35 namespace remoting { | 31 namespace remoting { |
| 32 namespace protocol { |
| 36 | 33 |
| 37 namespace { | 34 namespace { |
| 38 | 35 |
| 39 ACTION(FinishSend) { | 36 ACTION(FinishSend) { |
| 40 arg1.Run(); | 37 arg1.Run(); |
| 41 } | 38 } |
| 42 | 39 |
| 43 scoped_ptr<webrtc::DesktopFrame> CreateNullFrame( | 40 scoped_ptr<webrtc::DesktopFrame> CreateNullFrame( |
| 44 webrtc::DesktopCapturer::Callback*) { | 41 webrtc::DesktopCapturer::Callback*) { |
| 45 return nullptr; | 42 return nullptr; |
| 46 } | 43 } |
| 47 | 44 |
| 48 scoped_ptr<webrtc::DesktopFrame> CreateUnchangedFrame( | 45 scoped_ptr<webrtc::DesktopFrame> CreateUnchangedFrame( |
| 49 webrtc::DesktopCapturer::Callback*) { | 46 webrtc::DesktopCapturer::Callback*) { |
| 50 const webrtc::DesktopSize kSize(800, 640); | 47 const webrtc::DesktopSize kSize(800, 640); |
| 51 // updated_region() is already empty by default in new BasicDesktopFrames. | 48 // updated_region() is already empty by default in new BasicDesktopFrames. |
| 52 return make_scoped_ptr(new webrtc::BasicDesktopFrame(kSize)); | 49 return make_scoped_ptr(new webrtc::BasicDesktopFrame(kSize)); |
| 53 } | 50 } |
| 54 | 51 |
| 52 class MockVideoEncoder : public VideoEncoder { |
| 53 public: |
| 54 MockVideoEncoder() {} |
| 55 ~MockVideoEncoder() {} |
| 56 |
| 57 MOCK_METHOD1(SetLosslessEncode, void(bool)); |
| 58 MOCK_METHOD1(SetLosslessColor, void(bool)); |
| 59 MOCK_METHOD1(EncodePtr, VideoPacket*(const webrtc::DesktopFrame&)); |
| 60 |
| 61 scoped_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame) { |
| 62 return make_scoped_ptr(EncodePtr(frame)); |
| 63 } |
| 64 }; |
| 65 |
| 55 } // namespace | 66 } // namespace |
| 56 | 67 |
| 57 static const int kWidth = 640; | 68 static const int kWidth = 640; |
| 58 static const int kHeight = 480; | 69 static const int kHeight = 480; |
| 59 | 70 |
| 60 class ThreadCheckVideoEncoder : public VideoEncoderVerbatim { | 71 class ThreadCheckVideoEncoder : public VideoEncoderVerbatim { |
| 61 public: | 72 public: |
| 62 ThreadCheckVideoEncoder( | 73 ThreadCheckVideoEncoder( |
| 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 64 : task_runner_(task_runner) { | 75 : task_runner_(task_runner) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TEST_F(VideoFramePumpTest, StartAndStop) { | 166 TEST_F(VideoFramePumpTest, StartAndStop) { |
| 156 scoped_ptr<ThreadCheckDesktopCapturer> capturer( | 167 scoped_ptr<ThreadCheckDesktopCapturer> capturer( |
| 157 new ThreadCheckDesktopCapturer(capture_task_runner_)); | 168 new ThreadCheckDesktopCapturer(capture_task_runner_)); |
| 158 scoped_ptr<ThreadCheckVideoEncoder> encoder( | 169 scoped_ptr<ThreadCheckVideoEncoder> encoder( |
| 159 new ThreadCheckVideoEncoder(encode_task_runner_)); | 170 new ThreadCheckVideoEncoder(encode_task_runner_)); |
| 160 | 171 |
| 161 base::RunLoop run_loop; | 172 base::RunLoop run_loop; |
| 162 | 173 |
| 163 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 174 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 164 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 175 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 165 .WillOnce(DoAll( | 176 .WillOnce(DoAll(FinishSend(), |
| 166 FinishSend(), | 177 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 167 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | |
| 168 .RetiresOnSaturation(); | 178 .RetiresOnSaturation(); |
| 169 | 179 |
| 170 // Start video frame capture. | 180 // Start video frame capture. |
| 171 pump_.reset(new VideoFramePump(encode_task_runner_, | 181 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), |
| 172 make_scoped_ptr(new DesktopCapturerProxy( | |
| 173 capture_task_runner_, capturer.Pass())), | |
| 174 encoder.Pass(), &video_stub_)); | 182 encoder.Pass(), &video_stub_)); |
| 175 | 183 |
| 176 // Run MessageLoop until the first frame is received. | 184 // Run MessageLoop until the first frame is received. |
| 177 run_loop.Run(); | 185 run_loop.Run(); |
| 178 } | 186 } |
| 179 | 187 |
| 180 // Tests that the pump handles null frames returned by the capturer. | 188 // Tests that the pump handles null frames returned by the capturer. |
| 181 TEST_F(VideoFramePumpTest, NullFrame) { | 189 TEST_F(VideoFramePumpTest, NullFrame) { |
| 182 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); | 190 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); |
| 183 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); | 191 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); |
| 184 | 192 |
| 185 base::RunLoop run_loop; | 193 base::RunLoop run_loop; |
| 186 | 194 |
| 187 // Set up the capturer to return null frames. | 195 // Set up the capturer to return null frames. |
| 188 capturer->set_frame_generator(base::Bind(&CreateNullFrame)); | 196 capturer->set_frame_generator(base::Bind(&CreateNullFrame)); |
| 189 | 197 |
| 190 // Expect that the VideoEncoder::Encode() method is never called. | 198 // Expect that the VideoEncoder::Encode() method is never called. |
| 191 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0); | 199 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0); |
| 192 | 200 |
| 193 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 201 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 194 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 202 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 195 .WillOnce(DoAll(FinishSend(), | 203 .WillOnce(DoAll(FinishSend(), |
| 196 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | 204 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 197 .RetiresOnSaturation(); | 205 .RetiresOnSaturation(); |
| 198 | 206 |
| 199 // Start video frame capture. | 207 // Start video frame capture. |
| 200 pump_.reset(new VideoFramePump(encode_task_runner_, | 208 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), |
| 201 make_scoped_ptr(new DesktopCapturerProxy( | |
| 202 capture_task_runner_, capturer.Pass())), | |
| 203 encoder.Pass(), &video_stub_)); | 209 encoder.Pass(), &video_stub_)); |
| 204 | 210 |
| 205 // Run MessageLoop until the first frame is received.. | 211 // Run MessageLoop until the first frame is received.. |
| 206 run_loop.Run(); | 212 run_loop.Run(); |
| 207 } | 213 } |
| 208 | 214 |
| 209 // Tests how the pump handles unchanged frames returned by the capturer. | 215 // Tests how the pump handles unchanged frames returned by the capturer. |
| 210 TEST_F(VideoFramePumpTest, UnchangedFrame) { | 216 TEST_F(VideoFramePumpTest, UnchangedFrame) { |
| 211 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); | 217 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); |
| 212 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); | 218 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); |
| 213 | 219 |
| 214 base::RunLoop run_loop; | 220 base::RunLoop run_loop; |
| 215 | 221 |
| 216 // Set up the capturer to return unchanged frames. | 222 // Set up the capturer to return unchanged frames. |
| 217 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame)); | 223 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame)); |
| 218 | 224 |
| 219 // Expect that the VideoEncoder::Encode() method is called. | 225 // Expect that the VideoEncoder::Encode() method is called. |
| 220 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr)); | 226 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr)); |
| 221 | 227 |
| 222 // When the first ProcessVideoPacket is received we stop the VideoFramePump. | 228 // When the first ProcessVideoPacket is received we stop the VideoFramePump. |
| 223 // TODO(wez): Verify that the generated packet has no content here. | 229 // TODO(wez): Verify that the generated packet has no content here. |
| 224 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) | 230 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) |
| 225 .WillOnce(DoAll(FinishSend(), | 231 .WillOnce(DoAll(FinishSend(), |
| 226 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) | 232 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) |
| 227 .RetiresOnSaturation(); | 233 .RetiresOnSaturation(); |
| 228 | 234 |
| 229 // Start video frame capture. | 235 // Start video frame capture. |
| 230 pump_.reset(new VideoFramePump(encode_task_runner_, | 236 pump_.reset(new VideoFramePump(encode_task_runner_, capturer.Pass(), |
| 231 make_scoped_ptr(new DesktopCapturerProxy( | |
| 232 capture_task_runner_, capturer.Pass())), | |
| 233 encoder.Pass(), &video_stub_)); | 237 encoder.Pass(), &video_stub_)); |
| 234 | 238 |
| 235 // Run MessageLoop until the first frame is received.. | 239 // Run MessageLoop until the first frame is received. |
| 236 run_loop.Run(); | 240 run_loop.Run(); |
| 237 } | 241 } |
| 238 | 242 |
| 243 } // namespace protocol |
| 239 } // namespace remoting | 244 } // namespace remoting |
| OLD | NEW |