OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2006 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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Sends at a constant rate but with random packet sizes. | 30 // Sends at a constant rate but with random packet sizes. |
31 struct Sender : public MessageHandler { | 31 struct Sender : public MessageHandler { |
32 Sender(Thread* th, AsyncSocket* s, uint32_t rt) | 32 Sender(Thread* th, AsyncSocket* s, uint32_t rt) |
33 : thread(th), | 33 : thread(th), |
34 socket(new AsyncUDPSocket(s)), | 34 socket(new AsyncUDPSocket(s)), |
35 done(false), | 35 done(false), |
36 rate(rt), | 36 rate(rt), |
37 count(0) { | 37 count(0) { |
38 last_send = rtc::TimeMillis(); | 38 last_send = rtc::TimeMillis(); |
39 thread->PostDelayed(NextDelay(), this, 1); | 39 thread->PostDelayed(RTC_FROM_HERE, NextDelay(), this, 1); |
40 } | 40 } |
41 | 41 |
42 uint32_t NextDelay() { | 42 uint32_t NextDelay() { |
43 uint32_t size = (rand() % 4096) + 1; | 43 uint32_t size = (rand() % 4096) + 1; |
44 return 1000 * size / rate; | 44 return 1000 * size / rate; |
45 } | 45 } |
46 | 46 |
47 void OnMessage(Message* pmsg) { | 47 void OnMessage(Message* pmsg) { |
48 ASSERT_EQ(1u, pmsg->message_id); | 48 ASSERT_EQ(1u, pmsg->message_id); |
49 | 49 |
50 if (done) | 50 if (done) |
51 return; | 51 return; |
52 | 52 |
53 int64_t cur_time = rtc::TimeMillis(); | 53 int64_t cur_time = rtc::TimeMillis(); |
54 int64_t delay = cur_time - last_send; | 54 int64_t delay = cur_time - last_send; |
55 uint32_t size = static_cast<uint32_t>(rate * delay / 1000); | 55 uint32_t size = static_cast<uint32_t>(rate * delay / 1000); |
56 size = std::min<uint32_t>(size, 4096); | 56 size = std::min<uint32_t>(size, 4096); |
57 size = std::max<uint32_t>(size, sizeof(uint32_t)); | 57 size = std::max<uint32_t>(size, sizeof(uint32_t)); |
58 | 58 |
59 count += size; | 59 count += size; |
60 memcpy(dummy, &cur_time, sizeof(cur_time)); | 60 memcpy(dummy, &cur_time, sizeof(cur_time)); |
61 socket->Send(dummy, size, options); | 61 socket->Send(dummy, size, options); |
62 | 62 |
63 last_send = cur_time; | 63 last_send = cur_time; |
64 thread->PostDelayed(NextDelay(), this, 1); | 64 thread->PostDelayed(RTC_FROM_HERE, NextDelay(), this, 1); |
65 } | 65 } |
66 | 66 |
67 Thread* thread; | 67 Thread* thread; |
68 std::unique_ptr<AsyncUDPSocket> socket; | 68 std::unique_ptr<AsyncUDPSocket> socket; |
69 rtc::PacketOptions options; | 69 rtc::PacketOptions options; |
70 bool done; | 70 bool done; |
71 uint32_t rate; // bytes per second | 71 uint32_t rate; // bytes per second |
72 uint32_t count; | 72 uint32_t count; |
73 int64_t last_send; | 73 int64_t last_send; |
74 char dummy[4096]; | 74 char dummy[4096]; |
75 }; | 75 }; |
76 | 76 |
77 struct Receiver : public MessageHandler, public sigslot::has_slots<> { | 77 struct Receiver : public MessageHandler, public sigslot::has_slots<> { |
78 Receiver(Thread* th, AsyncSocket* s, uint32_t bw) | 78 Receiver(Thread* th, AsyncSocket* s, uint32_t bw) |
79 : thread(th), | 79 : thread(th), |
80 socket(new AsyncUDPSocket(s)), | 80 socket(new AsyncUDPSocket(s)), |
81 bandwidth(bw), | 81 bandwidth(bw), |
82 done(false), | 82 done(false), |
83 count(0), | 83 count(0), |
84 sec_count(0), | 84 sec_count(0), |
85 sum(0), | 85 sum(0), |
86 sum_sq(0), | 86 sum_sq(0), |
87 samples(0) { | 87 samples(0) { |
88 socket->SignalReadPacket.connect(this, &Receiver::OnReadPacket); | 88 socket->SignalReadPacket.connect(this, &Receiver::OnReadPacket); |
89 thread->PostDelayed(1000, this, 1); | 89 thread->PostDelayed(RTC_FROM_HERE, 1000, this, 1); |
90 } | 90 } |
91 | 91 |
92 ~Receiver() { | 92 ~Receiver() { |
93 thread->Clear(this); | 93 thread->Clear(this); |
94 } | 94 } |
95 | 95 |
96 void OnReadPacket(AsyncPacketSocket* s, const char* data, size_t size, | 96 void OnReadPacket(AsyncPacketSocket* s, const char* data, size_t size, |
97 const SocketAddress& remote_addr, | 97 const SocketAddress& remote_addr, |
98 const PacketTime& packet_time) { | 98 const PacketTime& packet_time) { |
99 ASSERT_EQ(socket.get(), s); | 99 ASSERT_EQ(socket.get(), s); |
(...skipping 14 matching lines...) Expand all Loading... |
114 ASSERT_EQ(1u, pmsg->message_id); | 114 ASSERT_EQ(1u, pmsg->message_id); |
115 | 115 |
116 if (done) | 116 if (done) |
117 return; | 117 return; |
118 | 118 |
119 // It is always possible for us to receive more than expected because | 119 // It is always possible for us to receive more than expected because |
120 // packets can be further delayed in delivery. | 120 // packets can be further delayed in delivery. |
121 if (bandwidth > 0) | 121 if (bandwidth > 0) |
122 ASSERT_TRUE(sec_count <= 5 * bandwidth / 4); | 122 ASSERT_TRUE(sec_count <= 5 * bandwidth / 4); |
123 sec_count = 0; | 123 sec_count = 0; |
124 thread->PostDelayed(1000, this, 1); | 124 thread->PostDelayed(RTC_FROM_HERE, 1000, this, 1); |
125 } | 125 } |
126 | 126 |
127 Thread* thread; | 127 Thread* thread; |
128 std::unique_ptr<AsyncUDPSocket> socket; | 128 std::unique_ptr<AsyncUDPSocket> socket; |
129 uint32_t bandwidth; | 129 uint32_t bandwidth; |
130 bool done; | 130 bool done; |
131 size_t count; | 131 size_t count; |
132 size_t sec_count; | 132 size_t sec_count; |
133 double sum; | 133 double sum; |
134 double sum_sq; | 134 double sum_sq; |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 << " N=" << kTestSamples[sidx]; | 1052 << " N=" << kTestSamples[sidx]; |
1053 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1053 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
1054 << "M=" << kTestMean[midx] | 1054 << "M=" << kTestMean[midx] |
1055 << " SD=" << kStdDev | 1055 << " SD=" << kStdDev |
1056 << " N=" << kTestSamples[sidx]; | 1056 << " N=" << kTestSamples[sidx]; |
1057 delete f; | 1057 delete f; |
1058 } | 1058 } |
1059 } | 1059 } |
1060 } | 1060 } |
1061 } | 1061 } |
OLD | NEW |