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 <queue> | 14 #include <queue> |
| 15 | 15 |
| 16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
| 17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 18 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/system_wrappers/include/clock.h" | |
|
mflodman
2015/12/09 10:11:25
Forward declare and move to cc-file.
pbos-webrtc
2015/12/09 10:19:04
Done.
| |
| 19 #include "webrtc/system_wrappers/include/event_wrapper.h" | 20 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 20 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 class CriticalSectionWrapper; | 25 class CriticalSectionWrapper; |
| 25 class NetworkPacket; | 26 class NetworkPacket; |
| 26 class PacketReceiver; | 27 class PacketReceiver; |
| 27 | 28 |
| 28 // Class faking a network link. This is a simple and naive solution just faking | 29 // Class faking a network link. This is a simple and naive solution just faking |
| 29 // capacity and adding an extra transport delay in addition to the capacity | 30 // capacity and adding an extra transport delay in addition to the capacity |
| 30 // introduced delay. | 31 // introduced delay. |
| 31 | 32 |
| 32 // TODO(mflodman) Add random and bursty packet loss. | 33 // TODO(mflodman) Add random and bursty packet loss. |
| 33 class FakeNetworkPipe { | 34 class FakeNetworkPipe { |
| 34 public: | 35 public: |
| 35 struct Config { | 36 struct Config { |
| 36 Config() | 37 Config() {} |
| 37 : queue_length_packets(0), | |
| 38 queue_delay_ms(0), | |
| 39 delay_standard_deviation_ms(0), | |
| 40 link_capacity_kbps(0), | |
| 41 loss_percent(0) { | |
| 42 } | |
| 43 // Queue length in number of packets. | 38 // Queue length in number of packets. |
| 44 size_t queue_length_packets; | 39 size_t queue_length_packets = 0; |
| 45 // Delay in addition to capacity induced delay. | 40 // Delay in addition to capacity induced delay. |
| 46 int queue_delay_ms; | 41 int queue_delay_ms = 0; |
| 47 // Standard deviation of the extra delay. | 42 // Standard deviation of the extra delay. |
| 48 int delay_standard_deviation_ms; | 43 int delay_standard_deviation_ms = 0; |
| 49 // Link capacity in kbps. | 44 // Link capacity in kbps. |
| 50 int link_capacity_kbps; | 45 int link_capacity_kbps = 0; |
| 51 // Random packet loss. | 46 // Random packet loss. |
| 52 int loss_percent; | 47 int loss_percent = 0; |
| 53 }; | 48 }; |
| 54 | 49 |
| 55 explicit FakeNetworkPipe(const FakeNetworkPipe::Config& config); | 50 FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); |
| 56 ~FakeNetworkPipe(); | 51 ~FakeNetworkPipe(); |
| 57 | 52 |
| 58 // Must not be called in parallel with SendPacket or Process. | 53 // Must not be called in parallel with SendPacket or Process. |
| 59 void SetReceiver(PacketReceiver* receiver); | 54 void SetReceiver(PacketReceiver* receiver); |
| 60 | 55 |
| 61 // Sets a new configuration. This won't affect packets already in the pipe. | 56 // Sets a new configuration. This won't affect packets already in the pipe. |
| 62 void SetConfig(const FakeNetworkPipe::Config& config); | 57 void SetConfig(const FakeNetworkPipe::Config& config); |
| 63 | 58 |
| 64 // Sends a new packet to the link. | 59 // Sends a new packet to the link. |
| 65 void SendPacket(const uint8_t* packet, size_t packet_length); | 60 void SendPacket(const uint8_t* packet, size_t packet_length); |
| 66 | 61 |
| 67 // Processes the network queues and trigger PacketReceiver::IncomingPacket for | 62 // Processes the network queues and trigger PacketReceiver::IncomingPacket for |
| 68 // packets ready to be delivered. | 63 // packets ready to be delivered. |
| 69 void Process(); | 64 void Process(); |
| 70 int64_t TimeUntilNextProcess() const; | 65 int64_t TimeUntilNextProcess() const; |
| 71 | 66 |
| 72 // Get statistics. | 67 // Get statistics. |
| 73 float PercentageLoss(); | 68 float PercentageLoss(); |
| 74 int AverageDelay(); | 69 int AverageDelay(); |
| 75 size_t dropped_packets() { return dropped_packets_; } | 70 size_t dropped_packets() { return dropped_packets_; } |
| 76 size_t sent_packets() { return sent_packets_; } | 71 size_t sent_packets() { return sent_packets_; } |
| 77 | 72 |
| 78 private: | 73 private: |
| 74 Clock* const clock_; | |
| 79 mutable rtc::CriticalSection lock_; | 75 mutable rtc::CriticalSection lock_; |
| 80 PacketReceiver* packet_receiver_; | 76 PacketReceiver* packet_receiver_; |
| 81 std::queue<NetworkPacket*> capacity_link_; | 77 std::queue<NetworkPacket*> capacity_link_; |
| 82 std::queue<NetworkPacket*> delay_link_; | 78 std::queue<NetworkPacket*> delay_link_; |
| 83 | 79 |
| 84 // Link configuration. | 80 // Link configuration. |
| 85 Config config_; | 81 Config config_; |
| 86 | 82 |
| 87 // Statistics. | 83 // Statistics. |
| 88 size_t dropped_packets_; | 84 size_t dropped_packets_; |
| 89 size_t sent_packets_; | 85 size_t sent_packets_; |
| 90 int total_packet_delay_; | 86 int total_packet_delay_; |
| 91 | 87 |
| 92 int64_t next_process_time_; | 88 int64_t next_process_time_; |
| 93 | 89 |
| 94 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); | 90 RTC_DISALLOW_COPY_AND_ASSIGN(FakeNetworkPipe); |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 } // namespace webrtc | 93 } // namespace webrtc |
| 98 | 94 |
| 99 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ | 95 #endif // WEBRTC_TEST_FAKE_NETWORK_PIPE_H_ |
| OLD | NEW |