Refactor PacketSequencer in preparation for deferred sequencing.

This CL is extracted from
https://webrtc-review.googlesource.com/c/src/+/208584
PacketSequencer now has its own unit tests. They are maybe somewhat
redundant with a few RtpSender unit tests, but will defer cleanup to
a later CL.

Bug: webrtc:11340, webrtc:12470
Change-Id: I1c31004b85ae075ddc696bdf1100d2a5044d4ef5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227343
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34638}
This commit is contained in:
Erik Språng
2021-08-03 20:24:13 +02:00
committed by WebRTC LUCI CQ
parent 49c9b4ec37
commit 18c0cc2bbd
5 changed files with 302 additions and 45 deletions

View File

@ -22,21 +22,19 @@ namespace webrtc {
// This class is not thread safe, the caller must provide that.
class PacketSequencer {
public:
// If |require_marker_before_media_padding_| is true, padding packets on the
// If `require_marker_before_media_padding_` is true, padding packets on the
// media ssrc is not allowed unless the last sequenced media packet had the
// marker bit set (i.e. don't insert padding packets between the first and
// last packets of a video frame).
// Packets with unknown SSRCs will be ignored.
PacketSequencer(uint32_t media_ssrc,
uint32_t rtx_ssrc,
absl::optional<uint32_t> rtx_ssrc,
bool require_marker_before_media_padding,
Clock* clock);
// Assigns sequence number, and in the case of non-RTX padding also timestamps
// and payload type.
// Returns false if sequencing failed, which it can do for instance if the
// packet to squence is padding on the media ssrc, but the media is mid frame
// (the last marker bit is false).
bool Sequence(RtpPacketToSend& packet);
void Sequence(RtpPacketToSend& packet);
void set_media_sequence_number(uint16_t sequence_number) {
media_sequence_number_ = sequence_number;
@ -51,12 +49,16 @@ class PacketSequencer {
uint16_t media_sequence_number() const { return media_sequence_number_; }
uint16_t rtx_sequence_number() const { return rtx_sequence_number_; }
// Checks whether it is allowed to send padding on the media SSRC at this
// time, e.g. that we don't send padding in the middle of a video frame.
bool CanSendPaddingOnMediaSsrc() const;
private:
void UpdateLastPacketState(const RtpPacketToSend& packet);
bool PopulatePaddingFields(RtpPacketToSend& packet);
void PopulatePaddingFields(RtpPacketToSend& packet);
const uint32_t media_ssrc_;
const uint32_t rtx_ssrc_;
const absl::optional<uint32_t> rtx_ssrc_;
const bool require_marker_before_media_padding_;
Clock* const clock_;