OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 <queue> | 11 #include <queue> |
12 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webrtc/base/format_macros.h" | 14 #include "webrtc/base/format_macros.h" |
15 #include "webrtc/base/timeutils.h" | 15 #include "webrtc/base/timeutils.h" |
16 #include "webrtc/system_wrappers/interface/sleep.h" | 16 #include "webrtc/system_wrappers/interface/sleep.h" |
17 #include "webrtc/test/testsupport/fileutils.h" | |
17 #include "webrtc/voice_engine/test/auto_test/fakes/conference_transport.h" | 18 #include "webrtc/voice_engine/test/auto_test/fakes/conference_transport.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 static const int kRttMs = 25; | 21 static const int kRttMs = 25; |
21 | 22 |
22 static bool IsNear(int ref, int comp, int error) { | 23 static bool IsNear(int ref, int comp, int error) { |
23 return (ref - comp <= error) && (comp - ref >= -error); | 24 return (ref - comp <= error) && (comp - ref >= -error); |
24 } | 25 } |
26 static const std::string kInputFileName = | |
27 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); | |
28 static const webrtc::FileFormats kInputFormat = | |
29 webrtc::kFileFormatPcm32kHzFile; | |
25 } | 30 } |
26 | 31 |
27 namespace voetest { | 32 namespace voetest { |
28 | 33 |
29 TEST(VoeConferenceTest, RttAndStartNtpTime) { | 34 TEST(VoeConferenceTest, RttAndStartNtpTime) { |
30 struct Stats { | 35 struct Stats { |
31 Stats(int64_t rtt_receiver_1, int64_t rtt_receiver_2, int64_t ntp_delay) | 36 Stats(int64_t rtt_receiver_1, int64_t rtt_receiver_2, int64_t ntp_delay) |
32 : rtt_receiver_1_(rtt_receiver_1), | 37 : rtt_receiver_1_(rtt_receiver_1), |
33 rtt_receiver_2_(rtt_receiver_2), | 38 rtt_receiver_2_(rtt_receiver_2), |
34 ntp_delay_(ntp_delay) { | 39 ntp_delay_(ntp_delay) { |
35 } | 40 } |
36 int64_t rtt_receiver_1_; | 41 int64_t rtt_receiver_1_; |
37 int64_t rtt_receiver_2_; | 42 int64_t rtt_receiver_2_; |
38 int64_t ntp_delay_; | 43 int64_t ntp_delay_; |
39 }; | 44 }; |
40 | 45 |
41 const int kDelayMs = 987; | 46 const int kDelayMs = 987; |
42 ConferenceTransport trans; | 47 ConferenceTransport trans; |
43 trans.SetRtt(kRttMs); | 48 trans.SetRtt(kRttMs); |
44 | 49 |
45 unsigned int id_1 = trans.AddStream(); | 50 unsigned int id_1 = trans.AddStream(kInputFileName, kInputFormat); |
46 unsigned int id_2 = trans.AddStream(); | 51 unsigned int id_2 = trans.AddStream(kInputFileName, kInputFormat); |
47 | 52 |
48 EXPECT_TRUE(trans.StartPlayout(id_1)); | 53 EXPECT_TRUE(trans.StartPlayout(id_1)); |
49 // Start NTP time is the time when a stream is played out, rather than | 54 // Start NTP time is the time when a stream is played out, rather than |
50 // when it is added. | 55 // when it is added. |
51 webrtc::SleepMs(kDelayMs); | 56 webrtc::SleepMs(kDelayMs); |
52 EXPECT_TRUE(trans.StartPlayout(id_2)); | 57 EXPECT_TRUE(trans.StartPlayout(id_2)); |
53 | 58 |
54 const int kMaxRunTimeMs = 25000; | 59 const int kMaxRunTimeMs = 25000; |
55 const int kNeedSuccessivePass = 3; | 60 const int kNeedSuccessivePass = 3; |
56 const int kStatsRequestIntervalMs = 1000; | 61 const int kStatsRequestIntervalMs = 1000; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 printf("The most recent values (RTT for receiver 1, RTT for receiver 2, " | 103 printf("The most recent values (RTT for receiver 1, RTT for receiver 2, " |
99 "NTP delay between receiver 1 and 2) are (from oldest):\n"); | 104 "NTP delay between receiver 1 and 2) are (from oldest):\n"); |
100 while (!stats_buffer.empty()) { | 105 while (!stats_buffer.empty()) { |
101 Stats stats = stats_buffer.front(); | 106 Stats stats = stats_buffer.front(); |
102 printf("(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n", stats.rtt_receiver_1_, | 107 printf("(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n", stats.rtt_receiver_1_, |
103 stats.rtt_receiver_2_, stats.ntp_delay_); | 108 stats.rtt_receiver_2_, stats.ntp_delay_); |
104 stats_buffer.pop(); | 109 stats_buffer.pop(); |
105 } | 110 } |
106 } | 111 } |
107 } | 112 } |
113 | |
114 | |
115 TEST(VoeConferenceTest, ReceivedPackets) { | |
116 const int kPackets = 50; | |
117 const int kPacketDurationMs = 20; // Correspond to Opus. | |
118 | |
119 const std::string silence_file = | |
phoglund
2015/08/10 08:43:28
Extract this to a helper method CreateTempSilenceF
minyue-webrtc
2015/08/10 09:30:22
ok, will do.
| |
120 webrtc::test::TempFilename(webrtc::test::OutputPath(), "silence"); | |
121 FILE* fid = fopen(silence_file.c_str(), "wb"); | |
122 int temp = 0; | |
123 for (int i = 0; i < 32000; i++) { | |
124 // Write 1 second, but it does not matter since the file will be looped. | |
125 fwrite(&temp, 2, 1, fid); | |
126 } | |
127 fclose(fid); | |
128 | |
129 { | |
130 ConferenceTransport trans; | |
131 // Add silence to stream 0, so that it will be filtered out. | |
132 unsigned int id_0 = trans.AddStream(silence_file, kInputFormat); | |
133 unsigned int id_1 = trans.AddStream(kInputFileName, kInputFormat); | |
134 unsigned int id_2 = trans.AddStream(kInputFileName, kInputFormat); | |
135 unsigned int id_3 = trans.AddStream(kInputFileName, kInputFormat); | |
136 | |
137 EXPECT_TRUE(trans.StartPlayout(id_0)); | |
138 EXPECT_TRUE(trans.StartPlayout(id_1)); | |
139 EXPECT_TRUE(trans.StartPlayout(id_2)); | |
140 EXPECT_TRUE(trans.StartPlayout(id_3)); | |
141 | |
142 webrtc::SleepMs(kPacketDurationMs * kPackets); | |
143 | |
144 webrtc::CallStatistics stats_0; | |
145 webrtc::CallStatistics stats_1; | |
146 webrtc::CallStatistics stats_2; | |
147 webrtc::CallStatistics stats_3; | |
148 EXPECT_TRUE(trans.GetReceiverStatistics(id_0, &stats_0)); | |
149 EXPECT_TRUE(trans.GetReceiverStatistics(id_1, &stats_1)); | |
150 EXPECT_TRUE(trans.GetReceiverStatistics(id_2, &stats_2)); | |
151 EXPECT_TRUE(trans.GetReceiverStatistics(id_3, &stats_3)); | |
152 | |
153 // We expect stream 0 to be filtered out totally, but since it may join the | |
154 // call earlier than other streams and the beginning packets might have got | |
155 // through. So we only expect |packetsReceived| to be close to zero. | |
156 EXPECT_NEAR(stats_0.packetsReceived, 0, 2); | |
157 // We expect |packetsReceived| to match |kPackets|, but the actual value | |
158 // depends on the sleep timer. So we allow a small off from |kPackets|. | |
159 EXPECT_NEAR(stats_1.packetsReceived, kPackets, 2); | |
160 EXPECT_NEAR(stats_2.packetsReceived, kPackets, 2); | |
161 EXPECT_NEAR(stats_3.packetsReceived, kPackets, 2); | |
162 } | |
163 | |
164 remove(silence_file.c_str()); | |
165 } | |
166 | |
108 } // namespace voetest | 167 } // namespace voetest |
OLD | NEW |