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 |
27 #include <map> | 28 #include <map> |
28 #include <utility> | 29 #include <utility> |
29 #include <vector> | 30 #include <vector> |
30 | 31 |
31 #include "base/at_exit.h" | 32 #include "base/at_exit.h" |
32 #include "base/bind.h" | 33 #include "base/bind.h" |
33 #include "base/bind_helpers.h" | 34 #include "base/bind_helpers.h" |
34 #include "base/command_line.h" | 35 #include "base/command_line.h" |
35 #include "base/debug/profiler.h" | 36 #include "base/debug/profiler.h" |
| 37 #include "base/memory/ptr_util.h" |
36 #include "base/memory/weak_ptr.h" | 38 #include "base/memory/weak_ptr.h" |
37 #include "base/run_loop.h" | 39 #include "base/run_loop.h" |
38 #include "base/stl_util.h" | 40 #include "base/stl_util.h" |
39 #include "base/strings/string_number_conversions.h" | 41 #include "base/strings/string_number_conversions.h" |
40 #include "base/strings/stringprintf.h" | 42 #include "base/strings/stringprintf.h" |
41 #include "base/test/simple_test_tick_clock.h" | 43 #include "base/test/simple_test_tick_clock.h" |
42 #include "base/threading/thread.h" | 44 #include "base/threading/thread.h" |
43 #include "base/time/tick_clock.h" | 45 #include "base/time/tick_clock.h" |
44 #include "media/base/audio_bus.h" | 46 #include "media/base/audio_bus.h" |
45 #include "media/base/fake_single_thread_task_runner.h" | 47 #include "media/base/fake_single_thread_task_runner.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 transport_->AddPli(pli_message); | 170 transport_->AddPli(pli_message); |
169 } | 171 } |
170 | 172 |
171 void SendRtcpFromRtpReceiver() final { | 173 void SendRtcpFromRtpReceiver() final { |
172 transport_->SendRtcpFromRtpReceiver(); | 174 transport_->SendRtcpFromRtpReceiver(); |
173 } | 175 } |
174 | 176 |
175 void SetOptions(const base::DictionaryValue& options) final {} | 177 void SetOptions(const base::DictionaryValue& options) final {} |
176 | 178 |
177 private: | 179 private: |
178 scoped_ptr<CastTransport> transport_; | 180 std::unique_ptr<CastTransport> transport_; |
179 uint32_t audio_ssrc_, video_ssrc_; | 181 uint32_t audio_ssrc_, video_ssrc_; |
180 uint64_t* encoded_video_bytes_; | 182 uint64_t* encoded_video_bytes_; |
181 uint64_t* encoded_audio_bytes_; | 183 uint64_t* encoded_audio_bytes_; |
182 }; | 184 }; |
183 | 185 |
184 struct MeasuringPoint { | 186 struct MeasuringPoint { |
185 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) | 187 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) |
186 : bitrate(bitrate_), | 188 : bitrate(bitrate_), |
187 latency(latency_), | 189 latency(latency_), |
188 percent_packet_drop(percent_packet_drop_) {} | 190 percent_packet_drop(percent_packet_drop_) {} |
(...skipping 21 matching lines...) Expand all Loading... |
210 RunOneBenchmark() | 212 RunOneBenchmark() |
211 : start_time_(), | 213 : start_time_(), |
212 task_runner_(new FakeSingleThreadTaskRunner(&testing_clock_)), | 214 task_runner_(new FakeSingleThreadTaskRunner(&testing_clock_)), |
213 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), | 215 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), |
214 task_runner_sender_( | 216 task_runner_sender_( |
215 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 217 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
216 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), | 218 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), |
217 task_runner_receiver_( | 219 task_runner_receiver_( |
218 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 220 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
219 cast_environment_sender_(new CastEnvironment( | 221 cast_environment_sender_(new CastEnvironment( |
220 scoped_ptr<base::TickClock>(testing_clock_sender_), | 222 std::unique_ptr<base::TickClock>(testing_clock_sender_), |
221 task_runner_sender_, | 223 task_runner_sender_, |
222 task_runner_sender_, | 224 task_runner_sender_, |
223 task_runner_sender_)), | 225 task_runner_sender_)), |
224 cast_environment_receiver_(new CastEnvironment( | 226 cast_environment_receiver_(new CastEnvironment( |
225 scoped_ptr<base::TickClock>(testing_clock_receiver_), | 227 std::unique_ptr<base::TickClock>(testing_clock_receiver_), |
226 task_runner_receiver_, | 228 task_runner_receiver_, |
227 task_runner_receiver_, | 229 task_runner_receiver_, |
228 task_runner_receiver_)), | 230 task_runner_receiver_)), |
229 video_bytes_encoded_(0), | 231 video_bytes_encoded_(0), |
230 audio_bytes_encoded_(0), | 232 audio_bytes_encoded_(0), |
231 frames_sent_(0) { | 233 frames_sent_(0) { |
232 testing_clock_.Advance( | 234 testing_clock_.Advance( |
233 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 235 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
234 } | 236 } |
235 | 237 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 task_runner_sender_->SetSkew(1.0 / skew); | 270 task_runner_sender_->SetSkew(1.0 / skew); |
269 } | 271 } |
270 | 272 |
271 void SetReceiverClockSkew(double skew, base::TimeDelta offset) { | 273 void SetReceiverClockSkew(double skew, base::TimeDelta offset) { |
272 testing_clock_receiver_->SetSkew(skew, offset); | 274 testing_clock_receiver_->SetSkew(skew, offset); |
273 task_runner_receiver_->SetSkew(1.0 / skew); | 275 task_runner_receiver_->SetSkew(1.0 / skew); |
274 } | 276 } |
275 | 277 |
276 void Create(const MeasuringPoint& p); | 278 void Create(const MeasuringPoint& p); |
277 | 279 |
278 void ReceivePacket(scoped_ptr<Packet> packet) { | 280 void ReceivePacket(std::unique_ptr<Packet> packet) { |
279 cast_receiver_->ReceivePacket(std::move(packet)); | 281 cast_receiver_->ReceivePacket(std::move(packet)); |
280 } | 282 } |
281 | 283 |
282 virtual ~RunOneBenchmark() { | 284 virtual ~RunOneBenchmark() { |
283 cast_sender_.reset(); | 285 cast_sender_.reset(); |
284 cast_receiver_.reset(); | 286 cast_receiver_.reset(); |
285 task_runner_->RunTasks(); | 287 task_runner_->RunTasks(); |
286 } | 288 } |
287 | 289 |
288 base::TimeDelta VideoTimestamp(int frame_number) { | 290 base::TimeDelta VideoTimestamp(int frame_number) { |
(...skipping 17 matching lines...) Expand all Loading... |
306 void BasicPlayerGotVideoFrame( | 308 void BasicPlayerGotVideoFrame( |
307 const scoped_refptr<media::VideoFrame>& video_frame, | 309 const scoped_refptr<media::VideoFrame>& video_frame, |
308 const base::TimeTicks& render_time, | 310 const base::TimeTicks& render_time, |
309 bool continuous) { | 311 bool continuous) { |
310 video_ticks_.push_back( | 312 video_ticks_.push_back( |
311 std::make_pair(testing_clock_receiver_->NowTicks(), render_time)); | 313 std::make_pair(testing_clock_receiver_->NowTicks(), render_time)); |
312 cast_receiver_->RequestDecodedVideoFrame(base::Bind( | 314 cast_receiver_->RequestDecodedVideoFrame(base::Bind( |
313 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); | 315 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); |
314 } | 316 } |
315 | 317 |
316 void BasicPlayerGotAudioFrame(scoped_ptr<AudioBus> audio_bus, | 318 void BasicPlayerGotAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
317 const base::TimeTicks& playout_time, | 319 const base::TimeTicks& playout_time, |
318 bool is_continuous) { | 320 bool is_continuous) { |
319 audio_ticks_.push_back( | 321 audio_ticks_.push_back( |
320 std::make_pair(testing_clock_receiver_->NowTicks(), playout_time)); | 322 std::make_pair(testing_clock_receiver_->NowTicks(), playout_time)); |
321 cast_receiver_->RequestDecodedAudioFrame(base::Bind( | 323 cast_receiver_->RequestDecodedAudioFrame(base::Bind( |
322 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); | 324 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); |
323 } | 325 } |
324 | 326 |
325 void StartBasicPlayer() { | 327 void StartBasicPlayer() { |
326 cast_receiver_->RequestDecodedVideoFrame(base::Bind( | 328 cast_receiver_->RequestDecodedVideoFrame(base::Bind( |
327 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); | 329 &RunOneBenchmark::BasicPlayerGotVideoFrame, base::Unretained(this))); |
328 cast_receiver_->RequestDecodedAudioFrame(base::Bind( | 330 cast_receiver_->RequestDecodedAudioFrame(base::Bind( |
329 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); | 331 &RunOneBenchmark::BasicPlayerGotAudioFrame, base::Unretained(this))); |
330 } | 332 } |
331 | 333 |
332 scoped_ptr<test::PacketPipe> CreateSimplePipe(const MeasuringPoint& p) { | 334 std::unique_ptr<test::PacketPipe> CreateSimplePipe(const MeasuringPoint& p) { |
333 scoped_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); | 335 std::unique_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); |
334 pipe->AppendToPipe(test::NewRandomDrop(p.percent_packet_drop / 100.0)); | 336 pipe->AppendToPipe(test::NewRandomDrop(p.percent_packet_drop / 100.0)); |
335 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); | 337 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); |
336 return pipe; | 338 return pipe; |
337 } | 339 } |
338 | 340 |
339 void Run(const MeasuringPoint& p) { | 341 void Run(const MeasuringPoint& p) { |
340 available_bitrate_ = p.bitrate; | 342 available_bitrate_ = p.bitrate; |
341 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); | 343 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); |
342 Create(p); | 344 Create(p); |
343 StartBasicPlayer(); | 345 StartBasicPlayer(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // These run on the receiver timeline. | 429 // These run on the receiver timeline. |
428 test::SkewedTickClock* testing_clock_receiver_; | 430 test::SkewedTickClock* testing_clock_receiver_; |
429 scoped_refptr<test::SkewedSingleThreadTaskRunner> task_runner_receiver_; | 431 scoped_refptr<test::SkewedSingleThreadTaskRunner> task_runner_receiver_; |
430 | 432 |
431 scoped_refptr<CastEnvironment> cast_environment_sender_; | 433 scoped_refptr<CastEnvironment> cast_environment_sender_; |
432 scoped_refptr<CastEnvironment> cast_environment_receiver_; | 434 scoped_refptr<CastEnvironment> cast_environment_receiver_; |
433 | 435 |
434 LoopBackTransport* receiver_to_sender_; // Owned by CastTransportImpl. | 436 LoopBackTransport* receiver_to_sender_; // Owned by CastTransportImpl. |
435 LoopBackTransport* sender_to_receiver_; // Owned by CastTransportImpl. | 437 LoopBackTransport* sender_to_receiver_; // Owned by CastTransportImpl. |
436 CastTransportWrapper transport_sender_; | 438 CastTransportWrapper transport_sender_; |
437 scoped_ptr<CastTransport> transport_receiver_; | 439 std::unique_ptr<CastTransport> transport_receiver_; |
438 uint64_t video_bytes_encoded_; | 440 uint64_t video_bytes_encoded_; |
439 uint64_t audio_bytes_encoded_; | 441 uint64_t audio_bytes_encoded_; |
440 | 442 |
441 scoped_ptr<CastReceiver> cast_receiver_; | 443 std::unique_ptr<CastReceiver> cast_receiver_; |
442 scoped_ptr<CastSender> cast_sender_; | 444 std::unique_ptr<CastSender> cast_sender_; |
443 | 445 |
444 int frames_sent_; | 446 int frames_sent_; |
445 base::TimeDelta frame_duration_; | 447 base::TimeDelta frame_duration_; |
446 double available_bitrate_; | 448 double available_bitrate_; |
447 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > audio_ticks_; | 449 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > audio_ticks_; |
448 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > video_ticks_; | 450 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > video_ticks_; |
449 }; | 451 }; |
450 | 452 |
451 namespace { | 453 namespace { |
452 | 454 |
453 class TransportClient : public CastTransport::Client { | 455 class TransportClient : public CastTransport::Client { |
454 public: | 456 public: |
455 explicit TransportClient(RunOneBenchmark* run_one_benchmark) | 457 explicit TransportClient(RunOneBenchmark* run_one_benchmark) |
456 : run_one_benchmark_(run_one_benchmark) {} | 458 : run_one_benchmark_(run_one_benchmark) {} |
457 | 459 |
458 void OnStatusChanged(CastTransportStatus status) final { | 460 void OnStatusChanged(CastTransportStatus status) final { |
459 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || | 461 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || |
460 status == TRANSPORT_VIDEO_INITIALIZED); | 462 status == TRANSPORT_VIDEO_INITIALIZED); |
461 EXPECT_TRUE(result); | 463 EXPECT_TRUE(result); |
462 }; | 464 }; |
463 void OnLoggingEventsReceived( | 465 void OnLoggingEventsReceived( |
464 scoped_ptr<std::vector<FrameEvent>> frame_events, | 466 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
465 scoped_ptr<std::vector<PacketEvent>> packet_events) final{}; | 467 std::unique_ptr<std::vector<PacketEvent>> packet_events) final{}; |
466 void ProcessRtpPacket(scoped_ptr<Packet> packet) final { | 468 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final { |
467 if (run_one_benchmark_) | 469 if (run_one_benchmark_) |
468 run_one_benchmark_->ReceivePacket(std::move(packet)); | 470 run_one_benchmark_->ReceivePacket(std::move(packet)); |
469 }; | 471 }; |
470 | 472 |
471 private: | 473 private: |
472 RunOneBenchmark* const run_one_benchmark_; | 474 RunOneBenchmark* const run_one_benchmark_; |
473 | 475 |
474 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 476 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
475 }; | 477 }; |
476 | 478 |
477 } // namepspace | 479 } // namepspace |
478 | 480 |
479 void RunOneBenchmark::Create(const MeasuringPoint& p) { | 481 void RunOneBenchmark::Create(const MeasuringPoint& p) { |
480 sender_to_receiver_ = new LoopBackTransport(cast_environment_sender_); | 482 sender_to_receiver_ = new LoopBackTransport(cast_environment_sender_); |
481 transport_sender_.Init( | 483 transport_sender_.Init( |
482 new CastTransportImpl( | 484 new CastTransportImpl( |
483 testing_clock_sender_, base::TimeDelta::FromSeconds(1), | 485 testing_clock_sender_, base::TimeDelta::FromSeconds(1), |
484 make_scoped_ptr(new TransportClient(nullptr)), | 486 base::WrapUnique(new TransportClient(nullptr)), |
485 make_scoped_ptr(sender_to_receiver_), task_runner_sender_), | 487 base::WrapUnique(sender_to_receiver_), task_runner_sender_), |
486 &video_bytes_encoded_, &audio_bytes_encoded_); | 488 &video_bytes_encoded_, &audio_bytes_encoded_); |
487 | 489 |
488 receiver_to_sender_ = new LoopBackTransport(cast_environment_receiver_); | 490 receiver_to_sender_ = new LoopBackTransport(cast_environment_receiver_); |
489 transport_receiver_.reset(new CastTransportImpl( | 491 transport_receiver_.reset(new CastTransportImpl( |
490 testing_clock_receiver_, base::TimeDelta::FromSeconds(1), | 492 testing_clock_receiver_, base::TimeDelta::FromSeconds(1), |
491 make_scoped_ptr(new TransportClient(this)), | 493 base::WrapUnique(new TransportClient(this)), |
492 make_scoped_ptr(receiver_to_sender_), task_runner_receiver_)); | 494 base::WrapUnique(receiver_to_sender_), task_runner_receiver_)); |
493 | 495 |
494 cast_receiver_ = | 496 cast_receiver_ = |
495 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, | 497 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, |
496 video_receiver_config_, transport_receiver_.get()); | 498 video_receiver_config_, transport_receiver_.get()); |
497 | 499 |
498 cast_sender_ = | 500 cast_sender_ = |
499 CastSender::Create(cast_environment_sender_, &transport_sender_); | 501 CastSender::Create(cast_environment_sender_, &transport_sender_); |
500 | 502 |
501 cast_sender_->InitializeAudio(audio_sender_config_, | 503 cast_sender_->InitializeAudio(audio_sender_config_, |
502 base::Bind(&ExpectAudioSuccess)); | 504 base::Bind(&ExpectAudioSuccess)); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 media::cast::CastBenchmark benchmark; | 733 media::cast::CastBenchmark benchmark; |
732 if (getenv("PROFILE_FILE")) { | 734 if (getenv("PROFILE_FILE")) { |
733 std::string profile_file(getenv("PROFILE_FILE")); | 735 std::string profile_file(getenv("PROFILE_FILE")); |
734 base::debug::StartProfiling(profile_file); | 736 base::debug::StartProfiling(profile_file); |
735 benchmark.Run(); | 737 benchmark.Run(); |
736 base::debug::StopProfiling(); | 738 base::debug::StopProfiling(); |
737 } else { | 739 } else { |
738 benchmark.Run(); | 740 benchmark.Run(); |
739 } | 741 } |
740 } | 742 } |
OLD | NEW |