| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 public: | 90 public: |
| 91 // Takes ownership of |transport|. | 91 // Takes ownership of |transport|. |
| 92 void Init(CastTransport* transport, | 92 void Init(CastTransport* transport, |
| 93 uint64_t* encoded_video_bytes, | 93 uint64_t* encoded_video_bytes, |
| 94 uint64_t* encoded_audio_bytes) { | 94 uint64_t* encoded_audio_bytes) { |
| 95 transport_.reset(transport); | 95 transport_.reset(transport); |
| 96 encoded_video_bytes_ = encoded_video_bytes; | 96 encoded_video_bytes_ = encoded_video_bytes; |
| 97 encoded_audio_bytes_ = encoded_audio_bytes; | 97 encoded_audio_bytes_ = encoded_audio_bytes; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void InitializeAudio(const CastTransportRtpConfig& config, | 100 void InitializeStream(const CastTransportRtpConfig& config, |
| 101 std::unique_ptr<RtcpObserver> rtcp_observer) final { | 101 std::unique_ptr<RtcpObserver> rtcp_observer) final { |
| 102 audio_ssrc_ = config.ssrc; | 102 if (config.rtp_payload_type <= RtpPayloadType::AUDIO_LAST) |
| 103 transport_->InitializeAudio(config, std::move(rtcp_observer)); | 103 audio_ssrc_ = config.ssrc; |
| 104 } | 104 else |
| 105 | 105 video_ssrc_ = config.ssrc; |
| 106 void InitializeVideo(const CastTransportRtpConfig& config, | 106 transport_->InitializeStream(config, std::move(rtcp_observer)); |
| 107 std::unique_ptr<RtcpObserver> rtcp_observer) final { | |
| 108 video_ssrc_ = config.ssrc; | |
| 109 transport_->InitializeVideo(config, std::move(rtcp_observer)); | |
| 110 } | 107 } |
| 111 | 108 |
| 112 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final { | 109 void InsertFrame(uint32_t ssrc, const EncodedFrame& frame) final { |
| 113 if (ssrc == audio_ssrc_) { | 110 if (ssrc == audio_ssrc_) { |
| 114 *encoded_audio_bytes_ += frame.data.size(); | 111 *encoded_audio_bytes_ += frame.data.size(); |
| 115 } else if (ssrc == video_ssrc_) { | 112 } else if (ssrc == video_ssrc_) { |
| 116 *encoded_video_bytes_ += frame.data.size(); | 113 *encoded_video_bytes_ += frame.data.size(); |
| 117 } | 114 } |
| 118 transport_->InsertFrame(ssrc, frame); | 115 transport_->InsertFrame(ssrc, frame); |
| 119 } | 116 } |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 }; | 446 }; |
| 450 | 447 |
| 451 namespace { | 448 namespace { |
| 452 | 449 |
| 453 class TransportClient : public CastTransport::Client { | 450 class TransportClient : public CastTransport::Client { |
| 454 public: | 451 public: |
| 455 explicit TransportClient(RunOneBenchmark* run_one_benchmark) | 452 explicit TransportClient(RunOneBenchmark* run_one_benchmark) |
| 456 : run_one_benchmark_(run_one_benchmark) {} | 453 : run_one_benchmark_(run_one_benchmark) {} |
| 457 | 454 |
| 458 void OnStatusChanged(CastTransportStatus status) final { | 455 void OnStatusChanged(CastTransportStatus status) final { |
| 459 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || | 456 EXPECT_EQ(TRANSPORT_STREAM_INITIALIZED, status); |
| 460 status == TRANSPORT_VIDEO_INITIALIZED); | |
| 461 EXPECT_TRUE(result); | |
| 462 }; | 457 }; |
| 463 void OnLoggingEventsReceived( | 458 void OnLoggingEventsReceived( |
| 464 std::unique_ptr<std::vector<FrameEvent>> frame_events, | 459 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 465 std::unique_ptr<std::vector<PacketEvent>> packet_events) final{}; | 460 std::unique_ptr<std::vector<PacketEvent>> packet_events) final{}; |
| 466 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final { | 461 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final { |
| 467 if (run_one_benchmark_) | 462 if (run_one_benchmark_) |
| 468 run_one_benchmark_->ReceivePacket(std::move(packet)); | 463 run_one_benchmark_->ReceivePacket(std::move(packet)); |
| 469 }; | 464 }; |
| 470 | 465 |
| 471 private: | 466 private: |
| 472 RunOneBenchmark* const run_one_benchmark_; | 467 RunOneBenchmark* const run_one_benchmark_; |
| 473 | 468 |
| 474 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 469 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
| 475 }; | 470 }; |
| 476 | 471 |
| 477 } // namepspace | 472 } // namepspace |
| 478 | 473 |
| 479 void RunOneBenchmark::Create(const MeasuringPoint& p) { | 474 void RunOneBenchmark::Create(const MeasuringPoint& p) { |
| 480 sender_to_receiver_ = new LoopBackTransport(cast_environment_sender_); | 475 sender_to_receiver_ = new LoopBackTransport(cast_environment_sender_); |
| 481 transport_sender_.Init( | 476 transport_sender_.Init( |
| 482 new CastTransportImpl( | 477 new CastTransportImpl( |
| 483 testing_clock_sender_, base::TimeDelta::FromSeconds(1), | 478 testing_clock_sender_, base::TimeDelta::FromSeconds(1), |
| 484 base::WrapUnique(new TransportClient(nullptr)), | 479 base::MakeUnique<TransportClient>(nullptr), |
| 485 base::WrapUnique(sender_to_receiver_), task_runner_sender_), | 480 base::WrapUnique(sender_to_receiver_), task_runner_sender_), |
| 486 &video_bytes_encoded_, &audio_bytes_encoded_); | 481 &video_bytes_encoded_, &audio_bytes_encoded_); |
| 487 | 482 |
| 488 receiver_to_sender_ = new LoopBackTransport(cast_environment_receiver_); | 483 receiver_to_sender_ = new LoopBackTransport(cast_environment_receiver_); |
| 489 transport_receiver_.reset(new CastTransportImpl( | 484 transport_receiver_.reset(new CastTransportImpl( |
| 490 testing_clock_receiver_, base::TimeDelta::FromSeconds(1), | 485 testing_clock_receiver_, base::TimeDelta::FromSeconds(1), |
| 491 base::WrapUnique(new TransportClient(this)), | 486 base::MakeUnique<TransportClient>(this), |
| 492 base::WrapUnique(receiver_to_sender_), task_runner_receiver_)); | 487 base::WrapUnique(receiver_to_sender_), task_runner_receiver_)); |
| 493 | 488 |
| 494 cast_receiver_ = | 489 cast_receiver_ = |
| 495 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, | 490 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, |
| 496 video_receiver_config_, transport_receiver_.get()); | 491 video_receiver_config_, transport_receiver_.get()); |
| 497 | 492 |
| 498 cast_sender_ = | 493 cast_sender_ = |
| 499 CastSender::Create(cast_environment_sender_, &transport_sender_); | 494 CastSender::Create(cast_environment_sender_, &transport_sender_); |
| 500 | 495 |
| 501 cast_sender_->InitializeAudio(audio_sender_config_, | 496 cast_sender_->InitializeAudio(audio_sender_config_, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 media::cast::CastBenchmark benchmark; | 723 media::cast::CastBenchmark benchmark; |
| 729 if (getenv("PROFILE_FILE")) { | 724 if (getenv("PROFILE_FILE")) { |
| 730 std::string profile_file(getenv("PROFILE_FILE")); | 725 std::string profile_file(getenv("PROFILE_FILE")); |
| 731 base::debug::StartProfiling(profile_file); | 726 base::debug::StartProfiling(profile_file); |
| 732 benchmark.Run(); | 727 benchmark.Run(); |
| 733 base::debug::StopProfiling(); | 728 base::debug::StopProfiling(); |
| 734 } else { | 729 } else { |
| 735 benchmark.Run(); | 730 benchmark.Run(); |
| 736 } | 731 } |
| 737 } | 732 } |
| OLD | NEW |