| 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 |
| 11 // Test to verify correct operation for externally created decoders. | 11 // Test to verify correct operation for externally created decoders. |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "webrtc/modules/audio_coding/neteq/mock/mock_external_decoder_pcm16b.h" | 16 #include "webrtc/modules/audio_coding/neteq/mock/mock_external_decoder_pcm16b.h" |
| 17 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" | 17 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" |
| 18 #include "webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h" | 18 #include "webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h" |
| 19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" | 19 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" |
| 20 #include "webrtc/modules/include/module_common_types.h" |
| 20 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 using ::testing::_; | 25 using ::testing::_; |
| 25 using ::testing::Return; | 26 using ::testing::Return; |
| 26 | 27 |
| 27 class NetEqExternalDecoderUnitTest : public test::NetEqExternalDecoderTest { | 28 class NetEqExternalDecoderUnitTest : public test::NetEqExternalDecoderTest { |
| 28 protected: | 29 protected: |
| 29 static const int kFrameSizeMs = 10; // Frame size of Pcm16B. | 30 static const int kFrameSizeMs = 10; // Frame size of Pcm16B. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 182 } |
| 182 | 183 |
| 183 void SetUp() override { | 184 void SetUp() override { |
| 184 ASSERT_EQ(NetEq::kOK, neteq_internal_->RegisterPayloadType( | 185 ASSERT_EQ(NetEq::kOK, neteq_internal_->RegisterPayloadType( |
| 185 NetEqDecoder::kDecoderPCM16Bswb32kHz, | 186 NetEqDecoder::kDecoderPCM16Bswb32kHz, |
| 186 "pcm16-swb32", kPayloadType)); | 187 "pcm16-swb32", kPayloadType)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void GetAndVerifyOutput() override { | 190 void GetAndVerifyOutput() override { |
| 190 NetEqOutputType output_type; | 191 NetEqOutputType output_type; |
| 191 size_t samples_per_channel; | |
| 192 size_t num_channels; | |
| 193 // Get audio from internal decoder instance. | 192 // Get audio from internal decoder instance. |
| 194 EXPECT_EQ(NetEq::kOK, | 193 EXPECT_EQ(NetEq::kOK, |
| 195 neteq_internal_->GetAudio(kMaxBlockSize, | 194 neteq_internal_->GetAudio(&output_internal_, &output_type)); |
| 196 output_internal_, | 195 EXPECT_EQ(1u, output_internal_.num_channels_); |
| 197 &samples_per_channel, | |
| 198 &num_channels, | |
| 199 &output_type)); | |
| 200 EXPECT_EQ(1u, num_channels); | |
| 201 EXPECT_EQ(static_cast<size_t>(kOutputLengthMs * sample_rate_hz_ / 1000), | 196 EXPECT_EQ(static_cast<size_t>(kOutputLengthMs * sample_rate_hz_ / 1000), |
| 202 samples_per_channel); | 197 output_internal_.samples_per_channel_); |
| 203 | 198 |
| 204 // Get audio from external decoder instance. | 199 // Get audio from external decoder instance. |
| 205 samples_per_channel = GetOutputAudio(kMaxBlockSize, output_, &output_type); | 200 GetOutputAudio(&output_, &output_type); |
| 206 | 201 |
| 207 for (size_t i = 0; i < samples_per_channel; ++i) { | 202 for (size_t i = 0; i < output_.samples_per_channel_; ++i) { |
| 208 ASSERT_EQ(output_[i], output_internal_[i]) << | 203 ASSERT_EQ(output_.data_[i], output_internal_.data_[i]) |
| 209 "Diff in sample " << i << "."; | 204 << "Diff in sample " << i << "."; |
| 210 } | 205 } |
| 211 } | 206 } |
| 212 | 207 |
| 213 void InsertPacket(WebRtcRTPHeader rtp_header, | 208 void InsertPacket(WebRtcRTPHeader rtp_header, |
| 214 rtc::ArrayView<const uint8_t> payload, | 209 rtc::ArrayView<const uint8_t> payload, |
| 215 uint32_t receive_timestamp) override { | 210 uint32_t receive_timestamp) override { |
| 216 // Insert packet in internal decoder. | 211 // Insert packet in internal decoder. |
| 217 ASSERT_EQ(NetEq::kOK, neteq_internal_->InsertPacket(rtp_header, payload, | 212 ASSERT_EQ(NetEq::kOK, neteq_internal_->InsertPacket(rtp_header, payload, |
| 218 receive_timestamp)); | 213 receive_timestamp)); |
| 219 | 214 |
| 220 // Insert packet in external decoder instance. | 215 // Insert packet in external decoder instance. |
| 221 NetEqExternalDecoderUnitTest::InsertPacket(rtp_header, payload, | 216 NetEqExternalDecoderUnitTest::InsertPacket(rtp_header, payload, |
| 222 receive_timestamp); | 217 receive_timestamp); |
| 223 } | 218 } |
| 224 | 219 |
| 225 int NumExpectedDecodeCalls(int num_loops) override { return num_loops; } | 220 int NumExpectedDecodeCalls(int num_loops) override { return num_loops; } |
| 226 | 221 |
| 227 private: | 222 private: |
| 228 int sample_rate_hz_; | 223 int sample_rate_hz_; |
| 229 std::unique_ptr<NetEq> neteq_internal_; | 224 std::unique_ptr<NetEq> neteq_internal_; |
| 230 int16_t output_internal_[kMaxBlockSize]; | 225 AudioFrame output_internal_; |
| 231 int16_t output_[kMaxBlockSize]; | 226 AudioFrame output_; |
| 232 }; | 227 }; |
| 233 | 228 |
| 234 TEST_F(NetEqExternalVsInternalDecoderTest, RunTest) { | 229 TEST_F(NetEqExternalVsInternalDecoderTest, RunTest) { |
| 235 RunTest(100); // Run 100 laps @ 10 ms each in the test loop. | 230 RunTest(100); // Run 100 laps @ 10 ms each in the test loop. |
| 236 } | 231 } |
| 237 | 232 |
| 238 class LargeTimestampJumpTest : public NetEqExternalDecoderUnitTest, | 233 class LargeTimestampJumpTest : public NetEqExternalDecoderUnitTest, |
| 239 public ::testing::Test { | 234 public ::testing::Test { |
| 240 protected: | 235 protected: |
| 241 static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz. | 236 static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 279 } |
| 285 break; | 280 break; |
| 286 } | 281 } |
| 287 case kRecovered: { | 282 case kRecovered: { |
| 288 break; | 283 break; |
| 289 } | 284 } |
| 290 } | 285 } |
| 291 } | 286 } |
| 292 | 287 |
| 293 void GetAndVerifyOutput() override { | 288 void GetAndVerifyOutput() override { |
| 294 size_t num_samples; | 289 AudioFrame output; |
| 295 NetEqOutputType output_type; | 290 NetEqOutputType output_type; |
| 296 num_samples = GetOutputAudio(kMaxBlockSize, output_, &output_type); | 291 GetOutputAudio(&output, &output_type); |
| 297 UpdateState(output_type); | 292 UpdateState(output_type); |
| 298 | 293 |
| 299 if (test_state_ == kExpandPhase || test_state_ == kFadedExpandPhase) { | 294 if (test_state_ == kExpandPhase || test_state_ == kFadedExpandPhase) { |
| 300 // Don't verify the output in this phase of the test. | 295 // Don't verify the output in this phase of the test. |
| 301 return; | 296 return; |
| 302 } | 297 } |
| 303 | 298 |
| 304 for (size_t i = 0; i < num_samples; ++i) { | 299 ASSERT_EQ(1u, output.num_channels_); |
| 305 if (output_[i] != 0) | 300 for (size_t i = 0; i < output.samples_per_channel_; ++i) { |
| 301 if (output.data_[i] != 0) |
| 306 return; | 302 return; |
| 307 } | 303 } |
| 308 EXPECT_TRUE(false) | 304 EXPECT_TRUE(false) |
| 309 << "Expected at least one non-zero sample in each output block."; | 305 << "Expected at least one non-zero sample in each output block."; |
| 310 } | 306 } |
| 311 | 307 |
| 312 int NumExpectedDecodeCalls(int num_loops) override { | 308 int NumExpectedDecodeCalls(int num_loops) override { |
| 313 // Some packets at the end of the stream won't be decoded. When the jump in | 309 // Some packets at the end of the stream won't be decoded. When the jump in |
| 314 // timestamp happens, NetEq will do Expand during one GetAudio call. In the | 310 // timestamp happens, NetEq will do Expand during one GetAudio call. In the |
| 315 // next call it will decode the packet after the jump, but the net result is | 311 // next call it will decode the packet after the jump, but the net result is |
| 316 // that the delay increased by 1 packet. In another call, a Pre-emptive | 312 // that the delay increased by 1 packet. In another call, a Pre-emptive |
| 317 // Expand operation is performed, leading to delay increase by 1 packet. In | 313 // Expand operation is performed, leading to delay increase by 1 packet. In |
| 318 // total, the test will end with a 2-packet delay, which results in the 2 | 314 // total, the test will end with a 2-packet delay, which results in the 2 |
| 319 // last packets not being decoded. | 315 // last packets not being decoded. |
| 320 return num_loops - 2; | 316 return num_loops - 2; |
| 321 } | 317 } |
| 322 | 318 |
| 323 TestStates test_state_; | 319 TestStates test_state_; |
| 324 | |
| 325 private: | |
| 326 int16_t output_[kMaxBlockSize]; | |
| 327 }; | 320 }; |
| 328 | 321 |
| 329 TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRange) { | 322 TEST_F(LargeTimestampJumpTest, JumpLongerThanHalfRange) { |
| 330 // Set the timestamp series to start at 2880, increase to 7200, then jump to | 323 // Set the timestamp series to start at 2880, increase to 7200, then jump to |
| 331 // 2869342376. The sequence numbers start at 42076 and increase by 1 for each | 324 // 2869342376. The sequence numbers start at 42076 and increase by 1 for each |
| 332 // packet, also when the timestamp jumps. | 325 // packet, also when the timestamp jumps. |
| 333 static const uint16_t kStartSeqeunceNumber = 42076; | 326 static const uint16_t kStartSeqeunceNumber = 42076; |
| 334 static const uint32_t kStartTimestamp = 2880; | 327 static const uint32_t kStartTimestamp = 2880; |
| 335 static const uint32_t kJumpFromTimestamp = 7200; | 328 static const uint32_t kJumpFromTimestamp = 7200; |
| 336 static const uint32_t kJumpToTimestamp = 2869342376; | 329 static const uint32_t kJumpToTimestamp = 2869342376; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 kStartSeqeunceNumber, | 444 kStartSeqeunceNumber, |
| 452 kStartTimestamp, | 445 kStartTimestamp, |
| 453 kJumpFromTimestamp, | 446 kJumpFromTimestamp, |
| 454 kJumpToTimestamp)); | 447 kJumpToTimestamp)); |
| 455 | 448 |
| 456 RunTest(130); // Run 130 laps @ 10 ms each in the test loop. | 449 RunTest(130); // Run 130 laps @ 10 ms each in the test loop. |
| 457 EXPECT_EQ(kRecovered, test_state_); | 450 EXPECT_EQ(kRecovered, test_state_); |
| 458 } | 451 } |
| 459 | 452 |
| 460 } // namespace webrtc | 453 } // namespace webrtc |
| OLD | NEW |