Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: webrtc/modules/audio_coding/neteq/expand_unittest.cc

Issue 1290113002: NetEq: Implement logging of Delayed Packet Outage Events (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 // Unit tests for Expand class. 11 // Unit tests for Expand class.
12 12
13 #include "webrtc/modules/audio_coding/neteq/expand.h" 13 #include "webrtc/modules/audio_coding/neteq/expand.h"
14 14
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/safe_conversions.h"
18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
16 #include "webrtc/modules/audio_coding/neteq/background_noise.h" 19 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
17 #include "webrtc/modules/audio_coding/neteq/random_vector.h" 20 #include "webrtc/modules/audio_coding/neteq/random_vector.h"
21 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
18 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
23 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
24 #include "webrtc/test/testsupport/fileutils.h"
19 25
20 namespace webrtc { 26 namespace webrtc {
21 27
22 TEST(Expand, CreateAndDestroy) { 28 TEST(Expand, CreateAndDestroy) {
23 int fs = 8000; 29 int fs = 8000;
24 size_t channels = 1; 30 size_t channels = 1;
25 BackgroundNoise bgn(channels); 31 BackgroundNoise bgn(channels);
26 SyncBuffer sync_buffer(1, 1000); 32 SyncBuffer sync_buffer(1, 1000);
27 RandomVector random_vector; 33 RandomVector random_vector;
28 Expand expand(&bgn, &sync_buffer, &random_vector, fs, channels); 34 StatisticsCalculator statistics;
35 Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels);
29 } 36 }
30 37
31 TEST(Expand, CreateUsingFactory) { 38 TEST(Expand, CreateUsingFactory) {
32 int fs = 8000; 39 int fs = 8000;
33 size_t channels = 1; 40 size_t channels = 1;
34 BackgroundNoise bgn(channels); 41 BackgroundNoise bgn(channels);
35 SyncBuffer sync_buffer(1, 1000); 42 SyncBuffer sync_buffer(1, 1000);
36 RandomVector random_vector; 43 RandomVector random_vector;
44 StatisticsCalculator statistics;
37 ExpandFactory expand_factory; 45 ExpandFactory expand_factory;
38 Expand* expand = 46 Expand* expand = expand_factory.Create(&bgn, &sync_buffer, &random_vector,
39 expand_factory.Create(&bgn, &sync_buffer, &random_vector, fs, channels); 47 &statistics, fs, channels);
40 EXPECT_TRUE(expand != NULL); 48 EXPECT_TRUE(expand != NULL);
41 delete expand; 49 delete expand;
42 } 50 }
43 51
52 namespace {
53 class FakeStatisticsCalculator : public StatisticsCalculator {
54 public:
55 void LogDelayedPacketOutageEvent(int outage_duration_ms) override {
56 last_outage_duration_ms_ = outage_duration_ms;
57 }
58
59 int last_outage_duration_ms() const { return last_outage_duration_ms_; }
60
61 private:
62 int last_outage_duration_ms_ = 0;
63 };
64 } // namespace
65
66 class ExpandTest : public ::testing::Test {
67 protected:
68 ExpandTest()
69 : input_file_(test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
70 32000),
71 test_sample_rate_hz_(32000),
72 num_channels_(1),
73 background_noise_(num_channels_),
74 sync_buffer_(
75 num_channels_,
76 // Length of sync buffer is the same as in NetEq (120 ms).
77 rtc::CheckedDivExact(2 * 2880 * test_sample_rate_hz_, 8000)),
78 expand_(&background_noise_,
79 &sync_buffer_,
80 &random_vector_,
81 &statistics_,
82 test_sample_rate_hz_,
83 num_channels_) {
84 WebRtcSpl_Init();
85 input_file_.set_output_rate_hz(test_sample_rate_hz_);
86 }
87
88 virtual void SetUp() {
89 // Fast-forward the input file until there is speech (about 1.1 second into
90 // the file).
91 const size_t kSpeechStartSamples = test_sample_rate_hz_ * 1.1;
92 int16_t dummy_audio[kSpeechStartSamples];
93 ASSERT_TRUE(input_file_.Read(kSpeechStartSamples, dummy_audio));
94
95 // Pre-load the sync buffer with speech data.
96 ASSERT_TRUE(
97 input_file_.Read(sync_buffer_.Size(), &sync_buffer_.Channel(0)[0]));
98 ASSERT_EQ(1u, num_channels_) << "Fix: Must populate all channels.";
99 }
100
101 test::ResampleInputAudioFile input_file_;
102 int test_sample_rate_hz_;
103 size_t num_channels_;
104 BackgroundNoise background_noise_;
105 SyncBuffer sync_buffer_;
106 RandomVector random_vector_;
107 FakeStatisticsCalculator statistics_;
108 Expand expand_;
109 };
110
111 // This test calls the expand object to produce concealment data a few times,
112 // and then ends by calling SetParametersForNormalAfterExpand. This simulates
113 // the situation where the packet next up for decoding was just delayed, not
114 // lost.
115 TEST_F(ExpandTest, DelayedPacketOutage) {
116 AudioMultiVector output(num_channels_);
117 size_t sum_output_len_samples = 0;
118 for (int i = 0; i < 10; ++i) {
119 EXPECT_EQ(0, expand_.Process(&output));
120 EXPECT_GT(output.Size(), 0u);
121 sum_output_len_samples += output.Size();
122 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
123 }
124 expand_.SetParametersForNormalAfterExpand();
125 // Convert |sum_output_len_samples| to milliseconds.
126 EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples /
127 (test_sample_rate_hz_ / 1000)),
128 statistics_.last_outage_duration_ms());
129 }
130
131 // This test is similar to DelayedPacketOutage, but ends by calling
132 // SetParametersForMergeAfterExpand. This simulates the situation where the
133 // packet next up for decoding was actually lost (or at least a later packet
134 // arrived before it).
135 TEST_F(ExpandTest, LostPacketOutage) {
136 AudioMultiVector output(num_channels_);
137 size_t sum_output_len_samples = 0;
138 for (int i = 0; i < 10; ++i) {
139 EXPECT_EQ(0, expand_.Process(&output));
140 EXPECT_GT(output.Size(), 0u);
141 sum_output_len_samples += output.Size();
142 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
143 }
144 expand_.SetParametersForMergeAfterExpand();
145 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
146 }
147
44 // TODO(hlundin): Write more tests. 148 // TODO(hlundin): Write more tests.
45 149
46 } // namespace webrtc 150 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698