tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

packet_sequencer.h (2951B)


      1 /*
      2 *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef MODULES_RTP_RTCP_SOURCE_PACKET_SEQUENCER_H_
     12 #define MODULES_RTP_RTCP_SOURCE_PACKET_SEQUENCER_H_
     13 
     14 #include <cstdint>
     15 #include <optional>
     16 
     17 #include "api/units/timestamp.h"
     18 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     19 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
     20 #include "system_wrappers/include/clock.h"
     21 
     22 namespace webrtc {
     23 
     24 // Helper class used to assign RTP sequence numbers and populate some fields for
     25 // padding packets based on the last sequenced packets.
     26 // This class is not thread safe, the caller must provide that.
     27 class PacketSequencer {
     28 public:
     29  // If `require_marker_before_media_padding_` is true, padding packets on the
     30  // media ssrc is not allowed unless the last sequenced media packet had the
     31  // marker bit set (i.e. don't insert padding packets between the first and
     32  // last packets of a video frame).
     33  // Packets with unknown SSRCs will be ignored.
     34  PacketSequencer(uint32_t media_ssrc,
     35                  std::optional<uint32_t> rtx_ssrc,
     36                  bool require_marker_before_media_padding,
     37                  Clock* clock);
     38 
     39  // Assigns sequence number, and in the case of non-RTX padding also timestamps
     40  // and payload type.
     41  void Sequence(RtpPacketToSend& packet);
     42 
     43  void set_media_sequence_number(uint16_t sequence_number) {
     44    media_sequence_number_ = sequence_number;
     45  }
     46  void set_rtx_sequence_number(uint16_t sequence_number) {
     47    rtx_sequence_number_ = sequence_number;
     48  }
     49 
     50  void SetRtpState(const RtpState& state);
     51  void PopulateRtpState(RtpState& state) const;
     52 
     53  uint16_t media_sequence_number() const { return media_sequence_number_; }
     54  uint16_t rtx_sequence_number() const { return rtx_sequence_number_; }
     55 
     56  // Checks whether it is allowed to send padding on the media SSRC at this
     57  // time, e.g. that we don't send padding in the middle of a video frame.
     58  bool CanSendPaddingOnMediaSsrc() const;
     59 
     60 private:
     61  void UpdateLastPacketState(const RtpPacketToSend& packet);
     62  void PopulatePaddingFields(RtpPacketToSend& packet);
     63 
     64  const uint32_t media_ssrc_;
     65  const std::optional<uint32_t> rtx_ssrc_;
     66  const bool require_marker_before_media_padding_;
     67  Clock* const clock_;
     68 
     69  uint16_t media_sequence_number_;
     70  uint16_t rtx_sequence_number_;
     71 
     72  int8_t last_payload_type_;
     73  uint32_t last_rtp_timestamp_;
     74  Timestamp last_capture_time_ = Timestamp::MinusInfinity();
     75  Timestamp last_timestamp_time_ = Timestamp::MinusInfinity();
     76  bool last_packet_marker_bit_;
     77 };
     78 
     79 }  // namespace webrtc
     80 
     81 #endif  // MODULES_RTP_RTCP_SOURCE_PACKET_SEQUENCER_H_