Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: media/cast/test/utility/udp_proxy.h

Issue 362123005: Cast: Update simulator tool with more inputs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Diff Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_ 5 #ifndef MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_
6 #define MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_ 6 #define MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/linked_ptr.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
13 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
14 #include "media/cast/transport/cast_transport_config.h" 16 #include "media/cast/transport/cast_transport_config.h"
15 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "third_party/mt19937ar/mt19937ar.h"
16 19
17 namespace net { 20 namespace net {
18 class NetLog; 21 class NetLog;
19 }; 22 };
20 23
21 namespace base { 24 namespace base {
22 class TickClock; 25 class TickClock;
23 }; 26 };
24 27
25 namespace media { 28 namespace media {
(...skipping 10 matching lines...) Expand all
36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 39 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
37 base::TickClock* clock); 40 base::TickClock* clock);
38 virtual void AppendToPipe(scoped_ptr<PacketPipe> pipe); 41 virtual void AppendToPipe(scoped_ptr<PacketPipe> pipe);
39 protected: 42 protected:
40 scoped_ptr<PacketPipe> pipe_; 43 scoped_ptr<PacketPipe> pipe_;
41 // Allows injection of fake task runner for testing. 44 // Allows injection of fake task runner for testing.
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
43 base::TickClock* clock_; 46 base::TickClock* clock_;
44 }; 47 };
45 48
49 // Implements a Interrupted Poisson Process for packet delivery.
50 // The process has 2 states: ON and OFF, the rate of switching between
51 // these two states are defined.
52 // When in ON state packets are sent according to a defined rate.
53 // When in OFF state packets are not sent.
54 // The rate above is the average rate of a poisson distribution.
55 class InterruptedPoissonProcess {
56 public:
57 InterruptedPoissonProcess(
58 const std::vector<double>& average_rates,
59 double coef_burstiness,
60 double coef_variance,
61 uint32 rand_seed);
62
63 scoped_ptr<PacketPipe> NewBuffer(size_t size);
64
65 private:
66 class InternalBuffer;
67
68 // |task_runner| is the executor of the IO thread.
69 // |clock| is the system clock.
70 void InitOnIOThread(
71 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
72 base::TickClock* clock);
73
74 base::TimeDelta NextEvent(double rate);
75 double RandDouble();
76 void ComputeRates();
77 void UpdateRates();
78 void SwitchOff();
79 void SwitchOn();
80 void SendPacket();
81
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
83 base::TickClock* clock_;
84 const std::vector<double> average_rates_;
85 const double coef_burstiness_;
86 const double coef_variance_;
87 int rate_index_;
88
89 // The following rates are per milliseconds.
90 double send_rate_;
91 double switch_off_rate_;
92 double switch_on_rate_;
93 bool on_state_;
94
95 std::vector<base::WeakPtr<InternalBuffer> > send_buffers_;
96
97 // Fast pseudo random number generator.
98 MersenneTwister mt_rand_;
99
100 base::WeakPtrFactory<InterruptedPoissonProcess> weak_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(InterruptedPoissonProcess);
103 };
104
46 // A UDPProxy will set up a UDP socket and bind to |local_port|. 105 // A UDPProxy will set up a UDP socket and bind to |local_port|.
47 // Packets send to that port will be forwarded to |destination|. 106 // Packets send to that port will be forwarded to |destination|.
48 // Packets send from |destination| to |local_port| will be returned 107 // Packets send from |destination| to |local_port| will be returned
49 // to whoever sent a packet to |local_port| last. (Not counting packets 108 // to whoever sent a packet to |local_port| last. (Not counting packets
50 // from |destination|.) The UDPProxy will run a separate thread to 109 // from |destination|.) The UDPProxy will run a separate thread to
51 // do the forwarding of packets, and will keep doing so until destroyed. 110 // do the forwarding of packets, and will keep doing so until destroyed.
52 // You can insert delays and packet drops by supplying a PacketPipe. 111 // You can insert delays and packet drops by supplying a PacketPipe.
53 // The PacketPipes may also be NULL if you just want to forward packets. 112 // The PacketPipes may also be NULL if you just want to forward packets.
54 class UDPProxy { 113 class UDPProxy {
55 public: 114 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // This method builds a stack of PacketPipes to emulate a crappy wifi network. 166 // This method builds a stack of PacketPipes to emulate a crappy wifi network.
108 // ~2mbit, 20% packet loss, ~40ms latency and packets can get reordered. 167 // ~2mbit, 20% packet loss, ~40ms latency and packets can get reordered.
109 // 300ms drouputs every ~2 seconds. 168 // 300ms drouputs every ~2 seconds.
110 scoped_ptr<PacketPipe> EvilNetwork(); 169 scoped_ptr<PacketPipe> EvilNetwork();
111 170
112 } // namespace test 171 } // namespace test
113 } // namespace cast 172 } // namespace cast
114 } // namespace media 173 } // namespace media
115 174
116 #endif // MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_ 175 #endif // MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698