Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: remoting/protocol/video_frame_pump_unittest.cc

Issue 1462063004: Move VideoFramePump to remoting/protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/video_frame_pump.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void SetUp() override; 127 void SetUp() override;
117 void TearDown() override; 128 void TearDown() override;
118 129
119 void StartVideoFramePump( 130 void StartVideoFramePump(
120 scoped_ptr<webrtc::DesktopCapturer> capturer, 131 scoped_ptr<webrtc::DesktopCapturer> capturer,
121 scoped_ptr<VideoEncoder> encoder); 132 scoped_ptr<VideoEncoder> encoder);
122 133
123 protected: 134 protected:
124 base::MessageLoop message_loop_; 135 base::MessageLoop message_loop_;
125 base::RunLoop run_loop_; 136 base::RunLoop run_loop_;
126 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_;
127 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_; 137 scoped_refptr<AutoThreadTaskRunner> encode_task_runner_;
128 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; 138 scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
129 scoped_ptr<VideoFramePump> pump_; 139 scoped_ptr<VideoFramePump> pump_;
130 140
131 MockVideoStub video_stub_; 141 MockVideoStub video_stub_;
132 }; 142 };
133 143
134 void VideoFramePumpTest::SetUp() { 144 void VideoFramePumpTest::SetUp() {
135 main_task_runner_ = new AutoThreadTaskRunner( 145 main_task_runner_ = new AutoThreadTaskRunner(
136 message_loop_.task_runner(), run_loop_.QuitClosure()); 146 message_loop_.task_runner(), run_loop_.QuitClosure());
137 capture_task_runner_ = AutoThread::Create("capture", main_task_runner_);
138 encode_task_runner_ = AutoThread::Create("encode", main_task_runner_); 147 encode_task_runner_ = AutoThread::Create("encode", main_task_runner_);
139 } 148 }
140 149
141 void VideoFramePumpTest::TearDown() { 150 void VideoFramePumpTest::TearDown() {
142 pump_.reset(); 151 pump_.reset();
143 152
144 // Release the task runners, so that the test can quit. 153 // Release the task runners, so that the test can quit.
145 capture_task_runner_ = nullptr;
146 encode_task_runner_ = nullptr; 154 encode_task_runner_ = nullptr;
147 main_task_runner_ = nullptr; 155 main_task_runner_ = nullptr;
148 156
149 // Run the MessageLoop until everything has torn down. 157 // Run the MessageLoop until everything has torn down.
150 run_loop_.Run(); 158 run_loop_.Run();
151 } 159 }
152 160
153 // This test mocks capturer, encoder and network layer to simulate one capture 161 // This test mocks capturer, encoder and network layer to simulate one capture
154 // cycle. 162 // cycle.
155 TEST_F(VideoFramePumpTest, StartAndStop) { 163 TEST_F(VideoFramePumpTest, StartAndStop) {
156 scoped_ptr<ThreadCheckDesktopCapturer> capturer( 164 scoped_ptr<ThreadCheckDesktopCapturer> capturer(
157 new ThreadCheckDesktopCapturer(capture_task_runner_)); 165 new ThreadCheckDesktopCapturer(main_task_runner_));
158 scoped_ptr<ThreadCheckVideoEncoder> encoder( 166 scoped_ptr<ThreadCheckVideoEncoder> encoder(
159 new ThreadCheckVideoEncoder(encode_task_runner_)); 167 new ThreadCheckVideoEncoder(encode_task_runner_));
160 168
161 base::RunLoop run_loop; 169 base::RunLoop run_loop;
162 170
163 // When the first ProcessVideoPacket is received we stop the VideoFramePump. 171 // When the first ProcessVideoPacket is received we stop the VideoFramePump.
164 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 172 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
165 .WillOnce(DoAll( 173 .WillOnce(DoAll(FinishSend(),
166 FinishSend(), 174 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)))
167 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)))
168 .RetiresOnSaturation(); 175 .RetiresOnSaturation();
169 176
170 // Start video frame capture. 177 // Start video frame capture.
171 pump_.reset(new VideoFramePump(encode_task_runner_, 178 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_)); 179 encoder.Pass(), &video_stub_));
175 180
176 // Run MessageLoop until the first frame is received. 181 // Run MessageLoop until the first frame is received.
177 run_loop.Run(); 182 run_loop.Run();
178 } 183 }
179 184
180 // Tests that the pump handles null frames returned by the capturer. 185 // Tests that the pump handles null frames returned by the capturer.
181 TEST_F(VideoFramePumpTest, NullFrame) { 186 TEST_F(VideoFramePumpTest, NullFrame) {
182 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); 187 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer);
183 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); 188 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder);
184 189
185 base::RunLoop run_loop; 190 base::RunLoop run_loop;
186 191
187 // Set up the capturer to return null frames. 192 // Set up the capturer to return null frames.
188 capturer->set_frame_generator(base::Bind(&CreateNullFrame)); 193 capturer->set_frame_generator(base::Bind(&CreateNullFrame));
189 194
190 // Expect that the VideoEncoder::Encode() method is never called. 195 // Expect that the VideoEncoder::Encode() method is never called.
191 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0); 196 EXPECT_CALL(*encoder, EncodePtr(_)).Times(0);
192 197
193 // When the first ProcessVideoPacket is received we stop the VideoFramePump. 198 // When the first ProcessVideoPacket is received we stop the VideoFramePump.
194 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 199 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
195 .WillOnce(DoAll(FinishSend(), 200 .WillOnce(DoAll(FinishSend(),
196 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) 201 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)))
197 .RetiresOnSaturation(); 202 .RetiresOnSaturation();
198 203
199 // Start video frame capture. 204 // Start video frame capture.
200 pump_.reset(new VideoFramePump(encode_task_runner_, 205 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_)); 206 encoder.Pass(), &video_stub_));
204 207
205 // Run MessageLoop until the first frame is received.. 208 // Run MessageLoop until the first frame is received..
206 run_loop.Run(); 209 run_loop.Run();
207 } 210 }
208 211
209 // Tests how the pump handles unchanged frames returned by the capturer. 212 // Tests how the pump handles unchanged frames returned by the capturer.
210 TEST_F(VideoFramePumpTest, UnchangedFrame) { 213 TEST_F(VideoFramePumpTest, UnchangedFrame) {
211 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer); 214 scoped_ptr<FakeDesktopCapturer> capturer(new FakeDesktopCapturer);
212 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder); 215 scoped_ptr<MockVideoEncoder> encoder(new MockVideoEncoder);
213 216
214 base::RunLoop run_loop; 217 base::RunLoop run_loop;
215 218
216 // Set up the capturer to return unchanged frames. 219 // Set up the capturer to return unchanged frames.
217 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame)); 220 capturer->set_frame_generator(base::Bind(&CreateUnchangedFrame));
218 221
219 // Expect that the VideoEncoder::Encode() method is called. 222 // Expect that the VideoEncoder::Encode() method is called.
220 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr)); 223 EXPECT_CALL(*encoder, EncodePtr(_)).WillRepeatedly(Return(nullptr));
221 224
222 // When the first ProcessVideoPacket is received we stop the VideoFramePump. 225 // When the first ProcessVideoPacket is received we stop the VideoFramePump.
223 // TODO(wez): Verify that the generated packet has no content here. 226 // TODO(wez): Verify that the generated packet has no content here.
224 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)) 227 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _))
225 .WillOnce(DoAll(FinishSend(), 228 .WillOnce(DoAll(FinishSend(),
226 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit))) 229 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)))
227 .RetiresOnSaturation(); 230 .RetiresOnSaturation();
228 231
229 // Start video frame capture. 232 // Start video frame capture.
230 pump_.reset(new VideoFramePump(encode_task_runner_, 233 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_)); 234 encoder.Pass(), &video_stub_));
234 235
235 // Run MessageLoop until the first frame is received.. 236 // Run MessageLoop until the first frame is received.
236 run_loop.Run(); 237 run_loop.Run();
237 } 238 }
238 239
240 } // namespace protocol
239 } // namespace remoting 241 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/video_frame_pump.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698