Refactor ramp-up tests to have separate help files for the test classes, to make things more reusable.

R=pbos@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/18739004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6625 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org 2014-07-08 13:59:46 +00:00
parent ecb8723402
commit 3d7da88e06
4 changed files with 605 additions and 507 deletions

View File

@ -14,16 +14,6 @@
#include "webrtc/typedefs.h" #include "webrtc/typedefs.h"
namespace webrtc { namespace webrtc {
struct PaddingStrategy {
PaddingStrategy()
: redundant_payloads(false) {}
explicit PaddingStrategy(bool redundant_payloads)
: redundant_payloads(redundant_payloads) {}
virtual ~PaddingStrategy() {}
const bool redundant_payloads;
};
struct RemoteBitrateEstimatorMinRate { struct RemoteBitrateEstimatorMinRate {
RemoteBitrateEstimatorMinRate() : min_rate(30000) {} RemoteBitrateEstimatorMinRate() : min_rate(30000) {}
RemoteBitrateEstimatorMinRate(uint32_t min_rate) : min_rate(min_rate) {} RemoteBitrateEstimatorMinRate(uint32_t min_rate) : min_rate(min_rate) {}

View File

@ -7,49 +7,36 @@
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <assert.h>
#include <map>
#include <string>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/call.h"
#include "webrtc/common.h"
#include "webrtc/experiments.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/test/call_test.h"
#include "webrtc/test/direct_transport.h"
#include "webrtc/test/encoder_settings.h"
#include "webrtc/test/fake_decoder.h"
#include "webrtc/test/fake_encoder.h"
#include "webrtc/test/frame_generator_capturer.h"
#include "webrtc/test/testsupport/perf_test.h" #include "webrtc/test/testsupport/perf_test.h"
#include "webrtc/video/transport_adapter.h" #include "webrtc/video/rampup_tests.h"
namespace webrtc { namespace webrtc {
namespace { namespace {
static const int kTransmissionTimeOffsetExtensionId = 6;
static const int kMaxPacketSize = 1500;
static const unsigned int kSingleStreamTargetBps = 1000000;
class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { static const int kMaxPacketSize = 1500;
public:
typedef std::map<uint32_t, int> BytesSentMap; std::vector<uint32_t> GenerateSsrcs(size_t num_streams,
typedef std::map<uint32_t, uint32_t> SsrcMap; uint32_t ssrc_offset) {
StreamObserver(const SsrcMap& rtx_media_ssrcs, std::vector<uint32_t> ssrcs;
for (size_t i = 0; i != num_streams; ++i)
ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
return ssrcs;
}
} // namespace
StreamObserver::StreamObserver(const SsrcMap& rtx_media_ssrcs,
newapi::Transport* feedback_transport, newapi::Transport* feedback_transport,
Clock* clock) Clock* clock,
RemoteBitrateEstimatorFactory* rbe_factory,
RateControlType control_type)
: clock_(clock), : clock_(clock),
test_done_(EventWrapper::Create()), test_done_(EventWrapper::Create()),
rtp_parser_(RtpHeaderParser::Create()), rtp_parser_(RtpHeaderParser::Create()),
@ -66,7 +53,9 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
rtx_media_sent_(0), rtx_media_sent_(0),
total_packets_sent_(0), total_packets_sent_(0),
padding_packets_sent_(0), padding_packets_sent_(0),
rtx_media_packets_sent_(0) { rtx_media_packets_sent_(0),
test_start_ms_(clock_->TimeInMilliseconds()),
ramp_up_finished_ms_(0) {
// Ideally we would only have to instantiate an RtcpSender, an // Ideally we would only have to instantiate an RtcpSender, an
// RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current
// state of the RTP module we need a full module and receive statistics to // state of the RTP module we need a full module and receive statistics to
@ -78,27 +67,29 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
rtp_rtcp_->SetREMBStatus(true); rtp_rtcp_->SetREMBStatus(true);
rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound);
rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
kAbsSendTimeExtensionId);
rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset,
kTransmissionTimeOffsetExtensionId); kTransmissionTimeOffsetExtensionId);
AbsoluteSendTimeRemoteBitrateEstimatorFactory rbe_factory;
const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000;
remote_bitrate_estimator_.reset( remote_bitrate_estimator_.reset(
rbe_factory.Create(this, clock, kMimdControl, rbe_factory->Create(this, clock, control_type,
kRemoteBitrateEstimatorMinBitrateBps)); kRemoteBitrateEstimatorMinBitrateBps));
} }
void set_expected_bitrate_bps(unsigned int expected_bitrate_bps) { void StreamObserver::set_expected_bitrate_bps(
unsigned int expected_bitrate_bps) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
expected_bitrate_bps_ = expected_bitrate_bps; expected_bitrate_bps_ = expected_bitrate_bps;
} }
void set_start_bitrate_bps(unsigned int start_bitrate_bps) { void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
start_bitrate_bps_ = start_bitrate_bps; start_bitrate_bps_ = start_bitrate_bps;
} }
virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, void StreamObserver::OnReceiveBitrateChanged(
unsigned int bitrate) OVERRIDE { const std::vector<unsigned int>& ssrcs, unsigned int bitrate) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
assert(expected_bitrate_bps_ > 0); assert(expected_bitrate_bps_ > 0);
if (start_bitrate_bps_ != 0) { if (start_bitrate_bps_ != 0) {
@ -112,6 +103,7 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
start_bitrate_bps_ = 0; start_bitrate_bps_ = 0;
} }
if (bitrate >= expected_bitrate_bps_) { if (bitrate >= expected_bitrate_bps_) {
ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
// Just trigger if there was any rtx padding packet. // Just trigger if there was any rtx padding packet.
if (rtx_media_ssrcs_.empty() || rtx_media_sent_ > 0) { if (rtx_media_ssrcs_.empty() || rtx_media_sent_ > 0) {
TriggerTestDone(); TriggerTestDone();
@ -122,10 +114,10 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
rtp_rtcp_->Process(); rtp_rtcp_->Process();
} }
virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE { bool StreamObserver::SendRtp(const uint8_t* packet, size_t length) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
RTPHeader header; RTPHeader header;
EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header)); EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header));
receive_stats_->IncomingPacket(header, length, false); receive_stats_->IncomingPacket(header, length, false);
payload_registry_->SetIncomingPayloadType(header); payload_registry_->SetIncomingPayloadType(header);
remote_bitrate_estimator_->IncomingPacket( remote_bitrate_estimator_->IncomingPacket(
@ -151,21 +143,21 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
rtx_media_ssrcs_[header.ssrc], rtx_media_ssrcs_[header.ssrc],
header); header);
length = restored_length; length = restored_length;
EXPECT_TRUE(rtp_parser_->Parse(restored_packet, length, &header)); EXPECT_TRUE(rtp_parser_->Parse(
restored_packet, static_cast<int>(length), &header));
} else { } else {
rtp_rtcp_->SetRemoteSSRC(header.ssrc); rtp_rtcp_->SetRemoteSSRC(header.ssrc);
} }
return true; return true;
} }
virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE { bool StreamObserver::SendRtcp(const uint8_t* packet, size_t length) {
return true; return true;
} }
EventTypeWrapper Wait() { return test_done_->Wait(120 * 1000); } EventTypeWrapper StreamObserver::Wait() { return test_done_->Wait(120 * 1000); }
private: void StreamObserver::ReportResult(const std::string& measurement,
void ReportResult(const std::string& measurement,
size_t value, size_t value,
const std::string& units) { const std::string& units) {
webrtc::test::PrintResult( webrtc::test::PrintResult(
@ -174,42 +166,25 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
value, units, false); value, units, false);
} }
void TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) { void StreamObserver::TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) {
ReportResult("total-sent", total_sent_, "bytes"); ReportResult("ramp-up-total-sent", total_sent_, "bytes");
ReportResult("padding-sent", padding_sent_, "bytes"); ReportResult("ramp-up-padding-sent", padding_sent_, "bytes");
ReportResult("rtx-media-sent", rtx_media_sent_, "bytes"); ReportResult("ramp-up-rtx-media-sent", rtx_media_sent_, "bytes");
ReportResult("total-packets-sent", total_packets_sent_, "packets"); ReportResult("ramp-up-total-packets-sent", total_packets_sent_, "packets");
ReportResult("padding-packets-sent", padding_packets_sent_, "packets"); ReportResult("ramp-up-padding-packets-sent",
ReportResult("rtx-packets-sent", rtx_media_packets_sent_, "packets"); padding_packets_sent_,
"packets");
ReportResult("ramp-up-rtx-packets-sent",
rtx_media_packets_sent_,
"packets");
ReportResult("ramp-up-time",
ramp_up_finished_ms_ - test_start_ms_,
"milliseconds");
test_done_->Set(); test_done_->Set();
} }
Clock* const clock_; LowRateStreamObserver::LowRateStreamObserver(
const scoped_ptr<EventWrapper> test_done_; newapi::Transport* feedback_transport,
const scoped_ptr<RtpHeaderParser> rtp_parser_;
scoped_ptr<RtpRtcp> rtp_rtcp_;
internal::TransportAdapter feedback_transport_;
const scoped_ptr<ReceiveStatistics> receive_stats_;
const scoped_ptr<RTPPayloadRegistry> payload_registry_;
scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
const scoped_ptr<CriticalSectionWrapper> crit_;
unsigned int expected_bitrate_bps_ GUARDED_BY(crit_);
unsigned int start_bitrate_bps_ GUARDED_BY(crit_);
SsrcMap rtx_media_ssrcs_ GUARDED_BY(crit_);
size_t total_sent_ GUARDED_BY(crit_);
size_t padding_sent_ GUARDED_BY(crit_);
size_t rtx_media_sent_ GUARDED_BY(crit_);
int total_packets_sent_ GUARDED_BY(crit_);
int padding_packets_sent_ GUARDED_BY(crit_);
int rtx_media_packets_sent_ GUARDED_BY(crit_);
};
class LowRateStreamObserver : public test::DirectTransport,
public RemoteBitrateObserver,
public PacketReceiver {
public:
LowRateStreamObserver(newapi::Transport* feedback_transport,
Clock* clock, Clock* clock,
size_t number_of_streams, size_t number_of_streams,
bool rtx_used) bool rtx_used)
@ -250,12 +225,13 @@ class LowRateStreamObserver : public test::DirectTransport,
test::DirectTransport::SetReceiver(this); test::DirectTransport::SetReceiver(this);
} }
virtual void SetSendStream(const VideoSendStream* send_stream) { void LowRateStreamObserver::SetSendStream(const VideoSendStream* send_stream) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
send_stream_ = send_stream; send_stream_ = send_stream;
} }
virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, void LowRateStreamObserver::OnReceiveBitrateChanged(
const std::vector<unsigned int>& ssrcs,
unsigned int bitrate) { unsigned int bitrate) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
rtp_rtcp_->SetREMBData( rtp_rtcp_->SetREMBData(
@ -264,7 +240,7 @@ class LowRateStreamObserver : public test::DirectTransport,
last_remb_bps_ = bitrate; last_remb_bps_ = bitrate;
} }
virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE { bool LowRateStreamObserver::SendRtp(const uint8_t* data, size_t length) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
sent_bytes_ += length; sent_bytes_ += length;
int64_t now_ms = clock_->TimeInMilliseconds(); int64_t now_ms = clock_->TimeInMilliseconds();
@ -286,11 +262,11 @@ class LowRateStreamObserver : public test::DirectTransport,
return test::DirectTransport::SendRtp(data, length); return test::DirectTransport::SendRtp(data, length);
} }
virtual DeliveryStatus DeliverPacket(const uint8_t* packet, PacketReceiver::DeliveryStatus LowRateStreamObserver::DeliverPacket(
size_t length) OVERRIDE { const uint8_t* packet, size_t length) {
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
RTPHeader header; RTPHeader header;
EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header)); EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header));
receive_stats_->IncomingPacket(header, length, false); receive_stats_->IncomingPacket(header, length, false);
remote_bitrate_estimator_->IncomingPacket( remote_bitrate_estimator_->IncomingPacket(
clock_->TimeInMilliseconds(), static_cast<int>(length - 12), header); clock_->TimeInMilliseconds(), static_cast<int>(length - 12), header);
@ -301,16 +277,15 @@ class LowRateStreamObserver : public test::DirectTransport,
return DELIVERY_OK; return DELIVERY_OK;
} }
virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE { bool LowRateStreamObserver::SendRtcp(const uint8_t* packet, size_t length) {
return true; return true;
} }
// Produces a string similar to "1stream_nortx", depending on the values of std::string LowRateStreamObserver::GetModifierString() {
// number_of_streams_ and rtx_used_;
std::string GetModifierString() {
std::string str("_"); std::string str("_");
char temp_str[5]; char temp_str[5];
sprintf(temp_str, "%i", static_cast<int>(number_of_streams_)); sprintf(temp_str, "%i",
static_cast<int>(number_of_streams_));
str += std::string(temp_str); str += std::string(temp_str);
str += "stream"; str += "stream";
str += (number_of_streams_ > 1 ? "s" : ""); str += (number_of_streams_ > 1 ? "s" : "");
@ -320,8 +295,7 @@ class LowRateStreamObserver : public test::DirectTransport,
return str; return str;
} }
// This method defines the state machine for the ramp up-down-up test. void LowRateStreamObserver::EvolveTestState(unsigned int bitrate_bps) {
void EvolveTestState(unsigned int bitrate_bps) {
int64_t now = clock_->TimeInMilliseconds(); int64_t now = clock_->TimeInMilliseconds();
CriticalSectionScoped lock(crit_.get()); CriticalSectionScoped lock(crit_.get());
assert(send_stream_ != NULL); assert(send_stream_ != NULL);
@ -388,45 +362,14 @@ class LowRateStreamObserver : public test::DirectTransport,
} }
} }
EventTypeWrapper Wait() { EventTypeWrapper LowRateStreamObserver::Wait() {
return test_done_->Wait(test::CallTest::kLongTimeoutMs); return test_done_->Wait(test::CallTest::kLongTimeoutMs);
} }
private: void RampUpTest::RunRampUpTest(bool rtx,
static const unsigned int kHighBandwidthLimitBps = 80000;
static const unsigned int kExpectedHighBitrateBps = 60000;
static const unsigned int kLowBandwidthLimitBps = 20000;
static const unsigned int kExpectedLowBitrateBps = 20000;
enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
Clock* const clock_;
const size_t number_of_streams_;
const bool rtx_used_;
const scoped_ptr<EventWrapper> test_done_;
const scoped_ptr<RtpHeaderParser> rtp_parser_;
scoped_ptr<RtpRtcp> rtp_rtcp_;
internal::TransportAdapter feedback_transport_;
const scoped_ptr<ReceiveStatistics> receive_stats_;
scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
scoped_ptr<CriticalSectionWrapper> crit_;
const VideoSendStream* send_stream_ GUARDED_BY(crit_);
FakeNetworkPipe::Config forward_transport_config_ GUARDED_BY(crit_);
TestStates test_state_ GUARDED_BY(crit_);
int64_t state_start_ms_ GUARDED_BY(crit_);
int64_t interval_start_ms_ GUARDED_BY(crit_);
unsigned int last_remb_bps_ GUARDED_BY(crit_);
size_t sent_bytes_ GUARDED_BY(crit_);
size_t total_overuse_bytes_ GUARDED_BY(crit_);
bool suspended_in_stats_ GUARDED_BY(crit_);
};
} // namespace
class RampUpTest : public test::CallTest {
protected:
void RunRampUpTest(bool rtx,
size_t num_streams, size_t num_streams,
unsigned int start_bitrate_bps) { unsigned int start_bitrate_bps,
const std::string& extension_type) {
std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100)); std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100));
std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200)); std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200));
StreamObserver::SsrcMap rtx_ssrc_map; StreamObserver::SsrcMap rtx_ssrc_map;
@ -434,10 +377,29 @@ class RampUpTest : public test::CallTest {
for (size_t i = 0; i < ssrcs.size(); ++i) for (size_t i = 0; i < ssrcs.size(); ++i)
rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i]; rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i];
} }
CreateSendConfig(num_streams);
scoped_ptr<RemoteBitrateEstimatorFactory> rbe_factory;
RateControlType control_type;
if (extension_type == RtpExtension::kAbsSendTime) {
control_type = kAimdControl;
rbe_factory.reset(new AbsoluteSendTimeRemoteBitrateEstimatorFactory);
send_config_.rtp.extensions.push_back(RtpExtension(
extension_type.c_str(), kAbsSendTimeExtensionId));
} else {
control_type = kMimdControl;
rbe_factory.reset(new RemoteBitrateEstimatorFactory);
send_config_.rtp.extensions.push_back(RtpExtension(
extension_type.c_str(), kTransmissionTimeOffsetExtensionId));
}
test::DirectTransport receiver_transport; test::DirectTransport receiver_transport;
StreamObserver stream_observer(rtx_ssrc_map, StreamObserver stream_observer(rtx_ssrc_map,
&receiver_transport, &receiver_transport,
Clock::GetRealTimeClock()); Clock::GetRealTimeClock(),
rbe_factory.get(),
control_type);
Call::Config call_config(&stream_observer); Call::Config call_config(&stream_observer);
if (start_bitrate_bps != 0) { if (start_bitrate_bps != 0) {
@ -446,7 +408,6 @@ class RampUpTest : public test::CallTest {
} }
CreateSenderCall(call_config); CreateSenderCall(call_config);
CreateSendConfig(num_streams);
receiver_transport.SetReceiver(sender_call_->Receiver()); receiver_transport.SetReceiver(sender_call_->Receiver());
@ -462,8 +423,6 @@ class RampUpTest : public test::CallTest {
send_config_.rtp.rtx.ssrcs = rtx_ssrcs; send_config_.rtp.rtx.ssrcs = rtx_ssrcs;
send_config_.rtp.rtx.pad_with_redundant_payloads = true; send_config_.rtp.rtx.pad_with_redundant_payloads = true;
} }
send_config_.rtp.extensions.push_back(RtpExtension(
RtpExtension::kTOffset, kTransmissionTimeOffsetExtensionId));
if (num_streams == 1) { if (num_streams == 1) {
// For single stream rampup until 1mbps // For single stream rampup until 1mbps
@ -490,18 +449,12 @@ class RampUpTest : public test::CallTest {
DestroyStreams(); DestroyStreams();
} }
void RunRampUpDownUpTest(size_t number_of_streams, bool rtx) { void RampUpTest::RunRampUpDownUpTest(size_t number_of_streams, bool rtx) {
std::vector<uint32_t> ssrcs;
for (size_t i = 0; i < number_of_streams; ++i)
ssrcs.push_back(static_cast<uint32_t>(i + 1));
test::DirectTransport receiver_transport; test::DirectTransport receiver_transport;
LowRateStreamObserver stream_observer( LowRateStreamObserver stream_observer(
&receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx); &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx);
Call::Config call_config(&stream_observer); Call::Config call_config(&stream_observer);
webrtc::Config webrtc_config;
call_config.webrtc_config = &webrtc_config;
webrtc_config.Set<PaddingStrategy>(new PaddingStrategy(rtx));
CreateSenderCall(call_config); CreateSenderCall(call_config);
receiver_transport.SetReceiver(sender_call_->Receiver()); receiver_transport.SetReceiver(sender_call_->Receiver());
@ -511,6 +464,11 @@ class RampUpTest : public test::CallTest {
send_config_.rtp.extensions.push_back(RtpExtension( send_config_.rtp.extensions.push_back(RtpExtension(
RtpExtension::kTOffset, kTransmissionTimeOffsetExtensionId)); RtpExtension::kTOffset, kTransmissionTimeOffsetExtensionId));
send_config_.suspend_below_min_bitrate = true; send_config_.suspend_below_min_bitrate = true;
if (rtx) {
send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
send_config_.rtp.rtx.ssrcs = GenerateSsrcs(number_of_streams, 200);
send_config_.rtp.rtx.pad_with_redundant_payloads = true;
}
CreateStreams(); CreateStreams();
stream_observer.SetSendStream(send_stream_); stream_observer.SetSendStream(send_stream_);
@ -525,30 +483,20 @@ class RampUpTest : public test::CallTest {
DestroyStreams(); DestroyStreams();
} }
private:
std::vector<uint32_t> GenerateSsrcs(size_t num_streams,
uint32_t ssrc_offset) {
std::vector<uint32_t> ssrcs;
for (size_t i = 0; i != num_streams; ++i)
ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
return ssrcs;
}
};
TEST_F(RampUpTest, SingleStream) { TEST_F(RampUpTest, SingleStream) {
RunRampUpTest(false, 1, 0); RunRampUpTest(false, 1, 0, RtpExtension::kTOffset);
} }
TEST_F(RampUpTest, Simulcast) { TEST_F(RampUpTest, Simulcast) {
RunRampUpTest(false, 3, 0); RunRampUpTest(false, 3, 0, RtpExtension::kTOffset);
} }
TEST_F(RampUpTest, SimulcastWithRtx) { TEST_F(RampUpTest, SimulcastWithRtx) {
RunRampUpTest(true, 3, 0); RunRampUpTest(true, 3, 0, RtpExtension::kTOffset);
} }
TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) { TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) {
RunRampUpTest(false, 1, 0.9 * kSingleStreamTargetBps); RunRampUpTest(false, 1, 0.9 * kSingleStreamTargetBps, RtpExtension::kTOffset);
} }
TEST_F(RampUpTest, UpDownUpOneStream) { RunRampUpDownUpTest(1, false); } TEST_F(RampUpTest, UpDownUpOneStream) { RunRampUpDownUpTest(1, false); }

159
webrtc/video/rampup_tests.h Normal file
View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_VIDEO_RAMPUP_TESTS_H_
#define WEBRTC_VIDEO_RAMPUP_TESTS_H_
#include <map>
#include <string>
#include <vector>
#include "webrtc/call.h"
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/test/call_test.h"
#include "webrtc/video/transport_adapter.h"
namespace webrtc {
static const int kTransmissionTimeOffsetExtensionId = 6;
static const int kAbsSendTimeExtensionId = 7;
static const unsigned int kSingleStreamTargetBps = 1000000;
class Clock;
class CriticalSectionWrapper;
class ReceiveStatistics;
class RtpHeaderParser;
class RTPPayloadRegistry;
class RtpRtcp;
class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
public:
typedef std::map<uint32_t, int> BytesSentMap;
typedef std::map<uint32_t, uint32_t> SsrcMap;
StreamObserver(const SsrcMap& rtx_media_ssrcs,
newapi::Transport* feedback_transport,
Clock* clock,
RemoteBitrateEstimatorFactory* rbe_factory,
RateControlType control_type);
void set_expected_bitrate_bps(unsigned int expected_bitrate_bps);
void set_start_bitrate_bps(unsigned int start_bitrate_bps);
virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
unsigned int bitrate) OVERRIDE;
virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE;
virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
EventTypeWrapper Wait();
private:
void ReportResult(const std::string& measurement,
size_t value,
const std::string& units);
void TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_);
Clock* const clock_;
const scoped_ptr<EventWrapper> test_done_;
const scoped_ptr<RtpHeaderParser> rtp_parser_;
scoped_ptr<RtpRtcp> rtp_rtcp_;
internal::TransportAdapter feedback_transport_;
const scoped_ptr<ReceiveStatistics> receive_stats_;
const scoped_ptr<RTPPayloadRegistry> payload_registry_;
scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
const scoped_ptr<CriticalSectionWrapper> crit_;
unsigned int expected_bitrate_bps_ GUARDED_BY(crit_);
unsigned int start_bitrate_bps_ GUARDED_BY(crit_);
SsrcMap rtx_media_ssrcs_ GUARDED_BY(crit_);
size_t total_sent_ GUARDED_BY(crit_);
size_t padding_sent_ GUARDED_BY(crit_);
size_t rtx_media_sent_ GUARDED_BY(crit_);
int total_packets_sent_ GUARDED_BY(crit_);
int padding_packets_sent_ GUARDED_BY(crit_);
int rtx_media_packets_sent_ GUARDED_BY(crit_);
int64_t test_start_ms_ GUARDED_BY(crit_);
int64_t ramp_up_finished_ms_ GUARDED_BY(crit_);
};
class LowRateStreamObserver : public test::DirectTransport,
public RemoteBitrateObserver,
public PacketReceiver {
public:
LowRateStreamObserver(newapi::Transport* feedback_transport,
Clock* clock,
size_t number_of_streams,
bool rtx_used);
virtual void SetSendStream(const VideoSendStream* send_stream);
virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
unsigned int bitrate);
virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE;
virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
size_t length) OVERRIDE;
virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
// Produces a string similar to "1stream_nortx", depending on the values of
// number_of_streams_ and rtx_used_;
std::string GetModifierString();
// This method defines the state machine for the ramp up-down-up test.
void EvolveTestState(unsigned int bitrate_bps);
EventTypeWrapper Wait();
private:
static const unsigned int kHighBandwidthLimitBps = 80000;
static const unsigned int kExpectedHighBitrateBps = 60000;
static const unsigned int kLowBandwidthLimitBps = 20000;
static const unsigned int kExpectedLowBitrateBps = 20000;
enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
Clock* const clock_;
const size_t number_of_streams_;
const bool rtx_used_;
const scoped_ptr<EventWrapper> test_done_;
const scoped_ptr<RtpHeaderParser> rtp_parser_;
scoped_ptr<RtpRtcp> rtp_rtcp_;
internal::TransportAdapter feedback_transport_;
const scoped_ptr<ReceiveStatistics> receive_stats_;
scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
scoped_ptr<CriticalSectionWrapper> crit_;
const VideoSendStream* send_stream_ GUARDED_BY(crit_);
FakeNetworkPipe::Config forward_transport_config_ GUARDED_BY(crit_);
TestStates test_state_ GUARDED_BY(crit_);
int64_t state_start_ms_ GUARDED_BY(crit_);
int64_t interval_start_ms_ GUARDED_BY(crit_);
unsigned int last_remb_bps_ GUARDED_BY(crit_);
size_t sent_bytes_ GUARDED_BY(crit_);
size_t total_overuse_bytes_ GUARDED_BY(crit_);
bool suspended_in_stats_ GUARDED_BY(crit_);
};
class RampUpTest : public test::CallTest {
protected:
void RunRampUpTest(bool rtx,
size_t num_streams,
unsigned int start_bitrate_bps,
const std::string& extension_type);
void RunRampUpDownUpTest(size_t number_of_streams, bool rtx);
};
} // namespace webrtc
#endif // WEBRTC_VIDEO_RAMPUP_TESTS_H_

View File

@ -79,6 +79,7 @@
'video/call_perf_tests.cc', 'video/call_perf_tests.cc',
'video/full_stack.cc', 'video/full_stack.cc',
'video/rampup_tests.cc', 'video/rampup_tests.cc',
'video/rampup_tests.h',
], ],
'dependencies': [ 'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',