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