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 27 matching lines...) Expand all Loading... |
38 #include "base/test/simple_test_tick_clock.h" | 38 #include "base/test/simple_test_tick_clock.h" |
39 #include "base/threading/thread.h" | 39 #include "base/threading/thread.h" |
40 #include "base/time/tick_clock.h" | 40 #include "base/time/tick_clock.h" |
41 #include "media/base/audio_bus.h" | 41 #include "media/base/audio_bus.h" |
42 #include "media/base/video_frame.h" | 42 #include "media/base/video_frame.h" |
43 #include "media/cast/cast_config.h" | 43 #include "media/cast/cast_config.h" |
44 #include "media/cast/cast_environment.h" | 44 #include "media/cast/cast_environment.h" |
45 #include "media/cast/cast_receiver.h" | 45 #include "media/cast/cast_receiver.h" |
46 #include "media/cast/cast_sender.h" | 46 #include "media/cast/cast_sender.h" |
47 #include "media/cast/logging/simple_event_subscriber.h" | 47 #include "media/cast/logging/simple_event_subscriber.h" |
| 48 #include "media/cast/net/cast_transport_config.h" |
| 49 #include "media/cast/net/cast_transport_defines.h" |
| 50 #include "media/cast/net/cast_transport_sender.h" |
| 51 #include "media/cast/net/cast_transport_sender_impl.h" |
48 #include "media/cast/test/fake_single_thread_task_runner.h" | 52 #include "media/cast/test/fake_single_thread_task_runner.h" |
49 #include "media/cast/test/loopback_transport.h" | 53 #include "media/cast/test/loopback_transport.h" |
50 #include "media/cast/test/skewed_single_thread_task_runner.h" | 54 #include "media/cast/test/skewed_single_thread_task_runner.h" |
51 #include "media/cast/test/skewed_tick_clock.h" | 55 #include "media/cast/test/skewed_tick_clock.h" |
52 #include "media/cast/test/utility/audio_utility.h" | 56 #include "media/cast/test/utility/audio_utility.h" |
53 #include "media/cast/test/utility/default_config.h" | 57 #include "media/cast/test/utility/default_config.h" |
54 #include "media/cast/test/utility/test_util.h" | 58 #include "media/cast/test/utility/test_util.h" |
55 #include "media/cast/test/utility/udp_proxy.h" | 59 #include "media/cast/test/utility/udp_proxy.h" |
56 #include "media/cast/test/utility/video_utility.h" | 60 #include "media/cast/test/utility/video_utility.h" |
57 #include "media/cast/transport/cast_transport_config.h" | |
58 #include "media/cast/transport/cast_transport_defines.h" | |
59 #include "media/cast/transport/cast_transport_sender.h" | |
60 #include "media/cast/transport/cast_transport_sender_impl.h" | |
61 #include "testing/gtest/include/gtest/gtest.h" | 61 #include "testing/gtest/include/gtest/gtest.h" |
62 | 62 |
63 namespace media { | 63 namespace media { |
64 namespace cast { | 64 namespace cast { |
65 | 65 |
66 namespace { | 66 namespace { |
67 | 67 |
68 static const int64 kStartMillisecond = INT64_C(1245); | 68 static const int64 kStartMillisecond = INT64_C(1245); |
69 static const int kAudioChannels = 2; | 69 static const int kAudioChannels = 2; |
70 static const int kVideoHdWidth = 1280; | 70 static const int kVideoHdWidth = 1280; |
71 static const int kVideoHdHeight = 720; | 71 static const int kVideoHdHeight = 720; |
72 static const int kTargetPlayoutDelayMs = 300; | 72 static const int kTargetPlayoutDelayMs = 300; |
73 | 73 |
74 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; | 74 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; |
75 // a normal video is 30 fps hence the 33 ms between frames. | 75 // a normal video is 30 fps hence the 33 ms between frames. |
76 static const int kFrameTimerMs = 33; | 76 static const int kFrameTimerMs = 33; |
77 | 77 |
78 void UpdateCastTransportStatus(transport::CastTransportStatus status) { | 78 void UpdateCastTransportStatus(CastTransportStatus status) { |
79 bool result = (status == transport::TRANSPORT_AUDIO_INITIALIZED || | 79 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || |
80 status == transport::TRANSPORT_VIDEO_INITIALIZED); | 80 status == TRANSPORT_VIDEO_INITIALIZED); |
81 EXPECT_TRUE(result); | 81 EXPECT_TRUE(result); |
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 } | 93 } |
94 | 94 |
95 } // namespace | 95 } // namespace |
96 | 96 |
97 // Wraps a CastTransportSender and records some statistics about | 97 // Wraps a CastTransportSender and records some statistics about |
98 // the data that goes through it. | 98 // the data that goes through it. |
99 class CastTransportSenderWrapper : public transport::CastTransportSender { | 99 class CastTransportSenderWrapper : public CastTransportSender { |
100 public: | 100 public: |
101 // Takes ownership of |transport|. | 101 // Takes ownership of |transport|. |
102 void Init(CastTransportSender* transport, | 102 void Init(CastTransportSender* transport, |
103 uint64* encoded_video_bytes, | 103 uint64* encoded_video_bytes, |
104 uint64* encoded_audio_bytes) { | 104 uint64* encoded_audio_bytes) { |
105 transport_.reset(transport); | 105 transport_.reset(transport); |
106 encoded_video_bytes_ = encoded_video_bytes; | 106 encoded_video_bytes_ = encoded_video_bytes; |
107 encoded_audio_bytes_ = encoded_audio_bytes; | 107 encoded_audio_bytes_ = encoded_audio_bytes; |
108 } | 108 } |
109 | 109 |
110 virtual void InitializeAudio( | 110 virtual void InitializeAudio( |
111 const transport::CastTransportRtpConfig& config) OVERRIDE { | 111 const CastTransportRtpConfig& config) OVERRIDE { |
112 transport_->InitializeAudio(config); | 112 transport_->InitializeAudio(config); |
113 } | 113 } |
114 | 114 |
115 virtual void InitializeVideo( | 115 virtual void InitializeVideo( |
116 const transport::CastTransportRtpConfig& config) OVERRIDE { | 116 const CastTransportRtpConfig& config) OVERRIDE { |
117 transport_->InitializeVideo(config); | 117 transport_->InitializeVideo(config); |
118 } | 118 } |
119 | 119 |
120 virtual void SetPacketReceiver( | 120 virtual void SetPacketReceiver( |
121 const transport::PacketReceiverCallback& packet_receiver) OVERRIDE { | 121 const PacketReceiverCallback& packet_receiver) OVERRIDE { |
122 transport_->SetPacketReceiver(packet_receiver); | 122 transport_->SetPacketReceiver(packet_receiver); |
123 } | 123 } |
124 | 124 |
125 virtual void InsertCodedAudioFrame( | 125 virtual void InsertCodedAudioFrame( |
126 const transport::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 transport::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 SendRtcpFromRtpSender(uint32 packet_type_flags, |
138 uint32 ntp_seconds, | 138 uint32 ntp_seconds, |
139 uint32 ntp_fraction, | 139 uint32 ntp_fraction, |
140 uint32 rtp_timestamp, | 140 uint32 rtp_timestamp, |
141 const transport::RtcpDlrrReportBlock& dlrr, | 141 const RtcpDlrrReportBlock& dlrr, |
142 uint32 sending_ssrc, | 142 uint32 sending_ssrc, |
143 const std::string& c_name) OVERRIDE { | 143 const std::string& c_name) OVERRIDE { |
144 transport_->SendRtcpFromRtpSender(packet_type_flags, | 144 transport_->SendRtcpFromRtpSender(packet_type_flags, |
145 ntp_seconds, | 145 ntp_seconds, |
146 ntp_fraction, | 146 ntp_fraction, |
147 rtp_timestamp, | 147 rtp_timestamp, |
148 dlrr, | 148 dlrr, |
149 sending_ssrc, | 149 sending_ssrc, |
150 c_name); | 150 c_name); |
151 } | 151 } |
152 | 152 |
153 // Retransmission request. | 153 // Retransmission request. |
154 virtual void ResendPackets( | 154 virtual void ResendPackets( |
155 bool is_audio, | 155 bool is_audio, |
156 const MissingFramesAndPacketsMap& missing_packets, | 156 const MissingFramesAndPacketsMap& missing_packets, |
157 bool cancel_rtx_if_not_in_list, | 157 bool cancel_rtx_if_not_in_list, |
158 base::TimeDelta dedupe_window) OVERRIDE { | 158 base::TimeDelta dedupe_window) OVERRIDE { |
159 transport_->ResendPackets( | 159 transport_->ResendPackets( |
160 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); | 160 is_audio, missing_packets, cancel_rtx_if_not_in_list, dedupe_window); |
161 } | 161 } |
162 | 162 |
163 private: | 163 private: |
164 scoped_ptr<transport::CastTransportSender> transport_; | 164 scoped_ptr<CastTransportSender> transport_; |
165 uint64* encoded_video_bytes_; | 165 uint64* encoded_video_bytes_; |
166 uint64* encoded_audio_bytes_; | 166 uint64* encoded_audio_bytes_; |
167 }; | 167 }; |
168 | 168 |
169 struct MeasuringPoint { | 169 struct MeasuringPoint { |
170 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) | 170 MeasuringPoint(double bitrate_, double latency_, double percent_packet_drop_) |
171 : bitrate(bitrate_), | 171 : bitrate(bitrate_), |
172 latency(latency_), | 172 latency(latency_), |
173 percent_packet_drop(percent_packet_drop_) {} | 173 percent_packet_drop(percent_packet_drop_) {} |
174 bool operator<=(const MeasuringPoint& other) const { | 174 bool operator<=(const MeasuringPoint& other) const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 task_runner_receiver_)), | 213 task_runner_receiver_)), |
214 receiver_to_sender_(cast_environment_receiver_), | 214 receiver_to_sender_(cast_environment_receiver_), |
215 sender_to_receiver_(cast_environment_sender_), | 215 sender_to_receiver_(cast_environment_sender_), |
216 video_bytes_encoded_(0), | 216 video_bytes_encoded_(0), |
217 audio_bytes_encoded_(0), | 217 audio_bytes_encoded_(0), |
218 frames_sent_(0) { | 218 frames_sent_(0) { |
219 testing_clock_.Advance( | 219 testing_clock_.Advance( |
220 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 220 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
221 } | 221 } |
222 | 222 |
223 void Configure(transport::Codec video_codec, | 223 void Configure(Codec video_codec, |
224 transport::Codec audio_codec, | 224 Codec audio_codec, |
225 int audio_sampling_frequency, | 225 int audio_sampling_frequency, |
226 int max_number_of_video_buffers_used) { | 226 int max_number_of_video_buffers_used) { |
227 audio_sender_config_.ssrc = 1; | 227 audio_sender_config_.ssrc = 1; |
228 audio_sender_config_.incoming_feedback_ssrc = 2; | 228 audio_sender_config_.incoming_feedback_ssrc = 2; |
229 audio_sender_config_.target_playout_delay = | 229 audio_sender_config_.target_playout_delay = |
230 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs); | 230 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs); |
231 audio_sender_config_.rtp_payload_type = 96; | 231 audio_sender_config_.rtp_payload_type = 96; |
232 audio_sender_config_.use_external_encoder = false; | 232 audio_sender_config_.use_external_encoder = false; |
233 audio_sender_config_.frequency = audio_sampling_frequency; | 233 audio_sender_config_.frequency = audio_sampling_frequency; |
234 audio_sender_config_.channels = kAudioChannels; | 234 audio_sender_config_.channels = kAudioChannels; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 testing_clock_receiver_->SetSkew(skew, offset); | 291 testing_clock_receiver_->SetSkew(skew, offset); |
292 task_runner_receiver_->SetSkew(1.0 / skew); | 292 task_runner_receiver_->SetSkew(1.0 / skew); |
293 } | 293 } |
294 | 294 |
295 void Create(const MeasuringPoint& p) { | 295 void Create(const MeasuringPoint& p) { |
296 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, | 296 cast_receiver_ = CastReceiver::Create(cast_environment_receiver_, |
297 audio_receiver_config_, | 297 audio_receiver_config_, |
298 video_receiver_config_, | 298 video_receiver_config_, |
299 &receiver_to_sender_); | 299 &receiver_to_sender_); |
300 net::IPEndPoint dummy_endpoint; | 300 net::IPEndPoint dummy_endpoint; |
301 transport_sender_.Init(new transport::CastTransportSenderImpl( | 301 transport_sender_.Init(new CastTransportSenderImpl( |
302 NULL, | 302 NULL, |
303 testing_clock_sender_, | 303 testing_clock_sender_, |
304 dummy_endpoint, | 304 dummy_endpoint, |
305 base::Bind(&UpdateCastTransportStatus), | 305 base::Bind(&UpdateCastTransportStatus), |
306 base::Bind(&IgnoreRawEvents), | 306 base::Bind(&IgnoreRawEvents), |
307 base::TimeDelta::FromSeconds(1), | 307 base::TimeDelta::FromSeconds(1), |
308 task_runner_sender_, | 308 task_runner_sender_, |
309 &sender_to_receiver_), | 309 &sender_to_receiver_), |
310 &video_bytes_encoded_, | 310 &video_bytes_encoded_, |
311 &audio_bytes_encoded_); | 311 &audio_bytes_encoded_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 scoped_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); | 376 scoped_ptr<test::PacketPipe> pipe = test::NewBuffer(65536, p.bitrate); |
377 pipe->AppendToPipe( | 377 pipe->AppendToPipe( |
378 test::NewRandomDrop(p.percent_packet_drop / 100.0).Pass()); | 378 test::NewRandomDrop(p.percent_packet_drop / 100.0).Pass()); |
379 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); | 379 pipe->AppendToPipe(test::NewConstantDelay(p.latency / 1000.0)); |
380 return pipe.Pass(); | 380 return pipe.Pass(); |
381 } | 381 } |
382 | 382 |
383 void Run(const MeasuringPoint& p) { | 383 void Run(const MeasuringPoint& p) { |
384 available_bitrate_ = p.bitrate; | 384 available_bitrate_ = p.bitrate; |
385 Configure( | 385 Configure( |
386 transport::CODEC_VIDEO_FAKE, transport::CODEC_AUDIO_PCM16, 32000, 1); | 386 CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16, 32000, 1); |
387 Create(p); | 387 Create(p); |
388 StartBasicPlayer(); | 388 StartBasicPlayer(); |
389 | 389 |
390 for (int frame = 0; frame < 1000; frame++) { | 390 for (int frame = 0; frame < 1000; frame++) { |
391 SendFakeVideoFrame(); | 391 SendFakeVideoFrame(); |
392 RunTasks(kFrameTimerMs); | 392 RunTasks(kFrameTimerMs); |
393 } | 393 } |
394 RunTasks(100 * kFrameTimerMs); // Empty the pipeline. | 394 RunTasks(100 * kFrameTimerMs); // Empty the pipeline. |
395 VLOG(1) << "=============INPUTS============"; | 395 VLOG(1) << "=============INPUTS============"; |
396 VLOG(1) << "Bitrate: " << p.bitrate << " mbit/s"; | 396 VLOG(1) << "Bitrate: " << p.bitrate << " mbit/s"; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 media::cast::CastBenchmark benchmark; | 707 media::cast::CastBenchmark benchmark; |
708 if (getenv("PROFILE_FILE")) { | 708 if (getenv("PROFILE_FILE")) { |
709 std::string profile_file(getenv("PROFILE_FILE")); | 709 std::string profile_file(getenv("PROFILE_FILE")); |
710 base::debug::StartProfiling(profile_file); | 710 base::debug::StartProfiling(profile_file); |
711 benchmark.Run(); | 711 benchmark.Run(); |
712 base::debug::StopProfiling(); | 712 base::debug::StopProfiling(); |
713 } else { | 713 } else { |
714 benchmark.Run(); | 714 benchmark.Run(); |
715 } | 715 } |
716 } | 716 } |
OLD | NEW |