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

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

Issue 2650633003: Fix threading issues in the audio pipeline for WebRTC remoting protocol. (Closed)
Patch Set: . Created 3 years, 10 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/webrtc_audio_module.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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/threading/thread.h"
15 #include "base/threading/thread_checker.h"
14 #include "remoting/base/constants.h" 16 #include "remoting/base/constants.h"
15 #include "remoting/proto/audio.pb.h" 17 #include "remoting/proto/audio.pb.h"
16 #include "remoting/protocol/audio_source.h" 18 #include "remoting/protocol/audio_source.h"
17 #include "remoting/protocol/audio_stream.h" 19 #include "remoting/protocol/audio_stream.h"
18 #include "remoting/protocol/audio_stub.h" 20 #include "remoting/protocol/audio_stub.h"
19 #include "remoting/protocol/fake_session.h" 21 #include "remoting/protocol/fake_session.h"
20 #include "remoting/protocol/fake_video_renderer.h" 22 #include "remoting/protocol/fake_video_renderer.h"
21 #include "remoting/protocol/ice_connection_to_client.h" 23 #include "remoting/protocol/ice_connection_to_client.h"
22 #include "remoting/protocol/ice_connection_to_host.h" 24 #include "remoting/protocol/ice_connection_to_host.h"
23 #include "remoting/protocol/protocol_mock_objects.h" 25 #include "remoting/protocol/protocol_mock_objects.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 }; 180 };
179 181
180 class FakeAudioPlayer : public AudioStub { 182 class FakeAudioPlayer : public AudioStub {
181 public: 183 public:
182 FakeAudioPlayer() : weak_factory_(this) {} 184 FakeAudioPlayer() : weak_factory_(this) {}
183 ~FakeAudioPlayer() override {} 185 ~FakeAudioPlayer() override {}
184 186
185 // AudioStub interface. 187 // AudioStub interface.
186 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet, 188 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet,
187 const base::Closure& done) override { 189 const base::Closure& done) override {
190 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
188 EXPECT_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); 191 EXPECT_EQ(AudioPacket::ENCODING_RAW, packet->encoding());
189 EXPECT_EQ(AudioPacket::SAMPLING_RATE_48000, packet->sampling_rate()); 192 EXPECT_EQ(AudioPacket::SAMPLING_RATE_48000, packet->sampling_rate());
190 EXPECT_EQ(AudioPacket::BYTES_PER_SAMPLE_2, packet->bytes_per_sample()); 193 EXPECT_EQ(AudioPacket::BYTES_PER_SAMPLE_2, packet->bytes_per_sample());
191 EXPECT_EQ(AudioPacket::CHANNELS_STEREO, packet->channels()); 194 EXPECT_EQ(AudioPacket::CHANNELS_STEREO, packet->channels());
192 195
193 data_.insert(data_.end(), packet->data(0).begin(), packet->data(0).end()); 196 data_.insert(data_.end(), packet->data(0).begin(), packet->data(0).end());
194 197
195 if (run_loop_ && data_.size() >= samples_expected_ * 4) 198 if (run_loop_ && data_.size() >= samples_expected_ * 4)
196 run_loop_->Quit(); 199 run_loop_->Quit();
197 200
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 EXPECT_LE(kTestAudioSignalFrequencyLeftHz - 50, left_hz); 237 EXPECT_LE(kTestAudioSignalFrequencyLeftHz - 50, left_hz);
235 EXPECT_GE(kTestAudioSignalFrequencyLeftHz + 50, left_hz); 238 EXPECT_GE(kTestAudioSignalFrequencyLeftHz + 50, left_hz);
236 int right_hz = (right * kAudioSampleRate / (num_samples - skipped_samples)); 239 int right_hz = (right * kAudioSampleRate / (num_samples - skipped_samples));
237 EXPECT_LE(kTestAudioSignalFrequencyRightHz - 50, right_hz); 240 EXPECT_LE(kTestAudioSignalFrequencyRightHz - 50, right_hz);
238 EXPECT_GE(kTestAudioSignalFrequencyRightHz + 50, right_hz); 241 EXPECT_GE(kTestAudioSignalFrequencyRightHz + 50, right_hz);
239 } 242 }
240 243
241 base::WeakPtr<AudioStub> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } 244 base::WeakPtr<AudioStub> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
242 245
243 private: 246 private:
247 base::ThreadChecker thread_checker_;
244 std::vector<char> data_; 248 std::vector<char> data_;
245 base::RunLoop* run_loop_ = nullptr; 249 base::RunLoop* run_loop_ = nullptr;
246 size_t samples_expected_ = 0; 250 size_t samples_expected_ = 0;
247 251
248 base::WeakPtrFactory<FakeAudioPlayer> weak_factory_; 252 base::WeakPtrFactory<FakeAudioPlayer> weak_factory_;
249 }; 253 };
250 254
251 } // namespace 255 } // namespace
252 256
253 class ConnectionTest : public testing::Test, 257 class ConnectionTest : public testing::Test,
254 public testing::WithParamInterface<bool> { 258 public testing::WithParamInterface<bool> {
255 public: 259 public:
256 ConnectionTest() {} 260 ConnectionTest()
261 : video_encode_thread_("VideoEncode"),
262 audio_encode_thread_("AudioEncode"),
263 audio_decode_thread_("AudioDecode") {
264 video_encode_thread_.Start();
265 audio_encode_thread_.Start();
266 audio_decode_thread_.Start();
267 }
257 268
258 void DestroyHost() { 269 void DestroyHost() {
259 host_connection_.reset(); 270 host_connection_.reset();
260 run_loop_->Quit(); 271 run_loop_->Quit();
261 } 272 }
262 273
263 protected: 274 protected:
264 bool is_using_webrtc() { return GetParam(); } 275 bool is_using_webrtc() { return GetParam(); }
265 276
266 void SetUp() override { 277 void SetUp() override {
(...skipping 22 matching lines...) Expand all
289 host_connection_->SetEventHandler(&host_event_handler_); 300 host_connection_->SetEventHandler(&host_event_handler_);
290 host_connection_->set_clipboard_stub(&host_clipboard_stub_); 301 host_connection_->set_clipboard_stub(&host_clipboard_stub_);
291 host_connection_->set_host_stub(&host_stub_); 302 host_connection_->set_host_stub(&host_stub_);
292 host_connection_->set_input_stub(&host_input_stub_); 303 host_connection_->set_input_stub(&host_input_stub_);
293 304
294 // Setup client side. 305 // Setup client side.
295 client_connection_->set_client_stub(&client_stub_); 306 client_connection_->set_client_stub(&client_stub_);
296 client_connection_->set_clipboard_stub(&client_clipboard_stub_); 307 client_connection_->set_clipboard_stub(&client_clipboard_stub_);
297 client_connection_->set_video_renderer(&client_video_renderer_); 308 client_connection_->set_video_renderer(&client_video_renderer_);
298 309
299 client_connection_->InitializeAudio(message_loop_.task_runner(), 310 client_connection_->InitializeAudio(audio_decode_thread_.task_runner(),
300 client_audio_player_.GetWeakPtr()); 311 client_audio_player_.GetWeakPtr());
301 } 312 }
302 313
303 void Connect() { 314 void Connect() {
304 { 315 {
305 testing::InSequence sequence; 316 testing::InSequence sequence;
306 EXPECT_CALL(host_event_handler_, OnConnectionAuthenticating()); 317 EXPECT_CALL(host_event_handler_, OnConnectionAuthenticating());
307 EXPECT_CALL(host_event_handler_, OnConnectionAuthenticated()); 318 EXPECT_CALL(host_event_handler_, OnConnectionAuthenticated());
308 } 319 }
309 EXPECT_CALL(host_event_handler_, OnConnectionChannelsConnected()) 320 EXPECT_CALL(host_event_handler_, OnConnectionChannelsConnected())
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 MockConnectionToHostEventCallback client_event_handler_; 442 MockConnectionToHostEventCallback client_event_handler_;
432 MockClientStub client_stub_; 443 MockClientStub client_stub_;
433 MockClipboardStub client_clipboard_stub_; 444 MockClipboardStub client_clipboard_stub_;
434 FakeVideoRenderer client_video_renderer_; 445 FakeVideoRenderer client_video_renderer_;
435 FakeAudioPlayer client_audio_player_; 446 FakeAudioPlayer client_audio_player_;
436 std::unique_ptr<ConnectionToHost> client_connection_; 447 std::unique_ptr<ConnectionToHost> client_connection_;
437 FakeSession* client_session_; // Owned by |client_connection_|. 448 FakeSession* client_session_; // Owned by |client_connection_|.
438 std::unique_ptr<FakeSession> owned_client_session_; 449 std::unique_ptr<FakeSession> owned_client_session_;
439 bool client_connected_ = false; 450 bool client_connected_ = false;
440 451
452 base::Thread video_encode_thread_;
453 base::Thread audio_encode_thread_;
454 base::Thread audio_decode_thread_;
455
441 private: 456 private:
442 DISALLOW_COPY_AND_ASSIGN(ConnectionTest); 457 DISALLOW_COPY_AND_ASSIGN(ConnectionTest);
443 }; 458 };
444 459
445 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false)); 460 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false));
446 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true)); 461 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true));
447 462
448 TEST_P(ConnectionTest, RejectConnection) { 463 TEST_P(ConnectionTest, RejectConnection) {
449 EXPECT_CALL(client_event_handler_, 464 EXPECT_CALL(client_event_handler_,
450 OnConnectionState(ConnectionToHost::CONNECTING, OK)); 465 OnConnectionState(ConnectionToHost::CONNECTING, OK));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 auto capturer = base::MakeUnique<TestScreenCapturer>(); 669 auto capturer = base::MakeUnique<TestScreenCapturer>();
655 capturer->FailNthFrame(1); 670 capturer->FailNthFrame(1);
656 auto video_stream = host_connection_->StartVideoStream(std::move(capturer)); 671 auto video_stream = host_connection_->StartVideoStream(std::move(capturer));
657 672
658 WaitNextVideoFrame(); 673 WaitNextVideoFrame();
659 WaitNextVideoFrame(); 674 WaitNextVideoFrame();
660 } 675 }
661 676
662 } // namespace protocol 677 } // namespace protocol
663 } // namespace remoting 678 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/webrtc_audio_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698