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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 void AudioInitializationStatus(CastInitializationStatus status) { | 84 void AudioInitializationStatus(CastInitializationStatus status) { |
85 EXPECT_EQ(STATUS_AUDIO_INITIALIZED, status); | 85 EXPECT_EQ(STATUS_AUDIO_INITIALIZED, status); |
86 } | 86 } |
87 | 87 |
88 void VideoInitializationStatus(CastInitializationStatus status) { | 88 void VideoInitializationStatus(CastInitializationStatus status) { |
89 EXPECT_EQ(STATUS_VIDEO_INITIALIZED, 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 } | 94 } |
94 | 95 |
95 } // namespace | 96 } // namespace |
96 | 97 |
97 // Wraps a CastTransportSender and records some statistics about | 98 // Wraps a CastTransportSender and records some statistics about |
98 // the data that goes through it. | 99 // the data that goes through it. |
99 class CastTransportSenderWrapper : public CastTransportSender { | 100 class CastTransportSenderWrapper : public CastTransportSender { |
100 public: | 101 public: |
101 // Takes ownership of |transport|. | 102 // Takes ownership of |transport|. |
102 void Init(CastTransportSender* transport, | 103 void Init(CastTransportSender* transport, |
103 uint64* encoded_video_bytes, | 104 uint64* encoded_video_bytes, |
104 uint64* encoded_audio_bytes) { | 105 uint64* encoded_audio_bytes) { |
105 transport_.reset(transport); | 106 transport_.reset(transport); |
106 encoded_video_bytes_ = encoded_video_bytes; | 107 encoded_video_bytes_ = encoded_video_bytes; |
107 encoded_audio_bytes_ = encoded_audio_bytes; | 108 encoded_audio_bytes_ = encoded_audio_bytes; |
108 } | 109 } |
109 | 110 |
110 virtual void InitializeAudio( | 111 virtual void InitializeAudio( |
111 const CastTransportRtpConfig& config) OVERRIDE { | 112 const CastTransportRtpConfig& config, |
112 transport_->InitializeAudio(config); | 113 const RtcpCastMessageCallback& cast_message_cb, |
| 114 const RtcpRttCallback& rtt_cb) OVERRIDE { |
| 115 transport_->InitializeAudio(config, cast_message_cb, rtt_cb); |
113 } | 116 } |
114 | 117 |
115 virtual void InitializeVideo( | 118 virtual void InitializeVideo( |
116 const CastTransportRtpConfig& config) OVERRIDE { | 119 const CastTransportRtpConfig& config, |
117 transport_->InitializeVideo(config); | 120 const RtcpCastMessageCallback& cast_message_cb, |
118 } | 121 const RtcpRttCallback& rtt_cb) OVERRIDE { |
119 | 122 transport_->InitializeVideo(config, cast_message_cb, rtt_cb); |
120 virtual void SetPacketReceiver( | |
121 const PacketReceiverCallback& packet_receiver) OVERRIDE { | |
122 transport_->SetPacketReceiver(packet_receiver); | |
123 } | 123 } |
124 | 124 |
125 virtual void InsertCodedAudioFrame( | 125 virtual void InsertCodedAudioFrame( |
126 const EncodedFrame& audio_frame) OVERRIDE { | 126 const EncodedFrame& audio_frame) OVERRIDE { |
127 *encoded_audio_bytes_ += audio_frame.data.size(); | 127 *encoded_audio_bytes_ += audio_frame.data.size(); |
128 transport_->InsertCodedAudioFrame(audio_frame); | 128 transport_->InsertCodedAudioFrame(audio_frame); |
129 } | 129 } |
130 | 130 |
131 virtual void InsertCodedVideoFrame( | 131 virtual void InsertCodedVideoFrame( |
132 const EncodedFrame& video_frame) OVERRIDE { | 132 const EncodedFrame& video_frame) OVERRIDE { |
133 *encoded_video_bytes_ += video_frame.data.size(); | 133 *encoded_video_bytes_ += video_frame.data.size(); |
134 transport_->InsertCodedVideoFrame(video_frame); | 134 transport_->InsertCodedVideoFrame(video_frame); |
135 } | 135 } |
136 | 136 |
137 virtual void SendRtcpFromRtpSender(uint32 packet_type_flags, | 137 virtual void SendSenderReport( |
138 uint32 ntp_seconds, | 138 uint32 ssrc, |
139 uint32 ntp_fraction, | 139 base::TimeTicks current_time, |
140 uint32 rtp_timestamp, | 140 uint32 current_time_as_rtp_timestamp) OVERRIDE { |
141 const RtcpDlrrReportBlock& dlrr, | 141 transport_->SendSenderReport(ssrc, |
142 uint32 sending_ssrc, | 142 current_time, |
143 const std::string& c_name) OVERRIDE { | 143 current_time_as_rtp_timestamp); |
144 transport_->SendRtcpFromRtpSender(packet_type_flags, | |
145 ntp_seconds, | |
146 ntp_fraction, | |
147 rtp_timestamp, | |
148 dlrr, | |
149 sending_ssrc, | |
150 c_name); | |
151 } | 144 } |
152 | 145 |
153 // Retransmission request. | 146 // Retransmission request. |
154 virtual void ResendPackets( | 147 virtual void ResendPackets( |
155 bool is_audio, | 148 bool is_audio, |
156 const MissingFramesAndPacketsMap& missing_packets, | 149 const MissingFramesAndPacketsMap& missing_packets, |
157 bool cancel_rtx_if_not_in_list, | 150 bool cancel_rtx_if_not_in_list, |
158 base::TimeDelta dedupe_window) OVERRIDE { | 151 base::TimeDelta dedupe_window) OVERRIDE { |
159 transport_->ResendPackets( | 152 transport_->ResendPackets( |
160 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); | 153 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); |
161 } | 154 } |
162 | 155 |
| 156 virtual PacketReceiverCallback PacketReceiverForTesting() OVERRIDE { |
| 157 return transport_->PacketReceiverForTesting(); |
| 158 } |
| 159 |
163 private: | 160 private: |
164 scoped_ptr<CastTransportSender> transport_; | 161 scoped_ptr<CastTransportSender> transport_; |
165 uint64* encoded_video_bytes_; | 162 uint64* encoded_video_bytes_; |
166 uint64* encoded_audio_bytes_; | 163 uint64* encoded_audio_bytes_; |
167 }; | 164 }; |
168 | 165 |
169 struct MeasuringPoint { | 166 struct MeasuringPoint { |
170 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) | 167 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) |
171 : bitrate(bitrate_), | 168 : bitrate(bitrate_), |
172 latency(latency_), | 169 latency(latency_), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 testing_clock_receiver_->SetSkew(skew, offset); | 288 testing_clock_receiver_->SetSkew(skew, offset); |
292 task_runner_receiver_->SetSkew(1.0 / skew); | 289 task_runner_receiver_->SetSkew(1.0 / skew); |
293 } | 290 } |
294 | 291 |
295 void Create(const MeasuringPoint& p) { | 292 void Create(const MeasuringPoint& p) { |
296 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, | 293 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, |
297 audio_receiver_config_, | 294 audio_receiver_config_, |
298 video_receiver_config_, | 295 video_receiver_config_, |
299 &receiver_to_sender_); | 296 &receiver_to_sender_); |
300 net::IPEndPoint dummy_endpoint; | 297 net::IPEndPoint dummy_endpoint; |
301 transport_sender_.Init(new CastTransportSenderImpl( | 298 transport_sender_.Init( |
302 NULL, | 299 new CastTransportSenderImpl( |
303 testing_clock_sender_, | 300 NULL, |
304 dummy_endpoint, | 301 testing_clock_sender_, |
305 base::Bind(&UpdateCastTransportStatus), | 302 dummy_endpoint, |
306 base::Bind(&IgnoreRawEvents), | 303 base::Bind(&UpdateCastTransportStatus), |
307 base::TimeDelta::FromSeconds(1), | 304 base::Bind(&IgnoreRawEvents), |
308 task_runner_sender_, | 305 base::TimeDelta::FromSeconds(1), |
309 &sender_to_receiver_), | 306 task_runner_sender_, |
310 &video_bytes_encoded_, | 307 &sender_to_receiver_), |
311 &audio_bytes_encoded_); | 308 &video_bytes_encoded_, |
| 309 &audio_bytes_encoded_); |
312 | 310 |
313 cast_sender_ = | 311 cast_sender_ = |
314 CastSender::Create(cast_environment_sender_, &transport_sender_); | 312 CastSender::Create(cast_environment_sender_, &transport_sender_); |
315 | 313 |
316 // Initializing audio and video senders. | 314 // Initializing audio and video senders. |
317 cast_sender_->InitializeAudio(audio_sender_config_, | 315 cast_sender_->InitializeAudio(audio_sender_config_, |
318 base::Bind(&AudioInitializationStatus)); | 316 base::Bind(&AudioInitializationStatus)); |
319 cast_sender_->InitializeVideo(video_sender_config_, | 317 cast_sender_->InitializeVideo(video_sender_config_, |
320 base::Bind(&VideoInitializationStatus), | 318 base::Bind(&VideoInitializationStatus), |
321 CreateDefaultVideoEncodeAcceleratorCallback(), | 319 CreateDefaultVideoEncodeAcceleratorCallback(), |
322 CreateDefaultVideoEncodeMemoryCallback()); | 320 CreateDefaultVideoEncodeMemoryCallback()); |
323 | 321 |
324 receiver_to_sender_.Initialize( | 322 receiver_to_sender_.Initialize( |
325 CreateSimplePipe(p).Pass(), cast_sender_->packet_receiver(), | 323 CreateSimplePipe(p).Pass(), |
| 324 transport_sender_.PacketReceiverForTesting(), |
326 task_runner_, &testing_clock_); | 325 task_runner_, &testing_clock_); |
327 sender_to_receiver_.Initialize( | 326 sender_to_receiver_.Initialize( |
328 CreateSimplePipe(p).Pass(), cast_receiver_->packet_receiver(), | 327 CreateSimplePipe(p).Pass(), cast_receiver_->packet_receiver(), |
329 task_runner_, &testing_clock_); | 328 task_runner_, &testing_clock_); |
330 } | 329 } |
331 | 330 |
332 virtual ~RunOneBenchmark() { | 331 virtual ~RunOneBenchmark() { |
333 cast_sender_.reset(); | 332 cast_sender_.reset(); |
334 cast_receiver_.reset(); | 333 cast_receiver_.reset(); |
335 task_runner_->RunTasks(); | 334 task_runner_->RunTasks(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 media::cast::CastBenchmark benchmark; | 706 media::cast::CastBenchmark benchmark; |
708 if (getenv("PROFILE_FILE")) { | 707 if (getenv("PROFILE_FILE")) { |
709 std::string profile_file(getenv("PROFILE_FILE")); | 708 std::string profile_file(getenv("PROFILE_FILE")); |
710 base::debug::StartProfiling(profile_file); | 709 base::debug::StartProfiling(profile_file); |
711 benchmark.Run(); | 710 benchmark.Run(); |
712 base::debug::StopProfiling(); | 711 base::debug::StopProfiling(); |
713 } else { | 712 } else { |
714 benchmark.Run(); | 713 benchmark.Run(); |
715 } | 714 } |
716 } | 715 } |
OLD | NEW |