tor-browser

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

active_decode_targets_helper.h (2259B)


      1 /*
      2 *  Copyright (c) 2020 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_ACTIVE_DECODE_TARGETS_HELPER_H_
     12 #define MODULES_RTP_RTCP_SOURCE_ACTIVE_DECODE_TARGETS_HELPER_H_
     13 
     14 #include <stdint.h>
     15 
     16 #include <bitset>
     17 #include <optional>
     18 
     19 #include "api/array_view.h"
     20 
     21 namespace webrtc {
     22 
     23 // Helper class that decides when active_decode_target_bitmask should be written
     24 // into the dependency descriptor rtp header extension.
     25 // See: https://aomediacodec.github.io/av1-rtp-spec/#a44-switching
     26 // This class is thread-compatible
     27 class ActiveDecodeTargetsHelper {
     28 public:
     29  ActiveDecodeTargetsHelper() = default;
     30  ActiveDecodeTargetsHelper(const ActiveDecodeTargetsHelper&) = delete;
     31  ActiveDecodeTargetsHelper& operator=(const ActiveDecodeTargetsHelper&) =
     32      delete;
     33  ~ActiveDecodeTargetsHelper() = default;
     34 
     35  // Decides if active decode target bitmask should be attached to the frame
     36  // that is about to be sent.
     37  void OnFrame(ArrayView<const int> decode_target_protected_by_chain,
     38               std::bitset<32> active_decode_targets,
     39               bool is_keyframe,
     40               int64_t frame_id,
     41               ArrayView<const int> chain_diffs);
     42 
     43  // Returns active decode target to attach to the dependency descriptor.
     44  std::optional<uint32_t> ActiveDecodeTargetsBitmask() const {
     45    if (unsent_on_chain_.none())
     46      return std::nullopt;
     47    return last_active_decode_targets_.to_ulong();
     48  }
     49 
     50  std::bitset<32> ActiveChainsBitmask() const { return last_active_chains_; }
     51 
     52 private:
     53  // `unsent_on_chain_[i]` indicates last active decode
     54  // target bitmask wasn't attached to a packet on the chain with id `i`.
     55  std::bitset<32> unsent_on_chain_ = 0;
     56  std::bitset<32> last_active_decode_targets_ = 0;
     57  std::bitset<32> last_active_chains_ = 0;
     58  int64_t last_frame_id_ = 0;
     59 };
     60 
     61 }  // namespace webrtc
     62 
     63 #endif  // MODULES_RTP_RTCP_SOURCE_ACTIVE_DECODE_TARGETS_HELPER_H_