| OLD | NEW |
| 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/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "media/cast/transport/cast_transport_config.h" | 14 #include "media/cast/transport/cast_transport_config.h" |
| 15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class NetLog; | 18 class NetLog; |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 namespace base { |
| 22 class TickClock; |
| 23 }; |
| 24 |
| 21 namespace media { | 25 namespace media { |
| 22 namespace cast { | 26 namespace cast { |
| 23 namespace test { | 27 namespace test { |
| 24 | 28 |
| 25 class PacketPipe { | 29 class PacketPipe { |
| 26 public: | 30 public: |
| 27 PacketPipe(); | 31 PacketPipe(); |
| 28 virtual ~PacketPipe(); | 32 virtual ~PacketPipe(); |
| 29 virtual void Send(scoped_ptr<transport::Packet> packet) = 0; | 33 virtual void Send(scoped_ptr<transport::Packet> packet) = 0; |
| 30 // Allows injection of fake test runner for testing. | 34 // Allows injection of fake test runner for testing. |
| 31 virtual void InitOnIOThread( | 35 virtual void InitOnIOThread( |
| 32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 37 base::TickClock* clock); |
| 33 virtual void AppendToPipe(scoped_ptr<PacketPipe> pipe); | 38 virtual void AppendToPipe(scoped_ptr<PacketPipe> pipe); |
| 34 protected: | 39 protected: |
| 35 scoped_ptr<PacketPipe> pipe_; | 40 scoped_ptr<PacketPipe> pipe_; |
| 36 // Allows injection of fake task runner for testing. | 41 // Allows injection of fake task runner for testing. |
| 37 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 43 base::TickClock* clock_; |
| 38 }; | 44 }; |
| 39 | 45 |
| 40 // A UDPProxy will set up a UDP socket and bind to |local_port|. | 46 // A UDPProxy will set up a UDP socket and bind to |local_port|. |
| 41 // Packets send to that port will be forwarded to |destination|. | 47 // Packets send to that port will be forwarded to |destination|. |
| 42 // Packets send from |destination| to |local_port| will be returned | 48 // Packets send from |destination| to |local_port| will be returned |
| 43 // to whoever sent a packet to |local_port| last. (Not counting packets | 49 // to whoever sent a packet to |local_port| last. (Not counting packets |
| 44 // from |destination|.) The UDPProxy will run a separate thread to | 50 // from |destination|.) The UDPProxy will run a separate thread to |
| 45 // do the forwarding of packets, and will keep doing so until destroyed. | 51 // do the forwarding of packets, and will keep doing so until destroyed. |
| 46 // You can insert delays and packet drops by supplying a PacketPipe. | 52 // You can insert delays and packet drops by supplying a PacketPipe. |
| 47 // The PacketPipes may also be NULL if you just want to forward packets. | 53 // The PacketPipes may also be NULL if you just want to forward packets. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // This method builds a stack of PacketPipes to emulate a crappy wifi network. | 107 // This method builds a stack of PacketPipes to emulate a crappy wifi network. |
| 102 // ~2mbit, 20% packet loss, ~40ms latency and packets can get reordered. | 108 // ~2mbit, 20% packet loss, ~40ms latency and packets can get reordered. |
| 103 // 300ms drouputs every ~2 seconds. | 109 // 300ms drouputs every ~2 seconds. |
| 104 scoped_ptr<PacketPipe> EvilNetwork(); | 110 scoped_ptr<PacketPipe> EvilNetwork(); |
| 105 | 111 |
| 106 } // namespace test | 112 } // namespace test |
| 107 } // namespace cast | 113 } // namespace cast |
| 108 } // namespace media | 114 } // namespace media |
| 109 | 115 |
| 110 #endif // MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_ | 116 #endif // MEDIA_CAST_TEST_UTILITY_UDP_PROXY_H_ |
| OLD | NEW |