| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" | 13 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" |
| 14 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h" | 14 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h" |
| 15 #include "webrtc/rtc_base/checks.h" | 15 #include "webrtc/rtc_base/checks.h" |
| 16 #include "webrtc/rtc_base/flags.h" |
| 16 #include "webrtc/rtc_base/safe_conversions.h" | 17 #include "webrtc/rtc_base/safe_conversions.h" |
| 17 #include "webrtc/test/testsupport/fileutils.h" | 18 #include "webrtc/test/testsupport/fileutils.h" |
| 18 | 19 |
| 19 using google::RegisterFlagValidator; | |
| 20 using google::ParseCommandLineFlags; | |
| 21 using testing::InitGoogleTest; | 20 using testing::InitGoogleTest; |
| 22 | 21 |
| 23 namespace webrtc { | 22 namespace webrtc { |
| 24 namespace test { | 23 namespace test { |
| 25 namespace { | 24 namespace { |
| 26 static const int kInputSampleRateKhz = 8; | 25 static const int kInputSampleRateKhz = 8; |
| 27 static const int kOutputSampleRateKhz = 8; | 26 static const int kOutputSampleRateKhz = 8; |
| 28 | 27 |
| 29 // Define switch for frame size. | 28 DEFINE_int(frame_size_ms, 20, "Codec frame size (milliseconds)."); |
| 30 static bool ValidateFrameSize(const char* flagname, int32_t value) { | |
| 31 if (value >= 10 && value <= 60 && (value % 10) == 0) | |
| 32 return true; | |
| 33 printf("Invalid frame size, should be 10, 20, ..., 60 ms."); | |
| 34 return false; | |
| 35 } | |
| 36 | |
| 37 DEFINE_int32(frame_size_ms, 20, "Codec frame size (milliseconds)."); | |
| 38 | |
| 39 static const bool frame_size_dummy = | |
| 40 RegisterFlagValidator(&FLAGS_frame_size_ms, &ValidateFrameSize); | |
| 41 | 29 |
| 42 } // namespace | 30 } // namespace |
| 43 | 31 |
| 44 class NetEqPcmuQualityTest : public NetEqQualityTest { | 32 class NetEqPcmuQualityTest : public NetEqQualityTest { |
| 45 protected: | 33 protected: |
| 46 NetEqPcmuQualityTest() | 34 NetEqPcmuQualityTest() |
| 47 : NetEqQualityTest(FLAGS_frame_size_ms, | 35 : NetEqQualityTest(FLAG_frame_size_ms, |
| 48 kInputSampleRateKhz, | 36 kInputSampleRateKhz, |
| 49 kOutputSampleRateKhz, | 37 kOutputSampleRateKhz, |
| 50 NetEqDecoder::kDecoderPCMu) {} | 38 NetEqDecoder::kDecoderPCMu) { |
| 39 // Flag validation |
| 40 RTC_CHECK(FLAG_frame_size_ms >= 10 && FLAG_frame_size_ms <= 60 && |
| 41 (FLAG_frame_size_ms % 10) == 0) |
| 42 << "Invalid frame size, should be 10, 20, ..., 60 ms."; |
| 43 } |
| 51 | 44 |
| 52 void SetUp() override { | 45 void SetUp() override { |
| 53 ASSERT_EQ(1u, channels_) << "PCMu supports only mono audio."; | 46 ASSERT_EQ(1u, channels_) << "PCMu supports only mono audio."; |
| 54 AudioEncoderPcmU::Config config; | 47 AudioEncoderPcmU::Config config; |
| 55 config.frame_size_ms = FLAGS_frame_size_ms; | 48 config.frame_size_ms = FLAG_frame_size_ms; |
| 56 encoder_.reset(new AudioEncoderPcmU(config)); | 49 encoder_.reset(new AudioEncoderPcmU(config)); |
| 57 NetEqQualityTest::SetUp(); | 50 NetEqQualityTest::SetUp(); |
| 58 } | 51 } |
| 59 | 52 |
| 60 int EncodeBlock(int16_t* in_data, | 53 int EncodeBlock(int16_t* in_data, |
| 61 size_t block_size_samples, | 54 size_t block_size_samples, |
| 62 rtc::Buffer* payload, size_t max_bytes) override { | 55 rtc::Buffer* payload, size_t max_bytes) override { |
| 63 const size_t kFrameSizeSamples = 80; // Samples per 10 ms. | 56 const size_t kFrameSizeSamples = 80; // Samples per 10 ms. |
| 64 size_t encoded_samples = 0; | 57 size_t encoded_samples = 0; |
| 65 uint32_t dummy_timestamp = 0; | 58 uint32_t dummy_timestamp = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 private: | 70 private: |
| 78 std::unique_ptr<AudioEncoderPcmU> encoder_; | 71 std::unique_ptr<AudioEncoderPcmU> encoder_; |
| 79 }; | 72 }; |
| 80 | 73 |
| 81 TEST_F(NetEqPcmuQualityTest, Test) { | 74 TEST_F(NetEqPcmuQualityTest, Test) { |
| 82 Simulate(); | 75 Simulate(); |
| 83 } | 76 } |
| 84 | 77 |
| 85 } // namespace test | 78 } // namespace test |
| 86 } // namespace webrtc | 79 } // namespace webrtc |
| OLD | NEW |