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

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

Issue 2035803002: Fix WebRtcFrameScheduler to wait for first key frame request. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 | « no previous file | remoting/protocol/fake_session.h » ('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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 class TestScreenCapturer : public webrtc::DesktopCapturer { 64 class TestScreenCapturer : public webrtc::DesktopCapturer {
65 public: 65 public:
66 TestScreenCapturer() {} 66 TestScreenCapturer() {}
67 ~TestScreenCapturer() override {} 67 ~TestScreenCapturer() override {}
68 68
69 // webrtc::DesktopCapturer interface. 69 // webrtc::DesktopCapturer interface.
70 void Start(Callback* callback) override { 70 void Start(Callback* callback) override {
71 callback_ = callback; 71 callback_ = callback;
72 } 72 }
73 void Capture(const webrtc::DesktopRegion& region) override { 73 void Capture(const webrtc::DesktopRegion& region) override {
74 // Return black 10x10 frame. 74 // Return black 100x100 frame.
75 std::unique_ptr<webrtc::DesktopFrame> frame( 75 std::unique_ptr<webrtc::DesktopFrame> frame(
76 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100))); 76 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100)));
77 memset(frame->data(), 0, frame->stride() * frame->size().height()); 77 memset(frame->data(), 0, frame->stride() * frame->size().height());
78 frame->mutable_updated_region()->SetRect( 78
79 webrtc::DesktopRect::MakeSize(frame->size())); 79 // Set updated_region only for the first frame, as the frame content
80 // doesn't change.
81 if (!first_frame_sent_) {
82 first_frame_sent_ = true;
83 frame->mutable_updated_region()->SetRect(
84 webrtc::DesktopRect::MakeSize(frame->size()));
85 }
86
80 callback_->OnCaptureCompleted(frame.release()); 87 callback_->OnCaptureCompleted(frame.release());
81 } 88 }
82 89
83 private: 90 private:
84 Callback* callback_ = nullptr; 91 Callback* callback_ = nullptr;
92 bool first_frame_sent_ = false;
85 }; 93 };
86 94
87 } // namespace 95 } // namespace
88 96
89 class ConnectionTest : public testing::Test, 97 class ConnectionTest : public testing::Test,
90 public testing::WithParamInterface<bool> { 98 public testing::WithParamInterface<bool> {
91 public: 99 public:
92 ConnectionTest() {} 100 ConnectionTest() {}
93 101
94 protected: 102 protected:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (client_connected_ && run_loop_) 189 if (client_connected_ && run_loop_)
182 run_loop_->Quit(); 190 run_loop_->Quit();
183 } 191 }
184 192
185 void OnClientConnected() { 193 void OnClientConnected() {
186 client_connected_ = true; 194 client_connected_ = true;
187 if (host_connected_ && run_loop_) 195 if (host_connected_ && run_loop_)
188 run_loop_->Quit(); 196 run_loop_->Quit();
189 } 197 }
190 198
199 void WaitFirstVideoFrame() {
200 base::RunLoop run_loop;
201
202 // Expect frames to be passed to FrameConsumer when WebRTC is used, or to
203 // VideoStub otherwise.
204 if (is_using_webrtc()) {
205 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback(
206 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop)));
207 } else {
208 client_video_renderer_.GetVideoStub()->set_on_frame_callback(
209 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop)));
210 }
211
212 run_loop.Run();
213
214 if (is_using_webrtc()) {
215 EXPECT_EQ(
216 client_video_renderer_.GetFrameConsumer()->received_frames().size(),
217 1U);
218 EXPECT_EQ(
219 client_video_renderer_.GetVideoStub()->received_packets().size(), 0U);
220 } else {
221 EXPECT_EQ(
222 client_video_renderer_.GetFrameConsumer()->received_frames().size(),
223 0U);
224 EXPECT_EQ(
225 client_video_renderer_.GetVideoStub()->received_packets().size(), 1U);
226 }
227 }
228
191 base::MessageLoopForIO message_loop_; 229 base::MessageLoopForIO message_loop_;
192 std::unique_ptr<base::RunLoop> run_loop_; 230 std::unique_ptr<base::RunLoop> run_loop_;
193 231
194 MockConnectionToClientEventHandler host_event_handler_; 232 MockConnectionToClientEventHandler host_event_handler_;
195 MockClipboardStub host_clipboard_stub_; 233 MockClipboardStub host_clipboard_stub_;
196 MockHostStub host_stub_; 234 MockHostStub host_stub_;
197 MockInputStub host_input_stub_; 235 MockInputStub host_input_stub_;
198 std::unique_ptr<ConnectionToClient> host_connection_; 236 std::unique_ptr<ConnectionToClient> host_connection_;
199 FakeSession* host_session_; // Owned by |host_connection_|. 237 FakeSession* host_session_; // Owned by |host_connection_|.
200 bool host_connected_ = false; 238 bool host_connected_ = false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 run_loop.Run(); 316 run_loop.Run();
279 } 317 }
280 318
281 TEST_P(ConnectionTest, Video) { 319 TEST_P(ConnectionTest, Video) {
282 Connect(); 320 Connect();
283 321
284 std::unique_ptr<VideoStream> video_stream = 322 std::unique_ptr<VideoStream> video_stream =
285 host_connection_->StartVideoStream( 323 host_connection_->StartVideoStream(
286 base::WrapUnique(new TestScreenCapturer())); 324 base::WrapUnique(new TestScreenCapturer()));
287 325
288 base::RunLoop run_loop; 326 WaitFirstVideoFrame();
327 }
289 328
290 // Expect frames to be passed to FrameConsumer when WebRTC is used, or to 329 // Verifies that the VideoStream doesn't loose any video frames while the
291 // VideoStub otherwise. 330 // connection is being established.
292 if (is_using_webrtc()) { 331 TEST_P(ConnectionTest, VideoWithSlowSignaling) {
293 client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( 332 // Add signaling delay to slow down connection handshake.
294 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); 333 host_session_->set_signaling_delay(base::TimeDelta::FromMilliseconds(100));
295 } else { 334 client_session_->set_signaling_delay(base::TimeDelta::FromMilliseconds(100));
296 client_video_renderer_.GetVideoStub()->set_on_frame_callback(
297 base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop)));
298 }
299 335
300 run_loop.Run(); 336 Connect();
301 337
302 if (is_using_webrtc()) { 338 std::unique_ptr<VideoStream> video_stream =
303 EXPECT_EQ( 339 host_connection_->StartVideoStream(
304 client_video_renderer_.GetFrameConsumer()->received_frames().size(), 340 base::WrapUnique(new TestScreenCapturer()));
305 1U);
306 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(),
307 0U);
308 } else {
309 EXPECT_EQ(
310 client_video_renderer_.GetFrameConsumer()->received_frames().size(),
311 0U);
312 EXPECT_EQ(client_video_renderer_.GetVideoStub()->received_packets().size(),
313 1U);
314 }
315 341
342 WaitFirstVideoFrame();
316 } 343 }
317 344
318 } // namespace protocol 345 } // namespace protocol
319 } // namespace remoting 346 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/fake_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698