OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 "webrtc/base/format_macros.h" | 11 #include "webrtc/base/format_macros.h" |
12 #include "webrtc/base/timeutils.h" | 12 #include "webrtc/base/timeutils.h" |
13 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" | 13 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" |
14 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" | 14 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" |
15 #include "webrtc/test/gtest.h" | 15 #include "webrtc/test/gtest.h" |
16 #include "webrtc/test/testsupport/fileutils.h" | 16 #include "webrtc/test/testsupport/fileutils.h" |
17 #include "webrtc/test/testsupport/perf_test.h" | 17 #include "webrtc/test/testsupport/perf_test.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 namespace { | 21 namespace { |
22 int64_t RunComplexityTest(const AudioEncoderOpus::Config& config) { | 22 int64_t RunComplexityTest(const AudioEncoderOpusConfig& config) { |
23 // Create encoder. | 23 // Create encoder. |
24 AudioEncoderOpus encoder(config); | 24 constexpr int payload_type = 17; |
| 25 AudioEncoderOpusImpl encoder(config, payload_type); |
25 // Open speech file. | 26 // Open speech file. |
26 const std::string kInputFileName = | 27 const std::string kInputFileName = |
27 webrtc::test::ResourcePath("audio_coding/speech_mono_32_48kHz", "pcm"); | 28 webrtc::test::ResourcePath("audio_coding/speech_mono_32_48kHz", "pcm"); |
28 test::AudioLoop audio_loop; | 29 test::AudioLoop audio_loop; |
29 constexpr int kSampleRateHz = 48000; | 30 constexpr int kSampleRateHz = 48000; |
30 EXPECT_EQ(kSampleRateHz, encoder.SampleRateHz()); | 31 EXPECT_EQ(kSampleRateHz, encoder.SampleRateHz()); |
31 constexpr size_t kMaxLoopLengthSamples = | 32 constexpr size_t kMaxLoopLengthSamples = |
32 kSampleRateHz * 10; // 10 second loop. | 33 kSampleRateHz * 10; // 10 second loop. |
33 constexpr size_t kInputBlockSizeSamples = | 34 constexpr size_t kInputBlockSizeSamples = |
34 10 * kSampleRateHz / 1000; // 60 ms. | 35 10 * kSampleRateHz / 1000; // 60 ms. |
(...skipping 18 matching lines...) Expand all Loading... |
53 // between the two is calculated and tracked. This test explicitly sets the | 54 // between the two is calculated and tracked. This test explicitly sets the |
54 // low_rate_complexity to 9. When running on desktop platforms, this is the same | 55 // low_rate_complexity to 9. When running on desktop platforms, this is the same |
55 // as the regular complexity, and the expectation is that the resulting ratio | 56 // as the regular complexity, and the expectation is that the resulting ratio |
56 // should be less than 100% (since the encoder runs faster at lower bitrates, | 57 // should be less than 100% (since the encoder runs faster at lower bitrates, |
57 // given a fixed complexity setting). On the other hand, when running on | 58 // given a fixed complexity setting). On the other hand, when running on |
58 // mobiles, the regular complexity is 5, and we expect the resulting ratio to | 59 // mobiles, the regular complexity is 5, and we expect the resulting ratio to |
59 // be higher, since we have explicitly asked for a higher complexity setting at | 60 // be higher, since we have explicitly asked for a higher complexity setting at |
60 // the lower rate. | 61 // the lower rate. |
61 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOn) { | 62 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOn) { |
62 // Create config. | 63 // Create config. |
63 AudioEncoderOpus::Config config; | 64 AudioEncoderOpusConfig config; |
64 // The limit -- including the hysteresis window -- at which the complexity | 65 // The limit -- including the hysteresis window -- at which the complexity |
65 // shuold be increased. | 66 // shuold be increased. |
66 config.bitrate_bps = rtc::Optional<int>(11000 - 1); | 67 config.bitrate_bps = 11000 - 1; |
67 config.low_rate_complexity = 9; | 68 config.low_rate_complexity = 9; |
68 int64_t runtime_10999bps = RunComplexityTest(config); | 69 int64_t runtime_10999bps = RunComplexityTest(config); |
69 | 70 |
70 config.bitrate_bps = rtc::Optional<int>(15500); | 71 config.bitrate_bps = 15500; |
71 int64_t runtime_15500bps = RunComplexityTest(config); | 72 int64_t runtime_15500bps = RunComplexityTest(config); |
72 | 73 |
73 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on", | 74 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on", |
74 100.0 * runtime_10999bps / runtime_15500bps, "percent", | 75 100.0 * runtime_10999bps / runtime_15500bps, "percent", |
75 true); | 76 true); |
76 } | 77 } |
77 | 78 |
78 // This test is identical to the one above, but without the complexity | 79 // This test is identical to the one above, but without the complexity |
79 // adaptation enabled (neither on desktop, nor on mobile). The expectation is | 80 // adaptation enabled (neither on desktop, nor on mobile). The expectation is |
80 // that the resulting ratio is less than 100% at all times. | 81 // that the resulting ratio is less than 100% at all times. |
81 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOff) { | 82 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOff) { |
82 // Create config. | 83 // Create config. |
83 AudioEncoderOpus::Config config; | 84 AudioEncoderOpusConfig config; |
84 // The limit -- including the hysteresis window -- at which the complexity | 85 // The limit -- including the hysteresis window -- at which the complexity |
85 // shuold be increased (but not in this test since complexity adaptation is | 86 // shuold be increased (but not in this test since complexity adaptation is |
86 // disabled). | 87 // disabled). |
87 config.bitrate_bps = rtc::Optional<int>(11000 - 1); | 88 config.bitrate_bps = 11000 - 1; |
88 int64_t runtime_10999bps = RunComplexityTest(config); | 89 int64_t runtime_10999bps = RunComplexityTest(config); |
89 | 90 |
90 config.bitrate_bps = rtc::Optional<int>(15500); | 91 config.bitrate_bps = 15500; |
91 int64_t runtime_15500bps = RunComplexityTest(config); | 92 int64_t runtime_15500bps = RunComplexityTest(config); |
92 | 93 |
93 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off", | 94 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off", |
94 100.0 * runtime_10999bps / runtime_15500bps, "percent", | 95 100.0 * runtime_10999bps / runtime_15500bps, "percent", |
95 true); | 96 true); |
96 } | 97 } |
97 } // namespace webrtc | 98 } // namespace webrtc |
OLD | NEW |