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

Side by Side Diff: webrtc/voice_engine/test/auto_test/voe_conference_test.cc

Issue 3008273002: Replace voe_conference_test. (Closed)
Patch Set: rebase Created 3 years, 3 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
« no previous file with comments | « webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <queue>
12
13 #include "webrtc/rtc_base/format_macros.h"
14 #include "webrtc/rtc_base/timeutils.h"
15 #include "webrtc/system_wrappers/include/sleep.h"
16 #include "webrtc/test/gtest.h"
17 #include "webrtc/test/testsupport/fileutils.h"
18 #include "webrtc/voice_engine/test/auto_test/fakes/conference_transport.h"
19
20 namespace webrtc {
21 namespace {
22
23 const int kRttMs = 25;
24
25 bool IsNear(int ref, int comp, int error) {
26 return (ref - comp <= error) && (comp - ref >= -error);
27 }
28
29 void CreateSilenceFile(const std::string& silence_file, int sample_rate_hz) {
30 FILE* fid = fopen(silence_file.c_str(), "wb");
31 int16_t zero = 0;
32 for (int i = 0; i < sample_rate_hz; ++i) {
33 // Write 1 second, but it does not matter since the file will be looped.
34 fwrite(&zero, sizeof(int16_t), 1, fid);
35 }
36 fclose(fid);
37 }
38
39 } // namespace
40
41 namespace voetest {
42
43 TEST(VoeConferenceTest, RttAndStartNtpTime) {
44 struct Stats {
45 Stats(int64_t rtt_receiver_1, int64_t rtt_receiver_2, int64_t ntp_delay)
46 : rtt_receiver_1_(rtt_receiver_1),
47 rtt_receiver_2_(rtt_receiver_2),
48 ntp_delay_(ntp_delay) {
49 }
50 int64_t rtt_receiver_1_;
51 int64_t rtt_receiver_2_;
52 int64_t ntp_delay_;
53 };
54
55 const std::string input_file =
56 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
57 const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile;
58
59 const int kDelayMs = 987;
60 ConferenceTransport trans;
61 trans.SetRtt(kRttMs);
62
63 unsigned int id_1 = trans.AddStream(input_file, kInputFormat);
64 unsigned int id_2 = trans.AddStream(input_file, kInputFormat);
65
66 EXPECT_TRUE(trans.StartPlayout(id_1));
67 // Start NTP time is the time when a stream is played out, rather than
68 // when it is added.
69 webrtc::SleepMs(kDelayMs);
70 EXPECT_TRUE(trans.StartPlayout(id_2));
71
72 const int kMaxRunTimeMs = 25000;
73 const int kNeedSuccessivePass = 3;
74 const int kStatsRequestIntervalMs = 1000;
75 const int kStatsBufferSize = 3;
76
77 int64_t deadline = rtc::TimeAfter(kMaxRunTimeMs);
78 // Run the following up to |kMaxRunTimeMs| milliseconds.
79 int successive_pass = 0;
80 webrtc::CallStatistics stats_1;
81 webrtc::CallStatistics stats_2;
82 std::queue<Stats> stats_buffer;
83
84 while (rtc::TimeMillis() < deadline &&
85 successive_pass < kNeedSuccessivePass) {
86 webrtc::SleepMs(kStatsRequestIntervalMs);
87
88 EXPECT_TRUE(trans.GetReceiverStatistics(id_1, &stats_1));
89 EXPECT_TRUE(trans.GetReceiverStatistics(id_2, &stats_2));
90
91 // It is not easy to verify the NTP time directly. We verify it by testing
92 // the difference of two start NTP times.
93 int64_t captured_start_ntp_delay = stats_2.capture_start_ntp_time_ms_ -
94 stats_1.capture_start_ntp_time_ms_;
95
96 // For the checks of RTT and start NTP time, We allow 10% accuracy.
97 if (IsNear(kRttMs, stats_1.rttMs, kRttMs / 10 + 1) &&
98 IsNear(kRttMs, stats_2.rttMs, kRttMs / 10 + 1) &&
99 IsNear(kDelayMs, captured_start_ntp_delay, kDelayMs / 10 + 1)) {
100 successive_pass++;
101 } else {
102 successive_pass = 0;
103 }
104 if (stats_buffer.size() >= kStatsBufferSize) {
105 stats_buffer.pop();
106 }
107 stats_buffer.push(Stats(stats_1.rttMs, stats_2.rttMs,
108 captured_start_ntp_delay));
109 }
110
111 EXPECT_GE(successive_pass, kNeedSuccessivePass) << "Expected to get RTT and"
112 " start NTP time estimate within 10% of the correct value over "
113 << kStatsRequestIntervalMs * kNeedSuccessivePass / 1000
114 << " seconds.";
115 if (successive_pass < kNeedSuccessivePass) {
116 printf("The most recent values (RTT for receiver 1, RTT for receiver 2, "
117 "NTP delay between receiver 1 and 2) are (from oldest):\n");
118 while (!stats_buffer.empty()) {
119 Stats stats = stats_buffer.front();
120 printf("(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n", stats.rtt_receiver_1_,
121 stats.rtt_receiver_2_, stats.ntp_delay_);
122 stats_buffer.pop();
123 }
124 }
125 }
126
127
128 TEST(VoeConferenceTest, ReceivedPackets) {
129 const int kPackets = 50;
130 const int kPacketDurationMs = 20; // Correspond to Opus.
131
132 const std::string input_file =
133 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
134 const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile;
135
136 const std::string silence_file =
137 webrtc::test::TempFilename(webrtc::test::OutputPath(), "silence");
138 CreateSilenceFile(silence_file, 32000);
139
140 {
141 ConferenceTransport trans;
142 // Add silence to stream 0, so that it will be filtered out.
143 unsigned int id_0 = trans.AddStream(silence_file, kInputFormat);
144 unsigned int id_1 = trans.AddStream(input_file, kInputFormat);
145 unsigned int id_2 = trans.AddStream(input_file, kInputFormat);
146 unsigned int id_3 = trans.AddStream(input_file, kInputFormat);
147
148 EXPECT_TRUE(trans.StartPlayout(id_0));
149 EXPECT_TRUE(trans.StartPlayout(id_1));
150 EXPECT_TRUE(trans.StartPlayout(id_2));
151 EXPECT_TRUE(trans.StartPlayout(id_3));
152
153 webrtc::SleepMs(kPacketDurationMs * kPackets);
154
155 webrtc::CallStatistics stats_0;
156 webrtc::CallStatistics stats_1;
157 webrtc::CallStatistics stats_2;
158 webrtc::CallStatistics stats_3;
159 EXPECT_TRUE(trans.GetReceiverStatistics(id_0, &stats_0));
160 EXPECT_TRUE(trans.GetReceiverStatistics(id_1, &stats_1));
161 EXPECT_TRUE(trans.GetReceiverStatistics(id_2, &stats_2));
162 EXPECT_TRUE(trans.GetReceiverStatistics(id_3, &stats_3));
163
164 // We expect stream 0 to be filtered out totally, but since it may join the
165 // call earlier than other streams and the beginning packets might have got
166 // through. So we only expect |packetsReceived| to be close to zero.
167 EXPECT_NEAR(stats_0.packetsReceived, 0, 2);
168 // We expect |packetsReceived| to match |kPackets|, but the actual value
169 // depends on the sleep timer. So we allow a small off from |kPackets|.
170 EXPECT_NEAR(stats_1.packetsReceived, kPackets, 2);
171 EXPECT_NEAR(stats_2.packetsReceived, kPackets, 2);
172 EXPECT_NEAR(stats_3.packetsReceived, kPackets, 2);
173 }
174
175 remove(silence_file.c_str());
176 }
177
178 } // namespace voetest
179 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698