blob: fbcd27b139e859dc3f99c6c9f430b527de5d57f1 [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 Perssonecfe8da2022-08-31 09:46:41 +0200151constexpr ScalableVideoController::StreamLayersConfig kConfigS2T1h = {
152 /*num_spatial_layers=*/2,
153 /*num_temporal_layers=*/1,
154 /*uses_reference_scaling=*/false,
155 {2, 1},
156 {3, 1}};
157
Åsa Persson6d051642022-08-29 09:05:00 +0200158constexpr ScalableVideoController::StreamLayersConfig kConfigS2T2 = {
159 /*num_spatial_layers=*/2,
160 /*num_temporal_layers=*/2,
161 /*uses_reference_scaling=*/false,
162 {1, 1},
163 {2, 1}};
164
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200165constexpr ScalableVideoController::StreamLayersConfig kConfigS2T2h = {
166 /*num_spatial_layers=*/2,
167 /*num_temporal_layers=*/2,
168 /*uses_reference_scaling=*/false,
169 {2, 1},
170 {3, 1}};
171
Niels Möller3c24c092022-06-30 15:42:51 +0200172constexpr ScalableVideoController::StreamLayersConfig kConfigS2T3 = {
173 /*num_spatial_layers=*/2,
174 /*num_temporal_layers=*/3,
175 /*uses_reference_scaling=*/false,
176 {1, 1},
177 {2, 1}};
178
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200179constexpr ScalableVideoController::StreamLayersConfig kConfigS2T3h = {
180 /*num_spatial_layers=*/2,
181 /*num_temporal_layers=*/3,
182 /*uses_reference_scaling=*/false,
183 {2, 1},
184 {3, 1}};
185
Åsa Persson6d051642022-08-29 09:05:00 +0200186constexpr ScalableVideoController::StreamLayersConfig kConfigS3T1 = {
187 /*num_spatial_layers=*/3,
188 /*num_temporal_layers=*/1,
189 /*uses_reference_scaling=*/false,
190 {1, 1, 1},
191 {4, 2, 1}};
192
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200193constexpr ScalableVideoController::StreamLayersConfig kConfigS3T1h = {
194 /*num_spatial_layers=*/3,
195 /*num_temporal_layers=*/1,
196 /*uses_reference_scaling=*/false,
197 {4, 2, 1},
198 {9, 3, 1}};
199
Åsa Persson6d051642022-08-29 09:05:00 +0200200constexpr ScalableVideoController::StreamLayersConfig kConfigS3T2 = {
201 /*num_spatial_layers=*/3,
202 /*num_temporal_layers=*/2,
203 /*uses_reference_scaling=*/false,
204 {1, 1, 1},
205 {4, 2, 1}};
206
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200207constexpr ScalableVideoController::StreamLayersConfig kConfigS3T2h = {
208 /*num_spatial_layers=*/3,
209 /*num_temporal_layers=*/2,
210 /*uses_reference_scaling=*/false,
211 {4, 2, 1},
212 {9, 3, 1}};
213
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200214constexpr ScalableVideoController::StreamLayersConfig kConfigS3T3 = {
215 /*num_spatial_layers=*/3,
216 /*num_temporal_layers=*/3,
217 /*uses_reference_scaling=*/false,
218 {1, 1, 1},
219 {4, 2, 1}};
220
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200221constexpr ScalableVideoController::StreamLayersConfig kConfigS3T3h = {
222 /*num_spatial_layers=*/3,
223 /*num_temporal_layers=*/3,
224 /*uses_reference_scaling=*/false,
225 {4, 2, 1},
226 {9, 3, 1}};
227
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200228constexpr NamedStructureFactory kFactories[] = {
Niels Möller79d566b2022-04-29 11:03:13 +0200229 {ScalabilityMode::kL1T1, Create<ScalableVideoControllerNoLayering>,
230 kConfigL1T1},
231 {ScalabilityMode::kL1T2, Create<ScalabilityStructureL1T2>, kConfigL1T2},
232 {ScalabilityMode::kL1T3, Create<ScalabilityStructureL1T3>, kConfigL1T3},
233 {ScalabilityMode::kL2T1, Create<ScalabilityStructureL2T1>, kConfigL2T1},
234 {ScalabilityMode::kL2T1h, CreateH<ScalabilityStructureL2T1>, kConfigL2T1h},
235 {ScalabilityMode::kL2T1_KEY, Create<ScalabilityStructureL2T1Key>,
236 kConfigL2T1},
237 {ScalabilityMode::kL2T2, Create<ScalabilityStructureL2T2>, kConfigL2T2},
Åsa Persson319531e2022-08-30 11:32:24 +0200238 {ScalabilityMode::kL2T2h, CreateH<ScalabilityStructureL2T2>, kConfigL2T2h},
Niels Möller79d566b2022-04-29 11:03:13 +0200239 {ScalabilityMode::kL2T2_KEY, Create<ScalabilityStructureL2T2Key>,
240 kConfigL2T2},
241 {ScalabilityMode::kL2T2_KEY_SHIFT, Create<ScalabilityStructureL2T2KeyShift>,
242 kConfigL2T2},
Niels Möller3c24c092022-06-30 15:42:51 +0200243 {ScalabilityMode::kL2T3, Create<ScalabilityStructureL2T3>, kConfigL2T3},
Åsa Persson319531e2022-08-30 11:32:24 +0200244 {ScalabilityMode::kL2T3h, CreateH<ScalabilityStructureL2T3>, kConfigL2T3h},
Niels Möller79d566b2022-04-29 11:03:13 +0200245 {ScalabilityMode::kL2T3_KEY, Create<ScalabilityStructureL2T3Key>,
246 kConfigL2T3},
247 {ScalabilityMode::kL3T1, Create<ScalabilityStructureL3T1>, kConfigL3T1},
Åsa Persson319531e2022-08-30 11:32:24 +0200248 {ScalabilityMode::kL3T1h, CreateH<ScalabilityStructureL3T1>, kConfigL3T1h},
Åsa Persson46f4de52022-08-26 12:24:59 +0200249 {ScalabilityMode::kL3T1_KEY, Create<ScalabilityStructureL3T1Key>,
250 kConfigL3T1},
251 {ScalabilityMode::kL3T2, Create<ScalabilityStructureL3T2>, kConfigL3T2},
Åsa Persson319531e2022-08-30 11:32:24 +0200252 {ScalabilityMode::kL3T2h, CreateH<ScalabilityStructureL3T2>, kConfigL3T2h},
Åsa Persson46f4de52022-08-26 12:24:59 +0200253 {ScalabilityMode::kL3T2_KEY, Create<ScalabilityStructureL3T2Key>,
254 kConfigL3T2},
Niels Möller79d566b2022-04-29 11:03:13 +0200255 {ScalabilityMode::kL3T3, Create<ScalabilityStructureL3T3>, kConfigL3T3},
Åsa Persson319531e2022-08-30 11:32:24 +0200256 {ScalabilityMode::kL3T3h, CreateH<ScalabilityStructureL3T3>, kConfigL3T3h},
Niels Möller79d566b2022-04-29 11:03:13 +0200257 {ScalabilityMode::kL3T3_KEY, Create<ScalabilityStructureL3T3Key>,
258 kConfigL3T3},
259 {ScalabilityMode::kS2T1, Create<ScalabilityStructureS2T1>, kConfigS2T1},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200260 {ScalabilityMode::kS2T1h, CreateH<ScalabilityStructureS2T1>, kConfigS2T1h},
Åsa Persson6d051642022-08-29 09:05:00 +0200261 {ScalabilityMode::kS2T2, Create<ScalabilityStructureS2T2>, kConfigS2T2},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200262 {ScalabilityMode::kS2T2h, CreateH<ScalabilityStructureS2T2>, kConfigS2T2h},
Niels Möller3c24c092022-06-30 15:42:51 +0200263 {ScalabilityMode::kS2T3, Create<ScalabilityStructureS2T3>, kConfigS2T3},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200264 {ScalabilityMode::kS2T3h, CreateH<ScalabilityStructureS2T3>, kConfigS2T3h},
Åsa Persson6d051642022-08-29 09:05:00 +0200265 {ScalabilityMode::kS3T1, Create<ScalabilityStructureS3T1>, kConfigS3T1},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200266 {ScalabilityMode::kS3T1h, CreateH<ScalabilityStructureS3T1>, kConfigS3T1h},
Åsa Persson6d051642022-08-29 09:05:00 +0200267 {ScalabilityMode::kS3T2, Create<ScalabilityStructureS3T2>, kConfigS3T2},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200268 {ScalabilityMode::kS3T2h, CreateH<ScalabilityStructureS3T2>, kConfigS3T2h},
Niels Möller79d566b2022-04-29 11:03:13 +0200269 {ScalabilityMode::kS3T3, Create<ScalabilityStructureS3T3>, kConfigS3T3},
Åsa Perssonecfe8da2022-08-31 09:46:41 +0200270 {ScalabilityMode::kS3T3h, CreateH<ScalabilityStructureS3T3>, kConfigS3T3h},
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200271};
272
273} // namespace
274
275std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
Niels Möller79d566b2022-04-29 11:03:13 +0200276 ScalabilityMode name) {
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200277 for (const auto& entry : kFactories) {
278 if (entry.name == name) {
279 return entry.factory();
280 }
281 }
282 return nullptr;
283}
284
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200285absl::optional<ScalableVideoController::StreamLayersConfig>
Niels Möller79d566b2022-04-29 11:03:13 +0200286ScalabilityStructureConfig(ScalabilityMode name) {
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200287 for (const auto& entry : kFactories) {
288 if (entry.name == name) {
289 return entry.config;
290 }
291 }
292 return absl::nullopt;
293}
294
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200295} // namespace webrtc