Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 const size_t kOpus20msFrameSamples = kOpusRateKhz * 20; | 33 const size_t kOpus20msFrameSamples = kOpusRateKhz * 20; |
| 34 // Number of samples-per-channel in a 10 ms frame, sampled at 48 kHz. | 34 // Number of samples-per-channel in a 10 ms frame, sampled at 48 kHz. |
| 35 const size_t kOpus10msFrameSamples = kOpusRateKhz * 10; | 35 const size_t kOpus10msFrameSamples = kOpusRateKhz * 10; |
| 36 | 36 |
| 37 class OpusTest : public TestWithParam<::testing::tuple<int, int>> { | 37 class OpusTest : public TestWithParam<::testing::tuple<int, int>> { |
| 38 protected: | 38 protected: |
| 39 OpusTest(); | 39 OpusTest(); |
| 40 | 40 |
| 41 void TestDtxEffect(bool dtx, int block_length_ms); | 41 void TestDtxEffect(bool dtx, int block_length_ms); |
| 42 | 42 |
| 43 void TestCbrEffect(bool dtx, int block_length_ms); | |
| 44 | |
| 43 // Prepare |speech_data_| for encoding, read from a hard-coded file. | 45 // Prepare |speech_data_| for encoding, read from a hard-coded file. |
| 44 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a | 46 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a |
| 45 // block of |block_length_ms| milliseconds. The data is looped every | 47 // block of |block_length_ms| milliseconds. The data is looped every |
| 46 // |loop_length_ms| milliseconds. | 48 // |loop_length_ms| milliseconds. |
| 47 void PrepareSpeechData(size_t channel, | 49 void PrepareSpeechData(size_t channel, |
| 48 int block_length_ms, | 50 int block_length_ms, |
| 49 int loop_length_ms); | 51 int loop_length_ms); |
| 50 | 52 |
| 51 int EncodeDecode(WebRtcOpusEncInst* encoder, | 53 int EncodeDecode(WebRtcOpusEncInst* encoder, |
| 52 rtc::ArrayView<const int16_t> input_audio, | 54 rtc::ArrayView<const int16_t> input_audio, |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 295 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 294 EXPECT_EQ(0, audio_type); // Speech. | 296 EXPECT_EQ(0, audio_type); // Speech. |
| 295 } | 297 } |
| 296 | 298 |
| 297 // Free memory. | 299 // Free memory. |
| 298 delete[] output_data_decode; | 300 delete[] output_data_decode; |
| 299 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 301 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 300 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 302 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 301 } | 303 } |
| 302 | 304 |
| 305 // Test if CBR does what we expect. | |
| 306 void OpusTest::TestCbrEffect(bool cbr, int block_length_ms) { | |
|
minyue-webrtc
2017/03/30 20:36:17
it looks like that TestCbrEffect and TestDtxEffect
| |
| 307 PrepareSpeechData(channels_, block_length_ms, 2000); | |
| 308 const size_t samples = kOpusRateKhz * block_length_ms; | |
| 309 | |
| 310 int32_t max_pkt_size_diff = 0; | |
| 311 int32_t prev_pkt_size = 0; | |
| 312 | |
| 313 // Create encoder memory. | |
| 314 EXPECT_EQ(0, | |
| 315 WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_)); | |
| 316 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_)); | |
| 317 | |
| 318 // Set bitrate. | |
| 319 EXPECT_EQ( | |
| 320 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000)); | |
| 321 | |
| 322 // Setting CBR. | |
| 323 EXPECT_EQ(0, cbr ? WebRtcOpus_EnableCbr(opus_encoder_) | |
| 324 : WebRtcOpus_DisableCbr(opus_encoder_)); | |
| 325 | |
| 326 int16_t audio_type; | |
| 327 int16_t* output_data_decode = new int16_t[samples * channels_]; | |
|
minyue-webrtc
2017/03/30 20:36:17
std::vector<int16_t> output_data_decode(samples *
| |
| 328 | |
| 329 for (int i = 0; i < 100; ++i) { | |
| 330 EXPECT_EQ(samples, static_cast<size_t>(EncodeDecode( | |
| 331 opus_encoder_, speech_data_.GetNextBlock(), | |
| 332 opus_decoder_, output_data_decode, &audio_type))); | |
| 333 | |
| 334 if (prev_pkt_size > 0) { | |
| 335 int32_t diff = std::abs((int32_t)encoded_bytes_ - prev_pkt_size); | |
| 336 max_pkt_size_diff = std::max(max_pkt_size_diff, diff); | |
| 337 } | |
| 338 prev_pkt_size = encoded_bytes_; | |
| 339 } | |
| 340 | |
| 341 if (cbr) { | |
| 342 EXPECT_EQ(max_pkt_size_diff, 0); | |
| 343 } else { | |
| 344 EXPECT_GT(max_pkt_size_diff, 0); | |
| 345 } | |
| 346 | |
| 347 // Free memory. | |
| 348 delete[] output_data_decode; | |
| 349 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | |
| 350 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | |
| 351 } | |
| 352 | |
| 303 // Test failing Create. | 353 // Test failing Create. |
| 304 TEST(OpusTest, OpusCreateFail) { | 354 TEST(OpusTest, OpusCreateFail) { |
| 305 WebRtcOpusEncInst* opus_encoder; | 355 WebRtcOpusEncInst* opus_encoder; |
| 306 WebRtcOpusDecInst* opus_decoder; | 356 WebRtcOpusDecInst* opus_decoder; |
| 307 | 357 |
| 308 // Test to see that an invalid pointer is caught. | 358 // Test to see that an invalid pointer is caught. |
| 309 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(NULL, 1, 0)); | 359 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(NULL, 1, 0)); |
| 310 // Invalid channel number. | 360 // Invalid channel number. |
| 311 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 3, 0)); | 361 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 3, 0)); |
| 312 // Invalid applciation mode. | 362 // Invalid applciation mode. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 TestDtxEffect(false, 20); | 568 TestDtxEffect(false, 20); |
| 519 TestDtxEffect(false, 40); | 569 TestDtxEffect(false, 40); |
| 520 } | 570 } |
| 521 | 571 |
| 522 TEST_P(OpusTest, OpusDtxOn) { | 572 TEST_P(OpusTest, OpusDtxOn) { |
| 523 TestDtxEffect(true, 10); | 573 TestDtxEffect(true, 10); |
| 524 TestDtxEffect(true, 20); | 574 TestDtxEffect(true, 20); |
| 525 TestDtxEffect(true, 40); | 575 TestDtxEffect(true, 40); |
| 526 } | 576 } |
| 527 | 577 |
| 578 TEST_P(OpusTest, OpusCbrOff) { | |
| 579 TestCbrEffect(false, 10); | |
| 580 TestCbrEffect(false, 20); | |
| 581 TestCbrEffect(false, 40); | |
| 582 } | |
| 583 | |
| 584 TEST_P(OpusTest, OpusCbrOn) { | |
| 585 TestCbrEffect(true, 10); | |
| 586 TestCbrEffect(true, 20); | |
| 587 TestCbrEffect(true, 40); | |
| 588 } | |
| 589 | |
| 528 TEST_P(OpusTest, OpusSetPacketLossRate) { | 590 TEST_P(OpusTest, OpusSetPacketLossRate) { |
| 529 // Test without creating encoder memory. | 591 // Test without creating encoder memory. |
| 530 EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50)); | 592 EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50)); |
| 531 | 593 |
| 532 // Create encoder memory. | 594 // Create encoder memory. |
| 533 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, | 595 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, |
| 534 channels_, | 596 channels_, |
| 535 application_)); | 597 application_)); |
| 536 | 598 |
| 537 EXPECT_EQ(0, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50)); | 599 EXPECT_EQ(0, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50)); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 755 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 694 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 756 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 695 } | 757 } |
| 696 | 758 |
| 697 INSTANTIATE_TEST_CASE_P(VariousMode, | 759 INSTANTIATE_TEST_CASE_P(VariousMode, |
| 698 OpusTest, | 760 OpusTest, |
| 699 Combine(Values(1, 2), Values(0, 1))); | 761 Combine(Values(1, 2), Values(0, 1))); |
| 700 | 762 |
| 701 | 763 |
| 702 } // namespace webrtc | 764 } // namespace webrtc |
| OLD | NEW |