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

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

Issue 2286343002: Less lock acquisitions for AudioMixer. (Closed)
Patch Set: GUARDED_BY, ACCESS_ON, C header and EXPECT_EQ order. Created 4 years, 4 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
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..fd639f226cfb545a7c0446dcb06848c4493216f9 100644
--- a/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
+++ b/webrtc/modules/audio_mixer/test/audio_mixer_unittest.cc
@@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <string.h>
+
#include <memory>
#include <utility>
@@ -103,7 +105,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 +204,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,7 +391,7 @@ 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.";
}
}

Powered by Google App Engine
This is Rietveld 408576698