pbos@webrtc.org | fa996f2 | 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 | */ |
| 10 | #include <assert.h> |
| 11 | |
| 12 | #include <map> |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 13 | #include <string> |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 14 | #include <vector> |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 15 | |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 18 | #include "webrtc/call.h" |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 19 | #include "webrtc/common.h" |
| 20 | #include "webrtc/experiments.h" |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 22 | #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
| 23 | #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 24 | #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 25 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 26 | #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 27 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 28 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 29 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 30 | #include "webrtc/test/direct_transport.h" |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 31 | #include "webrtc/test/encoder_settings.h" |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 32 | #include "webrtc/test/fake_decoder.h" |
| 33 | #include "webrtc/test/fake_encoder.h" |
| 34 | #include "webrtc/test/frame_generator_capturer.h" |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 35 | #include "webrtc/test/testsupport/perf_test.h" |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 36 | #include "webrtc/video/transport_adapter.h" |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 37 | |
| 38 | namespace webrtc { |
| 39 | |
pbos@webrtc.org | 990c5e3 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 40 | namespace { |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 41 | static const int kAbsoluteSendTimeExtensionId = 7; |
| 42 | static const int kMaxPacketSize = 1500; |
pbos@webrtc.org | 990c5e3 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 43 | |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 44 | class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { |
| 45 | public: |
| 46 | typedef std::map<uint32_t, int> BytesSentMap; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 47 | typedef std::map<uint32_t, uint32_t> SsrcMap; |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 48 | StreamObserver(const SsrcMap& rtx_media_ssrcs, |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 49 | newapi::Transport* feedback_transport, |
| 50 | Clock* clock) |
| 51 | : critical_section_(CriticalSectionWrapper::CreateCriticalSection()), |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 52 | test_done_(EventWrapper::Create()), |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 53 | rtp_parser_(RtpHeaderParser::Create()), |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 54 | feedback_transport_(feedback_transport), |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 55 | receive_stats_(ReceiveStatistics::Create(clock)), |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 56 | payload_registry_( |
andresp@webrtc.org | 9968131 | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 57 | new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))), |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 58 | clock_(clock), |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 59 | expected_bitrate_bps_(0), |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 60 | rtx_media_ssrcs_(rtx_media_ssrcs), |
| 61 | total_sent_(0), |
| 62 | padding_sent_(0), |
| 63 | rtx_media_sent_(0), |
| 64 | total_packets_sent_(0), |
| 65 | padding_packets_sent_(0), |
| 66 | rtx_media_packets_sent_(0) { |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 67 | // Ideally we would only have to instantiate an RtcpSender, an |
| 68 | // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current |
| 69 | // state of the RTP module we need a full module and receive statistics to |
| 70 | // be able to produce an RTCP with REMB. |
| 71 | RtpRtcp::Configuration config; |
| 72 | config.receive_statistics = receive_stats_.get(); |
sprang@webrtc.org | 0a29815 | 2014-01-27 13:03:02 +0000 | [diff] [blame] | 73 | feedback_transport_.Enable(); |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 74 | config.outgoing_transport = &feedback_transport_; |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 75 | rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
| 76 | rtp_rtcp_->SetREMBStatus(true); |
| 77 | rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); |
pbos@webrtc.org | 46f7288 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 78 | rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 79 | kAbsoluteSendTimeExtensionId); |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 80 | AbsoluteSendTimeRemoteBitrateEstimatorFactory rbe_factory; |
henrik.lundin@webrtc.org | c49a3fa | 2013-12-13 08:42:42 +0000 | [diff] [blame] | 81 | const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; |
| 82 | remote_bitrate_estimator_.reset( |
stefan@webrtc.org | b9d0acb | 2014-03-24 09:42:08 +0000 | [diff] [blame] | 83 | rbe_factory.Create(this, clock, kMimdControl, |
| 84 | kRemoteBitrateEstimatorMinBitrateBps)); |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 87 | void set_expected_bitrate_bps(unsigned int expected_bitrate_bps) { |
| 88 | expected_bitrate_bps_ = expected_bitrate_bps; |
| 89 | } |
| 90 | |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 91 | virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 92 | unsigned int bitrate) OVERRIDE { |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 93 | CriticalSectionScoped lock(critical_section_.get()); |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 94 | assert(expected_bitrate_bps_ > 0); |
| 95 | if (bitrate >= expected_bitrate_bps_) { |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 96 | // Just trigger if there was any rtx padding packet. |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 97 | if (rtx_media_ssrcs_.empty() || rtx_media_sent_ > 0) { |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 98 | TriggerTestDone(); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 101 | rtp_rtcp_->SetREMBData( |
| 102 | bitrate, static_cast<uint8_t>(ssrcs.size()), &ssrcs[0]); |
| 103 | rtp_rtcp_->Process(); |
| 104 | } |
| 105 | |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 106 | virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE { |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 107 | CriticalSectionScoped lock(critical_section_.get()); |
| 108 | RTPHeader header; |
| 109 | EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header)); |
| 110 | receive_stats_->IncomingPacket(header, length, false); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 111 | payload_registry_->SetIncomingPayloadType(header); |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 112 | remote_bitrate_estimator_->IncomingPacket( |
| 113 | clock_->TimeInMilliseconds(), static_cast<int>(length - 12), header); |
| 114 | if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) { |
| 115 | remote_bitrate_estimator_->Process(); |
| 116 | } |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 117 | total_sent_ += length; |
| 118 | padding_sent_ += header.paddingLength; |
| 119 | ++total_packets_sent_; |
| 120 | if (header.paddingLength > 0) |
| 121 | ++padding_packets_sent_; |
| 122 | if (rtx_media_ssrcs_.find(header.ssrc) != rtx_media_ssrcs_.end()) { |
| 123 | rtx_media_sent_ += length - header.headerLength - header.paddingLength; |
| 124 | if (header.paddingLength == 0) |
| 125 | ++rtx_media_packets_sent_; |
| 126 | uint8_t restored_packet[kMaxPacketSize]; |
| 127 | uint8_t* restored_packet_ptr = restored_packet; |
| 128 | int restored_length = static_cast<int>(length); |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 129 | payload_registry_->RestoreOriginalPacket(&restored_packet_ptr, |
| 130 | packet, |
| 131 | &restored_length, |
| 132 | rtx_media_ssrcs_[header.ssrc], |
| 133 | header); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 134 | length = restored_length; |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 135 | EXPECT_TRUE(rtp_parser_->Parse( |
| 136 | restored_packet, static_cast<int>(length), &header)); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 137 | } else { |
| 138 | rtp_rtcp_->SetRemoteSSRC(header.ssrc); |
| 139 | } |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 140 | return true; |
| 141 | } |
| 142 | |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 143 | virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE { |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 144 | return true; |
| 145 | } |
| 146 | |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 147 | EventTypeWrapper Wait() { return test_done_->Wait(120 * 1000); } |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 148 | |
| 149 | private: |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 150 | void ReportResult(const std::string& measurement, |
| 151 | size_t value, |
| 152 | const std::string& units) { |
| 153 | webrtc::test::PrintResult( |
| 154 | measurement, "", |
| 155 | ::testing::UnitTest::GetInstance()->current_test_info()->name(), |
| 156 | value, units, false); |
| 157 | } |
| 158 | |
| 159 | void TriggerTestDone() { |
| 160 | ReportResult("total-sent", total_sent_, "bytes"); |
| 161 | ReportResult("padding-sent", padding_sent_, "bytes"); |
| 162 | ReportResult("rtx-media-sent", rtx_media_sent_, "bytes"); |
| 163 | ReportResult("total-packets-sent", total_packets_sent_, "packets"); |
| 164 | ReportResult("padding-packets-sent", padding_packets_sent_, "packets"); |
| 165 | ReportResult("rtx-packets-sent", rtx_media_packets_sent_, "packets"); |
| 166 | test_done_->Set(); |
| 167 | } |
| 168 | |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 169 | scoped_ptr<CriticalSectionWrapper> critical_section_; |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 170 | scoped_ptr<EventWrapper> test_done_; |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 171 | scoped_ptr<RtpHeaderParser> rtp_parser_; |
| 172 | scoped_ptr<RtpRtcp> rtp_rtcp_; |
pbos@webrtc.org | 3009c81 | 2013-11-20 12:17:04 +0000 | [diff] [blame] | 173 | internal::TransportAdapter feedback_transport_; |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 174 | scoped_ptr<ReceiveStatistics> receive_stats_; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 175 | scoped_ptr<RTPPayloadRegistry> payload_registry_; |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 176 | scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; |
| 177 | Clock* clock_; |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 178 | unsigned int expected_bitrate_bps_; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 179 | SsrcMap rtx_media_ssrcs_; |
| 180 | size_t total_sent_; |
| 181 | size_t padding_sent_; |
| 182 | size_t rtx_media_sent_; |
| 183 | int total_packets_sent_; |
| 184 | int padding_packets_sent_; |
| 185 | int rtx_media_packets_sent_; |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 188 | class LowRateStreamObserver : public test::DirectTransport, |
| 189 | public RemoteBitrateObserver, |
| 190 | public PacketReceiver { |
| 191 | public: |
| 192 | LowRateStreamObserver(newapi::Transport* feedback_transport, |
| 193 | Clock* clock, |
| 194 | size_t number_of_streams, |
| 195 | bool rtx_used) |
| 196 | : critical_section_(CriticalSectionWrapper::CreateCriticalSection()), |
| 197 | test_done_(EventWrapper::Create()), |
| 198 | rtp_parser_(RtpHeaderParser::Create()), |
| 199 | feedback_transport_(feedback_transport), |
| 200 | receive_stats_(ReceiveStatistics::Create(clock)), |
| 201 | clock_(clock), |
| 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 | number_of_streams_(number_of_streams), |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 209 | rtx_used_(rtx_used), |
| 210 | send_stream_(NULL), |
henrik.lundin@webrtc.org | 96616cb | 2014-03-13 15:39:27 +0000 | [diff] [blame] | 211 | suspended_in_stats_(false) { |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 212 | RtpRtcp::Configuration config; |
| 213 | config.receive_statistics = receive_stats_.get(); |
| 214 | feedback_transport_.Enable(); |
| 215 | config.outgoing_transport = &feedback_transport_; |
| 216 | rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
| 217 | rtp_rtcp_->SetREMBStatus(true); |
| 218 | rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); |
| 219 | rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 220 | kAbsoluteSendTimeExtensionId); |
| 221 | AbsoluteSendTimeRemoteBitrateEstimatorFactory rbe_factory; |
| 222 | const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 10000; |
| 223 | remote_bitrate_estimator_.reset( |
stefan@webrtc.org | b9d0acb | 2014-03-24 09:42:08 +0000 | [diff] [blame] | 224 | rbe_factory.Create(this, clock, kMimdControl, |
| 225 | kRemoteBitrateEstimatorMinBitrateBps)); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 226 | forward_transport_config_.link_capacity_kbps = |
| 227 | kHighBandwidthLimitBps / 1000; |
| 228 | forward_transport_config_.queue_length = 100; // Something large. |
| 229 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 230 | test::DirectTransport::SetReceiver(this); |
| 231 | } |
| 232 | |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 233 | virtual void SetSendStream(const VideoSendStream* send_stream) { |
| 234 | send_stream_ = send_stream; |
| 235 | } |
| 236 | |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 237 | virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, |
| 238 | unsigned int bitrate) { |
| 239 | CriticalSectionScoped lock(critical_section_.get()); |
| 240 | rtp_rtcp_->SetREMBData( |
| 241 | bitrate, static_cast<uint8_t>(ssrcs.size()), &ssrcs[0]); |
| 242 | rtp_rtcp_->Process(); |
| 243 | last_remb_bps_ = bitrate; |
| 244 | } |
| 245 | |
| 246 | virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE { |
| 247 | sent_bytes_ += length; |
| 248 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 249 | if (now_ms > interval_start_ms_ + 1000) { // Let at least 1 second pass. |
| 250 | // Verify that the send rate was about right. |
| 251 | unsigned int average_rate_bps = static_cast<unsigned int>(sent_bytes_) * |
| 252 | 8 * 1000 / (now_ms - interval_start_ms_); |
| 253 | // TODO(holmer): Why is this failing? |
| 254 | // EXPECT_LT(average_rate_bps, last_remb_bps_ * 1.1); |
| 255 | if (average_rate_bps > last_remb_bps_ * 1.1) { |
| 256 | total_overuse_bytes_ += |
| 257 | sent_bytes_ - |
| 258 | last_remb_bps_ / 8 * (now_ms - interval_start_ms_) / 1000; |
| 259 | } |
| 260 | EvolveTestState(average_rate_bps); |
| 261 | interval_start_ms_ = now_ms; |
| 262 | sent_bytes_ = 0; |
| 263 | } |
| 264 | return test::DirectTransport::SendRtp(data, length); |
| 265 | } |
| 266 | |
| 267 | virtual bool DeliverPacket(const uint8_t* packet, size_t length) OVERRIDE { |
| 268 | CriticalSectionScoped lock(critical_section_.get()); |
| 269 | RTPHeader header; |
| 270 | EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header)); |
| 271 | receive_stats_->IncomingPacket(header, length, false); |
| 272 | remote_bitrate_estimator_->IncomingPacket( |
| 273 | clock_->TimeInMilliseconds(), static_cast<int>(length - 12), header); |
| 274 | if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) { |
| 275 | remote_bitrate_estimator_->Process(); |
| 276 | } |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 277 | suspended_in_stats_ = send_stream_->GetStats().suspended; |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | |
| 281 | virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE { |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | // Produces a string similar to "1stream_nortx", depending on the values of |
| 286 | // number_of_streams_ and rtx_used_; |
| 287 | std::string GetModifierString() { |
| 288 | std::string str("_"); |
| 289 | char temp_str[5]; |
henrik.lundin@webrtc.org | 9deb87b | 2014-03-25 13:39:11 +0000 | [diff] [blame] | 290 | sprintf(temp_str, "%i", static_cast<int>(number_of_streams_)); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 291 | str += std::string(temp_str); |
| 292 | str += "stream"; |
| 293 | str += (number_of_streams_ > 1 ? "s" : ""); |
| 294 | str += "_"; |
| 295 | str += (rtx_used_ ? "" : "no"); |
| 296 | str += "rtx"; |
| 297 | return str; |
| 298 | } |
| 299 | |
| 300 | // This method defines the state machine for the ramp up-down-up test. |
| 301 | void EvolveTestState(unsigned int bitrate_bps) { |
| 302 | int64_t now = clock_->TimeInMilliseconds(); |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 303 | assert(send_stream_ != NULL); |
| 304 | CriticalSectionScoped lock(critical_section_.get()); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 305 | switch (test_state_) { |
| 306 | case kFirstRampup: { |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 307 | EXPECT_FALSE(suspended_in_stats_); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 308 | if (bitrate_bps > kExpectedHighBitrateBps) { |
| 309 | // The first ramp-up has reached the target bitrate. Change the |
| 310 | // channel limit, and move to the next test state. |
| 311 | forward_transport_config_.link_capacity_kbps = |
| 312 | kLowBandwidthLimitBps / 1000; |
| 313 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 314 | test_state_ = kLowRate; |
| 315 | webrtc::test::PrintResult("ramp_up_down_up", |
| 316 | GetModifierString(), |
| 317 | "first_rampup", |
| 318 | now - state_start_ms_, |
| 319 | "ms", |
| 320 | false); |
| 321 | state_start_ms_ = now; |
| 322 | interval_start_ms_ = now; |
| 323 | sent_bytes_ = 0; |
| 324 | } |
| 325 | break; |
| 326 | } |
| 327 | case kLowRate: { |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 328 | if (bitrate_bps < kExpectedLowBitrateBps && suspended_in_stats_) { |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 329 | // The ramp-down was successful. Change the channel limit back to a |
| 330 | // high value, and move to the next test state. |
| 331 | forward_transport_config_.link_capacity_kbps = |
| 332 | kHighBandwidthLimitBps / 1000; |
| 333 | test::DirectTransport::SetConfig(forward_transport_config_); |
| 334 | test_state_ = kSecondRampup; |
| 335 | webrtc::test::PrintResult("ramp_up_down_up", |
| 336 | GetModifierString(), |
| 337 | "rampdown", |
| 338 | now - state_start_ms_, |
| 339 | "ms", |
| 340 | false); |
| 341 | state_start_ms_ = now; |
| 342 | interval_start_ms_ = now; |
| 343 | sent_bytes_ = 0; |
| 344 | } |
| 345 | break; |
| 346 | } |
| 347 | case kSecondRampup: { |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 348 | if (bitrate_bps > kExpectedHighBitrateBps && !suspended_in_stats_) { |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 349 | webrtc::test::PrintResult("ramp_up_down_up", |
| 350 | GetModifierString(), |
| 351 | "second_rampup", |
| 352 | now - state_start_ms_, |
| 353 | "ms", |
| 354 | false); |
| 355 | webrtc::test::PrintResult("ramp_up_down_up", |
| 356 | GetModifierString(), |
| 357 | "total_overuse", |
| 358 | total_overuse_bytes_, |
| 359 | "bytes", |
| 360 | false); |
| 361 | test_done_->Set(); |
| 362 | } |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | EventTypeWrapper Wait() { return test_done_->Wait(120 * 1000); } |
| 369 | |
| 370 | private: |
| 371 | static const unsigned int kHighBandwidthLimitBps = 80000; |
| 372 | static const unsigned int kExpectedHighBitrateBps = 60000; |
| 373 | static const unsigned int kLowBandwidthLimitBps = 20000; |
| 374 | static const unsigned int kExpectedLowBitrateBps = 20000; |
| 375 | enum TestStates { kFirstRampup, kLowRate, kSecondRampup }; |
| 376 | |
| 377 | scoped_ptr<CriticalSectionWrapper> critical_section_; |
| 378 | scoped_ptr<EventWrapper> test_done_; |
| 379 | scoped_ptr<RtpHeaderParser> rtp_parser_; |
| 380 | scoped_ptr<RtpRtcp> rtp_rtcp_; |
| 381 | internal::TransportAdapter feedback_transport_; |
| 382 | scoped_ptr<ReceiveStatistics> receive_stats_; |
| 383 | scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; |
| 384 | Clock* clock_; |
| 385 | FakeNetworkPipe::Config forward_transport_config_; |
| 386 | TestStates test_state_; |
| 387 | int64_t state_start_ms_; |
| 388 | int64_t interval_start_ms_; |
| 389 | unsigned int last_remb_bps_; |
| 390 | size_t sent_bytes_; |
| 391 | size_t total_overuse_bytes_; |
| 392 | const size_t number_of_streams_; |
| 393 | const bool rtx_used_; |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 394 | const VideoSendStream* send_stream_; |
| 395 | bool suspended_in_stats_ GUARDED_BY(critical_section_); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 396 | }; |
| 397 | } |
| 398 | |
| 399 | class RampUpTest : public ::testing::Test { |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 400 | public: |
| 401 | virtual void SetUp() { reserved_ssrcs_.clear(); } |
| 402 | |
| 403 | protected: |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 404 | void RunRampUpTest(bool pacing, bool rtx, size_t num_streams) { |
| 405 | std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100)); |
| 406 | std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200)); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 407 | StreamObserver::SsrcMap rtx_ssrc_map; |
| 408 | if (rtx) { |
| 409 | for (size_t i = 0; i < ssrcs.size(); ++i) |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 410 | rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i]; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 411 | } |
| 412 | test::DirectTransport receiver_transport; |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 413 | StreamObserver stream_observer(rtx_ssrc_map, |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 414 | &receiver_transport, |
| 415 | Clock::GetRealTimeClock()); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 416 | |
| 417 | Call::Config call_config(&stream_observer); |
| 418 | webrtc::Config webrtc_config; |
| 419 | call_config.webrtc_config = &webrtc_config; |
| 420 | webrtc_config.Set<PaddingStrategy>(new PaddingStrategy(rtx)); |
| 421 | scoped_ptr<Call> call(Call::Create(call_config)); |
| 422 | VideoSendStream::Config send_config = call->GetDefaultSendConfig(); |
| 423 | |
| 424 | receiver_transport.SetReceiver(call->Receiver()); |
| 425 | |
| 426 | test::FakeEncoder encoder(Clock::GetRealTimeClock()); |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 427 | send_config.encoder_settings = |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 428 | test::CreateEncoderSettings(&encoder, "FAKE", 125, num_streams); |
| 429 | |
| 430 | if (num_streams == 1) { |
| 431 | send_config.encoder_settings.streams[0].target_bitrate_bps = 2000000; |
| 432 | send_config.encoder_settings.streams[0].max_bitrate_bps = 2000000; |
| 433 | } |
| 434 | |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 435 | send_config.pacing = pacing; |
| 436 | send_config.rtp.nack.rtp_history_ms = 1000; |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 437 | send_config.rtp.ssrcs = ssrcs; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 438 | if (rtx) { |
pbos@webrtc.org | c71929d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 439 | send_config.rtp.rtx.payload_type = 96; |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 440 | send_config.rtp.rtx.ssrcs = rtx_ssrcs; |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 441 | } |
| 442 | send_config.rtp.extensions.push_back( |
pbos@webrtc.org | 46f7288 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 443 | RtpExtension(RtpExtension::kAbsSendTime, kAbsoluteSendTimeExtensionId)); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 444 | |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 445 | if (num_streams == 1) { |
| 446 | // For single stream rampup until 1mbps |
| 447 | stream_observer.set_expected_bitrate_bps(1000000); |
| 448 | } else { |
| 449 | // For multi stream rampup until all streams are being sent. That means |
| 450 | // enough birate to sent all the target streams plus the min bitrate of |
| 451 | // the last one. |
| 452 | int expected_bitrate_bps = |
| 453 | send_config.encoder_settings.streams.back().min_bitrate_bps; |
| 454 | for (size_t i = 0; i < send_config.encoder_settings.streams.size() - 1; |
| 455 | ++i) { |
| 456 | expected_bitrate_bps += |
| 457 | send_config.encoder_settings.streams[i].target_bitrate_bps; |
| 458 | } |
| 459 | stream_observer.set_expected_bitrate_bps(expected_bitrate_bps); |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 460 | } |
| 461 | |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 462 | VideoSendStream* send_stream = call->CreateVideoSendStream(send_config); |
| 463 | |
| 464 | scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer( |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 465 | test::FrameGeneratorCapturer::Create( |
| 466 | send_stream->Input(), |
| 467 | send_config.encoder_settings.streams.back().width, |
| 468 | send_config.encoder_settings.streams.back().height, |
| 469 | send_config.encoder_settings.streams.back().max_framerate, |
| 470 | Clock::GetRealTimeClock())); |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 471 | |
| 472 | send_stream->StartSending(); |
| 473 | frame_generator_capturer->Start(); |
| 474 | |
| 475 | EXPECT_EQ(kEventSignaled, stream_observer.Wait()); |
| 476 | |
| 477 | frame_generator_capturer->Stop(); |
| 478 | send_stream->StopSending(); |
| 479 | |
| 480 | call->DestroyVideoSendStream(send_stream); |
| 481 | } |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 482 | |
| 483 | void RunRampUpDownUpTest(size_t number_of_streams, bool rtx) { |
| 484 | std::vector<uint32_t> ssrcs; |
| 485 | for (size_t i = 0; i < number_of_streams; ++i) |
| 486 | ssrcs.push_back(static_cast<uint32_t>(i + 1)); |
| 487 | test::DirectTransport receiver_transport; |
| 488 | LowRateStreamObserver stream_observer( |
| 489 | &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx); |
| 490 | |
| 491 | Call::Config call_config(&stream_observer); |
| 492 | webrtc::Config webrtc_config; |
| 493 | call_config.webrtc_config = &webrtc_config; |
| 494 | webrtc_config.Set<PaddingStrategy>(new PaddingStrategy(rtx)); |
| 495 | scoped_ptr<Call> call(Call::Create(call_config)); |
| 496 | VideoSendStream::Config send_config = call->GetDefaultSendConfig(); |
| 497 | |
| 498 | receiver_transport.SetReceiver(call->Receiver()); |
| 499 | |
| 500 | test::FakeEncoder encoder(Clock::GetRealTimeClock()); |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 501 | send_config.encoder_settings = |
| 502 | test::CreateEncoderSettings(&encoder, "FAKE", 125, number_of_streams); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 503 | send_config.rtp.nack.rtp_history_ms = 1000; |
| 504 | send_config.rtp.ssrcs.insert( |
| 505 | send_config.rtp.ssrcs.begin(), ssrcs.begin(), ssrcs.end()); |
| 506 | send_config.rtp.extensions.push_back( |
| 507 | RtpExtension(RtpExtension::kAbsSendTime, kAbsoluteSendTimeExtensionId)); |
| 508 | send_config.suspend_below_min_bitrate = true; |
| 509 | |
| 510 | VideoSendStream* send_stream = call->CreateVideoSendStream(send_config); |
henrik.lundin@webrtc.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 511 | stream_observer.SetSendStream(send_stream); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 512 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 513 | size_t width = 0; |
| 514 | size_t height = 0; |
| 515 | for (size_t i = 0; i < send_config.encoder_settings.streams.size(); ++i) { |
| 516 | size_t stream_width = send_config.encoder_settings.streams[i].width; |
| 517 | size_t stream_height = send_config.encoder_settings.streams[i].height; |
| 518 | if (stream_width > width) |
| 519 | width = stream_width; |
| 520 | if (stream_height > height) |
| 521 | height = stream_height; |
| 522 | } |
| 523 | |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 524 | scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer( |
| 525 | test::FrameGeneratorCapturer::Create(send_stream->Input(), |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 526 | width, |
| 527 | height, |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 528 | 30, |
| 529 | Clock::GetRealTimeClock())); |
| 530 | |
| 531 | send_stream->StartSending(); |
| 532 | frame_generator_capturer->Start(); |
| 533 | |
| 534 | EXPECT_EQ(kEventSignaled, stream_observer.Wait()); |
| 535 | |
henrik.lundin@webrtc.org | 96616cb | 2014-03-13 15:39:27 +0000 | [diff] [blame] | 536 | stream_observer.StopSending(); |
| 537 | receiver_transport.StopSending(); |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 538 | frame_generator_capturer->Stop(); |
| 539 | send_stream->StopSending(); |
| 540 | |
| 541 | call->DestroyVideoSendStream(send_stream); |
| 542 | } |
| 543 | |
andresp@webrtc.org | c6f6696 | 2014-03-17 15:34:57 +0000 | [diff] [blame] | 544 | private: |
| 545 | std::vector<uint32_t> GenerateSsrcs(size_t num_streams, |
| 546 | uint32_t ssrc_offset) { |
| 547 | std::vector<uint32_t> ssrcs; |
| 548 | for (size_t i = 0; i != num_streams; ++i) |
| 549 | ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i)); |
| 550 | return ssrcs; |
| 551 | } |
| 552 | |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 553 | std::map<uint32_t, bool> reserved_ssrcs_; |
| 554 | }; |
| 555 | |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 556 | TEST_F(RampUpTest, SingleStreamWithoutPacing) { |
| 557 | RunRampUpTest(false, false, 1); |
| 558 | } |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 559 | |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 560 | TEST_F(RampUpTest, SingleStreamWithPacing) { |
| 561 | RunRampUpTest(true, false, 1); |
| 562 | } |
| 563 | |
| 564 | TEST_F(RampUpTest, SimulcastWithoutPacing) { |
| 565 | RunRampUpTest(false, false, 3); |
| 566 | } |
| 567 | |
| 568 | TEST_F(RampUpTest, SimulcastWithPacing) { |
| 569 | RunRampUpTest(true, false, 3); |
| 570 | } |
stefan@webrtc.org | 47f0c41 | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 571 | |
pbos@webrtc.org | e2a7a77 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 572 | // TODO(pbos): Re-enable, webrtc:2992. |
andresp@webrtc.org | 700d14b | 2014-03-20 03:23:55 +0000 | [diff] [blame] | 573 | TEST_F(RampUpTest, DISABLED_SimulcastWithPacingAndRtx) { |
| 574 | RunRampUpTest(true, true, 3); |
| 575 | } |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 576 | |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 577 | TEST_F(RampUpTest, UpDownUpOneStream) { RunRampUpDownUpTest(1, false); } |
| 578 | |
henrik.lundin@webrtc.org | 691c5b2 | 2014-03-13 09:21:26 +0000 | [diff] [blame] | 579 | TEST_F(RampUpTest, UpDownUpThreeStreams) { RunRampUpDownUpTest(3, false); } |
henrik.lundin@webrtc.org | 0435a83 | 2014-03-06 09:12:00 +0000 | [diff] [blame] | 580 | |
henrik.lundin@webrtc.org | 691c5b2 | 2014-03-13 09:21:26 +0000 | [diff] [blame] | 581 | TEST_F(RampUpTest, UpDownUpOneStreamRtx) { RunRampUpDownUpTest(1, true); } |
henrik.lundin@webrtc.org | 0435a83 | 2014-03-06 09:12:00 +0000 | [diff] [blame] | 582 | |
henrik.lundin@webrtc.org | 691c5b2 | 2014-03-13 09:21:26 +0000 | [diff] [blame] | 583 | TEST_F(RampUpTest, UpDownUpThreeStreamsRtx) { RunRampUpDownUpTest(3, true); } |
henrik.lundin@webrtc.org | c766098 | 2014-03-06 07:19:28 +0000 | [diff] [blame] | 584 | |
pbos@webrtc.org | fa996f2 | 2013-09-10 09:26:25 +0000 | [diff] [blame] | 585 | } // namespace webrtc |