| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | |
| 7 #include <cstdio> | 6 #include <cstdio> |
| 8 #include <cstdlib> | 7 #include <cstdlib> |
| 9 #include <deque> | 8 #include <deque> |
| 10 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "media/cast/test/utility/udp_proxy.h" | 20 #include "media/cast/test/utility/udp_proxy.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 base::LazyInstance<GlobalCounter>::Leaky g_counter = | 76 base::LazyInstance<GlobalCounter>::Leaky g_counter = |
| 77 LAZY_INSTANCE_INITIALIZER; | 77 LAZY_INSTANCE_INITIALIZER; |
| 78 | 78 |
| 79 class ByteCounterPipe : public media::cast::test::PacketPipe { | 79 class ByteCounterPipe : public media::cast::test::PacketPipe { |
| 80 public: | 80 public: |
| 81 ByteCounterPipe(ByteCounter* counter) : counter_(counter) {} | 81 ByteCounterPipe(ByteCounter* counter) : counter_(counter) {} |
| 82 void Send(scoped_ptr<media::cast::Packet> packet) final { | 82 void Send(scoped_ptr<media::cast::Packet> packet) final { |
| 83 counter_->Increment(packet->size()); | 83 counter_->Increment(packet->size()); |
| 84 pipe_->Send(packet.Pass()); | 84 pipe_->Send(std::move(packet)); |
| 85 } | 85 } |
| 86 private: | 86 private: |
| 87 ByteCounter* counter_; | 87 ByteCounter* counter_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 void SetupByteCounters(scoped_ptr<media::cast::test::PacketPipe>* pipe, | 90 void SetupByteCounters(scoped_ptr<media::cast::test::PacketPipe>* pipe, |
| 91 ByteCounter* pipe_input_counter, | 91 ByteCounter* pipe_input_counter, |
| 92 ByteCounter* pipe_output_counter) { | 92 ByteCounter* pipe_output_counter) { |
| 93 media::cast::test::PacketPipe* new_pipe = | 93 media::cast::test::PacketPipe* new_pipe = |
| 94 new ByteCounterPipe(pipe_input_counter); | 94 new ByteCounterPipe(pipe_input_counter); |
| 95 new_pipe->AppendToPipe(pipe->Pass()); | 95 new_pipe->AppendToPipe(std::move(*pipe)); |
| 96 new_pipe->AppendToPipe( | 96 new_pipe->AppendToPipe(scoped_ptr<media::cast::test::PacketPipe>( |
| 97 scoped_ptr<media::cast::test::PacketPipe>( | 97 new ByteCounterPipe(pipe_output_counter))); |
| 98 new ByteCounterPipe(pipe_output_counter)).Pass()); | |
| 99 pipe->reset(new_pipe); | 98 pipe->reset(new_pipe); |
| 100 } | 99 } |
| 101 | 100 |
| 102 void CheckByteCounters() { | 101 void CheckByteCounters() { |
| 103 base::TimeTicks now = base::TimeTicks::Now(); | 102 base::TimeTicks now = base::TimeTicks::Now(); |
| 104 g_counter.Get().in_pipe_input_counter.push(now); | 103 g_counter.Get().in_pipe_input_counter.push(now); |
| 105 g_counter.Get().in_pipe_output_counter.push(now); | 104 g_counter.Get().in_pipe_output_counter.push(now); |
| 106 g_counter.Get().out_pipe_input_counter.push(now); | 105 g_counter.Get().out_pipe_input_counter.push(now); |
| 107 g_counter.Get().out_pipe_output_counter.push(now); | 106 g_counter.Get().out_pipe_output_counter.push(now); |
| 108 if ((now - g_counter.Get().last_printout).InSeconds() >= 5) { | 107 if ((now - g_counter.Get().last_printout).InSeconds() >= 5) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 static_cast<uint16_t>(remote_port)); | 165 static_cast<uint16_t>(remote_port)); |
| 167 net::IPEndPoint local_endpoint(local_ip_number, | 166 net::IPEndPoint local_endpoint(local_ip_number, |
| 168 static_cast<uint16_t>(local_port)); | 167 static_cast<uint16_t>(local_port)); |
| 169 scoped_ptr<media::cast::test::PacketPipe> in_pipe, out_pipe; | 168 scoped_ptr<media::cast::test::PacketPipe> in_pipe, out_pipe; |
| 170 scoped_ptr<media::cast::test::InterruptedPoissonProcess> ipp( | 169 scoped_ptr<media::cast::test::InterruptedPoissonProcess> ipp( |
| 171 media::cast::test::DefaultInterruptedPoissonProcess()); | 170 media::cast::test::DefaultInterruptedPoissonProcess()); |
| 172 | 171 |
| 173 if (network_type == "perfect") { | 172 if (network_type == "perfect") { |
| 174 // No action needed. | 173 // No action needed. |
| 175 } else if (network_type == "wifi") { | 174 } else if (network_type == "wifi") { |
| 176 in_pipe = media::cast::test::WifiNetwork().Pass(); | 175 in_pipe = media::cast::test::WifiNetwork(); |
| 177 out_pipe = media::cast::test::WifiNetwork().Pass(); | 176 out_pipe = media::cast::test::WifiNetwork(); |
| 178 } else if (network_type == "bad") { | 177 } else if (network_type == "bad") { |
| 179 in_pipe = media::cast::test::BadNetwork().Pass(); | 178 in_pipe = media::cast::test::BadNetwork(); |
| 180 out_pipe = media::cast::test::BadNetwork().Pass(); | 179 out_pipe = media::cast::test::BadNetwork(); |
| 181 } else if (network_type == "evil") { | 180 } else if (network_type == "evil") { |
| 182 in_pipe = media::cast::test::EvilNetwork().Pass(); | 181 in_pipe = media::cast::test::EvilNetwork(); |
| 183 out_pipe = media::cast::test::EvilNetwork().Pass(); | 182 out_pipe = media::cast::test::EvilNetwork(); |
| 184 } else if (network_type == "poisson-wifi") { | 183 } else if (network_type == "poisson-wifi") { |
| 185 in_pipe = ipp->NewBuffer(128 * 1024).Pass(); | 184 in_pipe = ipp->NewBuffer(128 * 1024); |
| 186 out_pipe = ipp->NewBuffer(128 * 1024).Pass(); | 185 out_pipe = ipp->NewBuffer(128 * 1024); |
| 187 } else { | 186 } else { |
| 188 fprintf(stderr, "Unknown network type.\n"); | 187 fprintf(stderr, "Unknown network type.\n"); |
| 189 exit(1); | 188 exit(1); |
| 190 } | 189 } |
| 191 | 190 |
| 192 SetupByteCounters(&in_pipe, &(g_counter.Get().in_pipe_input_counter), | 191 SetupByteCounters(&in_pipe, &(g_counter.Get().in_pipe_input_counter), |
| 193 &(g_counter.Get().in_pipe_output_counter)); | 192 &(g_counter.Get().in_pipe_output_counter)); |
| 194 SetupByteCounters( | 193 SetupByteCounters( |
| 195 &out_pipe, &(g_counter.Get().out_pipe_input_counter), | 194 &out_pipe, &(g_counter.Get().out_pipe_input_counter), |
| 196 &(g_counter.Get().out_pipe_output_counter)); | 195 &(g_counter.Get().out_pipe_output_counter)); |
| 197 | 196 |
| 198 printf("Press Ctrl-C when done.\n"); | 197 printf("Press Ctrl-C when done.\n"); |
| 199 scoped_ptr<media::cast::test::UDPProxy> proxy( | 198 scoped_ptr<media::cast::test::UDPProxy> proxy( |
| 200 media::cast::test::UDPProxy::Create(local_endpoint, | 199 media::cast::test::UDPProxy::Create(local_endpoint, remote_endpoint, |
| 201 remote_endpoint, | 200 std::move(in_pipe), |
| 202 in_pipe.Pass(), | 201 std::move(out_pipe), NULL)); |
| 203 out_pipe.Pass(), | |
| 204 NULL)); | |
| 205 base::MessageLoop message_loop; | 202 base::MessageLoop message_loop; |
| 206 g_counter.Get().last_printout = base::TimeTicks::Now(); | 203 g_counter.Get().last_printout = base::TimeTicks::Now(); |
| 207 CheckByteCounters(); | 204 CheckByteCounters(); |
| 208 message_loop.Run(); | 205 message_loop.Run(); |
| 209 return 1; | 206 return 1; |
| 210 } | 207 } |
| OLD | NEW |