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 // This program benchmarks the theoretical throughput of the cast library. | 5 // This program benchmarks the theoretical throughput of the cast library. |
6 // It runs using a fake clock, simulated network and fake codecs. This allows | 6 // It runs using a fake clock, simulated network and fake codecs. This allows |
7 // tests to run much faster than real time. | 7 // tests to run much faster than real time. |
8 // To run the program, run: | 8 // To run the program, run: |
9 // $ ./out/Release/cast_benchmarks | tee benchmarkoutput.asc | 9 // $ ./out/Release/cast_benchmarks | tee benchmarkoutput.asc |
10 // This may take a while, when it is done, you can view the data with | 10 // This may take a while, when it is done, you can view the data with |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include <stdint.h> | 25 #include <stdint.h> |
26 | 26 |
27 #include <map> | 27 #include <map> |
28 #include <vector> | 28 #include <vector> |
29 | 29 |
30 #include "base/at_exit.h" | 30 #include "base/at_exit.h" |
31 #include "base/bind.h" | 31 #include "base/bind.h" |
32 #include "base/bind_helpers.h" | 32 #include "base/bind_helpers.h" |
33 #include "base/command_line.h" | 33 #include "base/command_line.h" |
34 #include "base/debug/profiler.h" | 34 #include "base/debug/profiler.h" |
| 35 #include "base/memory/weak_ptr.h" |
| 36 #include "base/run_loop.h" |
35 #include "base/stl_util.h" | 37 #include "base/stl_util.h" |
36 #include "base/strings/string_number_conversions.h" | 38 #include "base/strings/string_number_conversions.h" |
37 #include "base/strings/stringprintf.h" | 39 #include "base/strings/stringprintf.h" |
38 #include "base/test/simple_test_tick_clock.h" | 40 #include "base/test/simple_test_tick_clock.h" |
39 #include "base/threading/thread.h" | 41 #include "base/threading/thread.h" |
40 #include "base/time/tick_clock.h" | 42 #include "base/time/tick_clock.h" |
41 #include "media/base/audio_bus.h" | 43 #include "media/base/audio_bus.h" |
42 #include "media/base/video_frame.h" | 44 #include "media/base/video_frame.h" |
43 #include "media/cast/cast_config.h" | 45 #include "media/cast/cast_config.h" |
44 #include "media/cast/cast_environment.h" | 46 #include "media/cast/cast_environment.h" |
(...skipping 29 matching lines...) Expand all Loading... |
74 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; | 76 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; |
75 // a normal video is 30 fps hence the 33 ms between frames. | 77 // a normal video is 30 fps hence the 33 ms between frames. |
76 static const int kFrameTimerMs = 33; | 78 static const int kFrameTimerMs = 33; |
77 | 79 |
78 void UpdateCastTransportStatus(CastTransportStatus status) { | 80 void UpdateCastTransportStatus(CastTransportStatus status) { |
79 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || | 81 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || |
80 status == TRANSPORT_VIDEO_INITIALIZED); | 82 status == TRANSPORT_VIDEO_INITIALIZED); |
81 EXPECT_TRUE(result); | 83 EXPECT_TRUE(result); |
82 } | 84 } |
83 | 85 |
84 void AudioInitializationStatus(CastInitializationStatus status) { | 86 void ExpectSuccessAndRunCallback(const base::Closure& done_cb, |
85 EXPECT_EQ(STATUS_AUDIO_INITIALIZED, status); | 87 OperationalStatus status) { |
86 } | 88 EXPECT_EQ(STATUS_INITIALIZED, status); |
87 | 89 done_cb.Run(); |
88 void VideoInitializationStatus(CastInitializationStatus status) { | |
89 EXPECT_EQ(STATUS_VIDEO_INITIALIZED, status); | |
90 } | 90 } |
91 | 91 |
92 void IgnoreRawEvents(const std::vector<PacketEvent>& packet_events, | 92 void IgnoreRawEvents(const std::vector<PacketEvent>& packet_events, |
93 const std::vector<FrameEvent>& frame_events) { | 93 const std::vector<FrameEvent>& frame_events) { |
94 } | 94 } |
95 | 95 |
96 } // namespace | 96 } // namespace |
97 | 97 |
98 // Wraps a CastTransportSender and records some statistics about | 98 // Wraps a CastTransportSender and records some statistics about |
99 // the data that goes through it. | 99 // the data that goes through it. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 &receiver_to_sender_)); | 339 &receiver_to_sender_)); |
340 | 340 |
341 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, | 341 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, |
342 audio_receiver_config_, | 342 audio_receiver_config_, |
343 video_receiver_config_, | 343 video_receiver_config_, |
344 transport_receiver_.get()); | 344 transport_receiver_.get()); |
345 | 345 |
346 cast_sender_ = | 346 cast_sender_ = |
347 CastSender::Create(cast_environment_sender_, &transport_sender_); | 347 CastSender::Create(cast_environment_sender_, &transport_sender_); |
348 | 348 |
349 // Initializing audio and video senders. | 349 // Initializing audio and video senders. The funny dance here is to |
350 cast_sender_->InitializeAudio(audio_sender_config_, | 350 // synchronize on the asynchronous initialization process. |
351 base::Bind(&AudioInitializationStatus)); | 351 base::RunLoop run_loop; |
352 cast_sender_->InitializeVideo(video_sender_config_, | 352 base::WeakPtrFactory<RunOneBenchmark> weak_factory(this); |
353 base::Bind(&VideoInitializationStatus), | 353 cast_sender_->InitializeAudio( |
354 CreateDefaultVideoEncodeAcceleratorCallback(), | 354 audio_sender_config_, |
355 CreateDefaultVideoEncodeMemoryCallback()); | 355 base::Bind(&ExpectSuccessAndRunCallback, run_loop.QuitClosure())); |
| 356 run_loop.Run(); // Wait for quit closure to run. |
| 357 weak_factory.InvalidateWeakPtrs(); |
| 358 cast_sender_->InitializeVideo( |
| 359 video_sender_config_, |
| 360 base::Bind(&ExpectSuccessAndRunCallback, run_loop.QuitClosure()), |
| 361 CreateDefaultVideoEncodeAcceleratorCallback(), |
| 362 CreateDefaultVideoEncodeMemoryCallback()); |
| 363 run_loop.Run(); // Wait for quit closure to run. |
| 364 weak_factory.InvalidateWeakPtrs(); |
356 | 365 |
357 receiver_to_sender_.Initialize( | 366 receiver_to_sender_.Initialize( |
358 CreateSimplePipe(p).Pass(), | 367 CreateSimplePipe(p).Pass(), |
359 transport_sender_.PacketReceiverForTesting(), | 368 transport_sender_.PacketReceiverForTesting(), |
360 task_runner_, &testing_clock_); | 369 task_runner_, &testing_clock_); |
361 sender_to_receiver_.Initialize( | 370 sender_to_receiver_.Initialize( |
362 CreateSimplePipe(p).Pass(), | 371 CreateSimplePipe(p).Pass(), |
363 transport_receiver_->PacketReceiverForTesting(), | 372 transport_receiver_->PacketReceiverForTesting(), |
364 task_runner_, &testing_clock_); | 373 task_runner_, &testing_clock_); |
365 } | 374 } |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 media::cast::CastBenchmark benchmark; | 756 media::cast::CastBenchmark benchmark; |
748 if (getenv("PROFILE_FILE")) { | 757 if (getenv("PROFILE_FILE")) { |
749 std::string profile_file(getenv("PROFILE_FILE")); | 758 std::string profile_file(getenv("PROFILE_FILE")); |
750 base::debug::StartProfiling(profile_file); | 759 base::debug::StartProfiling(profile_file); |
751 benchmark.Run(); | 760 benchmark.Run(); |
752 base::debug::StopProfiling(); | 761 base::debug::StopProfiling(); |
753 } else { | 762 } else { |
754 benchmark.Run(); | 763 benchmark.Run(); |
755 } | 764 } |
756 } | 765 } |
OLD | NEW |