blob: 8e939b4d133325f61d9d7fa29b244e267da1c73e [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
81constexpr ScalableVideoController::StreamLayersConfig kConfigL2T3 = {
82 /*num_spatial_layers=*/2,
83 /*num_temporal_layers=*/3,
84 /*uses_reference_scaling=*/true,
85 {1, 1},
86 {2, 1}};
87
88constexpr ScalableVideoController::StreamLayersConfig kConfigL3T1 = {
89 /*num_spatial_layers=*/3,
90 /*num_temporal_layers=*/1,
91 /*uses_reference_scaling=*/true,
92 {1, 1, 1},
93 {4, 2, 1}};
94
Åsa Persson46f4de52022-08-26 12:24:59 +020095constexpr ScalableVideoController::StreamLayersConfig kConfigL3T2 = {
96 /*num_spatial_layers=*/3,
97 /*num_temporal_layers=*/2,
98 /*uses_reference_scaling=*/true,
99 {1, 1, 1},
100 {4, 2, 1}};
101
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200102constexpr ScalableVideoController::StreamLayersConfig kConfigL3T3 = {
103 /*num_spatial_layers=*/3,
104 /*num_temporal_layers=*/3,
105 /*uses_reference_scaling=*/true,
106 {1, 1, 1},
107 {4, 2, 1}};
108
109constexpr ScalableVideoController::StreamLayersConfig kConfigS2T1 = {
110 /*num_spatial_layers=*/2,
111 /*num_temporal_layers=*/1,
112 /*uses_reference_scaling=*/false,
113 {1, 1},
114 {2, 1}};
115
Niels Möller3c24c092022-06-30 15:42:51 +0200116constexpr ScalableVideoController::StreamLayersConfig kConfigS2T3 = {
117 /*num_spatial_layers=*/2,
118 /*num_temporal_layers=*/3,
119 /*uses_reference_scaling=*/false,
120 {1, 1},
121 {2, 1}};
122
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200123constexpr ScalableVideoController::StreamLayersConfig kConfigS3T3 = {
124 /*num_spatial_layers=*/3,
125 /*num_temporal_layers=*/3,
126 /*uses_reference_scaling=*/false,
127 {1, 1, 1},
128 {4, 2, 1}};
129
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200130constexpr NamedStructureFactory kFactories[] = {
Niels Möller79d566b2022-04-29 11:03:13 +0200131 {ScalabilityMode::kL1T1, Create<ScalableVideoControllerNoLayering>,
132 kConfigL1T1},
133 {ScalabilityMode::kL1T2, Create<ScalabilityStructureL1T2>, kConfigL1T2},
134 {ScalabilityMode::kL1T3, Create<ScalabilityStructureL1T3>, kConfigL1T3},
135 {ScalabilityMode::kL2T1, Create<ScalabilityStructureL2T1>, kConfigL2T1},
136 {ScalabilityMode::kL2T1h, CreateH<ScalabilityStructureL2T1>, kConfigL2T1h},
137 {ScalabilityMode::kL2T1_KEY, Create<ScalabilityStructureL2T1Key>,
138 kConfigL2T1},
139 {ScalabilityMode::kL2T2, Create<ScalabilityStructureL2T2>, kConfigL2T2},
140 {ScalabilityMode::kL2T2_KEY, Create<ScalabilityStructureL2T2Key>,
141 kConfigL2T2},
142 {ScalabilityMode::kL2T2_KEY_SHIFT, Create<ScalabilityStructureL2T2KeyShift>,
143 kConfigL2T2},
Niels Möller3c24c092022-06-30 15:42:51 +0200144 {ScalabilityMode::kL2T3, Create<ScalabilityStructureL2T3>, kConfigL2T3},
Niels Möller79d566b2022-04-29 11:03:13 +0200145 {ScalabilityMode::kL2T3_KEY, Create<ScalabilityStructureL2T3Key>,
146 kConfigL2T3},
147 {ScalabilityMode::kL3T1, Create<ScalabilityStructureL3T1>, kConfigL3T1},
Åsa Persson46f4de52022-08-26 12:24:59 +0200148 {ScalabilityMode::kL3T1_KEY, Create<ScalabilityStructureL3T1Key>,
149 kConfigL3T1},
150 {ScalabilityMode::kL3T2, Create<ScalabilityStructureL3T2>, kConfigL3T2},
151 {ScalabilityMode::kL3T2_KEY, Create<ScalabilityStructureL3T2Key>,
152 kConfigL3T2},
Niels Möller79d566b2022-04-29 11:03:13 +0200153 {ScalabilityMode::kL3T3, Create<ScalabilityStructureL3T3>, kConfigL3T3},
154 {ScalabilityMode::kL3T3_KEY, Create<ScalabilityStructureL3T3Key>,
155 kConfigL3T3},
156 {ScalabilityMode::kS2T1, Create<ScalabilityStructureS2T1>, kConfigS2T1},
Niels Möller3c24c092022-06-30 15:42:51 +0200157 {ScalabilityMode::kS2T3, Create<ScalabilityStructureS2T3>, kConfigS2T3},
Niels Möller79d566b2022-04-29 11:03:13 +0200158 {ScalabilityMode::kS3T3, Create<ScalabilityStructureS3T3>, kConfigS3T3},
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200159};
160
161} // namespace
162
163std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
Niels Möller79d566b2022-04-29 11:03:13 +0200164 ScalabilityMode name) {
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200165 for (const auto& entry : kFactories) {
166 if (entry.name == name) {
167 return entry.factory();
168 }
169 }
170 return nullptr;
171}
172
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200173absl::optional<ScalableVideoController::StreamLayersConfig>
Niels Möller79d566b2022-04-29 11:03:13 +0200174ScalabilityStructureConfig(ScalabilityMode name) {
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200175 for (const auto& entry : kFactories) {
176 if (entry.name == name) {
177 return entry.config;
178 }
179 }
180 return absl::nullopt;
181}
182
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200183} // namespace webrtc