diff options
Diffstat (limited to 'media/cast/test/utility')
-rw-r--r-- | media/cast/test/utility/udp_proxy.cc | 27 | ||||
-rw-r--r-- | media/cast/test/utility/udp_proxy.h | 16 | ||||
-rw-r--r-- | media/cast/test/utility/udp_proxy_main.cc | 2 |
3 files changed, 23 insertions, 22 deletions
diff --git a/media/cast/test/utility/udp_proxy.cc b/media/cast/test/utility/udp_proxy.cc index 5936ef5..eed3744 100644 --- a/media/cast/test/utility/udp_proxy.cc +++ b/media/cast/test/utility/udp_proxy.cc @@ -21,10 +21,11 @@ const size_t kMaxPacketSize = 65536; PacketPipe::PacketPipe() {} PacketPipe::~PacketPipe() {} -void PacketPipe::InitOnIOThread() { - task_runner_ = base::MessageLoopProxy::current(); +void PacketPipe::InitOnIOThread( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { + task_runner_ = task_runner; if (pipe_) { - pipe_->InitOnIOThread(); + pipe_->InitOnIOThread(task_runner); } } void PacketPipe::AppendToPipe(scoped_ptr<PacketPipe> pipe) { @@ -181,8 +182,9 @@ class RandomSortedDelay : public PacketPipe { Schedule(); } } - virtual void InitOnIOThread() OVERRIDE { - PacketPipe::InitOnIOThread(); + virtual void InitOnIOThread( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) OVERRIDE { + PacketPipe::InitOnIOThread(task_runner); // As we start the stream, assume that we are in a random // place between two extra delays, thus multiplier = 1.0; ScheduleExtraDelay(1.0); @@ -261,8 +263,9 @@ class NetworkGlitchPipe : public PacketPipe { max_outage_time_(average_outage_time * 2), weak_factory_(this) {} - virtual void InitOnIOThread() OVERRIDE { - PacketPipe::InitOnIOThread(); + virtual void InitOnIOThread( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) OVERRIDE { + PacketPipe::InitOnIOThread(task_runner); Flip(); } @@ -444,8 +447,8 @@ class UDPProxyImpl : public UDPProxy { BuildPipe(&to_dest_pipe_, new PacketSender(socket_.get(), &destination_)); BuildPipe(&from_dest_pipe_, new PacketSender(socket_.get(), &return_address_)); - to_dest_pipe_->InitOnIOThread(); - from_dest_pipe_->InitOnIOThread(); + to_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current()); + from_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current()); VLOG(0) << "From:" << local_port_.ToString(); VLOG(0) << "To:" << destination_.ToString(); @@ -463,8 +466,7 @@ class UDPProxyImpl : public UDPProxy { stop_event->Signal(); } - void ProcessPacket(scoped_refptr<net::IOBuffer> recv_buf, - int len) { + void ProcessPacket(scoped_refptr<net::IOBuffer> recv_buf, int len) { DCHECK_NE(len, net::ERR_IO_PENDING); VLOG(1) << "Got packet, len = " << len; if (len < 0) { @@ -481,8 +483,7 @@ class UDPProxyImpl : public UDPProxy { } } - void ReadCallback(scoped_refptr<net::IOBuffer> recv_buf, - int len) { + void ReadCallback(scoped_refptr<net::IOBuffer> recv_buf, int len) { ProcessPacket(recv_buf, len); PollRead(); } diff --git a/media/cast/test/utility/udp_proxy.h b/media/cast/test/utility/udp_proxy.h index 322572a..41c686e 100644 --- a/media/cast/test/utility/udp_proxy.h +++ b/media/cast/test/utility/udp_proxy.h @@ -27,7 +27,9 @@ class PacketPipe { PacketPipe(); virtual ~PacketPipe(); virtual void Send(scoped_ptr<transport::Packet> packet) = 0; - virtual void InitOnIOThread(); + // Allows injection of fake test runner for testing. + virtual void InitOnIOThread( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); virtual void AppendToPipe(scoped_ptr<PacketPipe> pipe); protected: scoped_ptr<PacketPipe> pipe_; @@ -77,17 +79,15 @@ scoped_ptr<PacketPipe> NewRandomUnsortedDelay(double delay); // packet is asically |min_delay| + random( |random_delay| ) // However, every now and then a delay of |big_delay| will be // inserted (roughly every |seconds_between_big_delay| seconds). -scoped_ptr<PacketPipe> NewRandomSortedDelay( - double random_delay, - double big_delay, - double seconds_between_big_delay); +scoped_ptr<PacketPipe> NewRandomSortedDelay(double random_delay, + double big_delay, + double seconds_between_big_delay); // This PacketPipe emulates network outages. It basically waits // for 0-2*|average_work_time| seconds, then kills the network for // 0-|2*average_outage_time| seconds. Then it starts over again. -scoped_ptr<PacketPipe> NewNetworkGlitchPipe( - double average_work_time, - double average_outage_time); +scoped_ptr<PacketPipe> NewNetworkGlitchPipe(double average_work_time, + double average_outage_time); // This method builds a stack of PacketPipes to emulate a reasonably // good wifi network. ~5mbit, 1% packet loss, ~3ms latency. diff --git a/media/cast/test/utility/udp_proxy_main.cc b/media/cast/test/utility/udp_proxy_main.cc index 4e196d7..58019b4 100644 --- a/media/cast/test/utility/udp_proxy_main.cc +++ b/media/cast/test/utility/udp_proxy_main.cc @@ -15,7 +15,7 @@ int main(int argc, char** argv) { if (argc < 5) { fprintf(stderr, - "Usage: udp_proxy <localport> <remotehost> <remoteport> <type>\n", + "Usage: udp_proxy <localport> <remotehost> <remoteport> <type>\n" "Where type is one of: perfect, wifi, evil\n"); exit(1); } |