tor-browser

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

loss_notification_controller.h (4522B)


      1 /*
      2 *  Copyright (c) 2019 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_VIDEO_CODING_LOSS_NOTIFICATION_CONTROLLER_H_
     12 #define MODULES_VIDEO_CODING_LOSS_NOTIFICATION_CONTROLLER_H_
     13 
     14 #include <stdint.h>
     15 
     16 #include <optional>
     17 #include <set>
     18 
     19 #include "api/array_view.h"
     20 #include "api/sequence_checker.h"
     21 #include "modules/include/module_common_types.h"
     22 #include "rtc_base/system/no_unique_address.h"
     23 #include "rtc_base/thread_annotations.h"
     24 
     25 namespace webrtc {
     26 
     27 class LossNotificationController {
     28 public:
     29  struct FrameDetails {
     30    bool is_keyframe;
     31    int64_t frame_id;
     32    ArrayView<const int64_t> frame_dependencies;
     33  };
     34 
     35  LossNotificationController(KeyFrameRequestSender* key_frame_request_sender,
     36                             LossNotificationSender* loss_notification_sender);
     37  ~LossNotificationController();
     38 
     39  // An RTP packet was received from the network.
     40  // `frame` is non-null iff the packet is the first packet in the frame.
     41  void OnReceivedPacket(uint16_t rtp_seq_num, const FrameDetails* frame);
     42 
     43  // A frame was assembled from packets previously received.
     44  // (Should be called even if the frame was composed of a single packet.)
     45  void OnAssembledFrame(uint16_t first_seq_num,
     46                        int64_t frame_id,
     47                        bool discardable,
     48                        ArrayView<const int64_t> frame_dependencies);
     49 
     50 private:
     51  void DiscardOldInformation();
     52 
     53  bool AllDependenciesDecodable(
     54      ArrayView<const int64_t> frame_dependencies) const;
     55 
     56  // When the loss of a packet or the non-decodability of a frame is detected,
     57  // produces a key frame request or a loss notification.
     58  // 1. `last_received_seq_num` is the last received sequence number.
     59  // 2. `decodability_flag` refers to the frame associated with the last packet.
     60  //    It is set to `true` if and only if all of that frame's dependencies are
     61  //    known to be decodable, and the frame itself is not yet known to be
     62  //    unassemblable (i.e. no earlier parts of it were lost).
     63  //    Clarifications:
     64  //    a. In a multi-packet frame, the first packet reveals the frame's
     65  //       dependencies, but it is not yet known whether all parts of the
     66  //       current frame will be received.
     67  //    b. In a multi-packet frame, if the first packet is missed, the
     68  //       dependencies are unknown, but it is known that the frame itself
     69  //       is unassemblable.
     70  void HandleLoss(uint16_t last_received_seq_num, bool decodability_flag);
     71 
     72  KeyFrameRequestSender* const key_frame_request_sender_
     73      RTC_GUARDED_BY(sequence_checker_);
     74 
     75  LossNotificationSender* const loss_notification_sender_
     76      RTC_GUARDED_BY(sequence_checker_);
     77 
     78  // Tracked to avoid processing repeated frames (buggy/malicious remote).
     79  std::optional<int64_t> last_received_frame_id_
     80      RTC_GUARDED_BY(sequence_checker_);
     81 
     82  // Tracked to avoid processing repeated packets.
     83  std::optional<uint16_t> last_received_seq_num_
     84      RTC_GUARDED_BY(sequence_checker_);
     85 
     86  // Tracked in order to correctly report the potential-decodability of
     87  // multi-packet frames.
     88  bool current_frame_potentially_decodable_ RTC_GUARDED_BY(sequence_checker_);
     89 
     90  // Loss notifications contain the sequence number of the first packet of
     91  // the last decodable-and-non-discardable frame. Since this is a bit of
     92  // a mouthful, last_decodable_non_discardable_.first_seq_num is used,
     93  // which hopefully is a bit easier for human beings to parse
     94  // than `first_seq_num_of_last_decodable_non_discardable_`.
     95  struct FrameInfo {
     96    explicit FrameInfo(uint16_t first_seq_num) : first_seq_num(first_seq_num) {}
     97    uint16_t first_seq_num;
     98  };
     99  std::optional<FrameInfo> last_decodable_non_discardable_
    100      RTC_GUARDED_BY(sequence_checker_);
    101 
    102  // Track which frames are decodable. Later frames are also decodable if
    103  // all of their dependencies can be found in this container.
    104  // (Naturally, later frames must also be assemblable to be decodable.)
    105  std::set<int64_t> decodable_frame_ids_ RTC_GUARDED_BY(sequence_checker_);
    106 
    107  RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
    108 };
    109 
    110 }  // namespace webrtc
    111 
    112 #endif  // MODULES_VIDEO_CODING_LOSS_NOTIFICATION_CONTROLLER_H_