From f53cfa9ebef2dfe6c3d6f17242c90617ec38f703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Wed, 12 Jun 2019 13:58:17 +0200 Subject: [PATCH] Add new RtpPacketPacer interface, with callback. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL just adds the new interfaces, follow-ups will add implementation in various parts of the code, and then do cleanup once usage of old interface is gone. Bug: webrtc:10633 Change-Id: Icd916f4220065c0d0e4f3f0bfaaed248f8c70d08 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140891 Commit-Queue: Erik Språng Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#28252} --- modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/include/rtp_packet_pacer.h | 39 ++++++++++++++++++++ modules/rtp_rtcp/include/rtp_rtcp_defines.h | 10 ++--- modules/rtp_rtcp/source/flexfec_sender.cc | 3 +- modules/rtp_rtcp/source/rtp_packet_to_send.h | 17 ++++++--- modules/rtp_rtcp/source/rtp_sender.cc | 3 +- modules/rtp_rtcp/source/rtp_sender_video.cc | 2 +- 7 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 modules/rtp_rtcp/include/rtp_packet_pacer.h diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index f447b3e889..2818f95c0e 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -15,6 +15,7 @@ rtc_source_set("rtp_rtcp_format") { "include/rtcp_statistics.h", "include/rtp_cvo.h", "include/rtp_header_extension_map.h", + "include/rtp_packet_pacer.h", "include/rtp_rtcp_defines.h", "source/byte_io.h", "source/rtcp_packet.h", diff --git a/modules/rtp_rtcp/include/rtp_packet_pacer.h b/modules/rtp_rtcp/include/rtp_packet_pacer.h new file mode 100644 index 0000000000..9820fc2a46 --- /dev/null +++ b/modules/rtp_rtcp/include/rtp_packet_pacer.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 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 MODULES_RTP_RTCP_INCLUDE_RTP_PACKET_PACER_H_ +#define MODULES_RTP_RTCP_INCLUDE_RTP_PACKET_PACER_H_ + +#include + +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" +namespace webrtc { + +// Interface for a paced sender, as implemented in the pacing module. +// This intended to replace the RtpPacketSender interface defined in +// rtp_rtcp_defines.h +// TODO(bugs.webrtc.org/10633): Add things missing to this interface so that we +// can use multiple different pacer implementations, and stop inheriting from +// RtpPacketSender. +class RtpPacketPacer : RtpPacketSender { + public: + RtpPacketPacer() = default; + ~RtpPacketPacer() override; + + // Insert packet into queue, for eventual transmission. Based on the type of + // the packet, it will prioritized and scheduled relative to other packets and + // the current target send rate. + virtual void EnqueuePacket(std::unique_ptr packet) = 0; +}; + +} // namespace webrtc + +#endif // MODULES_RTP_RTCP_INCLUDE_RTP_PACKET_PACER_H_ diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h index 5d906126f9..d666ab4239 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h +++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h @@ -340,21 +340,21 @@ class RtcpRttStats { virtual ~RtcpRttStats() {} }; +// This class will be deprecated and replaced with RtpPacketPacer. class RtpPacketSender { public: RtpPacketSender() {} virtual ~RtpPacketSender() {} + // These are part of the legacy PacedSender interface and will be removed. enum Priority { kHighPriority = 0, // Pass through; will be sent immediately. kNormalPriority = 2, // Put in back of the line. kLowPriority = 3, // Put in back of the low priority line. }; - // Low priority packets are mixed with the normal priority packets - // while we are paused. - // Returns true if we send the packet now, else it will add the packet - // information to the queue and call TimeToSendPacket when it's time to send. + // Adds the packet information to the queue and call TimeToSendPacket when + // it's time to send. virtual void InsertPacket(Priority priority, uint32_t ssrc, uint16_t sequence_number, @@ -367,7 +367,7 @@ class RtpPacketSender { // the pacer budget calculation. The audio traffic still will be injected // at high priority. // TODO(alexnarest): Make it pure virtual after rtp_sender_unittest will be - // updated to support it + // updated to support it. virtual void SetAccountForAudioPackets(bool account_for_audio) {} }; diff --git a/modules/rtp_rtcp/source/flexfec_sender.cc b/modules/rtp_rtcp/source/flexfec_sender.cc index 02fee86aee..d7b8eca91c 100644 --- a/modules/rtp_rtcp/source/flexfec_sender.cc +++ b/modules/rtp_rtcp/source/flexfec_sender.cc @@ -126,7 +126,8 @@ std::vector> FlexfecSender::GetFecPackets() { for (const auto* fec_packet : ulpfec_generator_.generated_fec_packets_) { std::unique_ptr fec_packet_to_send( new RtpPacketToSend(&rtp_header_extension_map_)); - fec_packet_to_send->set_is_fec(true); + fec_packet_to_send->set_packet_type( + RtpPacketToSend::Type::kForwardErrorCorrection); // RTP header. fec_packet_to_send->SetMarker(false); diff --git a/modules/rtp_rtcp/source/rtp_packet_to_send.h b/modules/rtp_rtcp/source/rtp_packet_to_send.h index 21c9c86a4b..89612841e7 100644 --- a/modules/rtp_rtcp/source/rtp_packet_to_send.h +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.h @@ -14,6 +14,7 @@ #include #include +#include "absl/types/optional.h" #include "api/array_view.h" #include "api/video/video_timing.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" @@ -23,6 +24,14 @@ namespace webrtc { // Class to hold rtp packet with metadata for sender side. class RtpPacketToSend : public RtpPacket { public: + enum class Type { + kAudio, // Audio media packets. + kVideo, // Video media packets. + kRetransmission, // RTX (usually) packets send as response to NACK. + kForwardErrorCorrection, // FEC packets. + kPadding // RTX or plain padding sent to maintain BWE. + }; + explicit RtpPacketToSend(const ExtensionManager* extensions); RtpPacketToSend(const ExtensionManager* extensions, size_t capacity); RtpPacketToSend(const RtpPacketToSend& packet); @@ -38,9 +47,8 @@ class RtpPacketToSend : public RtpPacket { void set_capture_time_ms(int64_t time) { capture_time_ms_ = time; } - bool is_fec() const { return is_fec_; } - - void set_is_fec(bool fec) { is_fec_ = fec; } + void set_packet_type(Type type) { packet_type_ = type; } + absl::optional packet_type() const { return packet_type_; } // Additional data bound to the RTP packet for use in application code, // outside of WebRTC. @@ -78,8 +86,7 @@ class RtpPacketToSend : public RtpPacket { private: int64_t capture_time_ms_ = 0; - // Used for accounting purposes - bool is_fec_ = false; + absl::optional packet_type_; std::vector application_data_; }; diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index 3c80cae0f1..b7838592df 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -661,8 +661,9 @@ void RTPSender::UpdateRtpStats(const RtpPacketToSend& packet, if (counters->first_packet_time_ms == -1) counters->first_packet_time_ms = now_ms; - if (packet.is_fec()) + if (packet.packet_type() == RtpPacketToSend::Type::kForwardErrorCorrection) { counters->fec.AddPacket(packet); + } if (is_retransmit) { counters->retransmitted.AddPacket(packet); diff --git a/modules/rtp_rtcp/source/rtp_sender_video.cc b/modules/rtp_rtcp/source/rtp_sender_video.cc index 03110f784f..419e938e3c 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -307,7 +307,7 @@ void RTPSenderVideo::SendVideoPacketAsRedMaybeWithUlpfec( new RtpPacketToSend(*media_packet)); RTC_CHECK(rtp_packet->Parse(fec_packet->data(), fec_packet->length())); rtp_packet->set_capture_time_ms(media_packet->capture_time_ms()); - rtp_packet->set_is_fec(true); + rtp_packet->set_packet_type(RtpPacketToSend::Type::kForwardErrorCorrection); uint16_t fec_sequence_number = rtp_packet->SequenceNumber(); if (LogAndSendToNetwork(std::move(rtp_packet), kDontRetransmit, RtpPacketSender::kLowPriority)) {