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 const int kRttMs = 25; |
21 | 22 |
22 static bool IsNear(int ref, int comp, int error) { | 23 bool IsNear(int ref, int comp, int error) { |
23 return (ref - comp <= error) && (comp - ref >= -error); | 24 return (ref - comp <= error) && (comp - ref >= -error); |
| 25 } |
| 26 |
| 27 void CreateSilenceFile(const std::string& silence_file, int sample_rate_hz) { |
| 28 FILE* fid = fopen(silence_file.c_str(), "wb"); |
| 29 int16_t zero = 0; |
| 30 for (int i = 0; i < sample_rate_hz; ++i) { |
| 31 // Write 1 second, but it does not matter since the file will be looped. |
| 32 fwrite(&zero, sizeof(int16_t), 1, fid); |
24 } | 33 } |
| 34 fclose(fid); |
25 } | 35 } |
26 | 36 |
| 37 } // namespace |
| 38 |
27 namespace voetest { | 39 namespace voetest { |
28 | 40 |
29 TEST(VoeConferenceTest, RttAndStartNtpTime) { | 41 TEST(VoeConferenceTest, RttAndStartNtpTime) { |
30 struct Stats { | 42 struct Stats { |
31 Stats(int64_t rtt_receiver_1, int64_t rtt_receiver_2, int64_t ntp_delay) | 43 Stats(int64_t rtt_receiver_1, int64_t rtt_receiver_2, int64_t ntp_delay) |
32 : rtt_receiver_1_(rtt_receiver_1), | 44 : rtt_receiver_1_(rtt_receiver_1), |
33 rtt_receiver_2_(rtt_receiver_2), | 45 rtt_receiver_2_(rtt_receiver_2), |
34 ntp_delay_(ntp_delay) { | 46 ntp_delay_(ntp_delay) { |
35 } | 47 } |
36 int64_t rtt_receiver_1_; | 48 int64_t rtt_receiver_1_; |
37 int64_t rtt_receiver_2_; | 49 int64_t rtt_receiver_2_; |
38 int64_t ntp_delay_; | 50 int64_t ntp_delay_; |
39 }; | 51 }; |
40 | 52 |
| 53 const std::string input_file = |
| 54 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 55 const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile; |
| 56 |
41 const int kDelayMs = 987; | 57 const int kDelayMs = 987; |
42 ConferenceTransport trans; | 58 ConferenceTransport trans; |
43 trans.SetRtt(kRttMs); | 59 trans.SetRtt(kRttMs); |
44 | 60 |
45 unsigned int id_1 = trans.AddStream(); | 61 unsigned int id_1 = trans.AddStream(input_file, kInputFormat); |
46 unsigned int id_2 = trans.AddStream(); | 62 unsigned int id_2 = trans.AddStream(input_file, kInputFormat); |
47 | 63 |
48 EXPECT_TRUE(trans.StartPlayout(id_1)); | 64 EXPECT_TRUE(trans.StartPlayout(id_1)); |
49 // Start NTP time is the time when a stream is played out, rather than | 65 // Start NTP time is the time when a stream is played out, rather than |
50 // when it is added. | 66 // when it is added. |
51 webrtc::SleepMs(kDelayMs); | 67 webrtc::SleepMs(kDelayMs); |
52 EXPECT_TRUE(trans.StartPlayout(id_2)); | 68 EXPECT_TRUE(trans.StartPlayout(id_2)); |
53 | 69 |
54 const int kMaxRunTimeMs = 25000; | 70 const int kMaxRunTimeMs = 25000; |
55 const int kNeedSuccessivePass = 3; | 71 const int kNeedSuccessivePass = 3; |
56 const int kStatsRequestIntervalMs = 1000; | 72 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, " | 114 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"); | 115 "NTP delay between receiver 1 and 2) are (from oldest):\n"); |
100 while (!stats_buffer.empty()) { | 116 while (!stats_buffer.empty()) { |
101 Stats stats = stats_buffer.front(); | 117 Stats stats = stats_buffer.front(); |
102 printf("(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n", stats.rtt_receiver_1_, | 118 printf("(%" PRId64 ", %" PRId64 ", %" PRId64 ")\n", stats.rtt_receiver_1_, |
103 stats.rtt_receiver_2_, stats.ntp_delay_); | 119 stats.rtt_receiver_2_, stats.ntp_delay_); |
104 stats_buffer.pop(); | 120 stats_buffer.pop(); |
105 } | 121 } |
106 } | 122 } |
107 } | 123 } |
| 124 |
| 125 |
| 126 TEST(VoeConferenceTest, ReceivedPackets) { |
| 127 const int kPackets = 50; |
| 128 const int kPacketDurationMs = 20; // Correspond to Opus. |
| 129 |
| 130 const std::string input_file = |
| 131 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 132 const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile; |
| 133 |
| 134 const std::string silence_file = |
| 135 webrtc::test::TempFilename(webrtc::test::OutputPath(), "silence"); |
| 136 CreateSilenceFile(silence_file, 32000); |
| 137 |
| 138 { |
| 139 ConferenceTransport trans; |
| 140 // Add silence to stream 0, so that it will be filtered out. |
| 141 unsigned int id_0 = trans.AddStream(silence_file, kInputFormat); |
| 142 unsigned int id_1 = trans.AddStream(input_file, kInputFormat); |
| 143 unsigned int id_2 = trans.AddStream(input_file, kInputFormat); |
| 144 unsigned int id_3 = trans.AddStream(input_file, kInputFormat); |
| 145 |
| 146 EXPECT_TRUE(trans.StartPlayout(id_0)); |
| 147 EXPECT_TRUE(trans.StartPlayout(id_1)); |
| 148 EXPECT_TRUE(trans.StartPlayout(id_2)); |
| 149 EXPECT_TRUE(trans.StartPlayout(id_3)); |
| 150 |
| 151 webrtc::SleepMs(kPacketDurationMs * kPackets); |
| 152 |
| 153 webrtc::CallStatistics stats_0; |
| 154 webrtc::CallStatistics stats_1; |
| 155 webrtc::CallStatistics stats_2; |
| 156 webrtc::CallStatistics stats_3; |
| 157 EXPECT_TRUE(trans.GetReceiverStatistics(id_0, &stats_0)); |
| 158 EXPECT_TRUE(trans.GetReceiverStatistics(id_1, &stats_1)); |
| 159 EXPECT_TRUE(trans.GetReceiverStatistics(id_2, &stats_2)); |
| 160 EXPECT_TRUE(trans.GetReceiverStatistics(id_3, &stats_3)); |
| 161 |
| 162 // We expect stream 0 to be filtered out totally, but since it may join the |
| 163 // call earlier than other streams and the beginning packets might have got |
| 164 // through. So we only expect |packetsReceived| to be close to zero. |
| 165 EXPECT_NEAR(stats_0.packetsReceived, 0, 2); |
| 166 // We expect |packetsReceived| to match |kPackets|, but the actual value |
| 167 // depends on the sleep timer. So we allow a small off from |kPackets|. |
| 168 EXPECT_NEAR(stats_1.packetsReceived, kPackets, 2); |
| 169 EXPECT_NEAR(stats_2.packetsReceived, kPackets, 2); |
| 170 EXPECT_NEAR(stats_3.packetsReceived, kPackets, 2); |
| 171 } |
| 172 |
| 173 remove(silence_file.c_str()); |
| 174 } |
| 175 |
108 } // namespace voetest | 176 } // namespace voetest |
OLD | NEW |