blob: 070dcfe15c68bc9f0ff121026adba9cbd7af6f6f [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;
26 if (mode_string == "L1T3")
27 return ScalabilityMode::kL1T3;
28
29 if (mode_string == "L2T1")
30 return ScalabilityMode::kL2T1;
31 if (mode_string == "L2T1h")
32 return ScalabilityMode::kL2T1h;
33 if (mode_string == "L2T1_KEY")
34 return ScalabilityMode::kL2T1_KEY;
35
36 if (mode_string == "L2T2")
37 return ScalabilityMode::kL2T2;
Niels Möller3b048132022-05-05 14:37:05 +020038 if (mode_string == "L2T2h")
39 return ScalabilityMode::kL2T2h;
Niels Möller79d566b2022-04-29 11:03:13 +020040 if (mode_string == "L2T2_KEY")
41 return ScalabilityMode::kL2T2_KEY;
42 if (mode_string == "L2T2_KEY_SHIFT")
43 return ScalabilityMode::kL2T2_KEY_SHIFT;
Niels Möller3b048132022-05-05 14:37:05 +020044 if (mode_string == "L2T3")
45 return ScalabilityMode::kL2T3;
46 if (mode_string == "L2T3h")
47 return ScalabilityMode::kL2T3h;
Niels Möller79d566b2022-04-29 11:03:13 +020048 if (mode_string == "L2T3_KEY")
49 return ScalabilityMode::kL2T3_KEY;
50
51 if (mode_string == "L3T1")
52 return ScalabilityMode::kL3T1;
Niels Möller3b048132022-05-05 14:37:05 +020053 if (mode_string == "L3T1h")
54 return ScalabilityMode::kL3T1h;
55 if (mode_string == "L3T1_KEY")
56 return ScalabilityMode::kL3T1_KEY;
57
58 if (mode_string == "L3T2")
59 return ScalabilityMode::kL3T2;
60 if (mode_string == "L3T2h")
61 return ScalabilityMode::kL3T2h;
62 if (mode_string == "L3T2_KEY")
63 return ScalabilityMode::kL3T2_KEY;
64
Niels Möller79d566b2022-04-29 11:03:13 +020065 if (mode_string == "L3T3")
66 return ScalabilityMode::kL3T3;
Niels Möller3b048132022-05-05 14:37:05 +020067 if (mode_string == "L3T3h")
68 return ScalabilityMode::kL3T3h;
Niels Möller79d566b2022-04-29 11:03:13 +020069 if (mode_string == "L3T3_KEY")
70 return ScalabilityMode::kL3T3_KEY;
71
72 if (mode_string == "S2T1")
73 return ScalabilityMode::kS2T1;
Åsa Persson6d051642022-08-29 09:05:00 +020074 if (mode_string == "S2T2")
75 return ScalabilityMode::kS2T2;
Niels Möller3c24c092022-06-30 15:42:51 +020076 if (mode_string == "S2T3")
77 return ScalabilityMode::kS2T3;
Åsa Persson6d051642022-08-29 09:05:00 +020078 if (mode_string == "S3T1")
79 return ScalabilityMode::kS3T1;
80 if (mode_string == "S3T2")
81 return ScalabilityMode::kS3T2;
Niels Möller79d566b2022-04-29 11:03:13 +020082 if (mode_string == "S3T3")
83 return ScalabilityMode::kS3T3;
84
85 return absl::nullopt;
86}
87
Asa Perssoncde992d2022-05-16 22:37:34 +020088InterLayerPredMode ScalabilityModeToInterLayerPredMode(
89 ScalabilityMode scalability_mode) {
90 switch (scalability_mode) {
91 case ScalabilityMode::kL1T1:
92 case ScalabilityMode::kL1T2:
Asa Perssoncde992d2022-05-16 22:37:34 +020093 case ScalabilityMode::kL1T3:
Asa Perssoncde992d2022-05-16 22:37:34 +020094 case ScalabilityMode::kL2T1:
95 case ScalabilityMode::kL2T1h:
96 return InterLayerPredMode::kOn;
97 case ScalabilityMode::kL2T1_KEY:
98 return InterLayerPredMode::kOnKeyPic;
99 case ScalabilityMode::kL2T2:
100 case ScalabilityMode::kL2T2h:
101 return InterLayerPredMode::kOn;
102 case ScalabilityMode::kL2T2_KEY:
103 case ScalabilityMode::kL2T2_KEY_SHIFT:
104 return InterLayerPredMode::kOnKeyPic;
105 case ScalabilityMode::kL2T3:
106 case ScalabilityMode::kL2T3h:
107 return InterLayerPredMode::kOn;
108 case ScalabilityMode::kL2T3_KEY:
109 return InterLayerPredMode::kOnKeyPic;
110 case ScalabilityMode::kL3T1:
111 case ScalabilityMode::kL3T1h:
112 return InterLayerPredMode::kOn;
113 case ScalabilityMode::kL3T1_KEY:
114 return InterLayerPredMode::kOnKeyPic;
115 case ScalabilityMode::kL3T2:
116 case ScalabilityMode::kL3T2h:
117 return InterLayerPredMode::kOn;
118 case ScalabilityMode::kL3T2_KEY:
119 return InterLayerPredMode::kOnKeyPic;
120 case ScalabilityMode::kL3T3:
121 case ScalabilityMode::kL3T3h:
122 return InterLayerPredMode::kOn;
123 case ScalabilityMode::kL3T3_KEY:
124 return InterLayerPredMode::kOnKeyPic;
125 case ScalabilityMode::kS2T1:
Åsa Persson6d051642022-08-29 09:05:00 +0200126 case ScalabilityMode::kS2T2:
Niels Möller3c24c092022-06-30 15:42:51 +0200127 case ScalabilityMode::kS2T3:
Åsa Persson6d051642022-08-29 09:05:00 +0200128 case ScalabilityMode::kS3T1:
129 case ScalabilityMode::kS3T2:
Asa Perssoncde992d2022-05-16 22:37:34 +0200130 case ScalabilityMode::kS3T3:
131 return InterLayerPredMode::kOff;
132 }
133 RTC_CHECK_NOTREACHED();
134}
135
Asa Persson26983532022-05-13 16:24:22 +0200136int ScalabilityModeToNumSpatialLayers(ScalabilityMode scalability_mode) {
137 switch (scalability_mode) {
138 case ScalabilityMode::kL1T1:
139 case ScalabilityMode::kL1T2:
Asa Persson26983532022-05-13 16:24:22 +0200140 case ScalabilityMode::kL1T3:
Asa Persson26983532022-05-13 16:24:22 +0200141 return 1;
142 case ScalabilityMode::kL2T1:
143 case ScalabilityMode::kL2T1h:
144 case ScalabilityMode::kL2T1_KEY:
145 case ScalabilityMode::kL2T2:
146 case ScalabilityMode::kL2T2h:
147 case ScalabilityMode::kL2T2_KEY:
148 case ScalabilityMode::kL2T2_KEY_SHIFT:
149 case ScalabilityMode::kL2T3:
150 case ScalabilityMode::kL2T3h:
151 case ScalabilityMode::kL2T3_KEY:
152 return 2;
153 case ScalabilityMode::kL3T1:
154 case ScalabilityMode::kL3T1h:
155 case ScalabilityMode::kL3T1_KEY:
156 case ScalabilityMode::kL3T2:
157 case ScalabilityMode::kL3T2h:
158 case ScalabilityMode::kL3T2_KEY:
159 case ScalabilityMode::kL3T3:
160 case ScalabilityMode::kL3T3h:
161 case ScalabilityMode::kL3T3_KEY:
162 return 3;
163 case ScalabilityMode::kS2T1:
Åsa Persson6d051642022-08-29 09:05:00 +0200164 case ScalabilityMode::kS2T2:
Niels Möller3c24c092022-06-30 15:42:51 +0200165 case ScalabilityMode::kS2T3:
Asa Persson26983532022-05-13 16:24:22 +0200166 return 2;
Åsa Persson6d051642022-08-29 09:05:00 +0200167 case ScalabilityMode::kS3T1:
168 case ScalabilityMode::kS3T2:
Asa Persson26983532022-05-13 16:24:22 +0200169 case ScalabilityMode::kS3T3:
170 return 3;
171 }
172 RTC_CHECK_NOTREACHED();
173}
174
Niels Möller05954892022-05-13 13:34:37 +0200175int ScalabilityModeToNumTemporalLayers(ScalabilityMode scalability_mode) {
176 switch (scalability_mode) {
177 case ScalabilityMode::kL1T1:
178 return 1;
179 case ScalabilityMode::kL1T2:
Niels Möller05954892022-05-13 13:34:37 +0200180 return 2;
181 case ScalabilityMode::kL1T3:
Niels Möller05954892022-05-13 13:34:37 +0200182 return 3;
183 case ScalabilityMode::kL2T1:
184 case ScalabilityMode::kL2T1h:
185 case ScalabilityMode::kL2T1_KEY:
186 return 1;
187 case ScalabilityMode::kL2T2:
188 case ScalabilityMode::kL2T2h:
189 case ScalabilityMode::kL2T2_KEY:
190 case ScalabilityMode::kL2T2_KEY_SHIFT:
191 return 2;
192 case ScalabilityMode::kL2T3:
193 case ScalabilityMode::kL2T3h:
194 case ScalabilityMode::kL2T3_KEY:
195 return 3;
196 case ScalabilityMode::kL3T1:
197 case ScalabilityMode::kL3T1h:
198 case ScalabilityMode::kL3T1_KEY:
199 return 1;
200 case ScalabilityMode::kL3T2:
201 case ScalabilityMode::kL3T2h:
202 case ScalabilityMode::kL3T2_KEY:
203 return 2;
204 case ScalabilityMode::kL3T3:
205 case ScalabilityMode::kL3T3h:
206 case ScalabilityMode::kL3T3_KEY:
207 return 3;
208 case ScalabilityMode::kS2T1:
Åsa Persson6d051642022-08-29 09:05:00 +0200209 case ScalabilityMode::kS3T1:
Niels Möller05954892022-05-13 13:34:37 +0200210 return 1;
Åsa Persson6d051642022-08-29 09:05:00 +0200211 case ScalabilityMode::kS2T2:
212 case ScalabilityMode::kS3T2:
213 return 2;
Niels Möller3c24c092022-06-30 15:42:51 +0200214 case ScalabilityMode::kS2T3:
Niels Möller05954892022-05-13 13:34:37 +0200215 case ScalabilityMode::kS3T3:
216 return 3;
217 }
218 RTC_CHECK_NOTREACHED();
219}
220
Byoungchan Lee2d7db712022-08-30 19:07:17 +0900221absl::optional<ScalabilityModeResolutionRatio> ScalabilityModeToResolutionRatio(
222 ScalabilityMode scalability_mode) {
223 switch (scalability_mode) {
224 case ScalabilityMode::kL1T1:
225 case ScalabilityMode::kL1T2:
Byoungchan Lee2d7db712022-08-30 19:07:17 +0900226 case ScalabilityMode::kL1T3:
Byoungchan Lee2d7db712022-08-30 19:07:17 +0900227 return absl::nullopt;
228 case ScalabilityMode::kL2T1:
229 case ScalabilityMode::kL2T1_KEY:
230 case ScalabilityMode::kL2T2:
231 case ScalabilityMode::kL2T2_KEY:
232 case ScalabilityMode::kL2T2_KEY_SHIFT:
233 case ScalabilityMode::kL2T3:
234 case ScalabilityMode::kL2T3_KEY:
235 case ScalabilityMode::kL3T1:
236 case ScalabilityMode::kL3T1_KEY:
237 case ScalabilityMode::kL3T2:
238 case ScalabilityMode::kL3T2_KEY:
239 case ScalabilityMode::kL3T3:
240 case ScalabilityMode::kL3T3_KEY:
241 case ScalabilityMode::kS2T1:
242 case ScalabilityMode::kS2T2:
243 case ScalabilityMode::kS2T3:
244 case ScalabilityMode::kS3T1:
245 case ScalabilityMode::kS3T2:
246 case ScalabilityMode::kS3T3:
247 return ScalabilityModeResolutionRatio::kTwoToOne;
248 case ScalabilityMode::kL2T1h:
249 case ScalabilityMode::kL2T2h:
250 case ScalabilityMode::kL2T3h:
251 case ScalabilityMode::kL3T1h:
252 case ScalabilityMode::kL3T2h:
253 case ScalabilityMode::kL3T3h:
254 return ScalabilityModeResolutionRatio::kThreeToTwo;
255 }
256 RTC_CHECK_NOTREACHED();
257}
258
Niels Möller79d566b2022-04-29 11:03:13 +0200259} // namespace webrtc