blob: addcdd13424b1e7aad0ad201f8e90c366ed33d87 [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
Asa Perssoncde992d2022-05-16 22:37:34 +020086InterLayerPredMode ScalabilityModeToInterLayerPredMode(
87 ScalabilityMode scalability_mode) {
88 switch (scalability_mode) {
89 case ScalabilityMode::kL1T1:
90 case ScalabilityMode::kL1T2:
91 case ScalabilityMode::kL1T2h:
92 case ScalabilityMode::kL1T3:
93 case ScalabilityMode::kL1T3h:
94 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:
Niels Möller3c24c092022-06-30 15:42:51 +0200126 case ScalabilityMode::kS2T3:
Asa Perssoncde992d2022-05-16 22:37:34 +0200127 case ScalabilityMode::kS3T3:
128 return InterLayerPredMode::kOff;
129 }
130 RTC_CHECK_NOTREACHED();
131}
132
Asa Persson26983532022-05-13 16:24:22 +0200133int ScalabilityModeToNumSpatialLayers(ScalabilityMode scalability_mode) {
134 switch (scalability_mode) {
135 case ScalabilityMode::kL1T1:
136 case ScalabilityMode::kL1T2:
137 case ScalabilityMode::kL1T2h:
138 case ScalabilityMode::kL1T3:
139 case ScalabilityMode::kL1T3h:
140 return 1;
141 case ScalabilityMode::kL2T1:
142 case ScalabilityMode::kL2T1h:
143 case ScalabilityMode::kL2T1_KEY:
144 case ScalabilityMode::kL2T2:
145 case ScalabilityMode::kL2T2h:
146 case ScalabilityMode::kL2T2_KEY:
147 case ScalabilityMode::kL2T2_KEY_SHIFT:
148 case ScalabilityMode::kL2T3:
149 case ScalabilityMode::kL2T3h:
150 case ScalabilityMode::kL2T3_KEY:
151 return 2;
152 case ScalabilityMode::kL3T1:
153 case ScalabilityMode::kL3T1h:
154 case ScalabilityMode::kL3T1_KEY:
155 case ScalabilityMode::kL3T2:
156 case ScalabilityMode::kL3T2h:
157 case ScalabilityMode::kL3T2_KEY:
158 case ScalabilityMode::kL3T3:
159 case ScalabilityMode::kL3T3h:
160 case ScalabilityMode::kL3T3_KEY:
161 return 3;
162 case ScalabilityMode::kS2T1:
Niels Möller3c24c092022-06-30 15:42:51 +0200163 case ScalabilityMode::kS2T3:
Asa Persson26983532022-05-13 16:24:22 +0200164 return 2;
165 case ScalabilityMode::kS3T3:
166 return 3;
167 }
168 RTC_CHECK_NOTREACHED();
169}
170
Niels Möller05954892022-05-13 13:34:37 +0200171int ScalabilityModeToNumTemporalLayers(ScalabilityMode scalability_mode) {
172 switch (scalability_mode) {
173 case ScalabilityMode::kL1T1:
174 return 1;
175 case ScalabilityMode::kL1T2:
176 case ScalabilityMode::kL1T2h:
177 return 2;
178 case ScalabilityMode::kL1T3:
179 case ScalabilityMode::kL1T3h:
180 return 3;
181 case ScalabilityMode::kL2T1:
182 case ScalabilityMode::kL2T1h:
183 case ScalabilityMode::kL2T1_KEY:
184 return 1;
185 case ScalabilityMode::kL2T2:
186 case ScalabilityMode::kL2T2h:
187 case ScalabilityMode::kL2T2_KEY:
188 case ScalabilityMode::kL2T2_KEY_SHIFT:
189 return 2;
190 case ScalabilityMode::kL2T3:
191 case ScalabilityMode::kL2T3h:
192 case ScalabilityMode::kL2T3_KEY:
193 return 3;
194 case ScalabilityMode::kL3T1:
195 case ScalabilityMode::kL3T1h:
196 case ScalabilityMode::kL3T1_KEY:
197 return 1;
198 case ScalabilityMode::kL3T2:
199 case ScalabilityMode::kL3T2h:
200 case ScalabilityMode::kL3T2_KEY:
201 return 2;
202 case ScalabilityMode::kL3T3:
203 case ScalabilityMode::kL3T3h:
204 case ScalabilityMode::kL3T3_KEY:
205 return 3;
206 case ScalabilityMode::kS2T1:
207 return 1;
Niels Möller3c24c092022-06-30 15:42:51 +0200208 case ScalabilityMode::kS2T3:
Niels Möller05954892022-05-13 13:34:37 +0200209 case ScalabilityMode::kS3T3:
210 return 3;
211 }
212 RTC_CHECK_NOTREACHED();
213}
214
Niels Möller79d566b2022-04-29 11:03:13 +0200215} // namespace webrtc