Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 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_SIMULCAST_H_ |
| 11 | #define MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_ |
| 12 | |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "api/transport/rtp/dependency_descriptor.h" |
| 16 | #include "api/video/video_bitrate_allocation.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 | // Scalability structure with multiple independent spatial layers each with the |
| 23 | // same temporal layering. |
| 24 | class ScalabilityStructureSimulcast : public ScalableVideoController { |
| 25 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 26 | struct ScalingFactor { |
| 27 | int num = 1; |
| 28 | int den = 2; |
| 29 | }; |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 30 | ScalabilityStructureSimulcast(int num_spatial_layers, |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 31 | int num_temporal_layers, |
| 32 | ScalingFactor resolution_factor); |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 33 | ~ScalabilityStructureSimulcast() override; |
| 34 | |
| 35 | StreamLayersConfig StreamConfig() const override; |
| 36 | std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override; |
| 37 | GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override; |
| 38 | void OnRatesUpdated(const VideoBitrateAllocation& bitrates) override; |
| 39 | |
| 40 | private: |
| 41 | enum FramePattern { |
| 42 | kNone, |
| 43 | kDeltaT2A, |
| 44 | kDeltaT1, |
| 45 | kDeltaT2B, |
| 46 | kDeltaT0, |
| 47 | }; |
| 48 | static constexpr int kMaxNumSpatialLayers = 3; |
| 49 | static constexpr int kMaxNumTemporalLayers = 3; |
| 50 | |
| 51 | // Index of the buffer to store last frame for layer (`sid`, `tid`) |
| 52 | int BufferIndex(int sid, int tid) const { |
| 53 | return tid * num_spatial_layers_ + sid; |
| 54 | } |
| 55 | bool DecodeTargetIsActive(int sid, int tid) const { |
| 56 | return active_decode_targets_[sid * num_temporal_layers_ + tid]; |
| 57 | } |
| 58 | void SetDecodeTargetIsActive(int sid, int tid, bool value) { |
| 59 | active_decode_targets_.set(sid * num_temporal_layers_ + tid, value); |
| 60 | } |
| 61 | FramePattern NextPattern() const; |
| 62 | bool TemporalLayerIsActive(int tid) const; |
| 63 | |
| 64 | const int num_spatial_layers_; |
| 65 | const int num_temporal_layers_; |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 66 | const ScalingFactor resolution_factor_; |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 67 | |
| 68 | FramePattern last_pattern_ = kNone; |
| 69 | std::bitset<kMaxNumSpatialLayers> can_reference_t0_frame_for_spatial_id_ = 0; |
| 70 | std::bitset<kMaxNumSpatialLayers> can_reference_t1_frame_for_spatial_id_ = 0; |
| 71 | std::bitset<32> active_decode_targets_; |
| 72 | }; |
| 73 | |
| 74 | // S1 0--0--0- |
| 75 | // ... |
| 76 | // S0 0--0--0- |
| 77 | class ScalabilityStructureS2T1 : public ScalabilityStructureSimulcast { |
| 78 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 79 | explicit ScalabilityStructureS2T1(ScalingFactor resolution_factor = {}) |
| 80 | : ScalabilityStructureSimulcast(2, 1, resolution_factor) {} |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 81 | ~ScalabilityStructureS2T1() override = default; |
| 82 | |
| 83 | FrameDependencyStructure DependencyStructure() const override; |
| 84 | }; |
| 85 | |
Åsa Persson | 6d05164 | 2022-08-29 09:05:00 +0200 | [diff] [blame] | 86 | class ScalabilityStructureS2T2 : public ScalabilityStructureSimulcast { |
| 87 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 88 | explicit ScalabilityStructureS2T2(ScalingFactor resolution_factor = {}) |
| 89 | : ScalabilityStructureSimulcast(2, 2, resolution_factor) {} |
Åsa Persson | 6d05164 | 2022-08-29 09:05:00 +0200 | [diff] [blame] | 90 | ~ScalabilityStructureS2T2() override = default; |
| 91 | |
| 92 | FrameDependencyStructure DependencyStructure() const override; |
| 93 | }; |
| 94 | |
Niels Möller | 3c24c09 | 2022-06-30 15:42:51 +0200 | [diff] [blame] | 95 | // S1T2 3 7 |
| 96 | // | / |
| 97 | // S1T1 / 5 |
| 98 | // |_/ |
| 99 | // S1T0 1-------9... |
| 100 | // |
| 101 | // S0T2 2 6 |
| 102 | // | / |
| 103 | // S0T1 / 4 |
| 104 | // |_/ |
| 105 | // S0T0 0-------8... |
| 106 | // Time-> 0 1 2 3 4 |
| 107 | class ScalabilityStructureS2T3 : public ScalabilityStructureSimulcast { |
| 108 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 109 | explicit ScalabilityStructureS2T3(ScalingFactor resolution_factor = {}) |
| 110 | : ScalabilityStructureSimulcast(2, 3, resolution_factor) {} |
Niels Möller | 3c24c09 | 2022-06-30 15:42:51 +0200 | [diff] [blame] | 111 | ~ScalabilityStructureS2T3() override = default; |
| 112 | |
| 113 | FrameDependencyStructure DependencyStructure() const override; |
| 114 | }; |
| 115 | |
Åsa Persson | 6d05164 | 2022-08-29 09:05:00 +0200 | [diff] [blame] | 116 | class ScalabilityStructureS3T1 : public ScalabilityStructureSimulcast { |
| 117 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 118 | explicit ScalabilityStructureS3T1(ScalingFactor resolution_factor = {}) |
| 119 | : ScalabilityStructureSimulcast(3, 1, resolution_factor) {} |
Åsa Persson | 6d05164 | 2022-08-29 09:05:00 +0200 | [diff] [blame] | 120 | ~ScalabilityStructureS3T1() override = default; |
| 121 | |
| 122 | FrameDependencyStructure DependencyStructure() const override; |
| 123 | }; |
| 124 | |
| 125 | class ScalabilityStructureS3T2 : public ScalabilityStructureSimulcast { |
| 126 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 127 | explicit ScalabilityStructureS3T2(ScalingFactor resolution_factor = {}) |
| 128 | : ScalabilityStructureSimulcast(3, 2, resolution_factor) {} |
Åsa Persson | 6d05164 | 2022-08-29 09:05:00 +0200 | [diff] [blame] | 129 | ~ScalabilityStructureS3T2() override = default; |
| 130 | |
| 131 | FrameDependencyStructure DependencyStructure() const override; |
| 132 | }; |
| 133 | |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 134 | class ScalabilityStructureS3T3 : public ScalabilityStructureSimulcast { |
| 135 | public: |
Åsa Persson | ecfe8da | 2022-08-31 09:46:41 +0200 | [diff] [blame^] | 136 | explicit ScalabilityStructureS3T3(ScalingFactor resolution_factor = {}) |
| 137 | : ScalabilityStructureSimulcast(3, 3, resolution_factor) {} |
Danil Chapovalov | 735e33f | 2021-02-18 14:39:52 +0100 | [diff] [blame] | 138 | ~ScalabilityStructureS3T3() override = default; |
| 139 | |
| 140 | FrameDependencyStructure DependencyStructure() const override; |
| 141 | }; |
| 142 | |
| 143 | } // namespace webrtc |
| 144 | |
| 145 | #endif // MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_ |