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