From f3995f71cec25402ee516707543dc7d76f2f3edb Mon Sep 17 00:00:00 2001 From: "henrik.lundin" Date: Tue, 10 May 2016 05:54:35 -0700 Subject: [PATCH] NetEq: Implement Expand::Muted Adding a new method to the Expand class, which will answer the question whether an ongoing expansion has been faded down to zero amplitude (i.e., been muted). Also adding a test. This new functionality will be used in CLs to follow. BUG=webrtc:5608 NOTRY=True Review-Url: https://codereview.webrtc.org/1967473004 Cr-Commit-Position: refs/heads/master@{#12672} --- webrtc/modules/audio_coding/neteq/expand.cc | 11 +++++++ webrtc/modules/audio_coding/neteq/expand.h | 4 +++ .../audio_coding/neteq/expand_unittest.cc | 31 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/webrtc/modules/audio_coding/neteq/expand.cc b/webrtc/modules/audio_coding/neteq/expand.cc index 5cb18db462..4c17fd558d 100644 --- a/webrtc/modules/audio_coding/neteq/expand.cc +++ b/webrtc/modules/audio_coding/neteq/expand.cc @@ -327,6 +327,17 @@ void Expand::SetParametersForMergeAfterExpand() { stop_muting_ = true; } +bool Expand::Muted() const { + if (first_expand_ || stop_muting_) + return false; + RTC_DCHECK(channel_parameters_); + for (size_t ch = 0; ch < num_channels_; ++ch) { + if (channel_parameters_[ch].mute_factor != 0) + return false; + } + return true; +} + size_t Expand::overlap_length() const { return overlap_length_; } diff --git a/webrtc/modules/audio_coding/neteq/expand.h b/webrtc/modules/audio_coding/neteq/expand.h index 44ced0ab6c..0feba3693a 100644 --- a/webrtc/modules/audio_coding/neteq/expand.h +++ b/webrtc/modules/audio_coding/neteq/expand.h @@ -62,6 +62,10 @@ class Expand { return channel_parameters_[channel].mute_factor; } + // Returns true if expansion has been faded down to zero amplitude (for all + // channels); false otherwise. + bool Muted() const; + // Accessors and mutators. virtual size_t overlap_length() const; size_t max_lag() const { return max_lag_; } diff --git a/webrtc/modules/audio_coding/neteq/expand_unittest.cc b/webrtc/modules/audio_coding/neteq/expand_unittest.cc index 1441704102..cbc6e47562 100644 --- a/webrtc/modules/audio_coding/neteq/expand_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/expand_unittest.cc @@ -169,6 +169,37 @@ TEST_F(ExpandTest, CheckOutageStatsAfterReset) { statistics_.last_outage_duration_ms()); } +namespace { +// Runs expand until Muted() returns true. Times out after 1000 calls. +void ExpandUntilMuted(size_t num_channels, Expand* expand) { + EXPECT_FALSE(expand->Muted()) << "Instance is muted from the start"; + AudioMultiVector output(num_channels); + int num_calls = 0; + while (!expand->Muted()) { + ASSERT_LT(num_calls++, 1000) << "Test timed out"; + EXPECT_EQ(0, expand->Process(&output)); + } +} +} // namespace + +// Verifies that Muted() returns true after a long expand period. Also verifies +// that Muted() is reset to false after calling Reset(), +// SetParametersForMergeAfterExpand() and SetParametersForNormalAfterExpand(). +TEST_F(ExpandTest, Muted) { + ExpandUntilMuted(num_channels_, &expand_); + expand_.Reset(); + EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted. + + ExpandUntilMuted(num_channels_, &expand_); + expand_.SetParametersForMergeAfterExpand(); + EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted. + + expand_.Reset(); // Must reset in order to start a new expand period. + ExpandUntilMuted(num_channels_, &expand_); + expand_.SetParametersForNormalAfterExpand(); + EXPECT_FALSE(expand_.Muted()); // Should be back to unmuted. +} + // TODO(hlundin): Write more tests. } // namespace webrtc