Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc

Issue 2746763005: Fixing a few tests for the upcoming Opus 1.2-alpha. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 static_cast<size_t>(WebRtcOpus_DurationEst( 637 static_cast<size_t>(WebRtcOpus_DurationEst(
638 opus_decoder_, bitstream_, 638 opus_decoder_, bitstream_,
639 static_cast<size_t>(encoded_bytes_int)))); 639 static_cast<size_t>(encoded_bytes_int))));
640 640
641 // Free memory. 641 // Free memory.
642 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); 642 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
643 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); 643 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
644 } 644 }
645 645
646 TEST_P(OpusTest, OpusDecodeRepacketized) { 646 TEST_P(OpusTest, OpusDecodeRepacketized) {
647 const int kPackets = 6; 647 constexpr size_t kPackets = 6;
648 648
649 PrepareSpeechData(channels_, 20, 20 * kPackets); 649 PrepareSpeechData(channels_, 20, 20 * kPackets);
650 650
651 // Create encoder memory. 651 // Create encoder memory.
652 ASSERT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, 652 ASSERT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_,
653 channels_, 653 channels_,
654 application_)); 654 application_));
655 ASSERT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, 655 ASSERT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_,
656 channels_)); 656 channels_));
657 657
658 // Set bitrate. 658 // Set bitrate.
659 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, 659 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_,
660 channels_ == 1 ? 32000 : 64000)); 660 channels_ == 1 ? 32000 : 64000));
661 661
662 // Check number of channels for decoder. 662 // Check number of channels for decoder.
663 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_)); 663 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_));
664 664
665 // Encode & decode. 665 // Encode & decode.
666 int16_t audio_type; 666 int16_t audio_type;
667 std::unique_ptr<int16_t[]> output_data_decode( 667 std::unique_ptr<int16_t[]> output_data_decode(
668 new int16_t[kPackets * kOpus20msFrameSamples * channels_]); 668 new int16_t[kPackets * kOpus20msFrameSamples * channels_]);
669 OpusRepacketizer* rp = opus_repacketizer_create(); 669 OpusRepacketizer* rp = opus_repacketizer_create();
670 670
671 for (int idx = 0; idx < kPackets; idx++) { 671 size_t num_packets = 0;
672 constexpr size_t kMaxCycles = 100;
673 for (size_t idx = 0; idx < kMaxCycles; ++idx) {
672 auto speech_block = speech_data_.GetNextBlock(); 674 auto speech_block = speech_data_.GetNextBlock();
673 encoded_bytes_ = 675 encoded_bytes_ =
674 WebRtcOpus_Encode(opus_encoder_, speech_block.data(), 676 WebRtcOpus_Encode(opus_encoder_, speech_block.data(),
675 rtc::CheckedDivExact(speech_block.size(), channels_), 677 rtc::CheckedDivExact(speech_block.size(), channels_),
676 kMaxBytes, bitstream_); 678 kMaxBytes, bitstream_);
677 EXPECT_EQ(OPUS_OK, opus_repacketizer_cat(rp, bitstream_, encoded_bytes_)); 679 if (opus_repacketizer_cat(rp, bitstream_, encoded_bytes_) == OPUS_OK) {
680 ++num_packets;
681 if (num_packets == kPackets) {
682 break;
683 }
684 } else {
685 // Opus repacketizer cannot guarantee a success. We try again if it fails.
686 opus_repacketizer_init(rp);
687 num_packets = 0;
688 }
678 } 689 }
690 EXPECT_EQ(kPackets, num_packets);
679 691
680 encoded_bytes_ = opus_repacketizer_out(rp, bitstream_, kMaxBytes); 692 encoded_bytes_ = opus_repacketizer_out(rp, bitstream_, kMaxBytes);
681 693
682 EXPECT_EQ(kOpus20msFrameSamples * kPackets, 694 EXPECT_EQ(kOpus20msFrameSamples * kPackets,
683 static_cast<size_t>(WebRtcOpus_DurationEst( 695 static_cast<size_t>(WebRtcOpus_DurationEst(
684 opus_decoder_, bitstream_, encoded_bytes_))); 696 opus_decoder_, bitstream_, encoded_bytes_)));
685 697
686 EXPECT_EQ(kOpus20msFrameSamples * kPackets, 698 EXPECT_EQ(kOpus20msFrameSamples * kPackets,
687 static_cast<size_t>(WebRtcOpus_Decode( 699 static_cast<size_t>(WebRtcOpus_Decode(
688 opus_decoder_, bitstream_, encoded_bytes_, 700 opus_decoder_, bitstream_, encoded_bytes_,
689 output_data_decode.get(), &audio_type))); 701 output_data_decode.get(), &audio_type)));
690 702
691 // Free memory. 703 // Free memory.
692 opus_repacketizer_destroy(rp); 704 opus_repacketizer_destroy(rp);
693 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); 705 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
694 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); 706 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
695 } 707 }
696 708
697 INSTANTIATE_TEST_CASE_P(VariousMode, 709 INSTANTIATE_TEST_CASE_P(VariousMode,
698 OpusTest, 710 OpusTest,
699 Combine(Values(1, 2), Values(0, 1))); 711 Combine(Values(1, 2), Values(0, 1)));
700 712
701 713
702 } // namespace webrtc 714 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698