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 |
11 // meshlab by running: | 11 // meshlab by running: |
12 // $ meshlab benchmarkoutput.asc | 12 // $ meshlab benchmarkoutput.asc |
13 // After starting meshlab, turn on Render->Show Axis. The red axis will | 13 // After starting meshlab, turn on Render->Show Axis. The red axis will |
14 // represent bandwidth (in megabits) the blue axis will be packet drop | 14 // represent bandwidth (in megabits) the blue axis will be packet drop |
15 // (in percent) and the green axis will be latency (in milliseconds). | 15 // (in percent) and the green axis will be latency (in milliseconds). |
16 // | 16 // |
17 // This program can also be used for profiling. On linux it has | 17 // This program can also be used for profiling. On linux it has |
18 // built-in support for this. Simply set the environment variable | 18 // built-in support for this. Simply set the environment variable |
19 // PROFILE_FILE before running it, like so: | 19 // PROFILE_FILE before running it, like so: |
20 // $ export PROFILE_FILE=cast_benchmark.profile | 20 // $ export PROFILE_FILE=cast_benchmark.profile |
21 // Then after running the program, you can view the profile with: | 21 // Then after running the program, you can view the profile with: |
22 // $ pprof ./out/Release/cast_benchmarks $PROFILE_FILE --gv | 22 // $ pprof ./out/Release/cast_benchmarks $PROFILE_FILE --gv |
23 | 23 |
24 #include <math.h> | 24 #include <math.h> |
25 #include <stddef.h> | 25 #include <stddef.h> |
26 #include <stdint.h> | 26 #include <stdint.h> |
27 | |
28 #include <map> | 27 #include <map> |
| 28 #include <utility> |
29 #include <vector> | 29 #include <vector> |
30 | 30 |
31 #include "base/at_exit.h" | 31 #include "base/at_exit.h" |
32 #include "base/bind.h" | 32 #include "base/bind.h" |
33 #include "base/bind_helpers.h" | 33 #include "base/bind_helpers.h" |
34 #include "base/command_line.h" | 34 #include "base/command_line.h" |
35 #include "base/debug/profiler.h" | 35 #include "base/debug/profiler.h" |
36 #include "base/memory/weak_ptr.h" | 36 #include "base/memory/weak_ptr.h" |
37 #include "base/run_loop.h" | 37 #include "base/run_loop.h" |
38 #include "base/stl_util.h" | 38 #include "base/stl_util.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 RunOneBenchmark() | 204 RunOneBenchmark() |
205 : start_time_(), | 205 : start_time_(), |
206 task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)), | 206 task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)), |
207 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), | 207 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), |
208 task_runner_sender_( | 208 task_runner_sender_( |
209 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 209 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
210 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), | 210 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), |
211 task_runner_receiver_( | 211 task_runner_receiver_( |
212 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 212 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
213 cast_environment_sender_(new CastEnvironment( | 213 cast_environment_sender_(new CastEnvironment( |
214 scoped_ptr<base::TickClock>(testing_clock_sender_).Pass(), | 214 scoped_ptr<base::TickClock>(testing_clock_sender_), |
215 task_runner_sender_, | 215 task_runner_sender_, |
216 task_runner_sender_, | 216 task_runner_sender_, |
217 task_runner_sender_)), | 217 task_runner_sender_)), |
218 cast_environment_receiver_(new CastEnvironment( | 218 cast_environment_receiver_(new CastEnvironment( |
219 scoped_ptr<base::TickClock>(testing_clock_receiver_).Pass(), | 219 scoped_ptr<base::TickClock>(testing_clock_receiver_), |
220 task_runner_receiver_, | 220 task_runner_receiver_, |
221 task_runner_receiver_, | 221 task_runner_receiver_, |
222 task_runner_receiver_)), | 222 task_runner_receiver_)), |
223 receiver_to_sender_(cast_environment_receiver_), | 223 receiver_to_sender_(cast_environment_receiver_), |
224 sender_to_receiver_(cast_environment_sender_), | 224 sender_to_receiver_(cast_environment_sender_), |
225 video_bytes_encoded_(0), | 225 video_bytes_encoded_(0), |
226 audio_bytes_encoded_(0), | 226 audio_bytes_encoded_(0), |
227 frames_sent_(0) { | 227 frames_sent_(0) { |
228 testing_clock_.Advance( | 228 testing_clock_.Advance( |
229 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 229 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 cast_sender_->InitializeAudio( | 312 cast_sender_->InitializeAudio( |
313 audio_sender_config_, | 313 audio_sender_config_, |
314 base::Bind(&ExpectAudioSuccess)); | 314 base::Bind(&ExpectAudioSuccess)); |
315 cast_sender_->InitializeVideo( | 315 cast_sender_->InitializeVideo( |
316 video_sender_config_, | 316 video_sender_config_, |
317 base::Bind(&ExpectVideoSuccess), | 317 base::Bind(&ExpectVideoSuccess), |
318 CreateDefaultVideoEncodeAcceleratorCallback(), | 318 CreateDefaultVideoEncodeAcceleratorCallback(), |
319 CreateDefaultVideoEncodeMemoryCallback()); | 319 CreateDefaultVideoEncodeMemoryCallback()); |
320 | 320 |
321 receiver_to_sender_.Initialize( | 321 receiver_to_sender_.Initialize(CreateSimplePipe(p), |
322 CreateSimplePipe(p).Pass(), | 322 transport_sender_.PacketReceiverForTesting(), |
323 transport_sender_.PacketReceiverForTesting(), | 323 task_runner_, &testing_clock_); |
324 task_runner_, &testing_clock_); | |
325 sender_to_receiver_.Initialize( | 324 sender_to_receiver_.Initialize( |
326 CreateSimplePipe(p).Pass(), | 325 CreateSimplePipe(p), transport_receiver_->PacketReceiverForTesting(), |
327 transport_receiver_->PacketReceiverForTesting(), | |
328 task_runner_, &testing_clock_); | 326 task_runner_, &testing_clock_); |
329 | 327 |
330 task_runner_->RunTasks(); | 328 task_runner_->RunTasks(); |
331 } | 329 } |
332 | 330 |
333 void ReceivePacket(scoped_ptr<Packet> packet) { | 331 void ReceivePacket(scoped_ptr<Packet> packet) { |
334 cast_receiver_->ReceivePacket(packet.Pass()); | 332 cast_receiver_->ReceivePacket(std::move(packet)); |
335 } | 333 } |
336 | 334 |
337 virtual ~RunOneBenchmark() { | 335 virtual ~RunOneBenchmark() { |
338 cast_sender_.reset(); | 336 cast_sender_.reset(); |
339 cast_receiver_.reset(); | 337 cast_receiver_.reset(); |
340 task_runner_->RunTasks(); | 338 task_runner_->RunTasks(); |
341 } | 339 } |
342 | 340 |
343 base::TimeDelta VideoTimestamp(int frame_number) { | 341 base::TimeDelta VideoTimestamp(int frame_number) { |
344 return (frame_number * base::TimeDelta::FromSeconds(1)) / | 342 return (frame_number * base::TimeDelta::FromSeconds(1)) / |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 377 |
380 void StartBasicPlayer() { | 378 void StartBasicPlayer() { |
381 cast_receiver_->RequestDecodedVideoFrame(base::Bind( | 379 cast_receiver_->RequestDecodedVideoFrame(base::Bind( |
382 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); | 380 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); |
383 cast_receiver_->RequestDecodedAudioFrame(base::Bind( | 381 cast_receiver_->RequestDecodedAudioFrame(base::Bind( |
384 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); | 382 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); |
385 } | 383 } |
386 | 384 |
387 scoped_ptr<test::PacketPipe> CreateSimplePipe(const MeasuringPoint& p) { | 385 scoped_ptr<test::PacketPipe> CreateSimplePipe(const MeasuringPoint& p) { |
388 scoped_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); | 386 scoped_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); |
389 pipe->AppendToPipe( | 387 pipe->AppendToPipe(test::NewRandomDrop(p.percent_packet_drop / 100.0)); |
390 test::NewRandomDrop(p.percent_packet_drop / 100.0).Pass()); | |
391 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); | 388 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); |
392 return pipe.Pass(); | 389 return pipe; |
393 } | 390 } |
394 | 391 |
395 void Run(const MeasuringPoint& p) { | 392 void Run(const MeasuringPoint& p) { |
396 available_bitrate_ = p.bitrate; | 393 available_bitrate_ = p.bitrate; |
397 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); | 394 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); |
398 Create(p); | 395 Create(p); |
399 StartBasicPlayer(); | 396 StartBasicPlayer(); |
400 | 397 |
401 for (int frame = 0; frame < 1000; frame++) { | 398 for (int frame = 0; frame < 1000; frame++) { |
402 SendFakeVideoFrame(); | 399 SendFakeVideoFrame(); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 media::cast::CastBenchmark benchmark; | 717 media::cast::CastBenchmark benchmark; |
721 if (getenv("PROFILE_FILE")) { | 718 if (getenv("PROFILE_FILE")) { |
722 std::string profile_file(getenv("PROFILE_FILE")); | 719 std::string profile_file(getenv("PROFILE_FILE")); |
723 base::debug::StartProfiling(profile_file); | 720 base::debug::StartProfiling(profile_file); |
724 benchmark.Run(); | 721 benchmark.Run(); |
725 base::debug::StopProfiling(); | 722 base::debug::StopProfiling(); |
726 } else { | 723 } else { |
727 benchmark.Run(); | 724 benchmark.Run(); |
728 } | 725 } |
729 } | 726 } |
OLD | NEW |