| 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 #include <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <linux/if_tun.h> | 6 #include <linux/if_tun.h> |
| 7 #include <linux/types.h> | 7 #include <linux/types.h> |
| 8 #include <math.h> | 8 #include <math.h> |
| 9 #include <net/if.h> | 9 #include <net/if.h> |
| 10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sys/ioctl.h> | 13 #include <sys/ioctl.h> |
| 14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
| 15 #include <sys/types.h> | 15 #include <sys/types.h> |
| 16 #include <unistd.h> | 16 #include <unistd.h> |
| 17 | 17 |
| 18 #include <deque> | 18 #include <deque> |
| 19 #include <map> | 19 #include <map> |
| 20 | 20 |
| 21 #include "base/at_exit.h" | 21 #include "base/at_exit.h" |
| 22 #include "base/bind.h" | 22 #include "base/bind.h" |
| 23 #include "base/command_line.h" | 23 #include "base/command_line.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
| 26 #include "base/single_thread_task_runner.h" |
| 26 #include "base/synchronization/waitable_event.h" | 27 #include "base/synchronization/waitable_event.h" |
| 28 #include "base/thread_task_runner_handle.h" |
| 27 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
| 28 #include "base/time/default_tick_clock.h" | 30 #include "base/time/default_tick_clock.h" |
| 29 #include "media/cast/test/utility/udp_proxy.h" | 31 #include "media/cast/test/utility/udp_proxy.h" |
| 30 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 31 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
| 32 #include "net/udp/udp_socket.h" | 34 #include "net/udp/udp_socket.h" |
| 33 | 35 |
| 34 namespace media { | 36 namespace media { |
| 35 namespace cast { | 37 namespace cast { |
| 36 namespace test { | 38 namespace test { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 CHECK(base::MessageLoopForIO::current()->WatchFileDescriptor( | 76 CHECK(base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 75 input_fd_, true, base::MessageLoopForIO::WATCH_READ, | 77 input_fd_, true, base::MessageLoopForIO::WATCH_READ, |
| 76 &read_socket_watcher_, this)); | 78 &read_socket_watcher_, this)); |
| 77 | 79 |
| 78 scoped_ptr<PacketPipe> tmp(new SendToFDPipe(output_fd)); | 80 scoped_ptr<PacketPipe> tmp(new SendToFDPipe(output_fd)); |
| 79 if (packet_pipe_) { | 81 if (packet_pipe_) { |
| 80 packet_pipe_->AppendToPipe(tmp.Pass()); | 82 packet_pipe_->AppendToPipe(tmp.Pass()); |
| 81 } else { | 83 } else { |
| 82 packet_pipe_ = tmp.Pass(); | 84 packet_pipe_ = tmp.Pass(); |
| 83 } | 85 } |
| 84 packet_pipe_->InitOnIOThread(base::MessageLoopProxy::current(), | 86 packet_pipe_->InitOnIOThread(base::ThreadTaskRunnerHandle::Get(), |
| 85 &tick_clock_); | 87 &tick_clock_); |
| 86 } | 88 } |
| 87 | 89 |
| 88 ~QueueManager() final {} | 90 ~QueueManager() final {} |
| 89 | 91 |
| 90 // MessageLoopForIO::Watcher methods | 92 // MessageLoopForIO::Watcher methods |
| 91 void OnFileCanReadWithoutBlocking(int fd) final { | 93 void OnFileCanReadWithoutBlocking(int fd) final { |
| 92 scoped_ptr<Packet> packet(new Packet(kMaxPacketSize)); | 94 scoped_ptr<Packet> packet(new Packet(kMaxPacketSize)); |
| 93 int nread = read(input_fd_, | 95 int nread = read(input_fd_, |
| 94 reinterpret_cast<char*>(&packet->front()), | 96 reinterpret_cast<char*>(&packet->front()), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 in_pipe_output_counter.packets_per_second(), | 204 in_pipe_output_counter.packets_per_second(), |
| 203 in_pipe_input_counter.packets_per_second()); | 205 in_pipe_input_counter.packets_per_second()); |
| 204 fprintf(stderr, "Receiving: %5.2f / %5.2f mbps %6.2f / %6.2f packets / s\n", | 206 fprintf(stderr, "Receiving: %5.2f / %5.2f mbps %6.2f / %6.2f packets / s\n", |
| 205 out_pipe_output_counter.megabits_per_second(), | 207 out_pipe_output_counter.megabits_per_second(), |
| 206 out_pipe_input_counter.megabits_per_second(), | 208 out_pipe_input_counter.megabits_per_second(), |
| 207 out_pipe_output_counter.packets_per_second(), | 209 out_pipe_output_counter.packets_per_second(), |
| 208 out_pipe_input_counter.packets_per_second()); | 210 out_pipe_input_counter.packets_per_second()); |
| 209 | 211 |
| 210 last_printout = now; | 212 last_printout = now; |
| 211 } | 213 } |
| 212 base::MessageLoopProxy::current()->PostDelayedTask( | 214 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 213 FROM_HERE, | 215 FROM_HERE, |
| 214 base::Bind(&CheckByteCounters), | 216 base::Bind(&CheckByteCounters), |
| 215 base::TimeDelta::FromMilliseconds(100)); | 217 base::TimeDelta::FromMilliseconds(100)); |
| 216 } | 218 } |
| 217 | 219 |
| 218 int tun_alloc(char *dev, int flags) { | 220 int tun_alloc(char *dev, int flags) { |
| 219 struct ifreq ifr; | 221 struct ifreq ifr; |
| 220 int fd, err; | 222 int fd, err; |
| 221 const char *clonedev = "/dev/net/tun"; | 223 const char *clonedev = "/dev/net/tun"; |
| 222 | 224 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 int fd2 = tun_alloc(argv[2], IFF_TAP); | 307 int fd2 = tun_alloc(argv[2], IFF_TAP); |
| 306 | 308 |
| 307 base::MessageLoopForIO message_loop; | 309 base::MessageLoopForIO message_loop; |
| 308 last_printout = base::TimeTicks::Now(); | 310 last_printout = base::TimeTicks::Now(); |
| 309 media::cast::test::QueueManager qm1(fd1, fd2, in_pipe.Pass()); | 311 media::cast::test::QueueManager qm1(fd1, fd2, in_pipe.Pass()); |
| 310 media::cast::test::QueueManager qm2(fd2, fd1, out_pipe.Pass()); | 312 media::cast::test::QueueManager qm2(fd2, fd1, out_pipe.Pass()); |
| 311 CheckByteCounters(); | 313 CheckByteCounters(); |
| 312 printf("Press Ctrl-C when done.\n"); | 314 printf("Press Ctrl-C when done.\n"); |
| 313 message_loop.Run(); | 315 message_loop.Run(); |
| 314 } | 316 } |
| OLD | NEW |