pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 10 | |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 12 | #include "webrtc/base/checks.h" |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 13 | #include "webrtc/base/common.h" |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
| 15 | #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 18 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 19 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 20 | #include "webrtc/test/testsupport/perf_test.h" |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 21 | #include "webrtc/video/rampup_tests.h" |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 24 | namespace { |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 25 | |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 26 | static const int kMaxPacketSize = 1500; |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 27 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 28 | std::vector<uint32_t> GenerateSsrcs(size_t num_streams, |
| 29 | uint32_t ssrc_offset) { |
| 30 | std::vector<uint32_t> ssrcs; |
| 31 | for (size_t i = 0; i != num_streams; ++i) |
| 32 | ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i)); |
| 33 | return ssrcs; |
| 34 | } |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 35 | } // namespace |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 36 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 37 | StreamObserver::StreamObserver(const SsrcMap& rtx_media_ssrcs, |
| 38 | newapi::Transport* feedback_transport, |
| 39 | Clock* clock, |
| 40 | RemoteBitrateEstimatorFactory* rbe_factory, |
| 41 | RateControlType control_type) |
| 42 | : clock_(clock), |
| 43 | test_done_(EventWrapper::Create()), |
| 44 | rtp_parser_(RtpHeaderParser::Create()), |
| 45 | feedback_transport_(feedback_transport), |
| 46 | receive_stats_(ReceiveStatistics::Create(clock)), |
| 47 | payload_registry_( |
| 48 | new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))), |
| 49 | crit_(CriticalSectionWrapper::CreateCriticalSection()), |
| 50 | expected_bitrate_bps_(0), |
| 51 | start_bitrate_bps_(0), |
| 52 | rtx_media_ssrcs_(rtx_media_ssrcs), |
| 53 | total_sent_(0), |
| 54 | padding_sent_(0), |
| 55 | rtx_media_sent_(0), |
| 56 | total_packets_sent_(0), |
| 57 | padding_packets_sent_(0), |
| 58 | rtx_media_packets_sent_(0), |
| 59 | test_start_ms_(clock_->TimeInMilliseconds()), |
| 60 | ramp_up_finished_ms_(0) { |
| 61 | // Ideally we would only have to instantiate an RtcpSender, an |
| 62 | // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current |
| 63 | // state of the RTP module we need a full module and receive statistics to |
| 64 | // be able to produce an RTCP with REMB. |
| 65 | RtpRtcp::Configuration config; |
| 66 | config.receive_statistics = receive_stats_.get(); |
| 67 | feedback_transport_.Enable(); |
| 68 | config.outgoing_transport = &feedback_transport_; |
| 69 | rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
| 70 | rtp_rtcp_->SetREMBStatus(true); |
| 71 | rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); |
| 72 | rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 73 | kAbsSendTimeExtensionId); |
| 74 | rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
| 75 | kTransmissionTimeOffsetExtensionId); |
| 76 | const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; |
| 77 | remote_bitrate_estimator_.reset( |
| 78 | rbe_factory->Create(this, clock, control_type, |
| 79 | kRemoteBitrateEstimatorMinBitrateBps)); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 80 | payload_registry_->SetRtxPayloadType(RampUpTest::kSendRtxPayloadType, |
| 81 | RampUpTest::kFakeSendPayloadType); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void StreamObserver::set_expected_bitrate_bps( |
| 85 | unsigned int expected_bitrate_bps) { |
| 86 | CriticalSectionScoped lock(crit_.get()); |
| 87 | expected_bitrate_bps_ = expected_bitrate_bps; |
| 88 | } |
| 89 | |
| 90 | void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) { |
| 91 | CriticalSectionScoped lock(crit_.get()); |
| 92 | start_bitrate_bps_ = start_bitrate_bps; |
| 93 | } |
| 94 | |
| 95 | void StreamObserver::OnReceiveBitrateChanged( |
| 96 | const std::vector<unsigned int>& ssrcs, unsigned int bitrate) { |
| 97 | CriticalSectionScoped lock(crit_.get()); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 98 | DCHECK_GT(expected_bitrate_bps_, 0u); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 99 | if (start_bitrate_bps_ != 0) { |
| 100 | // For tests with an explicitly set start bitrate, verify the first |
| 101 | // bitrate estimate is close to the start bitrate and lower than the |
| 102 | // test target bitrate. This is to verify a call respects the configured |
| 103 | // start bitrate, but due to the BWE implementation we can't guarantee the |
| 104 | // first estimate really is as high as the start bitrate. |
| 105 | EXPECT_GT(bitrate, 0.9 * start_bitrate_bps_); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 106 | start_bitrate_bps_ = 0; |
| 107 | } |
| 108 | if (bitrate >= expected_bitrate_bps_) { |
| 109 | ramp_up_finished_ms_ = clock_->TimeInMilliseconds(); |
| 110 | // Just trigger if there was any rtx padding packet. |
| 111 | if (rtx_media_ssrcs_.empty() || rtx_media_sent_ > 0) { |
| 112 | TriggerTestDone(); |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 113 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 114 | } |
pbos@webrtc.org | 49ff40e | 2014-11-13 14:42:37 +0000 | [diff] [blame] | 115 | rtp_rtcp_->SetREMBData(bitrate, ssrcs); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 116 | rtp_rtcp_->Process(); |
| 117 | } |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 118 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 119 | bool StreamObserver::SendRtp(const uint8_t* packet, size_t length) { |
| 120 | CriticalSectionScoped lock(crit_.get()); |
| 121 | RTPHeader header; |
pbos@webrtc.org | b951eb1 | 2014-11-25 11:13:28 +0000 | [diff] [blame] | 122 | EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header)); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 123 | receive_stats_->IncomingPacket(header, length, false); |
andrew@webrtc.org | 8f27fcc | 2015-01-09 20:22:46 +0000 | [diff] [blame] | 124 | payload_registry_->SetIncomingPayloadType(header); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 125 | remote_bitrate_estimator_->IncomingPacket( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 126 | clock_->TimeInMilliseconds(), length - 12, header); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 127 | if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) { |
| 128 | remote_bitrate_estimator_->Process(); |
| 129 | } |
| 130 | total_sent_ += length; |
| 131 | padding_sent_ += header.paddingLength; |
| 132 | ++total_packets_sent_; |
| 133 | if (header.paddingLength > 0) |
| 134 | ++padding_packets_sent_; |
| 135 | if (rtx_media_ssrcs_.find(header.ssrc) != rtx_media_ssrcs_.end()) { |
| 136 | rtx_media_sent_ += length - header.headerLength - header.paddingLength; |
| 137 | if (header.paddingLength == 0) |
| 138 | ++rtx_media_packets_sent_; |
| 139 | uint8_t restored_packet[kMaxPacketSize]; |
| 140 | uint8_t* restored_packet_ptr = restored_packet; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 141 | size_t restored_length = length; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 142 | EXPECT_TRUE(payload_registry_->RestoreOriginalPacket( |
| 143 | &restored_packet_ptr, packet, &restored_length, |
| 144 | rtx_media_ssrcs_[header.ssrc], header)); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 145 | length = restored_length; |
| 146 | EXPECT_TRUE(rtp_parser_->Parse( |
| 147 | restored_packet, static_cast<int>(length), &header)); |
| 148 | } else { |
| 149 | rtp_rtcp_->SetRemoteSSRC(header.ssrc); |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | bool StreamObserver::SendRtcp(const uint8_t* packet, size_t length) { |
| 155 | return true; |
| 156 | } |
| 157 | |
pbos@webrtc.org | 32452b2 | 2014-10-22 12:15:24 +0000 | [diff] [blame] | 158 | EventTypeWrapper StreamObserver::Wait() { |
| 159 | return test_done_->Wait(test::CallTest::kLongTimeoutMs); |
| 160 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 161 | |
| 162 | void StreamObserver::ReportResult(const std::string& measurement, |
| 163 | size_t value, |
| 164 | const std::string& units) { |
| 165 | webrtc::test::PrintResult( |
| 166 | measurement, "", |
| 167 | ::testing::UnitTest::GetInstance()->current_test_info()->name(), |
| 168 | value, units, false); |
| 169 | } |
| 170 | |
| 171 | void StreamObserver::TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
| 172 | ReportResult("ramp-up-total-sent", total_sent_, "bytes"); |
| 173 | ReportResult("ramp-up-padding-sent", padding_sent_, "bytes"); |
| 174 | ReportResult("ramp-up-rtx-media-sent", rtx_media_sent_, "bytes"); |
| 175 | ReportResult("ramp-up-total-packets-sent", total_packets_sent_, "packets"); |
| 176 | ReportResult("ramp-up-padding-packets-sent", |
| 177 | padding_packets_sent_, |
| 178 | "packets"); |
| 179 | ReportResult("ramp-up-rtx-packets-sent", |
| 180 | rtx_media_packets_sent_, |
| 181 | "packets"); |
| 182 | ReportResult("ramp-up-time", |
| 183 | ramp_up_finished_ms_ - test_start_ms_, |
| 184 | "milliseconds"); |
| 185 | test_done_->Set(); |
| 186 | } |
| 187 | |
| 188 | LowRateStreamObserver::LowRateStreamObserver( |
| 189 | newapi::Transport* feedback_transport, |
| 190 | Clock* clock, |
| 191 | size_t number_of_streams, |
| 192 | bool rtx_used) |
| 193 | : clock_(clock), |
| 194 | number_of_streams_(number_of_streams), |
| 195 | rtx_used_(rtx_used), |
| 196 | test_done_(EventWrapper::Create()), |
| 197 | rtp_parser_(RtpHeaderParser::Create()), |
| 198 | feedback_transport_(feedback_transport), |
| 199 | receive_stats_(ReceiveStatistics::Create(clock)), |
| 200 | crit_(CriticalSectionWrapper::CreateCriticalSection()), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 201 | send_stream_(nullptr), |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 202 | test_state_(kFirstRampup), |
| 203 | state_start_ms_(clock_->TimeInMilliseconds()), |
| 204 | interval_start_ms_(state_start_ms_), |
| 205 | last_remb_bps_(0), |
| 206 | sent_bytes_(0), |
| 207 | total_overuse_bytes_(0), |
| 208 | suspended_in_stats_(false) { |
| 209 | RtpRtcp::Configuration config; |
| 210 | config.receive_statistics = receive_stats_.get(); |
| 211 | feedback_transport_.Enable(); |
| 212 | config.outgoing_transport = &feedback_transport_; |
| 213 | rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
| 214 | rtp_rtcp_->SetREMBStatus(true); |
| 215 | rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); |
stefan@webrtc.org | 8817256 | 2014-12-19 18:00:21 +0000 | [diff] [blame] | 216 | rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 217 | kAbsSendTimeExtensionId); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 218 | AbsoluteSendTimeRemoteBitrateEstimatorFactory rbe_factory; |
| 219 | const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 10000; |
| 220 | remote_bitrate_estimator_.reset( |
stefan@webrtc.org | 8817256 | 2014-12-19 18:00:21 +0000 | [diff] [blame] | 221 | rbe_factory.Create(this, clock, kAimdControl, |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 222 | kRemoteBitrateEstimatorMinBitrateBps)); |
| 223 | forward_transport_config_.link_capacity_kbps = |
| 224 | kHighBandwidthLimitBps / 1000; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 +0000 | [diff] [blame] | 225 | forward_transport_config_.queue_length_packets = 100; // Something large. |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 226 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 227 | test::DirectTransport::SetReceiver(this); |
| 228 | } |
| 229 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 230 | void LowRateStreamObserver::SetSendStream(VideoSendStream* send_stream) { |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 231 | CriticalSectionScoped lock(crit_.get()); |
| 232 | send_stream_ = send_stream; |
| 233 | } |
| 234 | |
| 235 | void LowRateStreamObserver::OnReceiveBitrateChanged( |
| 236 | const std::vector<unsigned int>& ssrcs, |
| 237 | unsigned int bitrate) { |
| 238 | CriticalSectionScoped lock(crit_.get()); |
pbos@webrtc.org | 49ff40e | 2014-11-13 14:42:37 +0000 | [diff] [blame] | 239 | rtp_rtcp_->SetREMBData(bitrate, ssrcs); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 240 | rtp_rtcp_->Process(); |
| 241 | last_remb_bps_ = bitrate; |
| 242 | } |
| 243 | |
| 244 | bool LowRateStreamObserver::SendRtp(const uint8_t* data, size_t length) { |
| 245 | CriticalSectionScoped lock(crit_.get()); |
| 246 | sent_bytes_ += length; |
| 247 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 248 | if (now_ms > interval_start_ms_ + 1000) { // Let at least 1 second pass. |
| 249 | // Verify that the send rate was about right. |
| 250 | unsigned int average_rate_bps = static_cast<unsigned int>(sent_bytes_) * |
| 251 | 8 * 1000 / (now_ms - interval_start_ms_); |
| 252 | // TODO(holmer): Why is this failing? |
| 253 | // EXPECT_LT(average_rate_bps, last_remb_bps_ * 1.1); |
| 254 | if (average_rate_bps > last_remb_bps_ * 1.1) { |
| 255 | total_overuse_bytes_ += |
| 256 | sent_bytes_ - |
| 257 | last_remb_bps_ / 8 * (now_ms - interval_start_ms_) / 1000; |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 258 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 259 | EvolveTestState(average_rate_bps); |
| 260 | interval_start_ms_ = now_ms; |
| 261 | sent_bytes_ = 0; |
| 262 | } |
| 263 | return test::DirectTransport::SendRtp(data, length); |
| 264 | } |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 265 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 266 | PacketReceiver::DeliveryStatus LowRateStreamObserver::DeliverPacket( |
| 267 | const uint8_t* packet, size_t length) { |
| 268 | CriticalSectionScoped lock(crit_.get()); |
| 269 | RTPHeader header; |
pbos@webrtc.org | b951eb1 | 2014-11-25 11:13:28 +0000 | [diff] [blame] | 270 | EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header)); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 271 | receive_stats_->IncomingPacket(header, length, false); |
| 272 | remote_bitrate_estimator_->IncomingPacket( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 273 | clock_->TimeInMilliseconds(), length - 12, header); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 274 | if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) { |
| 275 | remote_bitrate_estimator_->Process(); |
| 276 | } |
| 277 | suspended_in_stats_ = send_stream_->GetStats().suspended; |
| 278 | return DELIVERY_OK; |
| 279 | } |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 280 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 281 | bool LowRateStreamObserver::SendRtcp(const uint8_t* packet, size_t length) { |
| 282 | return true; |
| 283 | } |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 284 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 285 | std::string LowRateStreamObserver::GetModifierString() { |
| 286 | std::string str("_"); |
| 287 | char temp_str[5]; |
| 288 | sprintf(temp_str, "%i", |
| 289 | static_cast<int>(number_of_streams_)); |
| 290 | str += std::string(temp_str); |
| 291 | str += "stream"; |
| 292 | str += (number_of_streams_ > 1 ? "s" : ""); |
| 293 | str += "_"; |
| 294 | str += (rtx_used_ ? "" : "no"); |
| 295 | str += "rtx"; |
| 296 | return str; |
| 297 | } |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 298 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 299 | void LowRateStreamObserver::EvolveTestState(unsigned int bitrate_bps) { |
| 300 | int64_t now = clock_->TimeInMilliseconds(); |
| 301 | CriticalSectionScoped lock(crit_.get()); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 302 | DCHECK(send_stream_ != nullptr); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 303 | switch (test_state_) { |
| 304 | case kFirstRampup: { |
| 305 | EXPECT_FALSE(suspended_in_stats_); |
| 306 | if (bitrate_bps > kExpectedHighBitrateBps) { |
| 307 | // The first ramp-up has reached the target bitrate. Change the |
| 308 | // channel limit, and move to the next test state. |
| 309 | forward_transport_config_.link_capacity_kbps = |
| 310 | kLowBandwidthLimitBps / 1000; |
| 311 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 312 | test_state_ = kLowRate; |
| 313 | webrtc::test::PrintResult("ramp_up_down_up", |
| 314 | GetModifierString(), |
| 315 | "first_rampup", |
| 316 | now - state_start_ms_, |
| 317 | "ms", |
| 318 | false); |
| 319 | state_start_ms_ = now; |
| 320 | interval_start_ms_ = now; |
| 321 | sent_bytes_ = 0; |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 322 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 323 | break; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 324 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 325 | case kLowRate: { |
| 326 | if (bitrate_bps < kExpectedLowBitrateBps && suspended_in_stats_) { |
| 327 | // The ramp-down was successful. Change the channel limit back to a |
| 328 | // high value, and move to the next test state. |
| 329 | forward_transport_config_.link_capacity_kbps = |
| 330 | kHighBandwidthLimitBps / 1000; |
| 331 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 332 | test_state_ = kSecondRampup; |
| 333 | webrtc::test::PrintResult("ramp_up_down_up", |
| 334 | GetModifierString(), |
| 335 | "rampdown", |
| 336 | now - state_start_ms_, |
| 337 | "ms", |
| 338 | false); |
| 339 | state_start_ms_ = now; |
| 340 | interval_start_ms_ = now; |
| 341 | sent_bytes_ = 0; |
| 342 | } |
| 343 | break; |
| 344 | } |
| 345 | case kSecondRampup: { |
| 346 | if (bitrate_bps > kExpectedHighBitrateBps && !suspended_in_stats_) { |
| 347 | webrtc::test::PrintResult("ramp_up_down_up", |
| 348 | GetModifierString(), |
| 349 | "second_rampup", |
| 350 | now - state_start_ms_, |
| 351 | "ms", |
| 352 | false); |
| 353 | webrtc::test::PrintResult("ramp_up_down_up", |
| 354 | GetModifierString(), |
| 355 | "total_overuse", |
| 356 | total_overuse_bytes_, |
| 357 | "bytes", |
| 358 | false); |
| 359 | test_done_->Set(); |
| 360 | } |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | } |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 365 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 366 | EventTypeWrapper LowRateStreamObserver::Wait() { |
| 367 | return test_done_->Wait(test::CallTest::kLongTimeoutMs); |
| 368 | } |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 369 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 370 | void RampUpTest::RunRampUpTest(size_t num_streams, |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 371 | unsigned int start_bitrate_bps, |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 372 | const std::string& extension_type, |
| 373 | bool rtx, |
| 374 | bool red) { |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 375 | std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100)); |
| 376 | std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200)); |
| 377 | StreamObserver::SsrcMap rtx_ssrc_map; |
| 378 | if (rtx) { |
| 379 | for (size_t i = 0; i < ssrcs.size(); ++i) |
| 380 | rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i]; |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 381 | } |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 382 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 383 | CreateSendConfig(num_streams); |
Erik Språng | 9526187 | 2015-04-10 11:58:49 +0200 | [diff] [blame] | 384 | send_config_.rtp.extensions.clear(); |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 385 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 386 | rtc::scoped_ptr<RemoteBitrateEstimatorFactory> rbe_factory; |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 387 | RateControlType control_type; |
| 388 | if (extension_type == RtpExtension::kAbsSendTime) { |
| 389 | control_type = kAimdControl; |
| 390 | rbe_factory.reset(new AbsoluteSendTimeRemoteBitrateEstimatorFactory); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 391 | send_config_.rtp.extensions.push_back(RtpExtension( |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 392 | extension_type.c_str(), kAbsSendTimeExtensionId)); |
| 393 | } else { |
| 394 | control_type = kMimdControl; |
| 395 | rbe_factory.reset(new RemoteBitrateEstimatorFactory); |
| 396 | send_config_.rtp.extensions.push_back(RtpExtension( |
| 397 | extension_type.c_str(), kTransmissionTimeOffsetExtensionId)); |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 398 | } |
| 399 | |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 400 | test::DirectTransport receiver_transport; |
| 401 | StreamObserver stream_observer(rtx_ssrc_map, |
| 402 | &receiver_transport, |
| 403 | Clock::GetRealTimeClock(), |
| 404 | rbe_factory.get(), |
| 405 | control_type); |
| 406 | |
| 407 | Call::Config call_config(&stream_observer); |
| 408 | if (start_bitrate_bps != 0) { |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 409 | call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps; |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 410 | stream_observer.set_start_bitrate_bps(start_bitrate_bps); |
andresp@webrtc.org | a714eaf | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 411 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 412 | |
| 413 | CreateSenderCall(call_config); |
| 414 | |
| 415 | receiver_transport.SetReceiver(sender_call_->Receiver()); |
| 416 | |
| 417 | if (num_streams == 1) { |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 418 | encoder_config_.streams[0].target_bitrate_bps = 2000000; |
| 419 | encoder_config_.streams[0].max_bitrate_bps = 2000000; |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 423 | send_config_.rtp.ssrcs = ssrcs; |
| 424 | if (rtx) { |
| 425 | send_config_.rtp.rtx.payload_type = kSendRtxPayloadType; |
| 426 | send_config_.rtp.rtx.ssrcs = rtx_ssrcs; |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 427 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 428 | if (red) { |
| 429 | send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
| 430 | send_config_.rtp.fec.red_payload_type = kRedPayloadType; |
| 431 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 432 | |
| 433 | if (num_streams == 1) { |
| 434 | // For single stream rampup until 1mbps |
| 435 | stream_observer.set_expected_bitrate_bps(kSingleStreamTargetBps); |
| 436 | } else { |
| 437 | // For multi stream rampup until all streams are being sent. That means |
| 438 | // enough birate to send all the target streams plus the min bitrate of |
| 439 | // the last one. |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 440 | int expected_bitrate_bps = encoder_config_.streams.back().min_bitrate_bps; |
| 441 | for (size_t i = 0; i < encoder_config_.streams.size() - 1; ++i) { |
| 442 | expected_bitrate_bps += encoder_config_.streams[i].target_bitrate_bps; |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 443 | } |
| 444 | stream_observer.set_expected_bitrate_bps(expected_bitrate_bps); |
| 445 | } |
| 446 | |
| 447 | CreateStreams(); |
| 448 | CreateFrameGeneratorCapturer(); |
| 449 | |
| 450 | Start(); |
| 451 | |
| 452 | EXPECT_EQ(kEventSignaled, stream_observer.Wait()); |
| 453 | |
| 454 | Stop(); |
| 455 | DestroyStreams(); |
| 456 | } |
| 457 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 458 | void RampUpTest::RunRampUpDownUpTest(size_t number_of_streams, |
| 459 | bool rtx, |
| 460 | bool red) { |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 461 | test::DirectTransport receiver_transport; |
| 462 | LowRateStreamObserver stream_observer( |
| 463 | &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx); |
| 464 | |
| 465 | Call::Config call_config(&stream_observer); |
| 466 | CreateSenderCall(call_config); |
| 467 | receiver_transport.SetReceiver(sender_call_->Receiver()); |
| 468 | |
| 469 | CreateSendConfig(number_of_streams); |
| 470 | |
| 471 | send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 472 | send_config_.rtp.extensions.push_back(RtpExtension( |
stefan@webrtc.org | 8817256 | 2014-12-19 18:00:21 +0000 | [diff] [blame] | 473 | RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId)); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 474 | send_config_.suspend_below_min_bitrate = true; |
| 475 | if (rtx) { |
| 476 | send_config_.rtp.rtx.payload_type = kSendRtxPayloadType; |
| 477 | send_config_.rtp.rtx.ssrcs = GenerateSsrcs(number_of_streams, 200); |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 478 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 479 | if (red) { |
| 480 | send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
| 481 | send_config_.rtp.fec.red_payload_type = kRedPayloadType; |
| 482 | } |
stefan@webrtc.org | 3d7da88 | 2014-07-08 13:59:46 +0000 | [diff] [blame] | 483 | |
| 484 | CreateStreams(); |
| 485 | stream_observer.SetSendStream(send_stream_); |
| 486 | |
| 487 | CreateFrameGeneratorCapturer(); |
| 488 | |
| 489 | Start(); |
| 490 | |
| 491 | EXPECT_EQ(kEventSignaled, stream_observer.Wait()); |
| 492 | |
| 493 | Stop(); |
| 494 | DestroyStreams(); |
| 495 | } |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 496 | |
stefan@webrtc.org | cb254aa | 2014-06-12 15:12:25 +0000 | [diff] [blame] | 497 | TEST_F(RampUpTest, SingleStream) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 498 | RunRampUpTest(1, 0, RtpExtension::kTOffset, false, false); |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 499 | } |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 500 | |
stefan@webrtc.org | cb254aa | 2014-06-12 15:12:25 +0000 | [diff] [blame] | 501 | TEST_F(RampUpTest, Simulcast) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 502 | RunRampUpTest(3, 0, RtpExtension::kTOffset, false, false); |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 503 | } |
| 504 | |
stefan@webrtc.org | cb254aa | 2014-06-12 15:12:25 +0000 | [diff] [blame] | 505 | TEST_F(RampUpTest, SimulcastWithRtx) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 506 | RunRampUpTest(3, 0, RtpExtension::kTOffset, true, false); |
| 507 | } |
| 508 | |
| 509 | TEST_F(RampUpTest, SimulcastByRedWithRtx) { |
| 510 | RunRampUpTest(3, 0, RtpExtension::kTOffset, true, true); |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 514 | RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kTOffset, false, |
| 515 | false); |
andresp@webrtc.org | c148079 | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 516 | } |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 517 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 518 | TEST_F(RampUpTest, UpDownUpOneStream) { |
| 519 | RunRampUpDownUpTest(1, false, false); |
| 520 | } |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 521 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 522 | TEST_F(RampUpTest, UpDownUpThreeStreams) { |
| 523 | RunRampUpDownUpTest(3, false, false); |
| 524 | } |
henrik.lundin@webrtc.org | 998cb8f | 2014-03-06 09:12:00 +0000 | [diff] [blame] | 525 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 526 | TEST_F(RampUpTest, UpDownUpOneStreamRtx) { |
| 527 | RunRampUpDownUpTest(1, true, false); |
| 528 | } |
henrik.lundin@webrtc.org | 998cb8f | 2014-03-06 09:12:00 +0000 | [diff] [blame] | 529 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 530 | TEST_F(RampUpTest, UpDownUpThreeStreamsRtx) { |
| 531 | RunRampUpDownUpTest(3, true, false); |
| 532 | } |
| 533 | |
| 534 | TEST_F(RampUpTest, UpDownUpOneStreamByRedRtx) { |
| 535 | RunRampUpDownUpTest(1, true, true); |
| 536 | } |
| 537 | |
| 538 | TEST_F(RampUpTest, UpDownUpThreeStreamsByRedRtx) { |
| 539 | RunRampUpDownUpTest(3, true, true); |
| 540 | } |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 541 | |
pbos@webrtc.org | 85bd53e | 2014-12-10 10:36:20 +0000 | [diff] [blame] | 542 | TEST_F(RampUpTest, AbsSendTimeSingleStream) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 543 | RunRampUpTest(1, 0, RtpExtension::kAbsSendTime, false, false); |
pbos@webrtc.org | 85bd53e | 2014-12-10 10:36:20 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | TEST_F(RampUpTest, AbsSendTimeSimulcast) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 547 | RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, false, false); |
pbos@webrtc.org | 85bd53e | 2014-12-10 10:36:20 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | TEST_F(RampUpTest, AbsSendTimeSimulcastWithRtx) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 551 | RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, false); |
| 552 | } |
| 553 | |
| 554 | TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) { |
| 555 | RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, true); |
pbos@webrtc.org | 85bd53e | 2014-12-10 10:36:20 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame^] | 559 | RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kAbsSendTime, |
| 560 | false, false); |
pbos@webrtc.org | 85bd53e | 2014-12-10 10:36:20 +0000 | [diff] [blame] | 561 | } |
pbos@webrtc.org | 744fbc7 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 562 | } // namespace webrtc |