tor-browser

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

scalability_structure_key_svc.h (4609B)


      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 #ifndef MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_KEY_SVC_H_
     11 #define MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_KEY_SVC_H_
     12 
     13 #include <bitset>
     14 #include <vector>
     15 
     16 #include "api/transport/rtp/dependency_descriptor.h"
     17 #include "api/video/video_bitrate_allocation.h"
     18 #include "common_video/generic_frame_descriptor/generic_frame_info.h"
     19 #include "modules/video_coding/svc/scalable_video_controller.h"
     20 
     21 namespace webrtc {
     22 
     23 class ScalabilityStructureKeySvc : public ScalableVideoController {
     24 public:
     25  ScalabilityStructureKeySvc(int num_spatial_layers, int num_temporal_layers);
     26  ~ScalabilityStructureKeySvc() override;
     27 
     28  StreamLayersConfig StreamConfig() const override;
     29 
     30  std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
     31  GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
     32  void OnRatesUpdated(const VideoBitrateAllocation& bitrates) override;
     33 
     34 private:
     35  enum FramePattern : int {
     36    kNone,
     37    kKey,
     38    kDeltaT0,
     39    kDeltaT2A,
     40    kDeltaT1,
     41    kDeltaT2B,
     42  };
     43  static constexpr int kMaxNumSpatialLayers = 3;
     44  static constexpr int kMaxNumTemporalLayers = 3;
     45 
     46  // Index of the buffer to store last frame for layer (`sid`, `tid`)
     47  int BufferIndex(int sid, int tid) const {
     48    return tid * num_spatial_layers_ + sid;
     49  }
     50  bool DecodeTargetIsActive(int sid, int tid) const {
     51    return active_decode_targets_[sid * num_temporal_layers_ + tid];
     52  }
     53  void SetDecodeTargetIsActive(int sid, int tid, bool value) {
     54    active_decode_targets_.set(sid * num_temporal_layers_ + tid, value);
     55  }
     56  bool TemporalLayerIsActive(int tid) const;
     57  static DecodeTargetIndication Dti(int sid,
     58                                    int tid,
     59                                    const LayerFrameConfig& config);
     60 
     61  std::vector<LayerFrameConfig> KeyframeConfig();
     62  std::vector<LayerFrameConfig> T0Config();
     63  std::vector<LayerFrameConfig> T1Config();
     64  std::vector<LayerFrameConfig> T2Config(FramePattern pattern);
     65 
     66  FramePattern NextPattern(FramePattern last_pattern) const;
     67 
     68  const int num_spatial_layers_;
     69  const int num_temporal_layers_;
     70 
     71  FramePattern last_pattern_ = kNone;
     72  std::bitset<kMaxNumSpatialLayers> spatial_id_is_enabled_;
     73  std::bitset<kMaxNumSpatialLayers> can_reference_t1_frame_for_spatial_id_;
     74  std::bitset<32> active_decode_targets_;
     75 };
     76 
     77 // S1  0--0--0-
     78 //     |       ...
     79 // S0  0--0--0-
     80 class ScalabilityStructureL2T1Key : public ScalabilityStructureKeySvc {
     81 public:
     82  ScalabilityStructureL2T1Key() : ScalabilityStructureKeySvc(2, 1) {}
     83  ~ScalabilityStructureL2T1Key() override;
     84 
     85  FrameDependencyStructure DependencyStructure() const override;
     86 };
     87 
     88 // S1T1     0   0
     89 //         /   /   /
     90 // S1T0   0---0---0
     91 //        |         ...
     92 // S0T1   | 0   0
     93 //        |/   /   /
     94 // S0T0   0---0---0
     95 // Time-> 0 1 2 3 4
     96 class ScalabilityStructureL2T2Key : public ScalabilityStructureKeySvc {
     97 public:
     98  ScalabilityStructureL2T2Key() : ScalabilityStructureKeySvc(2, 2) {}
     99  ~ScalabilityStructureL2T2Key() override;
    100 
    101  FrameDependencyStructure DependencyStructure() const override;
    102 };
    103 
    104 class ScalabilityStructureL2T3Key : public ScalabilityStructureKeySvc {
    105 public:
    106  ScalabilityStructureL2T3Key() : ScalabilityStructureKeySvc(2, 3) {}
    107  ~ScalabilityStructureL2T3Key() override;
    108 
    109  FrameDependencyStructure DependencyStructure() const override;
    110 };
    111 
    112 class ScalabilityStructureL3T1Key : public ScalabilityStructureKeySvc {
    113 public:
    114  ScalabilityStructureL3T1Key() : ScalabilityStructureKeySvc(3, 1) {}
    115  ~ScalabilityStructureL3T1Key() override;
    116 
    117  FrameDependencyStructure DependencyStructure() const override;
    118 };
    119 
    120 class ScalabilityStructureL3T2Key : public ScalabilityStructureKeySvc {
    121 public:
    122  ScalabilityStructureL3T2Key() : ScalabilityStructureKeySvc(3, 2) {}
    123  ~ScalabilityStructureL3T2Key() override;
    124 
    125  FrameDependencyStructure DependencyStructure() const override;
    126 };
    127 
    128 class ScalabilityStructureL3T3Key : public ScalabilityStructureKeySvc {
    129 public:
    130  ScalabilityStructureL3T3Key() : ScalabilityStructureKeySvc(3, 3) {}
    131  ~ScalabilityStructureL3T3Key() override;
    132 
    133  FrameDependencyStructure DependencyStructure() const override;
    134 };
    135 
    136 }  // namespace webrtc
    137 
    138 #endif  // MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_KEY_SVC_H_