OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Create 10ms audio data blocks for a total packet size of "packet_size_ms". | 118 // Create 10ms audio data blocks for a total packet size of "packet_size_ms". |
119 std::unique_ptr<test::AudioLoop> Create10msAudioBlocks( | 119 std::unique_ptr<test::AudioLoop> Create10msAudioBlocks( |
120 const std::unique_ptr<AudioEncoderOpus>& encoder, | 120 const std::unique_ptr<AudioEncoderOpus>& encoder, |
121 int packet_size_ms) { | 121 int packet_size_ms) { |
122 const std::string file_name = | 122 const std::string file_name = |
123 test::ResourcePath("audio_coding/testfile32kHz", "pcm"); | 123 test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
124 | 124 |
125 std::unique_ptr<test::AudioLoop> speech_data(new test::AudioLoop()); | 125 std::unique_ptr<test::AudioLoop> speech_data(new test::AudioLoop()); |
126 int audio_samples_per_ms = | 126 int audio_samples_per_ms = |
127 rtc::CheckedDivExact(encoder->SampleRateHz(), 1000); | 127 rtc::CheckedDivExact(encoder->SampleRateHz(), 1000); |
128 RTC_DCHECK(speech_data->Init( | 128 if (!speech_data->Init( |
129 file_name, | 129 file_name, |
130 packet_size_ms * audio_samples_per_ms * encoder->num_channels_to_encode(), | 130 packet_size_ms * audio_samples_per_ms * |
131 10 * audio_samples_per_ms * encoder->num_channels_to_encode())); | 131 encoder->num_channels_to_encode(), |
| 132 10 * audio_samples_per_ms * encoder->num_channels_to_encode())) |
| 133 return nullptr; |
132 return speech_data; | 134 return speech_data; |
133 } | 135 } |
134 | 136 |
135 } // namespace | 137 } // namespace |
136 | 138 |
137 TEST(AudioEncoderOpusTest, DefaultApplicationModeMono) { | 139 TEST(AudioEncoderOpusTest, DefaultApplicationModeMono) { |
138 auto states = CreateCodec(1); | 140 auto states = CreateCodec(1); |
139 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); | 141 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); |
140 } | 142 } |
141 | 143 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 states.encoder->Encode( | 516 states.encoder->Encode( |
515 0, rtc::ArrayView<const int16_t>(audio.data(), audio.size()), &encoded); | 517 0, rtc::ArrayView<const int16_t>(audio.data(), audio.size()), &encoded); |
516 } | 518 } |
517 } | 519 } |
518 | 520 |
519 TEST(AudioEncoderOpusTest, EncodeAtMinBitrate) { | 521 TEST(AudioEncoderOpusTest, EncodeAtMinBitrate) { |
520 auto states = CreateCodec(1); | 522 auto states = CreateCodec(1); |
521 constexpr int kNumPacketsToEncode = 2; | 523 constexpr int kNumPacketsToEncode = 2; |
522 auto audio_frames = | 524 auto audio_frames = |
523 Create10msAudioBlocks(states.encoder, kNumPacketsToEncode * 20); | 525 Create10msAudioBlocks(states.encoder, kNumPacketsToEncode * 20); |
| 526 ASSERT_TRUE(audio_frames) << "Create10msAudioBlocks failed"; |
524 rtc::Buffer encoded; | 527 rtc::Buffer encoded; |
525 uint32_t rtp_timestamp = 12345; // Just a number not important to this test. | 528 uint32_t rtp_timestamp = 12345; // Just a number not important to this test. |
526 | 529 |
527 states.encoder->OnReceivedUplinkBandwidth(0, rtc::Optional<int64_t>()); | 530 states.encoder->OnReceivedUplinkBandwidth(0, rtc::Optional<int64_t>()); |
528 for (int packet_index = 0; packet_index < kNumPacketsToEncode; | 531 for (int packet_index = 0; packet_index < kNumPacketsToEncode; |
529 packet_index++) { | 532 packet_index++) { |
530 // Make sure we are not encoding before we have enough data for | 533 // Make sure we are not encoding before we have enough data for |
531 // a 20ms packet. | 534 // a 20ms packet. |
532 for (int index = 0; index < 1; index++) { | 535 for (int index = 0; index < 1; index++) { |
533 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | 536 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), |
534 &encoded); | 537 &encoded); |
535 EXPECT_EQ(0u, encoded.size()); | 538 EXPECT_EQ(0u, encoded.size()); |
536 } | 539 } |
537 | 540 |
538 // Should encode now. | 541 // Should encode now. |
539 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | 542 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), |
540 &encoded); | 543 &encoded); |
541 EXPECT_GT(encoded.size(), 0u); | 544 EXPECT_GT(encoded.size(), 0u); |
542 encoded.Clear(); | 545 encoded.Clear(); |
543 } | 546 } |
544 } | 547 } |
545 | 548 |
546 } // namespace webrtc | 549 } // namespace webrtc |
OLD | NEW |