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

Unified Diff: webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc

Issue 2286343002: Less lock acquisitions for AudioMixer. (Closed)
Patch Set: Rebase. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/audio_mixer/audio_mixer_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
diff --git a/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc b/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
index 36bd7c4211e6a9fc0398dfebe3773b91e69a4a1b..895535fdb2bca2502446d075180a51867e496891 100644
--- a/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
+++ b/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
@@ -8,10 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <string.h>
+
#include <memory>
#include <utility>
#include "testing/gmock/include/gmock/gmock.h"
+#include "webrtc/base/bind.h"
+#include "webrtc/base/thread.h"
#include "webrtc/modules/audio_mixer/audio_mixer_defines.h"
#include "webrtc/modules/audio_mixer/audio_mixer.h"
@@ -103,7 +107,7 @@ void MixAndCompare(
mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
for (int i = 0; i < num_audio_sources; i++) {
- EXPECT_EQ(participants[i].IsMixed(), expected_status[i])
+ EXPECT_EQ(expected_status[i], participants[i].IsMixed())
<< "Mixed status of AudioSource #" << i << " wrong.";
}
}
@@ -202,6 +206,63 @@ TEST(AudioMixer, LargestEnergyVadActiveMixed) {
}
}
+TEST(AudioMixer, FrameNotModifiedForSingleParticipant) {
+ const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
+
+ MockMixerAudioSource participant;
+
+ ResetFrame(participant.fake_frame());
+ const int n_samples = participant.fake_frame()->samples_per_channel_;
+
+ // Modify the frame so that it's not zero.
+ for (int j = 0; j < n_samples; j++) {
+ participant.fake_frame()->data_[j] = j;
+ }
+
+ EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
+ EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
+
+ AudioFrame audio_frame;
+ // Two mix iteration to compare after the ramp-up step.
+ for (int i = 0; i < 2; i++) {
+ mixer->Mix(kDefaultSampleRateHz,
+ 1, // number of channels
+ &audio_frame);
+ }
+
+ EXPECT_EQ(
+ 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples));
+}
+
+TEST(AudioMixer, FrameNotModifiedForSingleAnonymousParticipant) {
+ const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
+
+ MockMixerAudioSource participant;
+
+ ResetFrame(participant.fake_frame());
+ const int n_samples = participant.fake_frame()->samples_per_channel_;
+
+ // Modify the frame so that it's not zero.
+ for (int j = 0; j < n_samples; j++) {
+ participant.fake_frame()->data_[j] = j;
+ }
+
+ EXPECT_EQ(0, mixer->SetMixabilityStatus(&participant, true));
+ EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(&participant, true));
+ EXPECT_CALL(participant, GetAudioFrameWithMuted(_, _)).Times(Exactly(2));
+
+ AudioFrame audio_frame;
+ // Two mix iteration to compare after the ramp-up step.
+ for (int i = 0; i < 2; i++) {
+ mixer->Mix(kDefaultSampleRateHz,
+ 1, // number of channels
+ &audio_frame);
+ }
+
+ EXPECT_EQ(
+ 0, memcmp(participant.fake_frame()->data_, audio_frame.data_, n_samples));
+}
+
TEST(AudioMixer, ParticipantSampleRate) {
const std::unique_ptr<AudioMixer> mixer(AudioMixer::Create(kId));
@@ -332,11 +393,41 @@ TEST(AudioMixer, RampedOutSourcesShouldNotBeMarkedMixed) {
// The loudest participants should have been mixed.
for (int i = 1; i < kAudioSources; i++) {
- EXPECT_EQ(participants[i].IsMixed(), true)
+ EXPECT_EQ(true, participants[i].IsMixed())
<< "Mixed status of AudioSource #" << i << " wrong.";
}
}
+// This test checks that the initialization and participant addition
+// can be done on a different thread.
+TEST(AudioMixer, ConstructFromOtherThread) {
+ std::unique_ptr<rtc::Thread> init_thread = rtc::Thread::Create();
+ std::unique_ptr<rtc::Thread> participant_thread = rtc::Thread::Create();
+ init_thread->Start();
+ std::unique_ptr<AudioMixer> mixer(
+ init_thread->Invoke<std::unique_ptr<AudioMixer>>(
+ RTC_FROM_HERE, std::bind(&AudioMixer::Create, kId)));
+ MockMixerAudioSource participant;
+
+ ResetFrame(participant.fake_frame());
+
+ participant_thread->Start();
+ EXPECT_EQ(0, participant_thread->Invoke<int>(
+ RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetMixabilityStatus,
+ mixer.get(), &participant, true)));
+
+ EXPECT_EQ(
+ 0, participant_thread->Invoke<int>(
+ RTC_FROM_HERE, rtc::Bind(&AudioMixer::SetAnonymousMixabilityStatus,
+ mixer.get(), &participant, true)));
+
+ EXPECT_CALL(participant, GetAudioFrameWithMuted(_, kDefaultSampleRateHz))
+ .Times(Exactly(1));
+
+ // Do one mixer iteration
+ mixer->Mix(kDefaultSampleRateHz, 1, &frame_for_mixing);
+}
+
TEST(AudioMixer, MutedShouldMixAfterUnmuted) {
constexpr int kAudioSources =
AudioMixer::kMaximumAmountOfMixedAudioSources + 1;
« no previous file with comments | « webrtc/modules/audio_mixer/audio_mixer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698