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

Side by Side Diff: webrtc/modules/audio_conference_mixer/test/audio_conference_mixer_unittest.cc

Issue 1257583011: Adding unittests to AudioConferenceMixer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | webrtc/modules/modules.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/base/scoped_ptr.h"
12 #include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer .h"
13 #include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer _defines.h"
14
15 #include "testing/gmock/include/gmock/gmock.h"
Andrew MacDonald 2015/08/18 04:03:48 This can go with the other includes.
16
17 namespace webrtc {
18
19 using testing::_;
20 using testing::AtLeast;
21 using testing::Invoke;
22 using testing::Return;
23
24 class MockAudioMixerOutputReceiver : public AudioMixerOutputReceiver {
25 public:
26 MOCK_METHOD4(NewMixedAudio, void(const int32_t id,
27 const AudioFrame& general_audio_frame,
28 const AudioFrame** unique_audio_frames,
29 const uint32_t size));
30 };
31
32 class MockMixerParticipant : public MixerParticipant {
33 public:
34 MockMixerParticipant() {
35 ON_CALL(*this, GetAudioFrame(_, _))
36 .WillByDefault(Invoke(this, &MockMixerParticipant::FakeAudioFrame));
Andrew MacDonald 2015/08/18 04:03:48 If you always want this behavior, don't mock it, b
minyue-webrtc 2015/08/25 15:36:12 The reason that I mock GetAudioFrame is that I wan
ajm 2015/08/25 16:46:03 Ah OK. You can often define the methods actions di
37 }
38 MOCK_METHOD2(GetAudioFrame,
39 int32_t(const int32_t id, AudioFrame& audio_frame));
40 MOCK_METHOD1(NeededFrequency, int32_t(const int32_t id));
41 AudioFrame fake_frame_;
Andrew MacDonald 2015/08/18 04:03:48 This should be private with a setter.
minyue-webrtc 2015/08/25 15:36:12 Yes, it can be nicer but the it is more complicate
ajm 2015/08/25 16:46:03 The typical way to do this is: AudioFrame* fake_fr
minyue-webrtc 2015/08/31 14:28:39 I like the proposal, changes made accordingly.
42 private:
43 int32_t FakeAudioFrame(const int32_t id, AudioFrame& audio_frame) {
44 audio_frame.CopyFrom(fake_frame_);
45 return 0;
46 }
47 };
48
49 TEST(AudioConferenceMixer, AnonymousAndUnanonymous) {
Andrew MacDonald 2015/08/18 04:03:48 Nonanonymous is a bit more natural (but also weird
minyue-webrtc 2015/08/25 15:36:12 How about "Named"?
ajm 2015/08/25 16:46:03 Nice.
50 const int kId = 1;
51 // Should not matter even if partipants are more than
52 // kMaximumAmountOfMixedParticipants.
53 const int kUnanonymous =
54 AudioConferenceMixer::kMaximumAmountOfMixedParticipants + 1;
55 const int kAnonymous =
56 AudioConferenceMixer::kMaximumAmountOfMixedParticipants + 1;
57
58 rtc::scoped_ptr<AudioConferenceMixer> mixer;
59 mixer.reset(AudioConferenceMixer::Create(kId));
Andrew MacDonald 2015/08/18 04:03:48 Don't reset, assign directly: rtc::scoped_ptr<Audi
minyue-webrtc 2015/08/25 15:36:12 Done.
60
61 MockMixerParticipant unanonymous[kUnanonymous];
62 MockMixerParticipant anonymous[kAnonymous];
Andrew MacDonald 2015/08/18 04:03:48 Use vectors.
minyue-webrtc 2015/08/25 15:36:12 Done.
63
64 bool ret;
65 for (int i = 0; i < kUnanonymous; i++) {
Andrew MacDonald 2015/08/18 04:03:48 nit: ++i and below
minyue-webrtc 2015/08/25 15:36:12 Done.
66 EXPECT_EQ(0, mixer->SetMixabilityStatus(unanonymous[i], true));
67 EXPECT_EQ(0, mixer->MixabilityStatus(unanonymous[i], ret));
Andrew MacDonald 2015/08/18 04:03:48 Is there any value in testing this with more than
minyue-webrtc 2015/08/25 15:36:12 May be not very needed. But I made the number of "
68 EXPECT_TRUE(ret);
69 }
70
71 for (int i = 0; i < kAnonymous; i++) {
Andrew MacDonald 2015/08/18 04:03:48 Same here, is this loop adding any value? And the
minyue-webrtc 2015/08/25 15:36:12 I made the number of "named" to be larger than kMa
72 // Participant must be registered before turning it into anonymous.
73 EXPECT_EQ(-1, mixer->SetAnonymousMixabilityStatus(anonymous[i], true));
74 EXPECT_EQ(0, mixer->SetMixabilityStatus(anonymous[i], true));
75 EXPECT_EQ(0, mixer->MixabilityStatus(anonymous[i], ret));
76 EXPECT_TRUE(ret);
77 EXPECT_EQ(0, mixer->AnonymousMixabilityStatus(anonymous[i], ret));
78 EXPECT_FALSE(ret);
79
80 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(anonymous[i], true));
81 EXPECT_EQ(0, mixer->AnonymousMixabilityStatus(anonymous[i], ret));
82 EXPECT_TRUE(ret);
83
84 // Anonymous participants do not show status by MixabilityStatus.
85 EXPECT_EQ(0, mixer->MixabilityStatus(anonymous[i], ret));
86 EXPECT_FALSE(ret);
87 }
88
89 for (int i = 0; i < kUnanonymous; i++) {
90 EXPECT_EQ(0, mixer->SetMixabilityStatus(unanonymous[i], false));
91 EXPECT_EQ(0, mixer->MixabilityStatus(unanonymous[i], ret));
92 EXPECT_FALSE(ret);
93 }
94
95 for (int i = 0; i < kAnonymous - 1; i++) {
96 EXPECT_EQ(0, mixer->SetAnonymousMixabilityStatus(anonymous[i], false));
97 EXPECT_EQ(0, mixer->AnonymousMixabilityStatus(anonymous[i], ret));
98 EXPECT_FALSE(ret);
99 // SetAnonymousMixabilityStatus(anonymous, false) moves anonymous to the
100 // unanonymous group.
101 EXPECT_EQ(0, mixer->MixabilityStatus(anonymous[i], ret));
102 EXPECT_TRUE(ret);
103 }
104
105 // SetMixabilityStatus(anonymous, false) will remove anonymous from both
106 // anonymous and unanonymous groups.
107 EXPECT_EQ(0, mixer->SetMixabilityStatus(anonymous[kAnonymous - 1], false));
108 EXPECT_EQ(0, mixer->AnonymousMixabilityStatus(anonymous[kAnonymous - 1],
109 ret));
110 EXPECT_FALSE(ret);
111 EXPECT_EQ(0, mixer->MixabilityStatus(anonymous[kAnonymous - 1], ret));
112 EXPECT_FALSE(ret);
113 }
114
115 TEST(AudioConferenceMixer, LargestEnergyVadActiveMixed) {
116 const int kId = 1;
117 const int kParticipants =
118 AudioConferenceMixer::kMaximumAmountOfMixedParticipants + 3;
119
120 rtc::scoped_ptr<AudioConferenceMixer> mixer;
121 mixer.reset(AudioConferenceMixer::Create(kId));
Andrew MacDonald 2015/08/18 04:03:48 As above, reset is not needed.
minyue-webrtc 2015/08/25 15:36:12 Done.
122
123 MockAudioMixerOutputReceiver output_receiver;
124 EXPECT_EQ(0, mixer->RegisterMixedStreamCallback(output_receiver));
125
126 MockMixerParticipant participants[kParticipants];
Andrew MacDonald 2015/08/18 04:03:48 vector
minyue-webrtc 2015/08/25 15:36:12 Done.
127
128 for (int i = 0; i < kParticipants; i++) {
129 participants[i].fake_frame_.UpdateFrame(i, 0, nullptr, 320, 32000,
Andrew MacDonald 2015/08/18 04:03:48 This is a rarely used method. Could you just set t
minyue-webrtc 2015/08/25 15:36:12 I searched for its usage, and found that it is not
ajm 2015/08/25 16:46:03 I'd argue that this is _less_ readable since you h
minyue-webrtc 2015/08/31 14:28:39 I'd take your initial suggestion.
130 AudioFrame::kNormalSpeech,
131 AudioFrame::kVadActive, 1, 0);
132 // Use 80 to escape from ramped-in window.
Andrew MacDonald 2015/08/18 04:03:48 Do you mean that you need to choose a late enough
minyue-webrtc 2015/08/25 15:36:12 Done.
133 participants[i].fake_frame_.data_[80] = i;
134
135 EXPECT_EQ(0, mixer->SetMixabilityStatus(participants[i], true));
136 EXPECT_CALL(participants[i], GetAudioFrame(_, _))
137 .Times(AtLeast(1));
138 EXPECT_CALL(participants[i], NeededFrequency(_))
139 .WillRepeatedly(Return(32000));
140 }
141
142 // Last participant gives audio frame with passive VAD, although it has the
143 // largest energy.
144 participants[kParticipants - 1].fake_frame_.vad_activity_ =
145 AudioFrame::kVadPassive;
146
147 EXPECT_CALL(output_receiver, NewMixedAudio(_, _, _, _))
148 .Times(AtLeast(1));
149
150 EXPECT_EQ(0, mixer->Process());
151
152 bool ret;
Andrew MacDonald 2015/08/18 04:03:48 Instead of ret, name this what it is: is_mixed.
minyue-webrtc 2015/08/25 15:36:12 Done.
153 for (int i = 0; i < kParticipants; i++) {
154 EXPECT_EQ(0, participants[i].IsMixed(ret));
155 if (i == kParticipants - 1 || i < kParticipants - 1 -
156 AudioConferenceMixer::kMaximumAmountOfMixedParticipants) {
157 EXPECT_FALSE(ret) << "Mixing status of Participant #" << i << " wrong.";
158 } else {
159 EXPECT_TRUE(ret) << "Mixing status of Participant #" << i << " wrong.";
160 }
161 }
162
163 EXPECT_EQ(0, mixer->UnRegisterMixedStreamCallback());
164 }
165
166 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | webrtc/modules/modules.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698