Chromium Code Reviews| Index: media/cast/test/utility/udp_proxy_main.cc |
| diff --git a/media/cast/test/utility/udp_proxy_main.cc b/media/cast/test/utility/udp_proxy_main.cc |
| index 0244c3a1f0604e29ff4596dc9854236d29950244..bb4f016d501f62d5ec1ec03ea83a1344364006ab 100644 |
| --- a/media/cast/test/utility/udp_proxy_main.cc |
| +++ b/media/cast/test/utility/udp_proxy_main.cc |
| @@ -12,7 +12,6 @@ |
| #include "base/at_exit.h" |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| -#include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| @@ -75,8 +74,10 @@ struct GlobalCounter { |
| }; |
| } // namespace |
| -base::LazyInstance<GlobalCounter>::Leaky g_counter = |
| - LAZY_INSTANCE_INITIALIZER; |
| +GlobalCounter* GetGlobalCounter() { |
|
Mark Mentovai
2017/01/31 21:33:56
This should live in the unnamed namespace immediat
DaleCurtis
2017/01/31 22:04:33
Done, though this whole class is a bit wonky since
|
| + static GlobalCounter* counter = new GlobalCounter(); |
| + return counter; |
| +} |
| class ByteCounterPipe : public media::cast::test::PacketPipe { |
| public: |
| @@ -101,24 +102,26 @@ void SetupByteCounters(std::unique_ptr<media::cast::test::PacketPipe>* pipe, |
| } |
| void CheckByteCounters() { |
| + GlobalCounter* counter = GetGlobalCounter(); |
| + |
| base::TimeTicks now = base::TimeTicks::Now(); |
| - g_counter.Get().in_pipe_input_counter.push(now); |
| - g_counter.Get().in_pipe_output_counter.push(now); |
| - g_counter.Get().out_pipe_input_counter.push(now); |
| - g_counter.Get().out_pipe_output_counter.push(now); |
| - if ((now - g_counter.Get().last_printout).InSeconds() >= 5) { |
| + counter->in_pipe_input_counter.push(now); |
| + counter->in_pipe_output_counter.push(now); |
| + counter->out_pipe_input_counter.push(now); |
| + counter->out_pipe_output_counter.push(now); |
| + if ((now - counter->last_printout).InSeconds() >= 5) { |
| fprintf(stderr, "Sending : %5.2f / %5.2f mbps %6.2f / %6.2f packets / s\n", |
| - g_counter.Get().in_pipe_output_counter.megabits_per_second(), |
| - g_counter.Get().in_pipe_input_counter.megabits_per_second(), |
| - g_counter.Get().in_pipe_output_counter.packets_per_second(), |
| - g_counter.Get().in_pipe_input_counter.packets_per_second()); |
| + counter->in_pipe_output_counter.megabits_per_second(), |
| + counter->in_pipe_input_counter.megabits_per_second(), |
| + counter->in_pipe_output_counter.packets_per_second(), |
| + counter->in_pipe_input_counter.packets_per_second()); |
| fprintf(stderr, "Receiving: %5.2f / %5.2f mbps %6.2f / %6.2f packets / s\n", |
| - g_counter.Get().out_pipe_output_counter.megabits_per_second(), |
| - g_counter.Get().out_pipe_input_counter.megabits_per_second(), |
| - g_counter.Get().out_pipe_output_counter.packets_per_second(), |
| - g_counter.Get().out_pipe_input_counter.packets_per_second()); |
| + counter->out_pipe_output_counter.megabits_per_second(), |
| + counter->out_pipe_input_counter.megabits_per_second(), |
| + counter->out_pipe_output_counter.packets_per_second(), |
| + counter->out_pipe_input_counter.packets_per_second()); |
| - g_counter.Get().last_printout = now; |
| + counter->last_printout = now; |
| } |
| base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| FROM_HERE, |
| @@ -188,11 +191,12 @@ int main(int argc, char** argv) { |
| exit(1); |
| } |
| - SetupByteCounters(&in_pipe, &(g_counter.Get().in_pipe_input_counter), |
| - &(g_counter.Get().in_pipe_output_counter)); |
| - SetupByteCounters( |
| - &out_pipe, &(g_counter.Get().out_pipe_input_counter), |
| - &(g_counter.Get().out_pipe_output_counter)); |
| + GlobalCounter* counter = GetGlobalCounter(); |
| + |
| + SetupByteCounters(&in_pipe, &(counter->in_pipe_input_counter), |
| + &(counter->in_pipe_output_counter)); |
| + SetupByteCounters(&out_pipe, &(counter->out_pipe_input_counter), |
| + &(counter->out_pipe_output_counter)); |
| printf("Press Ctrl-C when done.\n"); |
| std::unique_ptr<media::cast::test::UDPProxy> proxy( |
| @@ -200,7 +204,7 @@ int main(int argc, char** argv) { |
| std::move(in_pipe), |
| std::move(out_pipe), NULL)); |
| base::MessageLoop message_loop; |
| - g_counter.Get().last_printout = base::TimeTicks::Now(); |
| + counter->last_printout = base::TimeTicks::Now(); |
| CheckByteCounters(); |
| base::RunLoop().Run(); |
| return 1; |