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