Change how background noise mode in NetEq is set
This change prepares for switching default background noise (bgn) mode
from on to off. The actual switch will be done later.
In this change, the bgn mode is included as a setting in NetEq's config
struct. We're also removing the connection between playout modes and
bgn modes in ACM. In practice this means that bgn mode will change from
off to on for streaming mode, but since the playout modes are not used
it does not matter.
BUG=3519
R=tina.legrand@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/21749004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@6843 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
index 0233e19..317c7b5 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
@@ -214,8 +214,6 @@
uint8_t* payload,
int* payload_len);
- void CheckBgnOff(int sampling_rate, NetEqBackgroundNoiseMode bgn_mode);
-
void WrapTest(uint16_t start_seq_no, uint32_t start_timestamp,
const std::set<uint16_t>& drop_seq_numbers,
bool expect_seq_no_wrap, bool expect_timestamp_wrap);
@@ -231,6 +229,7 @@
uint32_t PlayoutTimestamp();
NetEq* neteq_;
+ NetEq::Config config_;
FILE* rtp_fp_;
unsigned int sim_clock_;
int16_t out_data_[kMaxBlockSize];
@@ -248,17 +247,17 @@
NetEqDecodingTest::NetEqDecodingTest()
: neteq_(NULL),
+ config_(),
rtp_fp_(NULL),
sim_clock_(0),
output_sample_rate_(kInitSampleRateHz),
algorithmic_delay_ms_(0) {
+ config_.sample_rate_hz = kInitSampleRateHz;
memset(out_data_, 0, sizeof(out_data_));
}
void NetEqDecodingTest::SetUp() {
- NetEq::Config config;
- config.sample_rate_hz = kInitSampleRateHz;
- neteq_ = NetEq::Create(config);
+ neteq_ = NetEq::Create(config_);
NetEqNetworkStatistics stat;
ASSERT_EQ(0, neteq_->NetworkStatistics(&stat));
algorithmic_delay_ms_ = stat.current_buffer_size_ms;
@@ -425,107 +424,6 @@
*payload_len = 1; // Only noise level, no spectral parameters.
}
-void NetEqDecodingTest::CheckBgnOff(int sampling_rate_hz,
- NetEqBackgroundNoiseMode bgn_mode) {
- int expected_samples_per_channel = 0;
- uint8_t payload_type = 0xFF; // Invalid.
- if (sampling_rate_hz == 8000) {
- expected_samples_per_channel = kBlockSize8kHz;
- payload_type = 93; // PCM 16, 8 kHz.
- } else if (sampling_rate_hz == 16000) {
- expected_samples_per_channel = kBlockSize16kHz;
- payload_type = 94; // PCM 16, 16 kHZ.
- } else if (sampling_rate_hz == 32000) {
- expected_samples_per_channel = kBlockSize32kHz;
- payload_type = 95; // PCM 16, 32 kHz.
- } else {
- ASSERT_TRUE(false); // Unsupported test case.
- }
-
- NetEqOutputType type;
- int16_t output[kBlockSize32kHz]; // Maximum size is chosen.
- int16_t input[kBlockSize32kHz]; // Maximum size is chosen.
-
- // Payload of 10 ms of PCM16 32 kHz.
- uint8_t payload[kBlockSize32kHz * sizeof(int16_t)];
-
- // Random payload.
- for (int n = 0; n < expected_samples_per_channel; ++n) {
- input[n] = (rand() & ((1 << 10) - 1)) - ((1 << 5) - 1);
- }
- int enc_len_bytes = WebRtcPcm16b_EncodeW16(
- input, expected_samples_per_channel, reinterpret_cast<int16_t*>(payload));
- ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2);
-
- WebRtcRTPHeader rtp_info;
- PopulateRtpInfo(0, 0, &rtp_info);
- rtp_info.header.payloadType = payload_type;
-
- int number_channels = 0;
- int samples_per_channel = 0;
-
- uint32_t receive_timestamp = 0;
- for (int n = 0; n < 10; ++n) { // Insert few packets and get audio.
- number_channels = 0;
- samples_per_channel = 0;
- ASSERT_EQ(0, neteq_->InsertPacket(
- rtp_info, payload, enc_len_bytes, receive_timestamp));
- ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel,
- &number_channels, &type));
- ASSERT_EQ(1, number_channels);
- ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
- ASSERT_EQ(kOutputNormal, type);
-
- // Next packet.
- rtp_info.header.timestamp += expected_samples_per_channel;
- rtp_info.header.sequenceNumber++;
- receive_timestamp += expected_samples_per_channel;
- }
-
- number_channels = 0;
- samples_per_channel = 0;
-
- // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull one
- // frame without checking speech-type. This is the first frame pulled without
- // inserting any packet, and might not be labeled as PCL.
- ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel,
- &number_channels, &type));
- ASSERT_EQ(1, number_channels);
- ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
-
- // To be able to test the fading of background noise we need at lease to pull
- // 611 frames.
- const int kFadingThreshold = 611;
-
- // Test several CNG-to-PLC packet for the expected behavior. The number 20 is
- // arbitrary, but sufficiently large to test enough number of frames.
- const int kNumPlcToCngTestFrames = 20;
- bool plc_to_cng = false;
- for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) {
- number_channels = 0;
- samples_per_channel = 0;
- memset(output, 1, sizeof(output)); // Set to non-zero.
- ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel,
- &number_channels, &type));
- ASSERT_EQ(1, number_channels);
- ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
- if (type == kOutputPLCtoCNG) {
- plc_to_cng = true;
- double sum_squared = 0;
- for (int k = 0; k < number_channels * samples_per_channel; ++k)
- sum_squared += output[k] * output[k];
- if (bgn_mode == kBgnOn) {
- EXPECT_NE(0, sum_squared);
- } else if (bgn_mode == kBgnOff || n > kFadingThreshold) {
- EXPECT_EQ(0, sum_squared);
- }
- } else {
- EXPECT_EQ(kOutputPLC, type);
- }
- }
- EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred.
-}
-
TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(TestBitExactness)) {
const std::string input_rtp_file = webrtc::test::ProjectRootPath() +
"resources/audio_coding/neteq_universal_new.rtp";
@@ -993,26 +891,143 @@
}
}
-TEST_F(NetEqDecodingTest, BackgroundNoise) {
- neteq_->SetBackgroundNoiseMode(kBgnOn);
- CheckBgnOff(8000, kBgnOn);
- CheckBgnOff(16000, kBgnOn);
- CheckBgnOff(32000, kBgnOn);
- EXPECT_EQ(kBgnOn, neteq_->BackgroundNoiseMode());
+class NetEqBgnTest
+ : public NetEqDecodingTest,
+ public ::testing::WithParamInterface<NetEq::BackgroundNoiseMode> {
+ protected:
+ NetEqBgnTest() : NetEqDecodingTest() {
+ config_.background_noise_mode = GetParam();
+ }
- neteq_->SetBackgroundNoiseMode(kBgnOff);
- CheckBgnOff(8000, kBgnOff);
- CheckBgnOff(16000, kBgnOff);
- CheckBgnOff(32000, kBgnOff);
- EXPECT_EQ(kBgnOff, neteq_->BackgroundNoiseMode());
+ void CheckBgnOff(int sampling_rate_hz) {
+ int expected_samples_per_channel = 0;
+ uint8_t payload_type = 0xFF; // Invalid.
+ if (sampling_rate_hz == 8000) {
+ expected_samples_per_channel = kBlockSize8kHz;
+ payload_type = 93; // PCM 16, 8 kHz.
+ } else if (sampling_rate_hz == 16000) {
+ expected_samples_per_channel = kBlockSize16kHz;
+ payload_type = 94; // PCM 16, 16 kHZ.
+ } else if (sampling_rate_hz == 32000) {
+ expected_samples_per_channel = kBlockSize32kHz;
+ payload_type = 95; // PCM 16, 32 kHz.
+ } else {
+ ASSERT_TRUE(false); // Unsupported test case.
+ }
- neteq_->SetBackgroundNoiseMode(kBgnFade);
- CheckBgnOff(8000, kBgnFade);
- CheckBgnOff(16000, kBgnFade);
- CheckBgnOff(32000, kBgnFade);
- EXPECT_EQ(kBgnFade, neteq_->BackgroundNoiseMode());
+ NetEqOutputType type;
+ int16_t output[kBlockSize32kHz]; // Maximum size is chosen.
+ int16_t input[kBlockSize32kHz]; // Maximum size is chosen.
+
+ // Payload of 10 ms of PCM16 32 kHz.
+ uint8_t payload[kBlockSize32kHz * sizeof(int16_t)];
+
+ // Random payload.
+ for (int n = 0; n < expected_samples_per_channel; ++n) {
+ input[n] = (rand() & ((1 << 10) - 1)) - ((1 << 5) - 1);
+ }
+ int enc_len_bytes =
+ WebRtcPcm16b_EncodeW16(input,
+ expected_samples_per_channel,
+ reinterpret_cast<int16_t*>(payload));
+ ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2);
+
+ WebRtcRTPHeader rtp_info;
+ PopulateRtpInfo(0, 0, &rtp_info);
+ rtp_info.header.payloadType = payload_type;
+
+ int number_channels = 0;
+ int samples_per_channel = 0;
+
+ uint32_t receive_timestamp = 0;
+ for (int n = 0; n < 10; ++n) { // Insert few packets and get audio.
+ number_channels = 0;
+ samples_per_channel = 0;
+ ASSERT_EQ(0,
+ neteq_->InsertPacket(
+ rtp_info, payload, enc_len_bytes, receive_timestamp));
+ ASSERT_EQ(0,
+ neteq_->GetAudio(kBlockSize32kHz,
+ output,
+ &samples_per_channel,
+ &number_channels,
+ &type));
+ ASSERT_EQ(1, number_channels);
+ ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
+ ASSERT_EQ(kOutputNormal, type);
+
+ // Next packet.
+ rtp_info.header.timestamp += expected_samples_per_channel;
+ rtp_info.header.sequenceNumber++;
+ receive_timestamp += expected_samples_per_channel;
+ }
+
+ number_channels = 0;
+ samples_per_channel = 0;
+
+ // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull
+ // one frame without checking speech-type. This is the first frame pulled
+ // without inserting any packet, and might not be labeled as PLC.
+ ASSERT_EQ(0,
+ neteq_->GetAudio(kBlockSize32kHz,
+ output,
+ &samples_per_channel,
+ &number_channels,
+ &type));
+ ASSERT_EQ(1, number_channels);
+ ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
+
+ // To be able to test the fading of background noise we need at lease to
+ // pull 611 frames.
+ const int kFadingThreshold = 611;
+
+ // Test several CNG-to-PLC packet for the expected behavior. The number 20
+ // is arbitrary, but sufficiently large to test enough number of frames.
+ const int kNumPlcToCngTestFrames = 20;
+ bool plc_to_cng = false;
+ for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) {
+ number_channels = 0;
+ samples_per_channel = 0;
+ memset(output, 1, sizeof(output)); // Set to non-zero.
+ ASSERT_EQ(0,
+ neteq_->GetAudio(kBlockSize32kHz,
+ output,
+ &samples_per_channel,
+ &number_channels,
+ &type));
+ ASSERT_EQ(1, number_channels);
+ ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
+ if (type == kOutputPLCtoCNG) {
+ plc_to_cng = true;
+ double sum_squared = 0;
+ for (int k = 0; k < number_channels * samples_per_channel; ++k)
+ sum_squared += output[k] * output[k];
+ if (config_.background_noise_mode == NetEq::kBgnOn) {
+ EXPECT_NE(0, sum_squared);
+ } else if (config_.background_noise_mode == NetEq::kBgnOff ||
+ n > kFadingThreshold) {
+ EXPECT_EQ(0, sum_squared);
+ }
+ } else {
+ EXPECT_EQ(kOutputPLC, type);
+ }
+ }
+ EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred.
+ }
+};
+
+TEST_P(NetEqBgnTest, BackgroundNoise) {
+ CheckBgnOff(8000);
+ CheckBgnOff(16000);
+ CheckBgnOff(32000);
}
+INSTANTIATE_TEST_CASE_P(BgnModes,
+ NetEqBgnTest,
+ ::testing::Values(NetEq::kBgnOn,
+ NetEq::kBgnOff,
+ NetEq::kBgnFade));
+
TEST_F(NetEqDecodingTest, SyncPacketInsert) {
WebRtcRTPHeader rtp_info;
uint32_t receive_timestamp = 0;