Index: webrtc/modules/pacing/paced_sender.cc |
diff --git a/webrtc/modules/pacing/paced_sender.cc b/webrtc/modules/pacing/paced_sender.cc |
index fe918bbbb345221e32007db84b89e6e6753210c7..387276908ca404c72aa21bff744225d7ec78cc47 100644 |
--- a/webrtc/modules/pacing/paced_sender.cc |
+++ b/webrtc/modules/pacing/paced_sender.cc |
@@ -245,9 +245,12 @@ class IntervalBudget { |
const int64_t PacedSender::kMaxQueueLengthMs = 2000; |
const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
-PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender) |
+PacedSender::PacedSender(Clock* clock, |
+ PacketSender* packet_sender, |
+ PacingObserver* pacing_observer) |
: clock_(clock), |
packet_sender_(packet_sender), |
+ pacing_observer_(pacing_observer), |
critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
paused_(false), |
media_budget_(new paced_sender::IntervalBudget(0)), |
@@ -260,9 +263,12 @@ PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender) |
time_last_update_us_(clock->TimeInMicroseconds()), |
packets_(new paced_sender::PacketQueue(clock)), |
packet_counter_(0) { |
- UpdateBytesPerInterval(kMinPacketLimitMs); |
+ UpdateBudgetWithElapsedTime(kMinPacketLimitMs); |
} |
+PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender) |
+ : PacedSender(clock, packet_sender, nullptr) {} |
+ |
PacedSender::~PacedSender() {} |
void PacedSender::CreateProbeCluster(int bitrate_bps, int num_packets) { |
@@ -397,8 +403,8 @@ void PacedSender::Process() { |
media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
- int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
- UpdateBytesPerInterval(delta_time_ms); |
+ elapsed_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
+ UpdateBudgetWithElapsedTime(elapsed_time_ms); |
} |
bool is_probing = prober_->IsProbing(); |
@@ -443,6 +449,8 @@ void PacedSender::Process() { |
} |
if (is_probing && bytes_sent > 0) |
prober_->ProbeSent(clock_->TimeInMilliseconds(), bytes_sent); |
+ if (pacing_observer_) |
+ pacing_observer_->OnBytesSent(bytes_sent, elapsed_time_ms); |
} |
bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
@@ -469,8 +477,7 @@ bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
// are allocating bandwidth for audio. |
if (packet.priority != kHighPriority) { |
// Update media bytes sent. |
- media_budget_->UseBudget(packet.bytes); |
- padding_budget_->UseBudget(packet.bytes); |
+ UpdateBudgetWithBytesSent(packet.bytes); |
} |
} |
@@ -484,14 +491,18 @@ size_t PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
critsect_->Enter(); |
if (bytes_sent > 0) { |
- media_budget_->UseBudget(bytes_sent); |
- padding_budget_->UseBudget(bytes_sent); |
+ UpdateBudgetWithBytesSent(bytes_sent); |
} |
return bytes_sent; |
} |
-void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
+void PacedSender::UpdateBudgetWithElapsedTime(int64_t delta_time_ms) { |
media_budget_->IncreaseBudget(delta_time_ms); |
padding_budget_->IncreaseBudget(delta_time_ms); |
} |
+ |
+void PacedSender::UpdateBudgetWithBytesSent(size_t bytes_sent) { |
+ media_budget_->UseBudget(bytes_sent); |
+ padding_budget_->UseBudget(bytes_sent); |
+} |
} // namespace webrtc |