OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 "webrtc/base/testclient.h" | 11 #include "webrtc/base/testclient.h" |
12 #include "webrtc/base/thread.h" | 12 #include "webrtc/base/thread.h" |
13 #include "webrtc/base/timeutils.h" | 13 #include "webrtc/base/timeutils.h" |
14 | 14 |
15 namespace rtc { | 15 namespace rtc { |
16 | 16 |
17 // DESIGN: Each packet received is put it into a list of packets. | 17 // DESIGN: Each packet received is put it into a list of packets. |
18 // Callers can retrieve received packets from any thread by calling | 18 // Callers can retrieve received packets from any thread by calling |
19 // NextPacket. | 19 // NextPacket. |
20 | 20 |
21 TestClient::TestClient(AsyncPacketSocket* socket) | 21 TestClient::TestClient(AsyncPacketSocket* socket) |
22 : socket_(socket), ready_to_send_(false) { | 22 : socket_(socket), ready_to_send_(false), prev_packet_timestamp_(-1) { |
23 packets_ = new std::vector<Packet*>(); | 23 packets_ = new std::vector<Packet*>(); |
24 socket_->SignalReadPacket.connect(this, &TestClient::OnPacket); | 24 socket_->SignalReadPacket.connect(this, &TestClient::OnPacket); |
25 socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend); | 25 socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend); |
26 } | 26 } |
27 | 27 |
28 TestClient::~TestClient() { | 28 TestClient::~TestClient() { |
29 delete socket_; | 29 delete socket_; |
30 for (unsigned i = 0; i < packets_->size(); i++) | 30 for (unsigned i = 0; i < packets_->size(); i++) |
31 delete (*packets_)[i]; | 31 delete (*packets_)[i]; |
32 delete packets_; | 32 delete packets_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 } | 83 } |
84 | 84 |
85 return packet; | 85 return packet; |
86 } | 86 } |
87 | 87 |
88 bool TestClient::CheckNextPacket(const char* buf, size_t size, | 88 bool TestClient::CheckNextPacket(const char* buf, size_t size, |
89 SocketAddress* addr) { | 89 SocketAddress* addr) { |
90 bool res = false; | 90 bool res = false; |
91 Packet* packet = NextPacket(kTimeoutMs); | 91 Packet* packet = NextPacket(kTimeoutMs); |
92 if (packet) { | 92 if (packet) { |
93 res = (packet->size == size && memcmp(packet->buf, buf, size) == 0); | 93 int64_t packet_timestamp = packet->packet_time.timestamp; |
94 res = | |
95 packet->size == size && memcmp(packet->buf, buf, size) == 0 && | |
96 (prev_packet_timestamp_ == -1 || | |
juberti2
2016/05/11 19:57:22
I think that -1 should only be allowed when we kno
stefan-webrtc
2016/05/12 11:19:53
We don't expect -1 to be returned on any platform
| |
97 (packet_timestamp >= 0 && packet_timestamp >= prev_packet_timestamp_)); | |
98 prev_packet_timestamp_ = packet_timestamp; | |
94 if (addr) | 99 if (addr) |
95 *addr = packet->addr; | 100 *addr = packet->addr; |
96 delete packet; | 101 delete packet; |
97 } | 102 } |
98 return res; | 103 return res; |
99 } | 104 } |
100 | 105 |
101 bool TestClient::CheckNoPacket() { | 106 bool TestClient::CheckNoPacket() { |
102 bool res; | 107 bool res; |
103 Packet* packet = NextPacket(kNoPacketTimeoutMs); | 108 Packet* packet = NextPacket(kNoPacketTimeoutMs); |
(...skipping 11 matching lines...) Expand all Loading... | |
115 } | 120 } |
116 | 121 |
117 bool TestClient::ready_to_send() const { | 122 bool TestClient::ready_to_send() const { |
118 return ready_to_send_; | 123 return ready_to_send_; |
119 } | 124 } |
120 | 125 |
121 void TestClient::OnPacket(AsyncPacketSocket* socket, const char* buf, | 126 void TestClient::OnPacket(AsyncPacketSocket* socket, const char* buf, |
122 size_t size, const SocketAddress& remote_addr, | 127 size_t size, const SocketAddress& remote_addr, |
123 const PacketTime& packet_time) { | 128 const PacketTime& packet_time) { |
124 CritScope cs(&crit_); | 129 CritScope cs(&crit_); |
125 packets_->push_back(new Packet(remote_addr, buf, size)); | 130 packets_->push_back(new Packet(remote_addr, buf, size, packet_time)); |
126 } | 131 } |
127 | 132 |
128 void TestClient::OnReadyToSend(AsyncPacketSocket* socket) { | 133 void TestClient::OnReadyToSend(AsyncPacketSocket* socket) { |
129 ready_to_send_ = true; | 134 ready_to_send_ = true; |
130 } | 135 } |
131 | 136 |
132 TestClient::Packet::Packet(const SocketAddress& a, const char* b, size_t s) | 137 TestClient::Packet::Packet(const SocketAddress& a, |
133 : addr(a), buf(0), size(s) { | 138 const char* b, |
139 size_t s, | |
140 const PacketTime& packet_time) | |
141 : addr(a), buf(0), size(s), packet_time(packet_time) { | |
134 buf = new char[size]; | 142 buf = new char[size]; |
135 memcpy(buf, b, size); | 143 memcpy(buf, b, size); |
136 } | 144 } |
137 | 145 |
138 TestClient::Packet::Packet(const Packet& p) | 146 TestClient::Packet::Packet(const Packet& p) |
139 : addr(p.addr), buf(0), size(p.size) { | 147 : addr(p.addr), buf(0), size(p.size), packet_time(p.packet_time) { |
140 buf = new char[size]; | 148 buf = new char[size]; |
141 memcpy(buf, p.buf, size); | 149 memcpy(buf, p.buf, size); |
142 } | 150 } |
143 | 151 |
144 TestClient::Packet::~Packet() { | 152 TestClient::Packet::~Packet() { |
145 delete[] buf; | 153 delete[] buf; |
146 } | 154 } |
147 | 155 |
148 } // namespace rtc | 156 } // namespace rtc |
OLD | NEW |