blob: 510c9fd32cd33130031a771a74b883421d91346a [file] [log] [blame]
Niels Möller79d566b2022-04-29 11:03:13 +02001/*
2 * Copyright (c) 2022 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
11#include "modules/video_coding/svc/scalability_mode_util.h"
12
13#include "absl/strings/string_view.h"
14#include "absl/types/optional.h"
15#include "api/video_codecs/scalability_mode.h"
16#include "rtc_base/checks.h"
17
18namespace webrtc {
19
20absl::optional<ScalabilityMode> ScalabilityModeFromString(
21 absl::string_view mode_string) {
22 if (mode_string == "L1T1")
23 return ScalabilityMode::kL1T1;
24 if (mode_string == "L1T2")
25 return ScalabilityMode::kL1T2;
Niels Möller3b048132022-05-05 14:37:05 +020026 if (mode_string == "L1T2h")
27 return ScalabilityMode::kL1T2h;
Niels Möller79d566b2022-04-29 11:03:13 +020028 if (mode_string == "L1T3")
29 return ScalabilityMode::kL1T3;
Niels Möller3b048132022-05-05 14:37:05 +020030 if (mode_string == "L1T3h")
31 return ScalabilityMode::kL1T3h;
Niels Möller79d566b2022-04-29 11:03:13 +020032
33 if (mode_string == "L2T1")
34 return ScalabilityMode::kL2T1;
35 if (mode_string == "L2T1h")
36 return ScalabilityMode::kL2T1h;
37 if (mode_string == "L2T1_KEY")
38 return ScalabilityMode::kL2T1_KEY;
39
40 if (mode_string == "L2T2")
41 return ScalabilityMode::kL2T2;
Niels Möller3b048132022-05-05 14:37:05 +020042 if (mode_string == "L2T2h")
43 return ScalabilityMode::kL2T2h;
Niels Möller79d566b2022-04-29 11:03:13 +020044 if (mode_string == "L2T2_KEY")
45 return ScalabilityMode::kL2T2_KEY;
46 if (mode_string == "L2T2_KEY_SHIFT")
47 return ScalabilityMode::kL2T2_KEY_SHIFT;
Niels Möller3b048132022-05-05 14:37:05 +020048 if (mode_string == "L2T3")
49 return ScalabilityMode::kL2T3;
50 if (mode_string == "L2T3h")
51 return ScalabilityMode::kL2T3h;
Niels Möller79d566b2022-04-29 11:03:13 +020052 if (mode_string == "L2T3_KEY")
53 return ScalabilityMode::kL2T3_KEY;
54
55 if (mode_string == "L3T1")
56 return ScalabilityMode::kL3T1;
Niels Möller3b048132022-05-05 14:37:05 +020057 if (mode_string == "L3T1h")
58 return ScalabilityMode::kL3T1h;
59 if (mode_string == "L3T1_KEY")
60 return ScalabilityMode::kL3T1_KEY;
61
62 if (mode_string == "L3T2")
63 return ScalabilityMode::kL3T2;
64 if (mode_string == "L3T2h")
65 return ScalabilityMode::kL3T2h;
66 if (mode_string == "L3T2_KEY")
67 return ScalabilityMode::kL3T2_KEY;
68
Niels Möller79d566b2022-04-29 11:03:13 +020069 if (mode_string == "L3T3")
70 return ScalabilityMode::kL3T3;
Niels Möller3b048132022-05-05 14:37:05 +020071 if (mode_string == "L3T3h")
72 return ScalabilityMode::kL3T3h;
Niels Möller79d566b2022-04-29 11:03:13 +020073 if (mode_string == "L3T3_KEY")
74 return ScalabilityMode::kL3T3_KEY;
75
76 if (mode_string == "S2T1")
77 return ScalabilityMode::kS2T1;
Niels Möller3c24c092022-06-30 15:42:51 +020078 if (mode_string == "S2T3")
79 return ScalabilityMode::kS2T3;
Niels Möller79d566b2022-04-29 11:03:13 +020080 if (mode_string == "S3T3")
81 return ScalabilityMode::kS3T3;
82
83 return absl::nullopt;
84}
85
86absl::string_view ScalabilityModeToString(ScalabilityMode scalability_mode) {
87 switch (scalability_mode) {
88 case ScalabilityMode::kL1T1:
89 return "L1T1";
90 case ScalabilityMode::kL1T2:
91 return "L1T2";
Niels Möller3b048132022-05-05 14:37:05 +020092 case ScalabilityMode::kL1T2h:
93 return "L1T2h";
Niels Möller79d566b2022-04-29 11:03:13 +020094 case ScalabilityMode::kL1T3:
95 return "L1T3";
Niels Möller3b048132022-05-05 14:37:05 +020096 case ScalabilityMode::kL1T3h:
97 return "L1T3h";
Niels Möller79d566b2022-04-29 11:03:13 +020098 case ScalabilityMode::kL2T1:
99 return "L2T1";
100 case ScalabilityMode::kL2T1h:
101 return "L2T1h";
102 case ScalabilityMode::kL2T1_KEY:
103 return "L2T1_KEY";
104 case ScalabilityMode::kL2T2:
105 return "L2T2";
Niels Möller3b048132022-05-05 14:37:05 +0200106 case ScalabilityMode::kL2T2h:
107 return "L2T2h";
Niels Möller79d566b2022-04-29 11:03:13 +0200108 case ScalabilityMode::kL2T2_KEY:
109 return "L2T2_KEY";
110 case ScalabilityMode::kL2T2_KEY_SHIFT:
111 return "L2T2_KEY_SHIFT";
Niels Möller3b048132022-05-05 14:37:05 +0200112 case ScalabilityMode::kL2T3:
113 return "L2T3";
114 case ScalabilityMode::kL2T3h:
115 return "L2T3h";
Niels Möller79d566b2022-04-29 11:03:13 +0200116 case ScalabilityMode::kL2T3_KEY:
117 return "L2T3_KEY";
118 case ScalabilityMode::kL3T1:
119 return "L3T1";
Niels Möller3b048132022-05-05 14:37:05 +0200120 case ScalabilityMode::kL3T1h:
121 return "L3T1h";
122 case ScalabilityMode::kL3T1_KEY:
123 return "L3T1_KEY";
124 case ScalabilityMode::kL3T2:
125 return "L3T2";
126 case ScalabilityMode::kL3T2h:
127 return "L3T2h";
128 case ScalabilityMode::kL3T2_KEY:
129 return "L3T2_KEY";
Niels Möller79d566b2022-04-29 11:03:13 +0200130 case ScalabilityMode::kL3T3:
131 return "L3T3";
Niels Möller3b048132022-05-05 14:37:05 +0200132 case ScalabilityMode::kL3T3h:
133 return "L3T3h";
Niels Möller79d566b2022-04-29 11:03:13 +0200134 case ScalabilityMode::kL3T3_KEY:
135 return "L3T3_KEY";
136 case ScalabilityMode::kS2T1:
137 return "S2T1";
Niels Möller3c24c092022-06-30 15:42:51 +0200138 case ScalabilityMode::kS2T3:
139 return "S2T3";
Niels Möller79d566b2022-04-29 11:03:13 +0200140 case ScalabilityMode::kS3T3:
141 return "S3T3";
142 }
143 RTC_CHECK_NOTREACHED();
144}
145
Asa Perssoncde992d2022-05-16 22:37:34 +0200146InterLayerPredMode ScalabilityModeToInterLayerPredMode(
147 ScalabilityMode scalability_mode) {
148 switch (scalability_mode) {
149 case ScalabilityMode::kL1T1:
150 case ScalabilityMode::kL1T2:
151 case ScalabilityMode::kL1T2h:
152 case ScalabilityMode::kL1T3:
153 case ScalabilityMode::kL1T3h:
154 case ScalabilityMode::kL2T1:
155 case ScalabilityMode::kL2T1h:
156 return InterLayerPredMode::kOn;
157 case ScalabilityMode::kL2T1_KEY:
158 return InterLayerPredMode::kOnKeyPic;
159 case ScalabilityMode::kL2T2:
160 case ScalabilityMode::kL2T2h:
161 return InterLayerPredMode::kOn;
162 case ScalabilityMode::kL2T2_KEY:
163 case ScalabilityMode::kL2T2_KEY_SHIFT:
164 return InterLayerPredMode::kOnKeyPic;
165 case ScalabilityMode::kL2T3:
166 case ScalabilityMode::kL2T3h:
167 return InterLayerPredMode::kOn;
168 case ScalabilityMode::kL2T3_KEY:
169 return InterLayerPredMode::kOnKeyPic;
170 case ScalabilityMode::kL3T1:
171 case ScalabilityMode::kL3T1h:
172 return InterLayerPredMode::kOn;
173 case ScalabilityMode::kL3T1_KEY:
174 return InterLayerPredMode::kOnKeyPic;
175 case ScalabilityMode::kL3T2:
176 case ScalabilityMode::kL3T2h:
177 return InterLayerPredMode::kOn;
178 case ScalabilityMode::kL3T2_KEY:
179 return InterLayerPredMode::kOnKeyPic;
180 case ScalabilityMode::kL3T3:
181 case ScalabilityMode::kL3T3h:
182 return InterLayerPredMode::kOn;
183 case ScalabilityMode::kL3T3_KEY:
184 return InterLayerPredMode::kOnKeyPic;
185 case ScalabilityMode::kS2T1:
Niels Möller3c24c092022-06-30 15:42:51 +0200186 case ScalabilityMode::kS2T3:
Asa Perssoncde992d2022-05-16 22:37:34 +0200187 case ScalabilityMode::kS3T3:
188 return InterLayerPredMode::kOff;
189 }
190 RTC_CHECK_NOTREACHED();
191}
192
Asa Persson26983532022-05-13 16:24:22 +0200193int ScalabilityModeToNumSpatialLayers(ScalabilityMode scalability_mode) {
194 switch (scalability_mode) {
195 case ScalabilityMode::kL1T1:
196 case ScalabilityMode::kL1T2:
197 case ScalabilityMode::kL1T2h:
198 case ScalabilityMode::kL1T3:
199 case ScalabilityMode::kL1T3h:
200 return 1;
201 case ScalabilityMode::kL2T1:
202 case ScalabilityMode::kL2T1h:
203 case ScalabilityMode::kL2T1_KEY:
204 case ScalabilityMode::kL2T2:
205 case ScalabilityMode::kL2T2h:
206 case ScalabilityMode::kL2T2_KEY:
207 case ScalabilityMode::kL2T2_KEY_SHIFT:
208 case ScalabilityMode::kL2T3:
209 case ScalabilityMode::kL2T3h:
210 case ScalabilityMode::kL2T3_KEY:
211 return 2;
212 case ScalabilityMode::kL3T1:
213 case ScalabilityMode::kL3T1h:
214 case ScalabilityMode::kL3T1_KEY:
215 case ScalabilityMode::kL3T2:
216 case ScalabilityMode::kL3T2h:
217 case ScalabilityMode::kL3T2_KEY:
218 case ScalabilityMode::kL3T3:
219 case ScalabilityMode::kL3T3h:
220 case ScalabilityMode::kL3T3_KEY:
221 return 3;
222 case ScalabilityMode::kS2T1:
Niels Möller3c24c092022-06-30 15:42:51 +0200223 case ScalabilityMode::kS2T3:
Asa Persson26983532022-05-13 16:24:22 +0200224 return 2;
225 case ScalabilityMode::kS3T3:
226 return 3;
227 }
228 RTC_CHECK_NOTREACHED();
229}
230
Niels Möller05954892022-05-13 13:34:37 +0200231int ScalabilityModeToNumTemporalLayers(ScalabilityMode scalability_mode) {
232 switch (scalability_mode) {
233 case ScalabilityMode::kL1T1:
234 return 1;
235 case ScalabilityMode::kL1T2:
236 case ScalabilityMode::kL1T2h:
237 return 2;
238 case ScalabilityMode::kL1T3:
239 case ScalabilityMode::kL1T3h:
240 return 3;
241 case ScalabilityMode::kL2T1:
242 case ScalabilityMode::kL2T1h:
243 case ScalabilityMode::kL2T1_KEY:
244 return 1;
245 case ScalabilityMode::kL2T2:
246 case ScalabilityMode::kL2T2h:
247 case ScalabilityMode::kL2T2_KEY:
248 case ScalabilityMode::kL2T2_KEY_SHIFT:
249 return 2;
250 case ScalabilityMode::kL2T3:
251 case ScalabilityMode::kL2T3h:
252 case ScalabilityMode::kL2T3_KEY:
253 return 3;
254 case ScalabilityMode::kL3T1:
255 case ScalabilityMode::kL3T1h:
256 case ScalabilityMode::kL3T1_KEY:
257 return 1;
258 case ScalabilityMode::kL3T2:
259 case ScalabilityMode::kL3T2h:
260 case ScalabilityMode::kL3T2_KEY:
261 return 2;
262 case ScalabilityMode::kL3T3:
263 case ScalabilityMode::kL3T3h:
264 case ScalabilityMode::kL3T3_KEY:
265 return 3;
266 case ScalabilityMode::kS2T1:
267 return 1;
Niels Möller3c24c092022-06-30 15:42:51 +0200268 case ScalabilityMode::kS2T3:
Niels Möller05954892022-05-13 13:34:37 +0200269 case ScalabilityMode::kS3T3:
270 return 3;
271 }
272 RTC_CHECK_NOTREACHED();
273}
274
Niels Möller79d566b2022-04-29 11:03:13 +0200275} // namespace webrtc