Skip to content

Commit 0e4615a

Browse files
Integrate send-side BWE into simulation framework.
BUG=4173 [email protected], [email protected] Review URL: https://webrtc-codereview.appspot.com/34699004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8123 4adac7df-926f-26a2-2b94-8c16560cd09d
1 parent 6df5ade commit 0e4615a

File tree

4 files changed

+188
-47
lines changed

4 files changed

+188
-47
lines changed

webrtc/modules/remote_bitrate_estimator/test/bwe_test.cc

+37-10
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h"
1212

13+
#include "webrtc/modules/interface/module_common_types.h"
1314
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_baselinefile.h"
1415
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h"
1516
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
17+
#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
1618
#include "webrtc/system_wrappers/interface/clock.h"
1719
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
1820

@@ -23,13 +25,13 @@ namespace webrtc {
2325
namespace testing {
2426
namespace bwe {
2527

26-
class TestedEstimator : public RemoteBitrateObserver {
28+
class PacketReceiver : public RemoteBitrateObserver {
2729
public:
2830
static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000;
2931
static const int kDelayPlotIntervalMs = 100;
3032

31-
TestedEstimator(const string& test_name,
32-
const BweTestConfig::EstimatorConfig& config)
33+
PacketReceiver(const string& test_name,
34+
const BweTestConfig::EstimatorConfig& config)
3335
: debug_name_(config.debug_name),
3436
delay_log_prefix_(),
3537
estimate_log_prefix_(),
@@ -38,9 +40,12 @@ class TestedEstimator : public RemoteBitrateObserver {
3840
plot_estimate_(config.plot_estimate),
3941
clock_(0),
4042
stats_(),
43+
recv_stats_(ReceiveStatistics::Create(&clock_)),
4144
latest_estimate_bps_(-1),
4245
estimator_(config.estimator_factory->Create(
43-
this, &clock_, config.control_type,
46+
this,
47+
&clock_,
48+
config.control_type,
4449
kRemoteBitrateEstimatorMinBitrateBps)),
4550
baseline_(BaseLineFileInterface::Create(test_name + "_" + debug_name_,
4651
config.update_baseline)) {
@@ -60,6 +65,8 @@ class TestedEstimator : public RemoteBitrateObserver {
6065
void EatPacket(const Packet& packet) {
6166
BWE_TEST_LOGGING_CONTEXT(debug_name_);
6267

68+
recv_stats_->IncomingPacket(packet.header(), packet.payload_size(), false);
69+
6370
latest_estimate_bps_ = -1;
6471

6572
// We're treating the send time (from previous filter) as the arrival
@@ -89,12 +96,19 @@ class TestedEstimator : public RemoteBitrateObserver {
8996
ASSERT_TRUE(packet_time_ms == clock_.TimeInMilliseconds());
9097
}
9198

92-
bool CheckEstimate(PacketSender::Feedback* feedback) {
99+
bool GetFeedback(PacketSender::Feedback* feedback) {
93100
assert(feedback);
94101
BWE_TEST_LOGGING_CONTEXT(debug_name_);
95102
uint32_t estimated_bps = 0;
96103
if (LatestEstimate(&estimated_bps)) {
97104
feedback->estimated_bps = estimated_bps;
105+
StatisticianMap statisticians = recv_stats_->GetActiveStatisticians();
106+
if (statisticians.empty()) {
107+
feedback->report_block = RTCPReportBlock();
108+
} else {
109+
feedback->report_block =
110+
BuildReportBlock(statisticians.begin()->second);
111+
}
98112
baseline_->Estimate(clock_.TimeInMilliseconds(), estimated_bps);
99113

100114
double estimated_kbps = static_cast<double>(estimated_bps) / 1000.0;
@@ -123,6 +137,18 @@ class TestedEstimator : public RemoteBitrateObserver {
123137
}
124138

125139
private:
140+
static RTCPReportBlock BuildReportBlock(StreamStatistician* statistician) {
141+
RTCPReportBlock report_block;
142+
RtcpStatistics stats;
143+
if (!statistician->GetStatistics(&stats, true))
144+
return report_block;
145+
report_block.fractionLost = stats.fraction_lost;
146+
report_block.cumulativeLost = stats.cumulative_lost;
147+
report_block.extendedHighSeqNum = stats.extended_max_sequence_number;
148+
report_block.jitter = stats.jitter;
149+
return report_block;
150+
}
151+
126152
bool LatestEstimate(uint32_t* estimate_bps) {
127153
if (latest_estimate_bps_ < 0) {
128154
vector<unsigned int> ssrcs;
@@ -144,11 +170,12 @@ class TestedEstimator : public RemoteBitrateObserver {
144170
bool plot_estimate_;
145171
SimulatedClock clock_;
146172
Stats<double> stats_;
173+
scoped_ptr<ReceiveStatistics> recv_stats_;
147174
int64_t latest_estimate_bps_;
148175
scoped_ptr<RemoteBitrateEstimator> estimator_;
149176
scoped_ptr<BaseLineFileInterface> baseline_;
150177

151-
DISALLOW_IMPLICIT_CONSTRUCTORS(TestedEstimator);
178+
DISALLOW_IMPLICIT_CONSTRUCTORS(PacketReceiver);
152179
};
153180

154181
class PacketProcessorRunner {
@@ -242,8 +269,8 @@ void BweTest::SetupTestFromConfig(const BweTestConfig& config) {
242269
for (vector<BweTestConfig::EstimatorConfig>::const_iterator it =
243270
config.estimator_configs.begin(); it != config.estimator_configs.end();
244271
++it) {
245-
estimators_.insert(std::make_pair(it->flow_id, new TestedEstimator(
246-
test_name, *it)));
272+
estimators_.insert(
273+
std::make_pair(it->flow_id, new PacketReceiver(test_name, *it)));
247274
}
248275
BWE_TEST_LOGGING_GLOBAL_ENABLE(false);
249276
}
@@ -277,7 +304,7 @@ void BweTest::VerboseLogging(bool enable) {
277304
}
278305

279306
void BweTest::GiveFeedbackToAffectedSenders(int flow_id,
280-
TestedEstimator* estimator) {
307+
PacketReceiver* estimator) {
281308
std::list<PacketSender*> affected_senders;
282309
for (std::vector<PacketSender*>::iterator psit =
283310
senders_.begin(); psit != senders_.end(); ++psit) {
@@ -287,7 +314,7 @@ void BweTest::GiveFeedbackToAffectedSenders(int flow_id,
287314
}
288315
}
289316
PacketSender::Feedback feedback = {0};
290-
if (estimator->CheckEstimate(&feedback) && !affected_senders.empty()) {
317+
if (estimator->GetFeedback(&feedback) && !affected_senders.empty()) {
291318
// Allocate the bitrate evenly between the senders.
292319
feedback.estimated_bps /= affected_senders.size();
293320
for (std::list<PacketSender*>::iterator psit = affected_senders.begin();

webrtc/modules/remote_bitrate_estimator/test/bwe_test.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct BweTestConfig {
8686
std::vector<EstimatorConfig> estimator_configs;
8787
};
8888

89-
class TestedEstimator;
89+
class PacketReceiver;
9090
class PacketProcessorRunner;
9191

9292
class BweTest : public PacketProcessorListener {
@@ -104,11 +104,11 @@ class BweTest : public PacketProcessorListener {
104104
std::string GetTestName() const;
105105

106106
private:
107-
typedef std::map<int, TestedEstimator*> EstimatorMap;
107+
typedef std::map<int, PacketReceiver*> EstimatorMap;
108108

109109
void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in,
110110
Packets* out);
111-
void GiveFeedbackToAffectedSenders(int flow_id, TestedEstimator* estimator);
111+
void GiveFeedbackToAffectedSenders(int flow_id, PacketReceiver* estimator);
112112

113113
int64_t run_time_ms_;
114114
int64_t time_now_ms_;

webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc

+100-24
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,8 @@ void TraceBasedDeliveryFilter::ProceedToNextSlot() {
538538
PacketSender::PacketSender(PacketProcessorListener* listener)
539539
: PacketProcessor(listener, true) {}
540540

541-
PacketSender::PacketSender(PacketProcessorListener* listener,
542-
const FlowIds& flow_ids)
543-
: PacketProcessor(listener, flow_ids, true) {
544-
541+
PacketSender::PacketSender(PacketProcessorListener* listener, int flow_id)
542+
: PacketProcessor(listener, FlowIds(1, flow_id), true) {
545543
}
546544

547545
VideoSender::VideoSender(int flow_id,
@@ -550,7 +548,7 @@ VideoSender::VideoSender(int flow_id,
550548
uint32_t kbps,
551549
uint32_t ssrc,
552550
int64_t first_frame_offset_ms)
553-
: PacketSender(listener, FlowIds(1, flow_id)),
551+
: PacketSender(listener, flow_id),
554552
kMaxPayloadSizeBytes(1200),
555553
kTimestampBase(0xff80ff00ul),
556554
frame_period_ms_(1000.0 / fps),
@@ -677,17 +675,73 @@ uint32_t PeriodicKeyFrameSender::NextPacketSize(uint32_t frame_size,
677675
return std::min(avg_size, remaining_payload);
678676
}
679677

678+
RegularVideoSender::RegularVideoSender(PacketProcessorListener* listener,
679+
uint32_t kbps,
680+
AdaptiveVideoSender* source)
681+
// It is important that the first_frame_offset and the initial time of
682+
// clock_ are both zero, otherwise we can't have absolute time in this
683+
// class.
684+
: PacketSender(listener, source->flow_ids()[0]),
685+
clock_(0),
686+
start_of_run_ms_(0),
687+
bitrate_controller_(BitrateController::CreateBitrateController(&clock_,
688+
false)),
689+
feedback_observer_(bitrate_controller_->CreateRtcpBandwidthObserver()),
690+
source_(source),
691+
modules_() {
692+
const int kMinBitrateBps = 10000;
693+
const int kMaxBitrateBps = 20000000;
694+
bitrate_controller_->SetBitrateObserver(this, 1000 * kbps, kMinBitrateBps,
695+
kMaxBitrateBps);
696+
modules_.push_back(bitrate_controller_.get());
697+
}
698+
699+
RegularVideoSender::~RegularVideoSender() {
700+
}
701+
702+
void RegularVideoSender::GiveFeedback(const Feedback& feedback) {
703+
feedback_observer_->OnReceivedEstimatedBitrate(feedback.estimated_bps);
704+
ReportBlockList report_blocks;
705+
report_blocks.push_back(feedback.report_block);
706+
feedback_observer_->OnReceivedRtcpReceiverReport(report_blocks, 0,
707+
clock_.TimeInMilliseconds());
708+
bitrate_controller_->Process();
709+
}
710+
711+
void RegularVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
712+
start_of_run_ms_ = clock_.TimeInMilliseconds();
713+
source_->RunFor(time_ms, in_out);
714+
clock_.AdvanceTimeMilliseconds(time_ms);
715+
}
716+
717+
void RegularVideoSender::OnNetworkChanged(uint32_t target_bitrate_bps,
718+
uint8_t fraction_lost,
719+
int64_t rtt) {
720+
PacketSender::Feedback feedback;
721+
feedback.estimated_bps = target_bitrate_bps;
722+
source_->GiveFeedback(feedback);
723+
std::stringstream ss;
724+
ss << "SendEstimate_" << flow_ids()[0] << "#1";
725+
BWE_TEST_LOGGING_PLOT(ss.str(), clock_.TimeInMilliseconds(),
726+
target_bitrate_bps / 1000);
727+
}
728+
680729
PacedVideoSender::PacedVideoSender(PacketProcessorListener* listener,
681730
uint32_t kbps,
682731
AdaptiveVideoSender* source)
683732
// It is important that the first_frame_offset and the initial time of
684733
// clock_ are both zero, otherwise we can't have absolute time in this
685734
// class.
686-
: PacketSender(listener, source->flow_ids()),
687-
clock_(0),
688-
start_of_run_ms_(0),
689-
pacer_(&clock_, this, kbps, PacedSender::kDefaultPaceMultiplier* kbps, 0),
690-
source_(source) {
735+
: RegularVideoSender(listener, kbps, source),
736+
pacer_(&clock_,
737+
this,
738+
kbps,
739+
PacedSender::kDefaultPaceMultiplier* kbps,
740+
0) {
741+
modules_.push_back(&pacer_);
742+
}
743+
744+
PacedVideoSender::~PacedVideoSender() {
691745
}
692746

693747
void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
@@ -698,18 +752,18 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
698752
int64_t end_time_ms = clock_.TimeInMilliseconds() + time_ms;
699753
Packets::iterator it = generated_packets.begin();
700754
while (clock_.TimeInMilliseconds() <= end_time_ms) {
701-
int64_t time_until_process_ms = pacer_.TimeUntilNextProcess();
702-
if (time_until_process_ms < 0)
703-
time_until_process_ms = 0;
755+
int64_t time_until_process_ms = TimeUntilNextProcess(modules_);
756+
704757
int time_until_packet_ms = time_ms;
705758
if (it != generated_packets.end())
706759
time_until_packet_ms =
707760
(it->send_time_us() + 500) / 1000 - clock_.TimeInMilliseconds();
708761
assert(time_until_packet_ms >= 0);
762+
709763
int time_until_next_event_ms = time_until_packet_ms;
710-
if (time_until_process_ms < time_until_packet_ms &&
711-
pacer_.QueueSizePackets() > 0)
764+
if (time_until_process_ms < time_until_packet_ms) {
712765
time_until_next_event_ms = time_until_process_ms;
766+
}
713767

714768
if (clock_.TimeInMilliseconds() + time_until_next_event_ms > end_time_ms) {
715769
clock_.AdvanceTimeMilliseconds(end_time_ms - clock_.TimeInMilliseconds());
@@ -718,7 +772,7 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
718772
clock_.AdvanceTimeMilliseconds(time_until_next_event_ms);
719773
if (time_until_process_ms < time_until_packet_ms) {
720774
// Time to process.
721-
pacer_.Process();
775+
CallProcess(modules_);
722776
} else {
723777
// Time to send next packet to pacer.
724778
pacer_.SendPacket(PacedSender::kNormalPriority,
@@ -738,6 +792,27 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
738792
QueuePackets(in_out, end_time_ms * 1000);
739793
}
740794

795+
int64_t PacedVideoSender::TimeUntilNextProcess(
796+
const std::list<Module*>& modules) {
797+
int64_t time_until_next_process_ms = 10;
798+
for (auto* module : modules) {
799+
int64_t next_process_ms = module->TimeUntilNextProcess();
800+
if (next_process_ms < time_until_next_process_ms)
801+
time_until_next_process_ms = next_process_ms;
802+
}
803+
if (time_until_next_process_ms < 0)
804+
time_until_next_process_ms = 0;
805+
return time_until_next_process_ms;
806+
}
807+
808+
void PacedVideoSender::CallProcess(const std::list<Module*>& modules) {
809+
for (auto* module : modules) {
810+
if (module->TimeUntilNextProcess() <= 0) {
811+
module->Process();
812+
}
813+
}
814+
}
815+
741816
void PacedVideoSender::QueuePackets(Packets* batch,
742817
int64_t end_of_batch_time_us) {
743818
queue_.merge(*batch);
@@ -755,14 +830,6 @@ void PacedVideoSender::QueuePackets(Packets* batch,
755830
batch->merge(to_transfer);
756831
}
757832

758-
void PacedVideoSender::GiveFeedback(const PacketSender::Feedback& feedback) {
759-
source_->GiveFeedback(feedback);
760-
pacer_.UpdateBitrate(
761-
feedback.estimated_bps / 1000,
762-
PacedSender::kDefaultPaceMultiplier * feedback.estimated_bps / 1000,
763-
0);
764-
}
765-
766833
bool PacedVideoSender::TimeToSendPacket(uint32_t ssrc,
767834
uint16_t sequence_number,
768835
int64_t capture_time_ms,
@@ -786,6 +853,15 @@ bool PacedVideoSender::TimeToSendPacket(uint32_t ssrc,
786853
size_t PacedVideoSender::TimeToSendPadding(size_t bytes) {
787854
return 0;
788855
}
856+
857+
void PacedVideoSender::OnNetworkChanged(uint32_t target_bitrate_bps,
858+
uint8_t fraction_lost,
859+
int64_t rtt) {
860+
RegularVideoSender::OnNetworkChanged(target_bitrate_bps, fraction_lost, rtt);
861+
pacer_.UpdateBitrate(
862+
target_bitrate_bps / 1000,
863+
PacedSender::kDefaultPaceMultiplier * target_bitrate_bps / 1000, 0);
864+
}
789865
} // namespace bwe
790866
} // namespace testing
791867
} // namespace webrtc

0 commit comments

Comments
 (0)