| 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 <string.h> |
| 15 #include <map> |
| 14 #include <memory> | 16 #include <memory> |
| 17 #include <queue> |
| 15 #include <set> | 18 #include <set> |
| 16 #include <string.h> | |
| 17 #include <queue> | |
| 18 | 19 |
| 19 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
| 20 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
| 21 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
| 22 #include "webrtc/typedefs.h" | 23 #include "webrtc/typedefs.h" |
| 23 | 24 |
| 24 namespace webrtc { | 25 namespace webrtc { |
| 25 | 26 |
| 26 class Clock; | 27 class Clock; |
| 27 class PacketReceiver; | 28 class PacketReceiver; |
| (...skipping 48 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 MediaType media_type); | |
| 88 FakeNetworkPipe(Clock* clock, | 87 FakeNetworkPipe(Clock* clock, |
| 89 const FakeNetworkPipe::Config& config, MediaType media_type, | 88 const FakeNetworkPipe::Config& config, |
| 89 const std::map<uint8_t, MediaType>& payload_type_map); |
| 90 FakeNetworkPipe(Clock* clock, |
| 91 const FakeNetworkPipe::Config& config, |
| 92 const std::map<uint8_t, MediaType>& payload_type_map, |
| 90 uint64_t seed); | 93 uint64_t seed); |
| 91 ~FakeNetworkPipe(); | 94 ~FakeNetworkPipe(); |
| 92 | 95 |
| 93 // Must not be called in parallel with SendPacket or Process. | 96 // Must not be called in parallel with SendPacket or Process. |
| 94 void SetReceiver(PacketReceiver* receiver); | 97 void SetReceiver(PacketReceiver* receiver); |
| 95 | 98 |
| 96 // Sets a new configuration. This won't affect packets already in the pipe. | 99 // Sets a new configuration. This won't affect packets already in the pipe. |
| 97 void SetConfig(const FakeNetworkPipe::Config& config); | 100 void SetConfig(const FakeNetworkPipe::Config& config); |
| 98 | 101 |
| 99 // Sends a new packet to the link. | 102 // Sends a new packet to the link. |
| 100 void SendPacket(const uint8_t* packet, size_t packet_length); | 103 void SendPacket(const uint8_t* packet, size_t packet_length); |
| 101 | 104 |
| 102 // Processes the network queues and trigger PacketReceiver::IncomingPacket for | 105 // Processes the network queues and trigger PacketReceiver::IncomingPacket for |
| 103 // packets ready to be delivered. | 106 // packets ready to be delivered. |
| 104 void Process(); | 107 void Process(); |
| 105 int64_t TimeUntilNextProcess() const; | 108 int64_t TimeUntilNextProcess() const; |
| 106 | 109 |
| 107 // Get statistics. | 110 // Get statistics. |
| 108 float PercentageLoss(); | 111 float PercentageLoss(); |
| 109 int AverageDelay(); | 112 int AverageDelay(); |
| 110 size_t dropped_packets() { return dropped_packets_; } | 113 size_t dropped_packets() { return dropped_packets_; } |
| 111 size_t sent_packets() { return sent_packets_; } | 114 size_t sent_packets() { return sent_packets_; } |
| 112 | 115 |
| 113 private: | 116 private: |
| 114 Clock* const clock_; | 117 Clock* const clock_; |
| 115 const MediaType media_type_; | |
| 116 rtc::CriticalSection lock_; | 118 rtc::CriticalSection lock_; |
| 117 PacketReceiver* packet_receiver_; | 119 PacketReceiver* packet_receiver_; |
| 118 std::queue<NetworkPacket*> capacity_link_; | 120 std::queue<NetworkPacket*> capacity_link_; |
| 119 Random random_; | 121 Random random_; |
| 120 | 122 |
| 121 // Since we need to access both the packet with the earliest and latest | 123 // Since we need to access both the packet with the earliest and latest |
| 122 // arrival time we need to use a multiset to keep all packets sorted, | 124 // arrival time we need to use a multiset to keep all packets sorted, |
| 123 // hence, we cannot use a priority queue. | 125 // hence, we cannot use a priority queue. |
| 124 struct PacketArrivalTimeComparator { | 126 struct PacketArrivalTimeComparator { |
| 125 bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) { | 127 bool operator()(const NetworkPacket* p1, const NetworkPacket* p2) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 143 // burst of packet | 145 // burst of packet |
| 144 double prob_loss_bursting_; | 146 double prob_loss_bursting_; |
| 145 | 147 |
| 146 // The probability to drop a burst of packets. | 148 // The probability to drop a burst of packets. |
| 147 double prob_start_bursting_; | 149 double prob_start_bursting_; |
| 148 | 150 |
| 149 int64_t next_process_time_; | 151 int64_t next_process_time_; |
| 150 | 152 |
| 151 int64_t last_log_time_; | 153 int64_t last_log_time_; |
| 152 | 154 |
| 155 const std::map<uint8_t, MediaType> payload_type_map_; |
| 156 |
| 153 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); | 157 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); |
| 154 }; | 158 }; |
| 155 | 159 |
| 156 } // namespace webrtc | 160 } // namespace webrtc |
| 157 | 161 |
| 158 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ | 162 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
| OLD | NEW |