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/modules/audio_coding/codecs/opus/audio_encoder_opus.h" | 12 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" |
13 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" | 13 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" |
14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
15 #include "webrtc/test/testsupport/fileutils.h" | 15 #include "webrtc/test/testsupport/fileutils.h" |
16 #include "webrtc/test/testsupport/perf_test.h" | 16 #include "webrtc/test/testsupport/perf_test.h" |
17 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.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 AudioEncoderOpus::Config& config) { |
23 // Create encoder. | 23 // Create encoder. |
24 AudioEncoderOpus encoder(config); | 24 AudioEncoderOpus encoder(config); |
25 // Open speech file. | 25 // Open speech file. |
26 const std::string kInputFileName = | 26 const std::string kInputFileName = |
27 webrtc::test::ResourcePath("audio_coding/speech_mono_32_48kHz", "pcm"); | 27 webrtc::test::ResourcePath("audio_coding/speech_mono_32_48kHz", "pcm"); |
hlundin-webrtc
2016/12/19 12:54:15
This is where the resource file is used.
| |
28 test::AudioLoop audio_loop; | 28 test::AudioLoop audio_loop; |
29 constexpr int kSampleRateHz = 48000; | 29 constexpr int kSampleRateHz = 48000; |
30 EXPECT_EQ(kSampleRateHz, encoder.SampleRateHz()); | 30 EXPECT_EQ(kSampleRateHz, encoder.SampleRateHz()); |
31 constexpr size_t kMaxLoopLengthSamples = | 31 constexpr size_t kMaxLoopLengthSamples = |
32 kSampleRateHz * 10; // 10 second loop. | 32 kSampleRateHz * 10; // 10 second loop. |
33 constexpr size_t kInputBlockSizeSamples = | 33 constexpr size_t kInputBlockSizeSamples = |
34 10 * kSampleRateHz / 1000; // 60 ms. | 34 10 * kSampleRateHz / 1000; // 60 ms. |
35 EXPECT_TRUE(audio_loop.Init(kInputFileName, kMaxLoopLengthSamples, | 35 EXPECT_TRUE(audio_loop.Init(kInputFileName, kMaxLoopLengthSamples, |
36 kInputBlockSizeSamples)); | 36 kInputBlockSizeSamples)); |
37 // Encode. | 37 // Encode. |
38 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); | 38 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); |
39 const int64_t start_time_ms = clock->TimeInMilliseconds(); | 39 const int64_t start_time_ms = clock->TimeInMilliseconds(); |
40 AudioEncoder::EncodedInfo info; | 40 AudioEncoder::EncodedInfo info; |
41 rtc::Buffer encoded(500); | 41 rtc::Buffer encoded(500); |
42 uint32_t rtp_timestamp = 0u; | 42 uint32_t rtp_timestamp = 0u; |
43 for (size_t i = 0; i < 10000; ++i) { | 43 for (size_t i = 0; i < 10000; ++i) { |
44 encoded.Clear(); | 44 encoded.Clear(); |
45 info = encoder.Encode(rtp_timestamp, audio_loop.GetNextBlock(), &encoded); | 45 info = encoder.Encode(rtp_timestamp, audio_loop.GetNextBlock(), &encoded); |
46 rtp_timestamp += kInputBlockSizeSamples; | 46 rtp_timestamp += kInputBlockSizeSamples; |
47 } | 47 } |
48 return clock->TimeInMilliseconds() - start_time_ms; | 48 return clock->TimeInMilliseconds() - start_time_ms; |
49 } | 49 } |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 #if defined(WEBRTC_ANDROID) | |
53 #define MAYBE_AudioEncoderOpusComplexityAdaptationTest \ | |
54 DISABLED_AudioEncoderOpusComplexityAdaptationTest | |
55 #else | |
56 #define MAYBE_AudioEncoderOpusComplexityAdaptationTest \ | |
57 AudioEncoderOpusComplexityAdaptationTest | |
58 #endif | |
59 | |
60 // This test encodes an audio file using Opus twice with different bitrates | 52 // This test encodes an audio file using Opus twice with different bitrates |
61 // (12.5 kbps and 15.5 kbps). The runtime for each is measured, and the ratio | 53 // (12.5 kbps and 15.5 kbps). The runtime for each is measured, and the ratio |
62 // 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 |
63 // 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 |
64 // 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 |
65 // 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, |
66 // 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 |
67 // 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 |
68 // 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 |
69 // the lower rate. | 61 // the lower rate. |
70 TEST(MAYBE_AudioEncoderOpusComplexityAdaptationTest, AdaptationOn) { | 62 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOn) { |
71 // Create config. | 63 // Create config. |
72 AudioEncoderOpus::Config config; | 64 AudioEncoderOpus::Config config; |
73 config.bitrate_bps = rtc::Optional<int>(12500); | 65 // The limit -- including the hysteresis window -- at which the complexity |
66 // shuold be increased. | |
67 config.bitrate_bps = rtc::Optional<int>(11000 - 1); | |
74 config.low_rate_complexity = 9; | 68 config.low_rate_complexity = 9; |
75 int64_t runtime_12500bps = RunComplexityTest(config); | 69 int64_t runtime_12500bps = RunComplexityTest(config); |
76 | 70 |
77 config.bitrate_bps = rtc::Optional<int>(15500); | 71 config.bitrate_bps = rtc::Optional<int>(15500); |
78 int64_t runtime_15500bps = RunComplexityTest(config); | 72 int64_t runtime_15500bps = RunComplexityTest(config); |
79 | 73 |
80 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on", | 74 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_on", |
81 100.0 * runtime_12500bps / runtime_15500bps, "percent", | 75 100.0 * runtime_12500bps / runtime_15500bps, "percent", |
82 true); | 76 true); |
83 } | 77 } |
84 | 78 |
85 // 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 |
86 // adaptation enabled (neither on desktop, nor on mobile). The expectation is | 80 // adaptation enabled (neither on desktop, nor on mobile). The expectation is |
87 // that the resulting ratio is less than 100% at all times. | 81 // that the resulting ratio is less than 100% at all times. |
88 TEST(MAYBE_AudioEncoderOpusComplexityAdaptationTest, AdaptationOff) { | 82 TEST(AudioEncoderOpusComplexityAdaptationTest, AdaptationOff) { |
89 // Create config. | 83 // Create config. |
90 AudioEncoderOpus::Config config; | 84 AudioEncoderOpus::Config config; |
91 config.bitrate_bps = rtc::Optional<int>(12500); | 85 // The limit -- including the hysteresis window -- at which the complexity |
86 // shuold be increased (but not in this test since complexity adaptation is | |
87 // disabled). | |
88 config.bitrate_bps = rtc::Optional<int>(11000 - 1); | |
92 int64_t runtime_12500bps = RunComplexityTest(config); | 89 int64_t runtime_12500bps = RunComplexityTest(config); |
minyue-webrtc
2016/12/19 13:50:35
still 12500?
hlundin-webrtc
2016/12/19 13:55:16
No. My bad. Changed the variable name to runtime_1
| |
93 | 90 |
94 config.bitrate_bps = rtc::Optional<int>(15500); | 91 config.bitrate_bps = rtc::Optional<int>(15500); |
95 int64_t runtime_15500bps = RunComplexityTest(config); | 92 int64_t runtime_15500bps = RunComplexityTest(config); |
96 | 93 |
97 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off", | 94 test::PrintResult("opus_encoding_complexity_ratio", "", "adaptation_off", |
98 100.0 * runtime_12500bps / runtime_15500bps, "", true); | 95 100.0 * runtime_12500bps / runtime_15500bps, "percent", |
hlundin-webrtc
2016/12/19 12:54:15
This was missing; added now to match line 75.
| |
96 true); | |
99 } | 97 } |
100 } // namespace webrtc | 98 } // namespace webrtc |
OLD | NEW |