blob: ff7ecb4b40267a3cfcd9841d31a6e790201dab46 [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;
78 if (mode_string == "S3T3")
79 return ScalabilityMode::kS3T3;
80
81 return absl::nullopt;
82}
83
84absl::string_view ScalabilityModeToString(ScalabilityMode scalability_mode) {
85 switch (scalability_mode) {
86 case ScalabilityMode::kL1T1:
87 return "L1T1";
88 case ScalabilityMode::kL1T2:
89 return "L1T2";
Niels Möller3b048132022-05-05 14:37:05 +020090 case ScalabilityMode::kL1T2h:
91 return "L1T2h";
Niels Möller79d566b2022-04-29 11:03:13 +020092 case ScalabilityMode::kL1T3:
93 return "L1T3";
Niels Möller3b048132022-05-05 14:37:05 +020094 case ScalabilityMode::kL1T3h:
95 return "L1T3h";
Niels Möller79d566b2022-04-29 11:03:13 +020096 case ScalabilityMode::kL2T1:
97 return "L2T1";
98 case ScalabilityMode::kL2T1h:
99 return "L2T1h";
100 case ScalabilityMode::kL2T1_KEY:
101 return "L2T1_KEY";
102 case ScalabilityMode::kL2T2:
103 return "L2T2";
Niels Möller3b048132022-05-05 14:37:05 +0200104 case ScalabilityMode::kL2T2h:
105 return "L2T2h";
Niels Möller79d566b2022-04-29 11:03:13 +0200106 case ScalabilityMode::kL2T2_KEY:
107 return "L2T2_KEY";
108 case ScalabilityMode::kL2T2_KEY_SHIFT:
109 return "L2T2_KEY_SHIFT";
Niels Möller3b048132022-05-05 14:37:05 +0200110 case ScalabilityMode::kL2T3:
111 return "L2T3";
112 case ScalabilityMode::kL2T3h:
113 return "L2T3h";
Niels Möller79d566b2022-04-29 11:03:13 +0200114 case ScalabilityMode::kL2T3_KEY:
115 return "L2T3_KEY";
116 case ScalabilityMode::kL3T1:
117 return "L3T1";
Niels Möller3b048132022-05-05 14:37:05 +0200118 case ScalabilityMode::kL3T1h:
119 return "L3T1h";
120 case ScalabilityMode::kL3T1_KEY:
121 return "L3T1_KEY";
122 case ScalabilityMode::kL3T2:
123 return "L3T2";
124 case ScalabilityMode::kL3T2h:
125 return "L3T2h";
126 case ScalabilityMode::kL3T2_KEY:
127 return "L3T2_KEY";
Niels Möller79d566b2022-04-29 11:03:13 +0200128 case ScalabilityMode::kL3T3:
129 return "L3T3";
Niels Möller3b048132022-05-05 14:37:05 +0200130 case ScalabilityMode::kL3T3h:
131 return "L3T3h";
Niels Möller79d566b2022-04-29 11:03:13 +0200132 case ScalabilityMode::kL3T3_KEY:
133 return "L3T3_KEY";
134 case ScalabilityMode::kS2T1:
135 return "S2T1";
136 case ScalabilityMode::kS3T3:
137 return "S3T3";
138 }
139 RTC_CHECK_NOTREACHED();
140}
141
Niels Möller05954892022-05-13 13:34:37 +0200142int ScalabilityModeToNumTemporalLayers(ScalabilityMode scalability_mode) {
143 switch (scalability_mode) {
144 case ScalabilityMode::kL1T1:
145 return 1;
146 case ScalabilityMode::kL1T2:
147 case ScalabilityMode::kL1T2h:
148 return 2;
149 case ScalabilityMode::kL1T3:
150 case ScalabilityMode::kL1T3h:
151 return 3;
152 case ScalabilityMode::kL2T1:
153 case ScalabilityMode::kL2T1h:
154 case ScalabilityMode::kL2T1_KEY:
155 return 1;
156 case ScalabilityMode::kL2T2:
157 case ScalabilityMode::kL2T2h:
158 case ScalabilityMode::kL2T2_KEY:
159 case ScalabilityMode::kL2T2_KEY_SHIFT:
160 return 2;
161 case ScalabilityMode::kL2T3:
162 case ScalabilityMode::kL2T3h:
163 case ScalabilityMode::kL2T3_KEY:
164 return 3;
165 case ScalabilityMode::kL3T1:
166 case ScalabilityMode::kL3T1h:
167 case ScalabilityMode::kL3T1_KEY:
168 return 1;
169 case ScalabilityMode::kL3T2:
170 case ScalabilityMode::kL3T2h:
171 case ScalabilityMode::kL3T2_KEY:
172 return 2;
173 case ScalabilityMode::kL3T3:
174 case ScalabilityMode::kL3T3h:
175 case ScalabilityMode::kL3T3_KEY:
176 return 3;
177 case ScalabilityMode::kS2T1:
178 return 1;
179 case ScalabilityMode::kS3T3:
180 return 3;
181 }
182 RTC_CHECK_NOTREACHED();
183}
184
Niels Möller79d566b2022-04-29 11:03:13 +0200185} // namespace webrtc