Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <sstream> | 15 #include <sstream> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | 17 #include <utility> |
| 18 | 18 |
| 19 #include "webrtc/api/audio/audio_mixer.h" | 19 #include "webrtc/api/audio/audio_mixer.h" |
| 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
| 21 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h" | 21 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h" |
| 22 #include "webrtc/rtc_base/bind.h" | 22 #include "webrtc/rtc_base/bind.h" |
| 23 #include "webrtc/rtc_base/checks.h" | 23 #include "webrtc/rtc_base/checks.h" |
| 24 #include "webrtc/rtc_base/thread.h" | 24 #include "webrtc/rtc_base/event.h" |
| 25 #include "webrtc/rtc_base/task_queue.h" | |
| 25 #include "webrtc/test/gmock.h" | 26 #include "webrtc/test/gmock.h" |
| 26 | 27 |
| 27 using testing::_; | 28 using testing::_; |
| 28 using testing::Exactly; | 29 using testing::Exactly; |
| 29 using testing::Invoke; | 30 using testing::Invoke; |
| 30 using testing::Return; | 31 using testing::Return; |
| 31 | 32 |
| 32 namespace webrtc { | 33 namespace webrtc { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 for (int i = 1; i < kAudioSources; ++i) { | 367 for (int i = 1; i < kAudioSources; ++i) { |
| 367 EXPECT_EQ(true, | 368 EXPECT_EQ(true, |
| 368 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) | 369 mixer->GetAudioSourceMixabilityStatusForTest(&participants[i])) |
| 369 << "Mixed status of AudioSource #" << i << " wrong."; | 370 << "Mixed status of AudioSource #" << i << " wrong."; |
| 370 } | 371 } |
| 371 } | 372 } |
| 372 | 373 |
| 373 // This test checks that the initialization and participant addition | 374 // This test checks that the initialization and participant addition |
| 374 // can be done on a different thread. | 375 // can be done on a different thread. |
| 375 TEST(AudioMixer, ConstructFromOtherThread) { | 376 TEST(AudioMixer, ConstructFromOtherThread) { |
| 376 std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create(); | 377 rtc::TaskQueue init_queue("init"); |
| 377 std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create(); | 378 rtc::scoped_refptr<AudioMixer> mixer; |
| 378 init_thread->Start(); | 379 rtc::Event event(false, false); |
| 379 const auto mixer = init_thread->Invoke<rtc::scoped_refptr<AudioMixer>>( | 380 init_queue.PostTask([&mixer, &event]() { |
| 380 RTC_FROM_HERE, | 381 mixer = AudioMixerImpl::Create(); |
| 381 // Since AudioMixerImpl::Create is overloaded, we have to | 382 event.Set(); |
| 382 // specify the type of which version we want. | 383 }); |
| 383 static_cast<rtc::scoped_refptr<AudioMixerImpl>(*)()>( | 384 event.Wait(rtc::Event::kForever); |
| 384 &AudioMixerImpl::Create)); | 385 |
| 385 MockMixerAudioSource participant; | 386 MockMixerAudioSource participant; |
| 387 EXPECT_CALL(participant, PreferredSampleRate()) | |
|
minyue-webrtc
2017/07/11 11:16:20
would you explain why this additional expected cal
tommi
2017/07/11 11:58:36
This call is and should always be made so I'm sett
minyue-webrtc
2017/07/11 13:03:22
Acknowledged.
I also advice using StrictMock<Mock
tommi
2017/07/11 13:13:29
Yes that would be an improvement. This CL is abou
| |
| 388 .WillRepeatedly(Return(kDefaultSampleRateHz)); | |
| 386 | 389 |
| 387 ResetFrame(participant.fake_frame()); | 390 ResetFrame(participant.fake_frame()); |
| 388 | 391 |
| 389 participant_thread->Start(); | 392 rtc::TaskQueue participant_queue("participant"); |
| 390 EXPECT_TRUE(participant_thread->Invoke<int>( | 393 participant_queue.PostTask([&mixer, &event, &participant]() { |
| 391 RTC_FROM_HERE, | 394 mixer->AddSource(&participant); |
| 392 rtc::Bind(&AudioMixer::AddSource, mixer.get(), &participant))); | 395 event.Set(); |
| 396 }); | |
| 397 event.Wait(rtc::Event::kForever); | |
| 393 | 398 |
| 394 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz, _)) | 399 EXPECT_CALL(participant, GetAudioFrameWithInfo(kDefaultSampleRateHz, _)) |
| 395 .Times(Exactly(1)); | 400 .Times(Exactly(1)); |
| 396 | 401 |
| 397 // Do one mixer iteration | 402 // Do one mixer iteration |
| 398 mixer->Mix(1, &frame_for_mixing); | 403 mixer->Mix(1, &frame_for_mixing); |
| 399 } | 404 } |
| 400 | 405 |
| 401 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { | 406 TEST(AudioMixer, MutedShouldMixAfterUnmuted) { |
| 402 constexpr int kAudioSources = | 407 constexpr int kAudioSources = |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 } | 536 } |
| 532 | 537 |
| 533 mixer->Mix(number_of_channels, &frame_for_mixing); | 538 mixer->Mix(number_of_channels, &frame_for_mixing); |
| 534 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_); | 539 EXPECT_EQ(rate, frame_for_mixing.sample_rate_hz_); |
| 535 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); | 540 EXPECT_EQ(number_of_channels, frame_for_mixing.num_channels_); |
| 536 } | 541 } |
| 537 } | 542 } |
| 538 } | 543 } |
| 539 } | 544 } |
| 540 } // namespace webrtc | 545 } // namespace webrtc |
| OLD | NEW |