| Index: webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
|
| diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
|
| index db622a7c7f878381468b48293305f515f88cc597..55b84e90fdd96e97eab7494d5dbb0d4e78e0ea71 100644
|
| --- a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
|
| +++ b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
|
| @@ -53,6 +53,10 @@ class OpusTest : public TestWithParam<::testing::tuple<int, int>> {
|
| void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
|
| opus_int32 expect, int32_t set);
|
|
|
| + // Verify that all samples in |audio| are bounded in [-|bound|, |bound|].
|
| + void CheckAudioBounded(int16_t* audio, size_t samples, int channels,
|
| + uint16_t bound);
|
| +
|
| WebRtcOpusEncInst* opus_encoder_;
|
| WebRtcOpusDecInst* opus_decoder_;
|
|
|
| @@ -95,6 +99,16 @@ void OpusTest::SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
|
| EXPECT_EQ(expect, bandwidth);
|
| }
|
|
|
| +void OpusTest::CheckAudioBounded(int16_t* audio, size_t samples, int channels,
|
| + uint16_t bound) {
|
| + for (size_t i = 0; i < samples; ++i) {
|
| + for (int c = 0; c < channels; ++c, ++audio) {
|
| + EXPECT_GE(*audio, -bound);
|
| + EXPECT_LE(*audio, bound);
|
| + }
|
| + }
|
| +}
|
| +
|
| int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder,
|
| const int16_t* input_audio,
|
| size_t input_samples,
|
| @@ -177,9 +191,16 @@ void OpusTest::TestDtxEffect(bool dtx) {
|
|
|
| // When Opus is in DTX, it wakes up in a regular basis. It sends two packets,
|
| // one with an arbitrary size and the other of 1-byte, then stops sending for
|
| - // 19 frames.
|
| - const int cycles = 5;
|
| - for (int j = 0; j < cycles; ++j) {
|
| + // 19 frames. We run 10 second of pure silence, which is about 25 cycles
|
| + // (420 ms/cycle).
|
| + const int kCycles = 24;
|
| +
|
| + // We check that, after a certain cycles (given that the CNG in Opus needs
|
| + // time to adapt), the values of DTX decoded signal are bounded by [-1, 1].
|
| + const int kOutputValueCheckCycle = 18;
|
| + const uint16_t kOutputValueBound = 1;
|
| +
|
| + for (int j = 0; j < kCycles; ++j) {
|
| // DTX mode is maintained 19 frames.
|
| for (int i = 0; i < 19; ++i) {
|
| EXPECT_EQ(kOpus20msFrameSamples,
|
| @@ -192,6 +213,10 @@ void OpusTest::TestDtxEffect(bool dtx) {
|
| EXPECT_EQ(1, opus_encoder_->in_dtx_mode);
|
| EXPECT_EQ(1, opus_decoder_->in_dtx_mode);
|
| EXPECT_EQ(2, audio_type); // Comfort noise.
|
| + if (j >= kOutputValueCheckCycle) {
|
| + CheckAudioBounded(output_data_decode, kOpus20msFrameSamples,
|
| + channels_, kOutputValueBound);
|
| + }
|
| } else {
|
| EXPECT_GT(encoded_bytes_, 1U);
|
| EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
|
| @@ -221,6 +246,10 @@ void OpusTest::TestDtxEffect(bool dtx) {
|
| EXPECT_EQ(1, opus_encoder_->in_dtx_mode);
|
| EXPECT_EQ(1, opus_decoder_->in_dtx_mode);
|
| EXPECT_EQ(2, audio_type); // Comfort noise.
|
| + if (j >= kOutputValueCheckCycle) {
|
| + CheckAudioBounded(output_data_decode, kOpus20msFrameSamples,
|
| + channels_, kOutputValueBound);
|
| + }
|
| } else {
|
| EXPECT_GT(encoded_bytes_, 1U);
|
| EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
|
|
|