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

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: Fixing windows build 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/base/scoped_ptr.h"
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
16 #include "webrtc/modules/audio_coding/neteq/background_noise.h" 20 #include "webrtc/modules/audio_coding/neteq/background_noise.h"
17 #include "webrtc/modules/audio_coding/neteq/random_vector.h" 21 #include "webrtc/modules/audio_coding/neteq/random_vector.h"
22 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
18 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" 23 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h"
24 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
25 #include "webrtc/test/testsupport/fileutils.h"
19 26
20 namespace webrtc { 27 namespace webrtc {
21 28
22 TEST(Expand, CreateAndDestroy) { 29 TEST(Expand, CreateAndDestroy) {
23 int fs = 8000; 30 int fs = 8000;
24 size_t channels = 1; 31 size_t channels = 1;
25 BackgroundNoise bgn(channels); 32 BackgroundNoise bgn(channels);
26 SyncBuffer sync_buffer(1, 1000); 33 SyncBuffer sync_buffer(1, 1000);
27 RandomVector random_vector; 34 RandomVector random_vector;
28 Expand expand(&bgn, &sync_buffer, &random_vector, fs, channels); 35 StatisticsCalculator statistics;
36 Expand expand(&bgn, &sync_buffer, &random_vector, &statistics, fs, channels);
29 } 37 }
30 38
31 TEST(Expand, CreateUsingFactory) { 39 TEST(Expand, CreateUsingFactory) {
32 int fs = 8000; 40 int fs = 8000;
33 size_t channels = 1; 41 size_t channels = 1;
34 BackgroundNoise bgn(channels); 42 BackgroundNoise bgn(channels);
35 SyncBuffer sync_buffer(1, 1000); 43 SyncBuffer sync_buffer(1, 1000);
36 RandomVector random_vector; 44 RandomVector random_vector;
45 StatisticsCalculator statistics;
37 ExpandFactory expand_factory; 46 ExpandFactory expand_factory;
38 Expand* expand = 47 Expand* expand = expand_factory.Create(&bgn, &sync_buffer, &random_vector,
39 expand_factory.Create(&bgn, &sync_buffer, &random_vector, fs, channels); 48 &statistics, fs, channels);
40 EXPECT_TRUE(expand != NULL); 49 EXPECT_TRUE(expand != NULL);
41 delete expand; 50 delete expand;
42 } 51 }
43 52
53 namespace {
54 class FakeStatisticsCalculator : public StatisticsCalculator {
55 public:
56 void LogDelayedPacketOutageEvent(int outage_duration_ms) override {
57 last_outage_duration_ms_ = outage_duration_ms;
58 }
59
60 int last_outage_duration_ms() const { return last_outage_duration_ms_; }
61
62 private:
63 int last_outage_duration_ms_ = 0;
64 };
65 } // namespace
66
67 class ExpandTest : public ::testing::Test {
68 protected:
69 ExpandTest()
70 : input_file_(test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
71 32000),
72 test_sample_rate_hz_(32000),
73 num_channels_(1),
74 background_noise_(num_channels_),
75 sync_buffer_(
76 num_channels_,
77 // Length of sync buffer is the same as in NetEq (120 ms).
78 rtc::CheckedDivExact(2 * 2880 * test_sample_rate_hz_, 8000)),
79 expand_(&background_noise_,
80 &sync_buffer_,
81 &random_vector_,
82 &statistics_,
83 test_sample_rate_hz_,
84 num_channels_) {
85 WebRtcSpl_Init();
86 input_file_.set_output_rate_hz(test_sample_rate_hz_);
87 }
88
89 virtual void SetUp() {
90 // Fast-forward the input file until there is speech (about 1.1 second into
91 // the file).
92 const size_t speech_start_samples = test_sample_rate_hz_ * 1.1;
93 rtc::scoped_ptr<int16_t[]> dummy_audio(new int16_t[speech_start_samples]);
ivoc 2015/08/14 13:00:03 Wouldn't a vector be easier here? (I feel like the
hlundin-webrtc 2015/08/17 12:07:28 I did the right thing and added a Move method to t
94 ASSERT_TRUE(input_file_.Read(speech_start_samples, dummy_audio.get()));
95
96 // Pre-load the sync buffer with speech data.
97 ASSERT_TRUE(
98 input_file_.Read(sync_buffer_.Size(), &sync_buffer_.Channel(0)[0]));
99 ASSERT_EQ(1u, num_channels_) << "Fix: Must populate all channels.";
100 }
101
102 test::ResampleInputAudioFile input_file_;
103 int test_sample_rate_hz_;
104 size_t num_channels_;
105 BackgroundNoise background_noise_;
106 SyncBuffer sync_buffer_;
107 RandomVector random_vector_;
108 FakeStatisticsCalculator statistics_;
109 Expand expand_;
110 };
111
112 // This test calls the expand object to produce concealment data a few times,
113 // and then ends by calling SetParametersForNormalAfterExpand. This simulates
114 // the situation where the packet next up for decoding was just delayed, not
115 // lost.
116 TEST_F(ExpandTest, DelayedPacketOutage) {
117 AudioMultiVector output(num_channels_);
118 size_t sum_output_len_samples = 0;
119 for (int i = 0; i < 10; ++i) {
120 EXPECT_EQ(0, expand_.Process(&output));
121 EXPECT_GT(output.Size(), 0u);
122 sum_output_len_samples += output.Size();
123 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
124 }
125 expand_.SetParametersForNormalAfterExpand();
126 // Convert |sum_output_len_samples| to milliseconds.
127 EXPECT_EQ(rtc::checked_cast<int>(sum_output_len_samples /
128 (test_sample_rate_hz_ / 1000)),
129 statistics_.last_outage_duration_ms());
130 }
131
132 // This test is similar to DelayedPacketOutage, but ends by calling
133 // SetParametersForMergeAfterExpand. This simulates the situation where the
134 // packet next up for decoding was actually lost (or at least a later packet
135 // arrived before it).
136 TEST_F(ExpandTest, LostPacketOutage) {
137 AudioMultiVector output(num_channels_);
138 size_t sum_output_len_samples = 0;
139 for (int i = 0; i < 10; ++i) {
140 EXPECT_EQ(0, expand_.Process(&output));
141 EXPECT_GT(output.Size(), 0u);
142 sum_output_len_samples += output.Size();
143 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
144 }
145 expand_.SetParametersForMergeAfterExpand();
146 EXPECT_EQ(0, statistics_.last_outage_duration_ms());
147 }
148
44 // TODO(hlundin): Write more tests. 149 // TODO(hlundin): Write more tests.
45 150
46 } // namespace webrtc 151 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/expand.cc ('k') | webrtc/modules/audio_coding/neteq/merge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698