Chromium Code Reviews| 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 febea2f869fe7ca94897015ac2d35df7219233b7..1bbc590d68ba9b9a09ba83c178196bfde3d6fa25 100644 |
| --- a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc |
| +++ b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc |
| @@ -38,7 +38,7 @@ class OpusTest : public TestWithParam<::testing::tuple<int, int>> { |
| protected: |
| OpusTest(); |
| - void TestDtxEffect(bool dtx, int block_length_ms); |
| + void TestDtxAndCbrEffect(bool dtx, bool cbr, int block_length_ms); |
|
minyue-webrtc
2017/03/31 18:37:43
Merging DTX and CBR into this function isn't good.
|
| // Prepare |speech_data_| for encoding, read from a hard-coded file. |
| // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a |
| @@ -133,9 +133,11 @@ int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, |
| // Test if encoder/decoder can enter DTX mode properly and do not enter DTX when |
| // they should not. This test is signal dependent. |
| -void OpusTest::TestDtxEffect(bool dtx, int block_length_ms) { |
| +void OpusTest::TestDtxAndCbrEffect(bool dtx, bool cbr, int block_length_ms) { |
| PrepareSpeechData(channels_, block_length_ms, 2000); |
| const size_t samples = kOpusRateKhz * block_length_ms; |
| + int32_t max_pkt_size_diff = 0; |
| + int32_t prev_pkt_size = 0; |
| // Create encoder memory. |
| EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, |
| @@ -154,6 +156,10 @@ void OpusTest::TestDtxEffect(bool dtx, int block_length_ms) { |
| EXPECT_EQ(0, dtx ? WebRtcOpus_EnableDtx(opus_encoder_) : |
| WebRtcOpus_DisableDtx(opus_encoder_)); |
| + // Setting CBR. |
| + EXPECT_EQ(0, cbr ? WebRtcOpus_EnableCbr(opus_encoder_) |
| + : WebRtcOpus_DisableCbr(opus_encoder_)); |
| + |
| int16_t audio_type; |
| int16_t* output_data_decode = new int16_t[samples * channels_]; |
| @@ -170,6 +176,19 @@ void OpusTest::TestDtxEffect(bool dtx, int block_length_ms) { |
| EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| EXPECT_EQ(0, audio_type); // Speech. |
| } |
| + if (!opus_encoder_->in_dtx_mode) { |
| + if (prev_pkt_size > 0) { |
| + int32_t diff = std::abs((int32_t)encoded_bytes_ - prev_pkt_size); |
| + max_pkt_size_diff = std::max(max_pkt_size_diff, diff); |
| + } |
| + prev_pkt_size = encoded_bytes_; |
| + } |
| + } |
| + |
| + if (cbr) { |
| + EXPECT_EQ(max_pkt_size_diff, 0); |
| + } else { |
| + EXPECT_GT(max_pkt_size_diff, 0); |
| } |
| // We input some silent segments. In DTX mode, the encoder will stop sending. |
| @@ -514,17 +533,31 @@ TEST_P(OpusTest, OpusEnableDisableDtx) { |
| } |
| TEST_P(OpusTest, OpusDtxOff) { |
| - TestDtxEffect(false, 10); |
| - TestDtxEffect(false, 20); |
| - TestDtxEffect(false, 40); |
| + TestDtxAndCbrEffect(false, false, 10); |
| + TestDtxAndCbrEffect(false, false, 20); |
| + TestDtxAndCbrEffect(false, false, 40); |
| } |
| TEST_P(OpusTest, OpusDtxOn) { |
| - TestDtxEffect(true, 10); |
| - TestDtxEffect(true, 20); |
| - TestDtxEffect(true, 40); |
| + TestDtxAndCbrEffect(true, false, 10); |
| + TestDtxAndCbrEffect(true, false, 20); |
| + TestDtxAndCbrEffect(true, false, 40); |
| } |
| +TEST_P(OpusTest, OpusCbrOn) { |
| + TestDtxAndCbrEffect(false, true, 10); |
| + TestDtxAndCbrEffect(false, true, 20); |
| + TestDtxAndCbrEffect(false, true, 40); |
| +} |
| + |
| +#if 0 // The DTX part fails when both dtx and cbr is on |
| +TEST_P(OpusTest, OpusDtxOnCbrOn) { |
| + TestDtxAndCbrEffect(true, true, 10); |
| + TestDtxAndCbrEffect(true, true, 20); |
| + TestDtxAndCbrEffect(true, true, 40); |
| +} |
| +#endif |
| + |
| TEST_P(OpusTest, OpusSetPacketLossRate) { |
| // Test without creating encoder memory. |
| EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50)); |