tor-browser

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

flexfec_sender.h (3820B)


      1 /*
      2 *  Copyright (c) 2016 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_INCLUDE_FLEXFEC_SENDER_H_
     12 #define MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <memory>
     17 #include <optional>
     18 #include <string>
     19 #include <vector>
     20 
     21 #include "absl/strings/string_view.h"
     22 #include "api/array_view.h"
     23 #include "api/environment/environment.h"
     24 #include "api/rtp_parameters.h"
     25 #include "api/units/data_rate.h"
     26 #include "api/units/timestamp.h"
     27 #include "modules/include/module_fec_types.h"
     28 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
     29 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     30 #include "modules/rtp_rtcp/source/rtp_header_extension_size.h"
     31 #include "modules/rtp_rtcp/source/ulpfec_generator.h"
     32 #include "modules/rtp_rtcp/source/video_fec_generator.h"
     33 #include "rtc_base/bitrate_tracker.h"
     34 #include "rtc_base/random.h"
     35 #include "rtc_base/synchronization/mutex.h"
     36 #include "rtc_base/thread_annotations.h"
     37 
     38 namespace webrtc {
     39 
     40 class RtpPacketToSend;
     41 
     42 // Note that this class is not thread safe, and thus requires external
     43 // synchronization. Currently, this is done using the lock in PayloadRouter.
     44 
     45 class FlexfecSender : public VideoFecGenerator {
     46 public:
     47  FlexfecSender(const Environment& env,
     48                int payload_type,
     49                uint32_t ssrc,
     50                uint32_t protected_media_ssrc,
     51                absl::string_view mid,
     52                const std::vector<RtpExtension>& rtp_header_extensions,
     53                ArrayView<const RtpExtensionSize> extension_sizes,
     54                const RtpState* rtp_state);
     55  ~FlexfecSender();
     56 
     57  FecType GetFecType() const override {
     58    return VideoFecGenerator::FecType::kFlexFec;
     59  }
     60  std::optional<uint32_t> FecSsrc() override { return ssrc_; }
     61 
     62  // Sets the FEC rate, max frames sent before FEC packets are sent,
     63  // and what type of generator matrices are used.
     64  void SetProtectionParameters(const FecProtectionParams& delta_params,
     65                               const FecProtectionParams& key_params) override;
     66 
     67  // Adds a media packet to the internal buffer. When enough media packets
     68  // have been added, the FEC packets are generated and stored internally.
     69  // These FEC packets are then obtained by calling GetFecPackets().
     70  void AddPacketAndGenerateFec(const RtpPacketToSend& packet) override;
     71 
     72  // Returns generated FlexFEC packets.
     73  std::vector<std::unique_ptr<RtpPacketToSend>> GetFecPackets() override;
     74 
     75  // Returns the overhead, per packet, for FlexFEC.
     76  size_t MaxPacketOverhead() const override;
     77 
     78  DataRate CurrentFecRate() const override;
     79 
     80  // Only called on the VideoSendStream queue, after operation has shut down.
     81  std::optional<RtpState> GetRtpState() override;
     82 
     83 private:
     84  // Utility.
     85  const Environment env_;
     86  Random random_;
     87  Timestamp last_generated_packet_ = Timestamp::MinusInfinity();
     88 
     89  // Config.
     90  const int payload_type_;
     91  const uint32_t timestamp_offset_;
     92  const uint32_t ssrc_;
     93  const uint32_t protected_media_ssrc_;
     94  // MID value to send in the MID header extension.
     95  const std::string mid_;
     96  // Sequence number of next packet to generate.
     97  uint16_t seq_num_;
     98 
     99  // Implementation.
    100  UlpfecGenerator ulpfec_generator_;
    101  const RtpHeaderExtensionMap rtp_header_extension_map_;
    102  const size_t header_extensions_size_;
    103 
    104  mutable Mutex mutex_;
    105  BitrateTracker fec_bitrate_ RTC_GUARDED_BY(mutex_);
    106 };
    107 
    108 }  // namespace webrtc
    109 
    110 #endif  // MODULES_RTP_RTCP_INCLUDE_FLEXFEC_SENDER_H_