Index: media/cast/test/utility/udp_proxy.h |
diff --git a/media/cast/test/utility/udp_proxy.h b/media/cast/test/utility/udp_proxy.h |
index b102573a9416d8e93f39a3c58bc550aa8234f408..c0d05c5538e8b75b22852e4b1e91cf205eb58fe2 100644 |
--- a/media/cast/test/utility/udp_proxy.h |
+++ b/media/cast/test/utility/udp_proxy.h |
@@ -8,11 +8,14 @@ |
#include <vector> |
#include "base/basictypes.h" |
+#include "base/memory/linked_ptr.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/single_thread_task_runner.h" |
#include "media/cast/transport/cast_transport_config.h" |
#include "net/base/ip_endpoint.h" |
+#include "third_party/mt19937ar/mt19937ar.h" |
namespace net { |
class NetLog; |
@@ -43,6 +46,62 @@ class PacketPipe { |
base::TickClock* clock_; |
}; |
+// Implements a Interrupted Poisson Process for packet delivery. |
+// The process has 2 states: ON and OFF, the rate of switching between |
+// these two states are defined. |
+// When in ON state packets are sent according to a defined rate. |
+// When in OFF state packets are not sent. |
+// The rate above is the average rate of a poisson distribution. |
+class InterruptedPoissonProcess { |
+ public: |
+ InterruptedPoissonProcess( |
+ const std::vector<double>& average_rates, |
+ double coef_burstiness, |
+ double coef_variance, |
+ uint32 rand_seed); |
+ |
+ scoped_ptr<PacketPipe> NewBuffer(size_t size); |
+ |
+ private: |
+ class InternalBuffer; |
+ |
+ // |task_runner| is the executor of the IO thread. |
+ // |clock| is the system clock. |
+ void InitOnIOThread( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
+ base::TickClock* clock); |
+ |
+ base::TimeDelta NextEvent(double rate); |
+ double RandDouble(); |
+ void ComputeRates(); |
+ void UpdateRates(); |
+ void SwitchOff(); |
+ void SwitchOn(); |
+ void SendPacket(); |
+ |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ base::TickClock* clock_; |
+ const std::vector<double> average_rates_; |
+ const double coef_burstiness_; |
+ const double coef_variance_; |
+ int rate_index_; |
+ |
+ // The following rates are per milliseconds. |
+ double send_rate_; |
+ double switch_off_rate_; |
+ double switch_on_rate_; |
+ bool on_state_; |
+ |
+ std::vector<base::WeakPtr<InternalBuffer> > send_buffers_; |
+ |
+ // Fast pseudo random number generator. |
+ MersenneTwister mt_rand_; |
+ |
+ base::WeakPtrFactory<InterruptedPoissonProcess> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(InterruptedPoissonProcess); |
+}; |
+ |
// A UDPProxy will set up a UDP socket and bind to |local_port|. |
// Packets send to that port will be forwarded to |destination|. |
// Packets send from |destination| to |local_port| will be returned |