Skip to content

Commit

Permalink
Removes legacy PacketQueue implementation.
Browse files Browse the repository at this point in the history
Also cleans up usage of the new RoundRobinPacketQueue to reduce code
bloat.

Bug: webrtc:8288
Change-Id: I90f17a4422b32c1d4e2d7d5065573157346d6a0b
Reviewed-on: https://webrtc-review.googlesource.com/100306
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24744}
  • Loading branch information
jonex authored and Commit Bot committed Sep 14, 2018
1 parent c7d9358 commit 60570dc
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 383 deletions.
4 changes: 0 additions & 4 deletions modules/pacing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ rtc_static_library("pacing") {
"paced_sender.cc",
"paced_sender.h",
"pacer.h",
"packet_queue.cc",
"packet_queue.h",
"packet_queue_interface.cc",
"packet_queue_interface.h",
"packet_router.cc",
"packet_router.h",
"round_robin_packet_queue.cc",
Expand Down
42 changes: 16 additions & 26 deletions modules/pacing/paced_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "modules/include/module_common_types.h"
#include "modules/pacing/bitrate_prober.h"
#include "modules/pacing/interval_budget.h"
#include "modules/pacing/round_robin_packet_queue.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
Expand Down Expand Up @@ -51,15 +50,6 @@ const float PacedSender::kDefaultPaceMultiplier = 2.5f;
PacedSender::PacedSender(const Clock* clock,
PacketSender* packet_sender,
RtcEventLog* event_log)
: PacedSender(clock,
packet_sender,
event_log,
absl::make_unique<RoundRobinPacketQueue>(clock)) {}

PacedSender::PacedSender(const Clock* clock,
PacketSender* packet_sender,
RtcEventLog* event_log,
std::unique_ptr<PacketQueueInterface> packets)
: clock_(clock),
packet_sender_(packet_sender),
alr_detector_(absl::make_unique<AlrDetector>(event_log)),
Expand All @@ -80,7 +70,7 @@ PacedSender::PacedSender(const Clock* clock,
time_last_process_us_(clock->TimeInMicroseconds()),
last_send_time_us_(clock->TimeInMicroseconds()),
first_sent_packet_ms_(-1),
packets_(std::move(packets)),
packets_(clock),
packet_counter_(0),
pacing_factor_(kDefaultPaceMultiplier),
queue_time_limit(kMaxQueueLengthMs),
Expand All @@ -104,7 +94,7 @@ void PacedSender::Pause() {
if (!paused_)
RTC_LOG(LS_INFO) << "PacedSender paused.";
paused_ = true;
packets_->SetPauseState(true, TimeMilliseconds());
packets_.SetPauseState(true, TimeMilliseconds());
}
rtc::CritScope cs(&process_thread_lock_);
// Tell the process thread to call our TimeUntilNextProcess() method to get
Expand All @@ -119,7 +109,7 @@ void PacedSender::Resume() {
if (paused_)
RTC_LOG(LS_INFO) << "PacedSender resumed.";
paused_ = false;
packets_->SetPauseState(false, TimeMilliseconds());
packets_.SetPauseState(false, TimeMilliseconds());
}
rtc::CritScope cs(&process_thread_lock_);
// Tell the process thread to call our TimeUntilNextProcess() method to
Expand Down Expand Up @@ -212,7 +202,7 @@ void PacedSender::InsertPacket(RtpPacketSender::Priority priority,
if (capture_time_ms < 0)
capture_time_ms = now_ms;

packets_->Push(PacketQueueInterface::Packet(
packets_.Push(RoundRobinPacketQueue::Packet(
priority, ssrc, sequence_number, capture_time_ms, now_ms, bytes,
retransmission, packet_counter_++));
}
Expand All @@ -225,7 +215,7 @@ void PacedSender::SetAccountForAudioPackets(bool account_for_audio) {
int64_t PacedSender::ExpectedQueueTimeMs() const {
rtc::CritScope cs(&critsect_);
RTC_DCHECK_GT(pacing_bitrate_kbps_, 0);
return static_cast<int64_t>(packets_->SizeInBytes() * 8 /
return static_cast<int64_t>(packets_.SizeInBytes() * 8 /
pacing_bitrate_kbps_);
}

Expand All @@ -237,7 +227,7 @@ absl::optional<int64_t> PacedSender::GetApplicationLimitedRegionStartTime()

size_t PacedSender::QueueSizePackets() const {
rtc::CritScope cs(&critsect_);
return packets_->SizeInPackets();
return packets_.SizeInPackets();
}

int64_t PacedSender::FirstSentPacketTimeMs() const {
Expand All @@ -248,7 +238,7 @@ int64_t PacedSender::FirstSentPacketTimeMs() const {
int64_t PacedSender::QueueInMs() const {
rtc::CritScope cs(&critsect_);

int64_t oldest_packet = packets_->OldestEnqueueTimeMs();
int64_t oldest_packet = packets_.OldestEnqueueTimeMs();
if (oldest_packet == 0)
return 0;

Expand Down Expand Up @@ -303,15 +293,15 @@ void PacedSender::Process() {

if (elapsed_time_ms > 0) {
int target_bitrate_kbps = pacing_bitrate_kbps_;
size_t queue_size_bytes = packets_->SizeInBytes();
size_t queue_size_bytes = packets_.SizeInBytes();
if (queue_size_bytes > 0) {
// Assuming equal size packets and input/output rate, the average packet
// has avg_time_left_ms left to get queue_size_bytes out of the queue, if
// time constraint shall be met. Determine bitrate needed for that.
packets_->UpdateQueueTime(TimeMilliseconds());
packets_.UpdateQueueTime(TimeMilliseconds());
if (drain_large_queues_) {
int64_t avg_time_left_ms = std::max<int64_t>(
1, queue_time_limit - packets_->AverageQueueTimeMs());
1, queue_time_limit - packets_.AverageQueueTimeMs());
int min_bitrate_needed_kbps =
static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms);
if (min_bitrate_needed_kbps > target_bitrate_kbps)
Expand All @@ -333,26 +323,26 @@ void PacedSender::Process() {
}
// The paused state is checked in the loop since SendPacket leaves the
// critical section allowing the paused state to be changed from other code.
while (!packets_->Empty() && !paused_) {
while (!packets_.Empty() && !paused_) {
// Since we need to release the lock in order to send, we first pop the
// element from the priority queue but keep it in storage, so that we can
// reinsert it if send fails.
const PacketQueueInterface::Packet& packet = packets_->BeginPop();
const RoundRobinPacketQueue::Packet& packet = packets_.BeginPop();

if (SendPacket(packet, pacing_info)) {
bytes_sent += packet.bytes;
// Send succeeded, remove it from the queue.
packets_->FinalizePop(packet);
packets_.FinalizePop(packet);
if (is_probing && bytes_sent > recommended_probe_size)
break;
} else {
// Send failed, put it back into the queue.
packets_->CancelPop(packet);
packets_.CancelPop(packet);
break;
}
}

if (packets_->Empty() && !Congested()) {
if (packets_.Empty() && !Congested()) {
// We can not send padding unless a normal packet has first been sent. If we
// do, timestamps get messed up.
if (packet_counter_ > 0) {
Expand All @@ -378,7 +368,7 @@ void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) {
process_thread_ = process_thread;
}

bool PacedSender::SendPacket(const PacketQueueInterface::Packet& packet,
bool PacedSender::SendPacket(const RoundRobinPacketQueue::Packet& packet,
const PacedPacketInfo& pacing_info) {
RTC_DCHECK(!paused_);
bool audio_packet = packet.priority == kHighPriority;
Expand Down
12 changes: 3 additions & 9 deletions modules/pacing/paced_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "absl/types/optional.h"
#include "modules/pacing/pacer.h"
#include "modules/pacing/packet_queue_interface.h"
#include "modules/pacing/round_robin_packet_queue.h"
#include "rtc_base/criticalsection.h"
#include "rtc_base/thread_annotations.h"

Expand Down Expand Up @@ -65,11 +65,6 @@ class PacedSender : public Pacer {
PacketSender* packet_sender,
RtcEventLog* event_log);

PacedSender(const Clock* clock,
PacketSender* packet_sender,
RtcEventLog* event_log,
std::unique_ptr<PacketQueueInterface> packets);

~PacedSender() override;

virtual void CreateProbeCluster(int bitrate_bps);
Expand Down Expand Up @@ -149,7 +144,7 @@ class PacedSender : public Pacer {
void UpdateBudgetWithBytesSent(size_t bytes)
RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);

bool SendPacket(const PacketQueueInterface::Packet& packet,
bool SendPacket(const RoundRobinPacketQueue::Packet& packet,
const PacedPacketInfo& cluster_info)
RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_);
size_t SendPadding(size_t padding_needed, const PacedPacketInfo& cluster_info)
Expand Down Expand Up @@ -195,8 +190,7 @@ class PacedSender : public Pacer {
int64_t last_send_time_us_ RTC_GUARDED_BY(critsect_);
int64_t first_sent_packet_ms_ RTC_GUARDED_BY(critsect_);

const std::unique_ptr<PacketQueueInterface> packets_
RTC_PT_GUARDED_BY(critsect_);
RoundRobinPacketQueue packets_ RTC_GUARDED_BY(critsect_);
uint64_t packet_counter_ RTC_GUARDED_BY(critsect_);

int64_t congestion_window_bytes_ RTC_GUARDED_BY(critsect_) =
Expand Down
128 changes: 0 additions & 128 deletions modules/pacing/packet_queue.cc

This file was deleted.

Loading

0 comments on commit 60570dc

Please sign in to comment.