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