Index: webrtc/test/fake_network_pipe.h |
diff --git a/webrtc/test/fake_network_pipe.h b/webrtc/test/fake_network_pipe.h |
index 1af63b074983a35746b1a364ab00eea91b708f75..992d8ab0de03b1e2a12ee83a1898eb94506b07da 100644 |
--- a/webrtc/test/fake_network_pipe.h |
+++ b/webrtc/test/fake_network_pipe.h |
@@ -11,6 +11,8 @@ |
#ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
#define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
+#include <set> |
+#include <string.h> |
#include <queue> |
#include "webrtc/base/constructormagic.h" |
@@ -22,9 +24,38 @@ namespace webrtc { |
class Clock; |
class CriticalSectionWrapper; |
-class NetworkPacket; |
class PacketReceiver; |
+class NetworkPacket { |
+ public: |
+ NetworkPacket(const uint8_t* data, size_t length, int64_t send_time, |
+ int64_t arrival_time) |
+ : data_(new uint8_t[length]), |
+ data_length_(length), |
+ send_time_(send_time), |
+ arrival_time_(arrival_time) { |
+ memcpy(data_.get(), data, length); |
+ } |
+ |
+ uint8_t* data() const { return data_.get(); } |
+ size_t data_length() const { return data_length_; } |
+ int64_t send_time() const { return send_time_; } |
+ int64_t arrival_time() const { return arrival_time_; } |
+ void IncrementArrivalTime(int64_t extra_delay) { |
+ arrival_time_+= extra_delay; |
+ } |
+ |
+ private: |
+ // The packet data. |
+ rtc::scoped_ptr<uint8_t> data_; |
+ // Length of data_. |
+ size_t data_length_; |
+ // The time the packet was sent out on the network. |
+ const int64_t send_time_; |
+ // The time the packet should arrive at the reciver. |
stefan-webrtc
2016/01/25 13:16:57
s/reciver/receiver
philipel
2016/01/26 10:50:47
Done.
|
+ int64_t arrival_time_; |
+}; |
+ |
// Class faking a network link. This is a simple and naive solution just faking |
// capacity and adding an extra transport delay in addition to the capacity |
// introduced delay. |
@@ -44,6 +75,8 @@ class FakeNetworkPipe { |
int link_capacity_kbps = 0; |
// Random packet loss. |
int loss_percent = 0; |
+ // If packets are allowed to be reordered. |
+ bool allow_reordering = false; |
}; |
FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); |
@@ -74,7 +107,16 @@ class FakeNetworkPipe { |
mutable rtc::CriticalSection lock_; |
PacketReceiver* packet_receiver_; |
std::queue<NetworkPacket*> capacity_link_; |
- std::queue<NetworkPacket*> delay_link_; |
+ |
+ // Since we need to access both the packet with the earliest and latest |
+ // arrival time we need to use a multiset to keep all packets sorted, |
+ // hence, we cannot use a priority queue. |
stefan-webrtc
2016/01/25 13:16:57
I guess it's also a way to make sure that the pack
philipel
2016/01/26 10:50:47
The packets are always delivered in arrival time o
stefan-webrtc
2016/01/26 11:50:46
Yes, and that's one of the reasons why you need a
|
+ struct PacketArrivalTimeComparator { |
+ bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) { |
+ return p1->arrival_time() < p2->arrival_time(); |
+ } |
+ }; |
+ std::multiset<NetworkPacket*, PacketArrivalTimeComparator> delay_link_; |
// Link configuration. |
Config config_; |