Prepares RTPSender for extracting RtpSenderEgress

The post-pacing part of the RTP sender has been moved from RTPSender
into the new RtpSenderEgress class. However, that class is not directly
used and instead a subset of method calls are passed through RTPSender.

This CL prepares for removing dependencies between RTPSender and
RtpSenderEgress. All current behavior is preserved, and unit tests are
unchanged to verify this.

For more context, see patch set 2.

Change-Id: If795f2603aeb6302ac1565d9efaea514af240dc7
Bug: webrtc:11036
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158020
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29616}
This commit is contained in:
Erik Språng
2019-10-25 15:24:15 +02:00
committed by Commit Bot
parent 492fdf40fe
commit 67ac9e8ecb
7 changed files with 159 additions and 103 deletions

View File

@ -93,24 +93,11 @@ bool HasBweExtension(const RtpHeaderExtensionMap& extensions_map) {
} // namespace } // namespace
RTPSender::NonPacedPacketSender::NonPacedPacketSender(RTPSender* rtp_sender)
: transport_sequence_number_(0), rtp_sender_(rtp_sender) {}
RTPSender::NonPacedPacketSender::~NonPacedPacketSender() = default;
void RTPSender::NonPacedPacketSender::EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
for (auto& packet : packets) {
if (!packet->SetExtension<TransportSequenceNumber>(
++transport_sequence_number_)) {
--transport_sequence_number_;
}
packet->ReserveExtension<TransmissionOffset>();
packet->ReserveExtension<AbsoluteSendTime>();
rtp_sender_->TrySendPacket(packet.get(), PacedPacketInfo());
}
}
RTPSender::RTPSender(const RtpRtcp::Configuration& config) RTPSender::RTPSender(const RtpRtcp::Configuration& config)
: RTPSender(config, nullptr, config.paced_sender) {}
RTPSender::RTPSender(const RtpRtcp::Configuration& config,
RtpPacketHistory* packet_history,
RtpPacketSender* packet_sender)
: clock_(config.clock), : clock_(config.clock),
random_(clock_->TimeInMicroseconds()), random_(clock_->TimeInMicroseconds()),
audio_configured_(config.audio), audio_configured_(config.audio),
@ -119,15 +106,10 @@ RTPSender::RTPSender(const RtpRtcp::Configuration& config)
flexfec_ssrc_(config.flexfec_sender flexfec_ssrc_(config.flexfec_sender
? absl::make_optional(config.flexfec_sender->ssrc()) ? absl::make_optional(config.flexfec_sender->ssrc())
: absl::nullopt), : absl::nullopt),
non_paced_packet_sender_(
config.paced_sender ? nullptr : new NonPacedPacketSender(this)),
paced_sender_(config.paced_sender ? config.paced_sender
: non_paced_packet_sender_.get()),
sending_media_(true), // Default to sending media. sending_media_(true), // Default to sending media.
max_packet_size_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. max_packet_size_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP.
last_payload_type_(-1), last_payload_type_(-1),
rtp_header_extension_map_(config.extmap_allow_mixed), rtp_header_extension_map_(config.extmap_allow_mixed),
packet_history_(clock_),
// RTP variables // RTP variables
sequence_number_forced_(false), sequence_number_forced_(false),
ssrc_has_acked_(false), ssrc_has_acked_(false),
@ -139,14 +121,36 @@ RTPSender::RTPSender(const RtpRtcp::Configuration& config)
csrcs_(), csrcs_(),
rtx_(kRtxOff), rtx_(kRtxOff),
supports_bwe_extension_(false), supports_bwe_extension_(false),
retransmission_rate_limiter_(config.retransmission_rate_limiter), retransmission_rate_limiter_(config.retransmission_rate_limiter) {
egress_(config, &packet_history_, clock_) {
// This random initialization is not intended to be cryptographic strong. // This random initialization is not intended to be cryptographic strong.
timestamp_offset_ = random_.Rand<uint32_t>(); timestamp_offset_ = random_.Rand<uint32_t>();
// Random start, 16 bits. Can't be 0. // Random start, 16 bits. Can't be 0.
sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber);
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
if (packet_history == nullptr) {
// Packet history must be provided if using the new split sender, so if it
// is nullptr it means we are in backwards compatibility mode where
// RTPSender owns the history, RtpSenderEgress and non-paced sender adapter.
// TODO(bugs.webrtc.org/11036): Remove.
owned_history_ = std::make_unique<RtpPacketHistory>(clock_);
packet_history_ = owned_history_.get();
egress_ = std::make_unique<RtpSenderEgress>(config, packet_history_);
if (packet_sender) {
paced_sender_ = packet_sender;
} else {
non_paced_packet_sender_ =
std::make_unique<RtpSenderEgress::NonPacedPacketSender>(
egress_.get());
paced_sender_ = non_paced_packet_sender_.get();
}
} else {
packet_history_ = packet_history;
paced_sender_ = packet_sender;
}
RTC_DCHECK(paced_sender_); RTC_DCHECK(paced_sender_);
RTC_DCHECK(packet_history_);
} }
RTPSender::~RTPSender() { RTPSender::~RTPSender() {
@ -172,11 +176,13 @@ rtc::ArrayView<const RtpExtensionSize> RTPSender::VideoExtensionSizes() {
} }
uint16_t RTPSender::ActualSendBitrateKbit() const { uint16_t RTPSender::ActualSendBitrateKbit() const {
return egress_.SendBitrate().kbps<uint16_t>(); RTC_DCHECK(egress_);
return egress_->SendBitrate().kbps<uint16_t>();
} }
uint32_t RTPSender::NackOverheadRate() const { uint32_t RTPSender::NackOverheadRate() const {
return egress_.NackOverheadRate().bps<uint32_t>(); RTC_DCHECK(egress_);
return egress_->NackOverheadRate().bps<uint32_t>();
} }
void RTPSender::SetExtmapAllowMixed(bool extmap_allow_mixed) { void RTPSender::SetExtmapAllowMixed(bool extmap_allow_mixed) {
@ -252,14 +258,14 @@ void RTPSender::SetRtxPayloadType(int payload_type,
} }
void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) { void RTPSender::SetStorePacketsStatus(bool enable, uint16_t number_to_store) {
packet_history_.SetStorePacketsStatus( packet_history_->SetStorePacketsStatus(
enable ? RtpPacketHistory::StorageMode::kStoreAndCull enable ? RtpPacketHistory::StorageMode::kStoreAndCull
: RtpPacketHistory::StorageMode::kDisabled, : RtpPacketHistory::StorageMode::kDisabled,
number_to_store); number_to_store);
} }
bool RTPSender::StorePackets() const { bool RTPSender::StorePackets() const {
return packet_history_.GetStorageMode() != return packet_history_->GetStorageMode() !=
RtpPacketHistory::StorageMode::kDisabled; RtpPacketHistory::StorageMode::kDisabled;
} }
@ -267,7 +273,7 @@ int32_t RTPSender::ReSendPacket(uint16_t packet_id) {
// Try to find packet in RTP packet history. Also verify RTT here, so that we // Try to find packet in RTP packet history. Also verify RTT here, so that we
// don't retransmit too often. // don't retransmit too often.
absl::optional<RtpPacketHistory::PacketState> stored_packet = absl::optional<RtpPacketHistory::PacketState> stored_packet =
packet_history_.GetPacketState(packet_id); packet_history_->GetPacketState(packet_id);
if (!stored_packet || stored_packet->pending_transmission) { if (!stored_packet || stored_packet->pending_transmission) {
// Packet not found or already queued for retransmission, ignore. // Packet not found or already queued for retransmission, ignore.
return 0; return 0;
@ -277,7 +283,7 @@ int32_t RTPSender::ReSendPacket(uint16_t packet_id) {
const bool rtx = (RtxStatus() & kRtxRetransmitted) > 0; const bool rtx = (RtxStatus() & kRtxRetransmitted) > 0;
std::unique_ptr<RtpPacketToSend> packet = std::unique_ptr<RtpPacketToSend> packet =
packet_history_.GetPacketAndMarkAsPending( packet_history_->GetPacketAndMarkAsPending(
packet_id, [&](const RtpPacketToSend& stored_packet) { packet_id, [&](const RtpPacketToSend& stored_packet) {
// Check if we're overusing retransmission bitrate. // Check if we're overusing retransmission bitrate.
// TODO(sprang): Add histograms for nack success or failure // TODO(sprang): Add histograms for nack success or failure
@ -324,7 +330,7 @@ void RTPSender::OnReceivedAckOnRtxSsrc(
void RTPSender::OnReceivedNack( void RTPSender::OnReceivedNack(
const std::vector<uint16_t>& nack_sequence_numbers, const std::vector<uint16_t>& nack_sequence_numbers,
int64_t avg_rtt) { int64_t avg_rtt) {
packet_history_.SetRtt(5 + avg_rtt); packet_history_->SetRtt(5 + avg_rtt);
for (uint16_t seq_no : nack_sequence_numbers) { for (uint16_t seq_no : nack_sequence_numbers) {
const int32_t bytes_sent = ReSendPacket(seq_no); const int32_t bytes_sent = ReSendPacket(seq_no);
if (bytes_sent < 0) { if (bytes_sent < 0) {
@ -348,7 +354,8 @@ bool RTPSender::TrySendPacket(RtpPacketToSend* packet,
} }
} }
egress_.SendPacket(packet, pacing_info); RTC_DCHECK(egress_);
egress_->SendPacket(packet, pacing_info);
return true; return true;
} }
@ -365,6 +372,13 @@ bool RTPSender::SupportsRtxPayloadPadding() const {
std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding( std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
size_t target_size_bytes) { size_t target_size_bytes) {
RTC_DCHECK(egress_);
return GeneratePadding(target_size_bytes, egress_->MediaHasBeenSent());
}
std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
size_t target_size_bytes,
bool media_has_been_sent) {
// This method does not actually send packets, it just generates // This method does not actually send packets, it just generates
// them and puts them in the pacer queue. Since this should incur // them and puts them in the pacer queue. Since this should incur
// low overhead, keep the lock for the scope of the method in order // low overhead, keep the lock for the scope of the method in order
@ -375,7 +389,7 @@ std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
if (SupportsRtxPayloadPadding()) { if (SupportsRtxPayloadPadding()) {
while (bytes_left >= kMinPayloadPaddingBytes) { while (bytes_left >= kMinPayloadPaddingBytes) {
std::unique_ptr<RtpPacketToSend> packet = std::unique_ptr<RtpPacketToSend> packet =
packet_history_.GetPayloadPaddingPacket( packet_history_->GetPayloadPaddingPacket(
[&](const RtpPacketToSend& packet) [&](const RtpPacketToSend& packet)
-> std::unique_ptr<RtpPacketToSend> { -> std::unique_ptr<RtpPacketToSend> {
return BuildRtxPacket(packet); return BuildRtxPacket(packet);
@ -436,7 +450,7 @@ std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
// Without abs-send-time or transport sequence number a media packet // Without abs-send-time or transport sequence number a media packet
// must be sent before padding so that the timestamps used for // must be sent before padding so that the timestamps used for
// estimation are correct. // estimation are correct.
if (!egress_.MediaHasBeenSent() && if (!media_has_been_sent &&
!(rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId) || !(rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId) ||
rtp_header_extension_map_.IsRegistered( rtp_header_extension_map_.IsRegistered(
TransportSequenceNumber::kId))) { TransportSequenceNumber::kId))) {
@ -512,7 +526,8 @@ void RTPSender::EnqueuePackets(
} }
void RTPSender::ProcessBitrate() { void RTPSender::ProcessBitrate() {
egress_.ProcessBitrateAndNotifyObservers(); RTC_DCHECK(egress_);
egress_->ProcessBitrateAndNotifyObservers();
} }
size_t RTPSender::RtpHeaderLength() const { size_t RTPSender::RtpHeaderLength() const {
@ -533,7 +548,8 @@ uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats, void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats,
StreamDataCounters* rtx_stats) const { StreamDataCounters* rtx_stats) const {
egress_.GetDataCounters(rtp_stats, rtx_stats); RTC_DCHECK(egress_);
egress_->GetDataCounters(rtp_stats, rtx_stats);
} }
std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const { std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const {
@ -606,7 +622,8 @@ bool RTPSender::SendingMedia() const {
} }
void RTPSender::SetAsPartOfAllocation(bool part_of_allocation) { void RTPSender::SetAsPartOfAllocation(bool part_of_allocation) {
egress_.ForceIncludeSendPacketsInAllocation(part_of_allocation); RTC_DCHECK(egress_);
egress_->ForceIncludeSendPacketsInAllocation(part_of_allocation);
} }
void RTPSender::SetTimestampOffset(uint32_t timestamp) { void RTPSender::SetTimestampOffset(uint32_t timestamp) {
@ -653,7 +670,7 @@ void RTPSender::SetSequenceNumber(uint16_t seq) {
if (updated_sequence_number) { if (updated_sequence_number) {
// Sequence number series has been reset to a new value, clear RTP packet // Sequence number series has been reset to a new value, clear RTP packet
// history, since any packets there may conflict with new ones. // history, since any packets there may conflict with new ones.
packet_history_.Clear(); packet_history_->Clear();
} }
} }
@ -782,7 +799,8 @@ std::unique_ptr<RtpPacketToSend> RTPSender::BuildRtxPacket(
} }
uint32_t RTPSender::BitrateSent() const { uint32_t RTPSender::BitrateSent() const {
return egress_.SendBitrate().bps<uint32_t>(); RTC_DCHECK(egress_);
return egress_->SendBitrate().bps<uint32_t>();
} }
void RTPSender::SetRtpState(const RtpState& rtp_state) { void RTPSender::SetRtpState(const RtpState& rtp_state) {
@ -794,7 +812,9 @@ void RTPSender::SetRtpState(const RtpState& rtp_state) {
capture_time_ms_ = rtp_state.capture_time_ms; capture_time_ms_ = rtp_state.capture_time_ms;
last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms;
ssrc_has_acked_ = rtp_state.ssrc_has_acked; ssrc_has_acked_ = rtp_state.ssrc_has_acked;
egress_.SetMediaHasBeenSent(rtp_state.media_has_been_sent); if (egress_) {
egress_->SetMediaHasBeenSent(rtp_state.media_has_been_sent);
}
} }
RtpState RTPSender::GetRtpState() const { RtpState RTPSender::GetRtpState() const {
@ -806,8 +826,10 @@ RtpState RTPSender::GetRtpState() const {
state.timestamp = last_rtp_timestamp_; state.timestamp = last_rtp_timestamp_;
state.capture_time_ms = capture_time_ms_; state.capture_time_ms = capture_time_ms_;
state.last_timestamp_time_ms = last_timestamp_time_ms_; state.last_timestamp_time_ms = last_timestamp_time_ms_;
state.media_has_been_sent = egress_.MediaHasBeenSent();
state.ssrc_has_acked = ssrc_has_acked_; state.ssrc_has_acked = ssrc_has_acked_;
if (egress_) {
state.media_has_been_sent = egress_->MediaHasBeenSent();
}
return state; return state;
} }
@ -835,11 +857,11 @@ int64_t RTPSender::LastTimestampTimeMs() const {
} }
void RTPSender::SetRtt(int64_t rtt_ms) { void RTPSender::SetRtt(int64_t rtt_ms) {
packet_history_.SetRtt(rtt_ms); packet_history_->SetRtt(rtt_ms);
} }
void RTPSender::OnPacketsAcknowledged( void RTPSender::OnPacketsAcknowledged(
rtc::ArrayView<const uint16_t> sequence_numbers) { rtc::ArrayView<const uint16_t> sequence_numbers) {
packet_history_.CullAcknowledgedPackets(sequence_numbers); packet_history_->CullAcknowledgedPackets(sequence_numbers);
} }
} // namespace webrtc } // namespace webrtc

View File

@ -47,21 +47,23 @@ class RtpPacketToSend;
class RTPSender { class RTPSender {
public: public:
RTPSender(const RtpRtcp::Configuration& config,
RtpPacketHistory* packet_history,
RtpPacketSender* packet_sender);
explicit RTPSender(const RtpRtcp::Configuration& config); explicit RTPSender(const RtpRtcp::Configuration& config);
~RTPSender(); ~RTPSender();
// TODO(bugs.webrtc.org/11036): Remove.
void ProcessBitrate(); void ProcessBitrate();
uint16_t ActualSendBitrateKbit() const; uint16_t ActualSendBitrateKbit() const;
uint32_t NackOverheadRate() const; uint32_t NackOverheadRate() const;
void SetSendingMediaStatus(bool enabled); void SetSendingMediaStatus(bool enabled);
bool SendingMedia() const; bool SendingMedia() const;
// TODO(bugs.webrtc.org/11036): Remove.
void SetAsPartOfAllocation(bool part_of_allocation); void SetAsPartOfAllocation(bool part_of_allocation);
void GetDataCounters(StreamDataCounters* rtp_stats, void GetDataCounters(StreamDataCounters* rtp_stats,
StreamDataCounters* rtx_stats) const; StreamDataCounters* rtx_stats) const;
@ -91,13 +93,21 @@ class RTPSender {
// Tries to send packet to transport. Also updates any timing extensions, // Tries to send packet to transport. Also updates any timing extensions,
// calls observers waiting for packet send events, and updates stats. // calls observers waiting for packet send events, and updates stats.
// Returns true if packet belongs to this RTP module, false otherwise. // Returns true if packet belongs to this RTP module, false otherwise.
// TODO(bugs.webrtc.org/11036): Remove.
bool TrySendPacket(RtpPacketToSend* packet, bool TrySendPacket(RtpPacketToSend* packet,
const PacedPacketInfo& pacing_info); const PacedPacketInfo& pacing_info);
bool SupportsPadding() const; bool SupportsPadding() const;
bool SupportsRtxPayloadPadding() const; bool SupportsRtxPayloadPadding() const;
// TODO(bugs.webrtc.org/11036): Remove.
std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding( std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding(
size_t target_size_bytes); size_t target_size_bytes);
std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding(
size_t target_size_bytes,
bool media_has_been_sent);
// NACK. // NACK.
void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers, void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers,
int64_t avg_rtt); int64_t avg_rtt);
@ -151,6 +161,7 @@ class RTPSender {
// sending to the network. // sending to the network.
void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets); void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets);
// TODO(bugs.webrtc.org/11036): Remove.
uint32_t BitrateSent() const; uint32_t BitrateSent() const;
void SetRtpState(const RtpState& rtp_state); void SetRtpState(const RtpState& rtp_state);
@ -160,26 +171,11 @@ class RTPSender {
int64_t LastTimestampTimeMs() const; int64_t LastTimestampTimeMs() const;
// TODO(bugs.webrtc.org/11036): Remove.
void SetRtt(int64_t rtt_ms); void SetRtt(int64_t rtt_ms);
void OnPacketsAcknowledged(rtc::ArrayView<const uint16_t> sequence_numbers); void OnPacketsAcknowledged(rtc::ArrayView<const uint16_t> sequence_numbers);
private: private:
// Helper class that redirects packets directly to the send part of this class
// without passing through an actual paced sender.
class NonPacedPacketSender : public RtpPacketSender {
public:
explicit NonPacedPacketSender(RTPSender* rtp_sender);
virtual ~NonPacedPacketSender();
void EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) override;
private:
uint16_t transport_sequence_number_;
RTPSender* const rtp_sender_;
};
std::unique_ptr<RtpPacketToSend> BuildRtxPacket( std::unique_ptr<RtpPacketToSend> BuildRtxPacket(
const RtpPacketToSend& packet); const RtpPacketToSend& packet);
@ -194,8 +190,18 @@ class RTPSender {
const absl::optional<uint32_t> rtx_ssrc_; const absl::optional<uint32_t> rtx_ssrc_;
const absl::optional<uint32_t> flexfec_ssrc_; const absl::optional<uint32_t> flexfec_ssrc_;
const std::unique_ptr<NonPacedPacketSender> non_paced_packet_sender_; // TODO(bugs.webrtc.org/11036): Remove |owned_history_|, make
RtpPacketSender* const paced_sender_; // |packet_history_| ptr const.
std::unique_ptr<RtpPacketHistory> owned_history_;
RtpPacketHistory* packet_history_;
// TODO(bugs.webrtc.org/11036): Remove |egress_| and |non_paced_sender_|,
// make |paced_sender_| ptr const.
std::unique_ptr<RtpSenderEgress> egress_;
std::unique_ptr<RtpSenderEgress::NonPacedPacketSender>
non_paced_packet_sender_;
RtpPacketSender* paced_sender_;
rtc::CriticalSection send_critsect_; rtc::CriticalSection send_critsect_;
bool sending_media_ RTC_GUARDED_BY(send_critsect_); bool sending_media_ RTC_GUARDED_BY(send_critsect_);
@ -206,8 +212,6 @@ class RTPSender {
RtpHeaderExtensionMap rtp_header_extension_map_ RtpHeaderExtensionMap rtp_header_extension_map_
RTC_GUARDED_BY(send_critsect_); RTC_GUARDED_BY(send_critsect_);
RtpPacketHistory packet_history_;
// RTP variables // RTP variables
uint32_t timestamp_offset_ RTC_GUARDED_BY(send_critsect_); uint32_t timestamp_offset_ RTC_GUARDED_BY(send_critsect_);
bool sequence_number_forced_ RTC_GUARDED_BY(send_critsect_); bool sequence_number_forced_ RTC_GUARDED_BY(send_critsect_);
@ -233,8 +237,6 @@ class RTPSender {
RateLimiter* const retransmission_rate_limiter_; RateLimiter* const retransmission_rate_limiter_;
RtpSenderEgress egress_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
}; };

View File

@ -17,7 +17,6 @@
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/audio_codecs/audio_format.h" #include "api/audio_codecs/audio_format.h"
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/byte_io.h" #include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h"
@ -258,7 +257,7 @@ bool RTPSenderAudio::SendAudio(AudioFrameType frame_type,
packet->SequenceNumber()); packet->SequenceNumber());
packet->set_packet_type(RtpPacketToSend::Type::kAudio); packet->set_packet_type(RtpPacketToSend::Type::kAudio);
packet->set_allow_retransmission(true); packet->set_allow_retransmission(true);
bool send_result = LogAndSendToNetwork(std::move(packet)); bool send_result = rtp_sender_->SendToNetwork(std::move(packet));
if (first_packet_sent_()) { if (first_packet_sent_()) {
RTC_LOG(LS_INFO) << "First audio RTP packet sent to pacer"; RTC_LOG(LS_INFO) << "First audio RTP packet sent to pacer";
} }
@ -343,25 +342,10 @@ bool RTPSenderAudio::SendTelephoneEventPacket(bool ended,
packet->set_packet_type(RtpPacketToSend::Type::kAudio); packet->set_packet_type(RtpPacketToSend::Type::kAudio);
packet->set_allow_retransmission(true); packet->set_allow_retransmission(true);
result = LogAndSendToNetwork(std::move(packet)); result = rtp_sender_->SendToNetwork(std::move(packet));
send_count--; send_count--;
} while (send_count > 0 && result); } while (send_count > 0 && result);
return result; return result;
} }
bool RTPSenderAudio::LogAndSendToNetwork(
std::unique_ptr<RtpPacketToSend> packet) {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
int64_t now_ms = clock_->TimeInMilliseconds();
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioTotBitrate_kbps", now_ms,
rtp_sender_->ActualSendBitrateKbit(),
packet->Ssrc());
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioNackBitrate_kbps", now_ms,
rtp_sender_->NackOverheadRate() / 1000,
packet->Ssrc());
#endif
return rtp_sender_->SendToNetwork(std::move(packet));
}
} // namespace webrtc } // namespace webrtc

View File

@ -63,8 +63,6 @@ class RTPSenderAudio {
bool MarkerBit(AudioFrameType frame_type, int8_t payload_type); bool MarkerBit(AudioFrameType frame_type, int8_t payload_type);
private: private:
bool LogAndSendToNetwork(std::unique_ptr<RtpPacketToSend> packet);
Clock* const clock_ = nullptr; Clock* const clock_ = nullptr;
RTPSender* const rtp_sender_ = nullptr; RTPSender* const rtp_sender_ = nullptr;

View File

@ -17,6 +17,7 @@
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/transport/field_trial_based_config.h" #include "api/transport/field_trial_based_config.h"
#include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h" #include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
namespace webrtc { namespace webrtc {
@ -33,9 +34,26 @@ bool IsEnabled(absl::string_view name,
} }
} // namespace } // namespace
RtpSenderEgress::NonPacedPacketSender::NonPacedPacketSender(
RtpSenderEgress* sender)
: transport_sequence_number_(0), sender_(sender) {}
RtpSenderEgress::NonPacedPacketSender::~NonPacedPacketSender() = default;
void RtpSenderEgress::NonPacedPacketSender::EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
for (auto& packet : packets) {
if (!packet->SetExtension<TransportSequenceNumber>(
++transport_sequence_number_)) {
--transport_sequence_number_;
}
packet->ReserveExtension<TransmissionOffset>();
packet->ReserveExtension<AbsoluteSendTime>();
sender_->SendPacket(packet.get(), PacedPacketInfo());
}
}
RtpSenderEgress::RtpSenderEgress(const RtpRtcp::Configuration& config, RtpSenderEgress::RtpSenderEgress(const RtpRtcp::Configuration& config,
RtpPacketHistory* packet_history, RtpPacketHistory* packet_history)
Clock* clock)
: ssrc_(config.local_media_ssrc), : ssrc_(config.local_media_ssrc),
rtx_ssrc_(config.rtx_send_ssrc), rtx_ssrc_(config.rtx_send_ssrc),
flexfec_ssrc_(config.flexfec_sender flexfec_ssrc_(config.flexfec_sender
@ -44,10 +62,11 @@ RtpSenderEgress::RtpSenderEgress(const RtpRtcp::Configuration& config,
populate_network2_timestamp_(config.populate_network2_timestamp), populate_network2_timestamp_(config.populate_network2_timestamp),
send_side_bwe_with_overhead_( send_side_bwe_with_overhead_(
IsEnabled("WebRTC-SendSideBwe-WithOverhead", config.field_trials)), IsEnabled("WebRTC-SendSideBwe-WithOverhead", config.field_trials)),
clock_(clock), clock_(config.clock),
packet_history_(packet_history), packet_history_(packet_history),
transport_(config.outgoing_transport), transport_(config.outgoing_transport),
event_log_(config.event_log), event_log_(config.event_log),
is_audio_(config.audio),
transport_feedback_observer_(config.transport_feedback_callback), transport_feedback_observer_(config.transport_feedback_callback),
send_side_delay_observer_(config.send_side_delay_observer), send_side_delay_observer_(config.send_side_delay_observer),
send_packet_observer_(config.send_packet_observer), send_packet_observer_(config.send_packet_observer),
@ -72,6 +91,23 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet,
const uint32_t packet_ssrc = packet->Ssrc(); const uint32_t packet_ssrc = packet->Ssrc();
RTC_DCHECK(packet->packet_type().has_value()); RTC_DCHECK(packet->packet_type().has_value());
RTC_DCHECK(HasCorrectSsrc(*packet)); RTC_DCHECK(HasCorrectSsrc(*packet));
int64_t now_ms = clock_->TimeInMilliseconds();
if (is_audio_) {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioTotBitrate_kbps", now_ms,
SendBitrate().kbps(), packet_ssrc);
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioNackBitrate_kbps", now_ms,
NackOverheadRate().kbps(), packet_ssrc);
#endif
} else {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoTotBitrate_kbps", now_ms,
SendBitrate().kbps(), packet_ssrc);
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoNackBitrate_kbps", now_ms,
NackOverheadRate().kbps(), packet_ssrc);
#endif
}
PacketOptions options; PacketOptions options;
{ {
@ -87,7 +123,6 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet,
// In case of VideoTimingExtension, since it's present not in every packet, // In case of VideoTimingExtension, since it's present not in every packet,
// data after rtp header may be corrupted if these packets are protected by // data after rtp header may be corrupted if these packets are protected by
// the FEC. // the FEC.
int64_t now_ms = clock_->TimeInMilliseconds();
int64_t diff_ms = now_ms - packet->capture_time_ms(); int64_t diff_ms = now_ms - packet->capture_time_ms();
if (packet->IsExtensionReserved<TransmissionOffset>()) { if (packet->IsExtensionReserved<TransmissionOffset>()) {
packet->SetExtension<TransmissionOffset>(kTimestampTicksPerMs * diff_ms); packet->SetExtension<TransmissionOffset>(kTimestampTicksPerMs * diff_ms);

View File

@ -12,6 +12,8 @@
#define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_EGRESS_H_ #define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_EGRESS_H_
#include <map> #include <map>
#include <memory>
#include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/call/transport.h" #include "api/call/transport.h"
@ -29,9 +31,23 @@ namespace webrtc {
class RtpSenderEgress { class RtpSenderEgress {
public: public:
explicit RtpSenderEgress(const RtpRtcp::Configuration& config, // Helper class that redirects packets directly to the send part of this class
RtpPacketHistory* packet_history, // without passing through an actual paced sender.
Clock* clock); class NonPacedPacketSender : public RtpPacketSender {
public:
explicit NonPacedPacketSender(RtpSenderEgress* sender);
virtual ~NonPacedPacketSender();
void EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) override;
private:
uint16_t transport_sequence_number_;
RtpSenderEgress* const sender_;
};
RtpSenderEgress(const RtpRtcp::Configuration& config,
RtpPacketHistory* packet_history);
~RtpSenderEgress() = default; ~RtpSenderEgress() = default;
void SendPacket(RtpPacketToSend* packet, const PacedPacketInfo& pacing_info); void SendPacket(RtpPacketToSend* packet, const PacedPacketInfo& pacing_info);
@ -83,6 +99,7 @@ class RtpSenderEgress {
RtpPacketHistory* const packet_history_; RtpPacketHistory* const packet_history_;
Transport* const transport_; Transport* const transport_;
RtcEventLog* const event_log_; RtcEventLog* const event_log_;
const bool is_audio_;
TransportFeedbackObserver* const transport_feedback_observer_; TransportFeedbackObserver* const transport_feedback_observer_;
SendSideDelayObserver* const send_side_delay_observer_; SendSideDelayObserver* const send_side_delay_observer_;

View File

@ -339,14 +339,12 @@ void RTPSenderVideo::LogAndSendToNetwork(
int64_t now_ms = clock_->TimeInMilliseconds(); int64_t now_ms = clock_->TimeInMilliseconds();
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE #if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
for (const auto& packet : packets) { for (const auto& packet : packets) {
if (packet->packet_type() ==
RtpPacketToSend::Type::kForwardErrorCorrection) {
const uint32_t ssrc = packet->Ssrc(); const uint32_t ssrc = packet->Ssrc();
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoTotBitrate_kbps", now_ms,
rtp_sender_->ActualSendBitrateKbit(), ssrc);
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoFecBitrate_kbps", now_ms, BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoFecBitrate_kbps", now_ms,
FecOverheadRate() / 1000, ssrc); FecOverheadRate() / 1000, ssrc);
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoNackBitrate_kbps", now_ms, }
rtp_sender_->NackOverheadRate() / 1000,
ssrc);
} }
#endif #endif