blob: dd3225cbf44219092a12ccc1db87b6d0db35df67 [file] [log] [blame]
Danil Chapovalova13e7a12020-07-14 12:34:36 +02001/*
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 */
Danil Chapovalovda7fe392020-10-15 15:57:17 +020010#include "modules/video_coding/svc/create_scalability_structure.h"
Danil Chapovalova13e7a12020-07-14 12:34:36 +020011
12#include <memory>
13
Niels Möller79d566b2022-04-29 11:03:13 +020014#include "api/video_codecs/scalability_mode.h"
Danil Chapovalovf91f8b52021-02-12 17:24:51 +010015#include "modules/video_coding/svc/scalability_structure_full_svc.h"
Danil Chapovalov4b18e242020-10-16 16:14:58 +020016#include "modules/video_coding/svc/scalability_structure_key_svc.h"
Danil Chapovalovda7fe392020-10-15 15:57:17 +020017#include "modules/video_coding/svc/scalability_structure_l2t2_key_shift.h"
Danil Chapovalov735e33f2021-02-18 14:39:52 +010018#include "modules/video_coding/svc/scalability_structure_simulcast.h"
Danil Chapovalovda7fe392020-10-15 15:57:17 +020019#include "modules/video_coding/svc/scalable_video_controller.h"
20#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
Danil Chapovalova13e7a12020-07-14 12:34:36 +020021#include "rtc_base/checks.h"
22
23namespace webrtc {
24namespace {
25
26struct NamedStructureFactory {
Niels Möller79d566b2022-04-29 11:03:13 +020027 ScalabilityMode name;
Danil Chapovalova13e7a12020-07-14 12:34:36 +020028 // Use function pointer to make NamedStructureFactory trivally destructable.
29 std::unique_ptr<ScalableVideoController> (*factory)();
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +020030 ScalableVideoController::StreamLayersConfig config;
Danil Chapovalova13e7a12020-07-14 12:34:36 +020031};
32
33// Wrap std::make_unique function to have correct return type.
34template <typename T>
35std::unique_ptr<ScalableVideoController> Create() {
36 return std::make_unique<T>();
37}
38
Danil Chapovalovf91f8b52021-02-12 17:24:51 +010039template <typename T>
40std::unique_ptr<ScalableVideoController> CreateH() {
41 // 1.5:1 scaling, see https://w3c.github.io/webrtc-svc/#scalabilitymodes*
42 typename T::ScalingFactor factor;
43 factor.num = 2;
44 factor.den = 3;
45 return std::make_unique<T>(factor);
46}
47
Niels Möllercc171952022-04-06 13:37:40 +020048constexpr ScalableVideoController::StreamLayersConfig kConfigL1T1 = {
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +020049 /*num_spatial_layers=*/1, /*num_temporal_layers=*/1,
50 /*uses_reference_scaling=*/false};
51
52constexpr ScalableVideoController::StreamLayersConfig kConfigL1T2 = {
53 /*num_spatial_layers=*/1, /*num_temporal_layers=*/2,
54 /*uses_reference_scaling=*/false};
55
56constexpr ScalableVideoController::StreamLayersConfig kConfigL1T3 = {
57 /*num_spatial_layers=*/1, /*num_temporal_layers=*/3,
58 /*uses_reference_scaling=*/false};
59
60constexpr ScalableVideoController::StreamLayersConfig kConfigL2T1 = {
61 /*num_spatial_layers=*/2,
62 /*num_temporal_layers=*/1,
63 /*uses_reference_scaling=*/true,
64 {1, 1},
65 {2, 1}};
66
67constexpr ScalableVideoController::StreamLayersConfig kConfigL2T1h = {
68 /*num_spatial_layers=*/2,
69 /*num_temporal_layers=*/1,
70 /*uses_reference_scaling=*/true,
71 {2, 1},
72 {3, 1}};
73
74constexpr ScalableVideoController::StreamLayersConfig kConfigL2T2 = {
75 /*num_spatial_layers=*/2,
76 /*num_temporal_layers=*/2,
77 /*uses_reference_scaling=*/true,
78 {1, 1},
79 {2, 1}};
80
Åsa Persson319531e2022-08-30 11:32:24 +020081constexpr ScalableVideoController::StreamLayersConfig kConfigL2T2h = {
82 /*num_spatial_layers=*/2,
83 /*num_temporal_layers=*/2,
84 /*uses_reference_scaling=*/true,
85 {2, 1},
86 {3, 1}};
87
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +020088constexpr ScalableVideoController::StreamLayersConfig kConfigL2T3 = {
89 /*num_spatial_layers=*/2,
90 /*num_temporal_layers=*/3,
91 /*uses_reference_scaling=*/true,
92 {1, 1},
93 {2, 1}};
94
Åsa Persson319531e2022-08-30 11:32:24 +020095constexpr ScalableVideoController::StreamLayersConfig kConfigL2T3h = {
96 /*num_spatial_layers=*/2,
97 /*num_temporal_layers=*/3,
98 /*uses_reference_scaling=*/true,
99 {2, 1},
100 {3, 1}};
101
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200102constexpr ScalableVideoController::StreamLayersConfig kConfigL3T1 = {
103 /*num_spatial_layers=*/3,
104 /*num_temporal_layers=*/1,
105 /*uses_reference_scaling=*/true,
106 {1, 1, 1},
107 {4, 2, 1}};
108
Åsa Persson319531e2022-08-30 11:32:24 +0200109constexpr ScalableVideoController::StreamLayersConfig kConfigL3T1h = {
110 /*num_spatial_layers=*/3,
111 /*num_temporal_layers=*/1,
112 /*uses_reference_scaling=*/true,
113 {4, 2, 1},
114 {9, 3, 1}};
115
Åsa Persson46f4de52022-08-26 12:24:59 +0200116constexpr ScalableVideoController::StreamLayersConfig kConfigL3T2 = {
117 /*num_spatial_layers=*/3,
118 /*num_temporal_layers=*/2,
119 /*uses_reference_scaling=*/true,
120 {1, 1, 1},
121 {4, 2, 1}};
122
Åsa Persson319531e2022-08-30 11:32:24 +0200123constexpr ScalableVideoController::StreamLayersConfig kConfigL3T2h = {
124 /*num_spatial_layers=*/3,
125 /*num_temporal_layers=*/2,
126 /*uses_reference_scaling=*/true,
127 {4, 2, 1},
128 {9, 3, 1}};
129
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200130constexpr ScalableVideoController::StreamLayersConfig kConfigL3T3 = {
131 /*num_spatial_layers=*/3,
132 /*num_temporal_layers=*/3,
133 /*uses_reference_scaling=*/true,
134 {1, 1, 1},
135 {4, 2, 1}};
136
Åsa Persson319531e2022-08-30 11:32:24 +0200137constexpr ScalableVideoController::StreamLayersConfig kConfigL3T3h = {
138 /*num_spatial_layers=*/3,
139 /*num_temporal_layers=*/3,
140 /*uses_reference_scaling=*/true,
141 {4, 2, 1},
142 {9, 3, 1}};
143
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200144constexpr ScalableVideoController::StreamLayersConfig kConfigS2T1 = {
145 /*num_spatial_layers=*/2,
146 /*num_temporal_layers=*/1,
147 /*uses_reference_scaling=*/false,
148 {1, 1},
149 {2, 1}};
150
Åsa Persson6d051642022-08-29 09:05:00 +0200151constexpr ScalableVideoController::StreamLayersConfig kConfigS2T2 = {
152 /*num_spatial_layers=*/2,
153 /*num_temporal_layers=*/2,
154 /*uses_reference_scaling=*/false,
155 {1, 1},
156 {2, 1}};
157
Niels Möller3c24c092022-06-30 15:42:51 +0200158constexpr ScalableVideoController::StreamLayersConfig kConfigS2T3 = {
159 /*num_spatial_layers=*/2,
160 /*num_temporal_layers=*/3,
161 /*uses_reference_scaling=*/false,
162 {1, 1},
163 {2, 1}};
164
Åsa Persson6d051642022-08-29 09:05:00 +0200165constexpr ScalableVideoController::StreamLayersConfig kConfigS3T1 = {
166 /*num_spatial_layers=*/3,
167 /*num_temporal_layers=*/1,
168 /*uses_reference_scaling=*/false,
169 {1, 1, 1},
170 {4, 2, 1}};
171
172constexpr ScalableVideoController::StreamLayersConfig kConfigS3T2 = {
173 /*num_spatial_layers=*/3,
174 /*num_temporal_layers=*/2,
175 /*uses_reference_scaling=*/false,
176 {1, 1, 1},
177 {4, 2, 1}};
178
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200179constexpr ScalableVideoController::StreamLayersConfig kConfigS3T3 = {
180 /*num_spatial_layers=*/3,
181 /*num_temporal_layers=*/3,
182 /*uses_reference_scaling=*/false,
183 {1, 1, 1},
184 {4, 2, 1}};
185
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200186constexpr NamedStructureFactory kFactories[] = {
Niels Möller79d566b2022-04-29 11:03:13 +0200187 {ScalabilityMode::kL1T1, Create<ScalableVideoControllerNoLayering>,
188 kConfigL1T1},
189 {ScalabilityMode::kL1T2, Create<ScalabilityStructureL1T2>, kConfigL1T2},
190 {ScalabilityMode::kL1T3, Create<ScalabilityStructureL1T3>, kConfigL1T3},
191 {ScalabilityMode::kL2T1, Create<ScalabilityStructureL2T1>, kConfigL2T1},
192 {ScalabilityMode::kL2T1h, CreateH<ScalabilityStructureL2T1>, kConfigL2T1h},
193 {ScalabilityMode::kL2T1_KEY, Create<ScalabilityStructureL2T1Key>,
194 kConfigL2T1},
195 {ScalabilityMode::kL2T2, Create<ScalabilityStructureL2T2>, kConfigL2T2},
Åsa Persson319531e2022-08-30 11:32:24 +0200196 {ScalabilityMode::kL2T2h, CreateH<ScalabilityStructureL2T2>, kConfigL2T2h},
Niels Möller79d566b2022-04-29 11:03:13 +0200197 {ScalabilityMode::kL2T2_KEY, Create<ScalabilityStructureL2T2Key>,
198 kConfigL2T2},
199 {ScalabilityMode::kL2T2_KEY_SHIFT, Create<ScalabilityStructureL2T2KeyShift>,
200 kConfigL2T2},
Niels Möller3c24c092022-06-30 15:42:51 +0200201 {ScalabilityMode::kL2T3, Create<ScalabilityStructureL2T3>, kConfigL2T3},
Åsa Persson319531e2022-08-30 11:32:24 +0200202 {ScalabilityMode::kL2T3h, CreateH<ScalabilityStructureL2T3>, kConfigL2T3h},
Niels Möller79d566b2022-04-29 11:03:13 +0200203 {ScalabilityMode::kL2T3_KEY, Create<ScalabilityStructureL2T3Key>,
204 kConfigL2T3},
205 {ScalabilityMode::kL3T1, Create<ScalabilityStructureL3T1>, kConfigL3T1},
Åsa Persson319531e2022-08-30 11:32:24 +0200206 {ScalabilityMode::kL3T1h, CreateH<ScalabilityStructureL3T1>, kConfigL3T1h},
Åsa Persson46f4de52022-08-26 12:24:59 +0200207 {ScalabilityMode::kL3T1_KEY, Create<ScalabilityStructureL3T1Key>,
208 kConfigL3T1},
209 {ScalabilityMode::kL3T2, Create<ScalabilityStructureL3T2>, kConfigL3T2},
Åsa Persson319531e2022-08-30 11:32:24 +0200210 {ScalabilityMode::kL3T2h, CreateH<ScalabilityStructureL3T2>, kConfigL3T2h},
Åsa Persson46f4de52022-08-26 12:24:59 +0200211 {ScalabilityMode::kL3T2_KEY, Create<ScalabilityStructureL3T2Key>,
212 kConfigL3T2},
Niels Möller79d566b2022-04-29 11:03:13 +0200213 {ScalabilityMode::kL3T3, Create<ScalabilityStructureL3T3>, kConfigL3T3},
Åsa Persson319531e2022-08-30 11:32:24 +0200214 {ScalabilityMode::kL3T3h, CreateH<ScalabilityStructureL3T3>, kConfigL3T3h},
Niels Möller79d566b2022-04-29 11:03:13 +0200215 {ScalabilityMode::kL3T3_KEY, Create<ScalabilityStructureL3T3Key>,
216 kConfigL3T3},
217 {ScalabilityMode::kS2T1, Create<ScalabilityStructureS2T1>, kConfigS2T1},
Åsa Persson6d051642022-08-29 09:05:00 +0200218 {ScalabilityMode::kS2T2, Create<ScalabilityStructureS2T2>, kConfigS2T2},
Niels Möller3c24c092022-06-30 15:42:51 +0200219 {ScalabilityMode::kS2T3, Create<ScalabilityStructureS2T3>, kConfigS2T3},
Åsa Persson6d051642022-08-29 09:05:00 +0200220 {ScalabilityMode::kS3T1, Create<ScalabilityStructureS3T1>, kConfigS3T1},
221 {ScalabilityMode::kS3T2, Create<ScalabilityStructureS3T2>, kConfigS3T2},
Niels Möller79d566b2022-04-29 11:03:13 +0200222 {ScalabilityMode::kS3T3, Create<ScalabilityStructureS3T3>, kConfigS3T3},
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200223};
224
225} // namespace
226
227std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
Niels Möller79d566b2022-04-29 11:03:13 +0200228 ScalabilityMode name) {
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200229 for (const auto& entry : kFactories) {
230 if (entry.name == name) {
231 return entry.factory();
232 }
233 }
234 return nullptr;
235}
236
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200237absl::optional<ScalableVideoController::StreamLayersConfig>
Niels Möller79d566b2022-04-29 11:03:13 +0200238ScalabilityStructureConfig(ScalabilityMode name) {
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200239 for (const auto& entry : kFactories) {
240 if (entry.name == name) {
241 return entry.config;
242 }
243 }
244 return absl::nullopt;
245}
246
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200247} // namespace webrtc