| Index: webrtc/base/testclient.cc
|
| diff --git a/webrtc/base/testclient.cc b/webrtc/base/testclient.cc
|
| index be4de82ad6006b445434e47d9c46fdef74105a43..fbb4f0cdf33b138a59f34ebe95898c8a74e05b89 100644
|
| --- a/webrtc/base/testclient.cc
|
| +++ b/webrtc/base/testclient.cc
|
| @@ -19,7 +19,7 @@ namespace rtc {
|
| // NextPacket.
|
|
|
| TestClient::TestClient(AsyncPacketSocket* socket)
|
| - : socket_(socket), ready_to_send_(false) {
|
| + : socket_(socket), ready_to_send_(false), prev_packet_timestamp_(-1) {
|
| packets_ = new std::vector<Packet*>();
|
| socket_->SignalReadPacket.connect(this, &TestClient::OnPacket);
|
| socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend);
|
| @@ -91,7 +91,8 @@ bool TestClient::CheckNextPacket(const char* buf, size_t size,
|
| bool res = false;
|
| Packet* packet = NextPacket(kTimeoutMs);
|
| if (packet) {
|
| - res = (packet->size == size && memcmp(packet->buf, buf, size) == 0);
|
| + res = (packet->size == size && memcmp(packet->buf, buf, size) == 0 &&
|
| + CheckTimestamp(packet->packet_time.timestamp));
|
| if (addr)
|
| *addr = packet->addr;
|
| delete packet;
|
| @@ -99,6 +100,29 @@ bool TestClient::CheckNextPacket(const char* buf, size_t size,
|
| return res;
|
| }
|
|
|
| +bool TestClient::CheckTimestamp(int64_t packet_timestamp) {
|
| + bool res = true;
|
| + if (packet_timestamp == -1) {
|
| + res = false;
|
| + }
|
| + int64_t time_us = rtc::TimeMicros();
|
| + if (prev_packet_timestamp_ != -1) {
|
| + if (packet_timestamp < prev_packet_timestamp_) {
|
| + res = false;
|
| + }
|
| + const int64_t kErrorMarginUs = 20000;
|
| + if (packet_timestamp - prev_packet_timestamp_ <
|
| + time_us - prev_time_us_ - kErrorMarginUs ||
|
| + packet_timestamp - prev_packet_timestamp_ >
|
| + time_us - prev_time_us_ + kErrorMarginUs) {
|
| + res = false;
|
| + }
|
| + }
|
| + prev_packet_timestamp_ = packet_timestamp;
|
| + prev_time_us_ = time_us;
|
| + return res;
|
| +}
|
| +
|
| bool TestClient::CheckNoPacket() {
|
| bool res;
|
| Packet* packet = NextPacket(kNoPacketTimeoutMs);
|
| @@ -123,21 +147,24 @@ void TestClient::OnPacket(AsyncPacketSocket* socket, const char* buf,
|
| size_t size, const SocketAddress& remote_addr,
|
| const PacketTime& packet_time) {
|
| CritScope cs(&crit_);
|
| - packets_->push_back(new Packet(remote_addr, buf, size));
|
| + packets_->push_back(new Packet(remote_addr, buf, size, packet_time));
|
| }
|
|
|
| void TestClient::OnReadyToSend(AsyncPacketSocket* socket) {
|
| ready_to_send_ = true;
|
| }
|
|
|
| -TestClient::Packet::Packet(const SocketAddress& a, const char* b, size_t s)
|
| - : addr(a), buf(0), size(s) {
|
| +TestClient::Packet::Packet(const SocketAddress& a,
|
| + const char* b,
|
| + size_t s,
|
| + const PacketTime& packet_time)
|
| + : addr(a), buf(0), size(s), packet_time(packet_time) {
|
| buf = new char[size];
|
| memcpy(buf, b, size);
|
| }
|
|
|
| TestClient::Packet::Packet(const Packet& p)
|
| - : addr(p.addr), buf(0), size(p.size) {
|
| + : addr(p.addr), buf(0), size(p.size), packet_time(p.packet_time) {
|
| buf = new char[size];
|
| memcpy(buf, p.buf, size);
|
| }
|
|
|