OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ | 11 #ifndef WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
12 #define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ | 12 #define WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <set> | 15 #include <set> |
16 #include <string.h> | 16 #include <string.h> |
17 #include <queue> | 17 #include <queue> |
18 | 18 |
19 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
21 #include "webrtc/base/random.h" | 21 #include "webrtc/base/random.h" |
22 #include "webrtc/typedefs.h" | 22 #include "webrtc/typedefs.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 class Clock; | 26 class Clock; |
27 class CriticalSectionWrapper; | 27 class CriticalSectionWrapper; |
28 class PacketReceiver; | 28 class PacketReceiver; |
| 29 enum class MediaType; |
29 | 30 |
30 class NetworkPacket { | 31 class NetworkPacket { |
31 public: | 32 public: |
32 NetworkPacket(const uint8_t* data, | 33 NetworkPacket(const uint8_t* data, |
33 size_t length, | 34 size_t length, |
34 int64_t send_time, | 35 int64_t send_time, |
35 int64_t arrival_time) | 36 int64_t arrival_time) |
36 : data_(new uint8_t[length]), | 37 : data_(new uint8_t[length]), |
37 data_length_(length), | 38 data_length_(length), |
38 send_time_(send_time), | 39 send_time_(send_time), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Link capacity in kbps. | 77 // Link capacity in kbps. |
77 int link_capacity_kbps = 0; | 78 int link_capacity_kbps = 0; |
78 // Random packet loss. | 79 // Random packet loss. |
79 int loss_percent = 0; | 80 int loss_percent = 0; |
80 // If packets are allowed to be reordered. | 81 // If packets are allowed to be reordered. |
81 bool allow_reordering = false; | 82 bool allow_reordering = false; |
82 // The average length of a burst of lost packets. | 83 // The average length of a burst of lost packets. |
83 int avg_burst_loss_length = -1; | 84 int avg_burst_loss_length = -1; |
84 }; | 85 }; |
85 | 86 |
86 FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); | 87 FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, |
| 88 MediaType media_type); |
87 FakeNetworkPipe(Clock* clock, | 89 FakeNetworkPipe(Clock* clock, |
88 const FakeNetworkPipe::Config& config, | 90 const FakeNetworkPipe::Config& config, MediaType media_type, |
89 uint64_t seed); | 91 uint64_t seed); |
90 ~FakeNetworkPipe(); | 92 ~FakeNetworkPipe(); |
91 | 93 |
92 // Must not be called in parallel with SendPacket or Process. | 94 // Must not be called in parallel with SendPacket or Process. |
93 void SetReceiver(PacketReceiver* receiver); | 95 void SetReceiver(PacketReceiver* receiver); |
94 | 96 |
95 // Sets a new configuration. This won't affect packets already in the pipe. | 97 // Sets a new configuration. This won't affect packets already in the pipe. |
96 void SetConfig(const FakeNetworkPipe::Config& config); | 98 void SetConfig(const FakeNetworkPipe::Config& config); |
97 | 99 |
98 // Sends a new packet to the link. | 100 // Sends a new packet to the link. |
99 void SendPacket(const uint8_t* packet, size_t packet_length); | 101 void SendPacket(const uint8_t* packet, size_t packet_length); |
100 | 102 |
101 // Processes the network queues and trigger PacketReceiver::IncomingPacket for | 103 // Processes the network queues and trigger PacketReceiver::IncomingPacket for |
102 // packets ready to be delivered. | 104 // packets ready to be delivered. |
103 void Process(); | 105 void Process(); |
104 int64_t TimeUntilNextProcess() const; | 106 int64_t TimeUntilNextProcess() const; |
105 | 107 |
106 // Get statistics. | 108 // Get statistics. |
107 float PercentageLoss(); | 109 float PercentageLoss(); |
108 int AverageDelay(); | 110 int AverageDelay(); |
109 size_t dropped_packets() { return dropped_packets_; } | 111 size_t dropped_packets() { return dropped_packets_; } |
110 size_t sent_packets() { return sent_packets_; } | 112 size_t sent_packets() { return sent_packets_; } |
111 | 113 |
112 private: | 114 private: |
113 Clock* const clock_; | 115 Clock* const clock_; |
| 116 const MediaType media_type_; |
114 rtc::CriticalSection lock_; | 117 rtc::CriticalSection lock_; |
115 PacketReceiver* packet_receiver_; | 118 PacketReceiver* packet_receiver_; |
116 std::queue<NetworkPacket*> capacity_link_; | 119 std::queue<NetworkPacket*> capacity_link_; |
117 Random random_; | 120 Random random_; |
118 | 121 |
119 // Since we need to access both the packet with the earliest and latest | 122 // Since we need to access both the packet with the earliest and latest |
120 // arrival time we need to use a multiset to keep all packets sorted, | 123 // arrival time we need to use a multiset to keep all packets sorted, |
121 // hence, we cannot use a priority queue. | 124 // hence, we cannot use a priority queue. |
122 struct PacketArrivalTimeComparator { | 125 struct PacketArrivalTimeComparator { |
123 bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) { | 126 bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) { |
(...skipping 23 matching lines...) Expand all Loading... |
147 int64_t next_process_time_; | 150 int64_t next_process_time_; |
148 | 151 |
149 int64_t last_log_time_; | 152 int64_t last_log_time_; |
150 | 153 |
151 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); | 154 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); |
152 }; | 155 }; |
153 | 156 |
154 } // namespace webrtc | 157 } // namespace webrtc |
155 | 158 |
156 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ | 159 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
OLD | NEW |