| 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 17 matching lines...) Expand all Loading... |
| 28 using namespace rtc; | 28 using namespace rtc; |
| 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::Time(); | 38 last_send = rtc::TimeMillis(); |
| 39 thread->PostDelayed(NextDelay(), this, 1); | 39 thread->PostDelayed(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 uint32_t cur_time = rtc::Time(); | 53 int64_t cur_time = rtc::TimeMillis(); |
| 54 uint32_t delay = cur_time - last_send; | 54 int64_t delay = cur_time - last_send; |
| 55 uint32_t size = 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(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 uint32_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), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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); |
| 100 ASSERT_GE(size, 4U); | 100 ASSERT_GE(size, 4U); |
| 101 | 101 |
| 102 count += size; | 102 count += size; |
| 103 sec_count += size; | 103 sec_count += size; |
| 104 | 104 |
| 105 uint32_t send_time = *reinterpret_cast<const uint32_t*>(data); | 105 uint32_t send_time = *reinterpret_cast<const uint32_t*>(data); |
| 106 uint32_t recv_time = rtc::Time(); | 106 uint32_t recv_time = rtc::TimeMillis(); |
| 107 uint32_t delay = recv_time - send_time; | 107 uint32_t delay = recv_time - send_time; |
| 108 sum += delay; | 108 sum += delay; |
| 109 sum_sq += delay * delay; | 109 sum_sq += delay * delay; |
| 110 samples += 1; | 110 samples += 1; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void OnMessage(Message* pmsg) { | 113 void OnMessage(Message* pmsg) { |
| 114 ASSERT_EQ(1u, pmsg->message_id); | 114 ASSERT_EQ(1u, pmsg->message_id); |
| 115 | 115 |
| 116 if (done) | 116 if (done) |
| (...skipping 935 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 |