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_FULL_SVC_H_ 11 #define MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_FULL_SVC_H_ 12 13 #include <bitset> 14 #include <vector> 15 16 #include "api/transport/rtp/dependency_descriptor.h" 17 #include "common_video/generic_frame_descriptor/generic_frame_info.h" 18 #include "modules/video_coding/svc/scalable_video_controller.h" 19 20 namespace webrtc { 21 22 class ScalabilityStructureFullSvc : public ScalableVideoController { 23 public: 24 struct ScalingFactor { 25 int num = 1; 26 int den = 2; 27 }; 28 ScalabilityStructureFullSvc(int num_spatial_layers, 29 int num_temporal_layers, 30 ScalingFactor resolution_factor); 31 ~ScalabilityStructureFullSvc() override; 32 33 StreamLayersConfig StreamConfig() const override; 34 35 std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override; 36 GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override; 37 void OnRatesUpdated(const VideoBitrateAllocation& bitrates) override; 38 39 private: 40 enum FramePattern { 41 kNone, 42 kKey, 43 kDeltaT2A, 44 kDeltaT1, 45 kDeltaT2B, 46 kDeltaT0, 47 }; 48 static constexpr absl::string_view kFramePatternNames[] = { 49 "None", "Key", "DeltaT2A", "DeltaT1", "DeltaT2B", "DeltaT0"}; 50 static constexpr int kMaxNumSpatialLayers = 3; 51 static constexpr int kMaxNumTemporalLayers = 3; 52 53 // Index of the buffer to store last frame for layer (`sid`, `tid`) BufferIndex(int sid,int tid)54 int BufferIndex(int sid, int tid) const { 55 return tid * num_spatial_layers_ + sid; 56 } DecodeTargetIsActive(int sid,int tid)57 bool DecodeTargetIsActive(int sid, int tid) const { 58 return active_decode_targets_[sid * num_temporal_layers_ + tid]; 59 } SetDecodeTargetIsActive(int sid,int tid,bool value)60 void SetDecodeTargetIsActive(int sid, int tid, bool value) { 61 active_decode_targets_.set(sid * num_temporal_layers_ + tid, value); 62 } 63 FramePattern NextPattern() const; 64 bool TemporalLayerIsActive(int tid) const; 65 static DecodeTargetIndication Dti(int sid, 66 int tid, 67 const LayerFrameConfig& frame); 68 69 const int num_spatial_layers_; 70 const int num_temporal_layers_; 71 const ScalingFactor resolution_factor_; 72 73 FramePattern last_pattern_ = kNone; 74 std::bitset<kMaxNumSpatialLayers> can_reference_t0_frame_for_spatial_id_ = 0; 75 std::bitset<kMaxNumSpatialLayers> can_reference_t1_frame_for_spatial_id_ = 0; 76 std::bitset<32> active_decode_targets_; 77 }; 78 79 // T1 0 0 80 // / / / ... 81 // T0 0---0---0-- 82 // Time-> 0 1 2 3 4 83 class ScalabilityStructureL1T2 : public ScalabilityStructureFullSvc { 84 public: 85 explicit ScalabilityStructureL1T2(ScalingFactor resolution_factor = {}) 86 : ScalabilityStructureFullSvc(1, 2, resolution_factor) {} 87 ~ScalabilityStructureL1T2() override = default; 88 89 FrameDependencyStructure DependencyStructure() const override; 90 }; 91 92 // T2 0 0 0 0 93 // | / | / 94 // T1 / 0 / 0 ... 95 // |_/ |_/ 96 // T0 0-------0------ 97 // Time-> 0 1 2 3 4 5 6 7 98 class ScalabilityStructureL1T3 : public ScalabilityStructureFullSvc { 99 public: 100 explicit ScalabilityStructureL1T3(ScalingFactor resolution_factor = {}) 101 : ScalabilityStructureFullSvc(1, 3, resolution_factor) {} 102 ~ScalabilityStructureL1T3() override = default; 103 104 FrameDependencyStructure DependencyStructure() const override; 105 }; 106 107 // S1 0--0--0- 108 // | | | ... 109 // S0 0--0--0- 110 class ScalabilityStructureL2T1 : public ScalabilityStructureFullSvc { 111 public: 112 explicit ScalabilityStructureL2T1(ScalingFactor resolution_factor = {}) 113 : ScalabilityStructureFullSvc(2, 1, resolution_factor) {} 114 ~ScalabilityStructureL2T1() override = default; 115 116 FrameDependencyStructure DependencyStructure() const override; 117 }; 118 119 // S1T1 0 0 120 // /| /| / 121 // S1T0 0-+-0-+-0 122 // | | | | | ... 123 // S0T1 | 0 | 0 | 124 // |/ |/ |/ 125 // S0T0 0---0---0-- 126 // Time-> 0 1 2 3 4 127 class ScalabilityStructureL2T2 : public ScalabilityStructureFullSvc { 128 public: 129 explicit ScalabilityStructureL2T2(ScalingFactor resolution_factor = {}) 130 : ScalabilityStructureFullSvc(2, 2, resolution_factor) {} 131 ~ScalabilityStructureL2T2() override = default; 132 133 FrameDependencyStructure DependencyStructure() const override; 134 }; 135 136 // S1T2 4 ,8 137 // S1T1 / | 6' | 138 // S1T0 2--+-'+--+-... 139 // | | | | 140 // S0T2 | 3 | ,7 141 // S0T1 | / 5' 142 // S0T0 1----'-----... 143 // Time-> 0 1 2 3 144 class ScalabilityStructureL2T3 : public ScalabilityStructureFullSvc { 145 public: 146 explicit ScalabilityStructureL2T3(ScalingFactor resolution_factor = {}) 147 : ScalabilityStructureFullSvc(2, 3, resolution_factor) {} 148 ~ScalabilityStructureL2T3() override = default; 149 150 FrameDependencyStructure DependencyStructure() const override; 151 }; 152 153 // S2 0-0-0- 154 // | | | 155 // S1 0-0-0-... 156 // | | | 157 // S0 0-0-0- 158 // Time-> 0 1 2 159 class ScalabilityStructureL3T1 : public ScalabilityStructureFullSvc { 160 public: 161 explicit ScalabilityStructureL3T1(ScalingFactor resolution_factor = {}) 162 : ScalabilityStructureFullSvc(3, 1, resolution_factor) {} 163 ~ScalabilityStructureL3T1() override = default; 164 165 FrameDependencyStructure DependencyStructure() const override; 166 }; 167 168 // https://www.w3.org/TR/webrtc-svc/#L3T2* 169 class ScalabilityStructureL3T2 : public ScalabilityStructureFullSvc { 170 public: 171 explicit ScalabilityStructureL3T2(ScalingFactor resolution_factor = {}) 172 : ScalabilityStructureFullSvc(3, 2, resolution_factor) {} 173 ~ScalabilityStructureL3T2() override = default; 174 175 FrameDependencyStructure DependencyStructure() const override; 176 }; 177 178 // https://www.w3.org/TR/webrtc-svc/#L3T3* 179 class ScalabilityStructureL3T3 : public ScalabilityStructureFullSvc { 180 public: 181 explicit ScalabilityStructureL3T3(ScalingFactor resolution_factor = {}) 182 : ScalabilityStructureFullSvc(3, 3, resolution_factor) {} 183 ~ScalabilityStructureL3T3() override = default; 184 185 FrameDependencyStructure DependencyStructure() const override; 186 }; 187 188 } // namespace webrtc 189 190 #endif // MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_FULL_SVC_H_ 191