tor-browser

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

fec_test_helper.h (4050B)


      1 /*
      2 *  Copyright (c) 2012 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_FEC_TEST_HELPER_H_
     12 #define MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 
     17 #include "modules/rtp_rtcp/source/forward_error_correction.h"
     18 #include "modules/rtp_rtcp/source/rtp_packet.h"
     19 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
     20 #include "rtc_base/random.h"
     21 
     22 namespace webrtc {
     23 namespace test {
     24 namespace fec {
     25 
     26 // TODO(brandtr): Consider merging MediaPacketGenerator and
     27 // AugmentedPacketGenerator into a single class, since their functionality is
     28 // similar.
     29 
     30 // This class generates media packets corresponding to a single frame.
     31 class MediaPacketGenerator {
     32 public:
     33  MediaPacketGenerator(uint32_t min_packet_size,
     34                       uint32_t max_packet_size,
     35                       uint32_t ssrc,
     36                       Random* random);
     37  ~MediaPacketGenerator();
     38 
     39  // Construct the media packets, up to `num_media_packets` packets.
     40  ForwardErrorCorrection::PacketList ConstructMediaPackets(
     41      int num_media_packets,
     42      uint16_t start_seq_num);
     43  ForwardErrorCorrection::PacketList ConstructMediaPackets(
     44      int num_media_packets);
     45 
     46  uint16_t GetNextSeqNum();
     47 
     48 private:
     49  uint32_t min_packet_size_;
     50  uint32_t max_packet_size_;
     51  uint32_t ssrc_;
     52  Random* random_;
     53 
     54  ForwardErrorCorrection::PacketList media_packets_;
     55  uint16_t next_seq_num_;
     56 };
     57 
     58 // This class generates media packets with a certain structure of the payload.
     59 class AugmentedPacketGenerator {
     60 public:
     61  explicit AugmentedPacketGenerator(uint32_t ssrc);
     62 
     63  // Prepare for generating a new set of packets, corresponding to a frame.
     64  void NewFrame(size_t num_packets);
     65 
     66  // Increment and return the newly incremented sequence number.
     67  uint16_t NextPacketSeqNum();
     68 
     69  // Return the next packet in the current frame.
     70  template <typename T = RtpPacket>
     71  T NextPacket(size_t offset, size_t length) {
     72    T rtp_packet(/*extensions=*/nullptr);
     73    NextPacket(offset, length, rtp_packet);
     74    return rtp_packet;
     75  }
     76 
     77 protected:
     78  // Number of packets left to generate, in the current frame.
     79  size_t num_packets_;
     80 
     81 private:
     82  void NextPacket(size_t offset, size_t length, RtpPacket& packet);
     83 
     84  uint32_t ssrc_;
     85  uint16_t seq_num_;
     86  uint32_t timestamp_;
     87 };
     88 
     89 // This class generates media and FlexFEC packets for a single frame.
     90 class FlexfecPacketGenerator : public AugmentedPacketGenerator {
     91 public:
     92  FlexfecPacketGenerator(uint32_t media_ssrc, uint32_t flexfec_ssrc);
     93 
     94  // Creates a new AugmentedPacket (with RTP headers) from a
     95  // FlexFEC packet (without RTP headers).
     96  RtpPacketReceived BuildFlexfecPacket(
     97      const ForwardErrorCorrection::Packet& packet);
     98 
     99 private:
    100  uint32_t flexfec_ssrc_;
    101  uint16_t flexfec_seq_num_;
    102  uint32_t flexfec_timestamp_;
    103 };
    104 
    105 // This class generates media and ULPFEC packets (both encapsulated in RED)
    106 // for a single frame.
    107 class UlpfecPacketGenerator : public AugmentedPacketGenerator {
    108 public:
    109  explicit UlpfecPacketGenerator(uint32_t ssrc);
    110 
    111  // Creates a new RtpPacket with the RED header added to the packet.
    112  static RtpPacketReceived BuildMediaRedPacket(const RtpPacket& packet,
    113                                               bool is_recovered);
    114 
    115  // Creates a new RtpPacket with FEC payload and RED header. Does this by
    116  // creating a new fake media AugmentedPacket, clears the marker bit and adds a
    117  // RED header. Finally replaces the payload with the content of
    118  // `packet->data`.
    119  RtpPacketReceived BuildUlpfecRedPacket(
    120      const ForwardErrorCorrection::Packet& packet);
    121 };
    122 
    123 }  // namespace fec
    124 }  // namespace test
    125 }  // namespace webrtc
    126 
    127 #endif  // MODULES_RTP_RTCP_SOURCE_FEC_TEST_HELPER_H_