blob: 8e5c06fca9ea4356ee28040e6a88cbbdaf2eef78 [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
14#include "absl/strings/string_view.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 {
27 absl::string_view name;
28 // 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
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +020048constexpr ScalableVideoController::StreamLayersConfig kConfigNone = {
49 /*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
95constexpr ScalableVideoController::StreamLayersConfig kConfigL3T3 = {
96 /*num_spatial_layers=*/3,
97 /*num_temporal_layers=*/3,
98 /*uses_reference_scaling=*/true,
99 {1, 1, 1},
100 {4, 2, 1}};
101
102constexpr ScalableVideoController::StreamLayersConfig kConfigS2T1 = {
103 /*num_spatial_layers=*/2,
104 /*num_temporal_layers=*/1,
105 /*uses_reference_scaling=*/false,
106 {1, 1},
107 {2, 1}};
108
109constexpr ScalableVideoController::StreamLayersConfig kConfigS3T3 = {
110 /*num_spatial_layers=*/3,
111 /*num_temporal_layers=*/3,
112 /*uses_reference_scaling=*/false,
113 {1, 1, 1},
114 {4, 2, 1}};
115
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200116constexpr NamedStructureFactory kFactories[] = {
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200117 {"NONE", Create<ScalableVideoControllerNoLayering>, kConfigNone},
118 {"L1T2", Create<ScalabilityStructureL1T2>, kConfigL1T2},
119 {"L1T3", Create<ScalabilityStructureL1T3>, kConfigL1T3},
120 {"L2T1", Create<ScalabilityStructureL2T1>, kConfigL2T1},
121 {"L2T1h", CreateH<ScalabilityStructureL2T1>, kConfigL2T1h},
122 {"L2T1_KEY", Create<ScalabilityStructureL2T1Key>, kConfigL2T1},
123 {"L2T2", Create<ScalabilityStructureL2T2>, kConfigL2T2},
124 {"L2T2_KEY", Create<ScalabilityStructureL2T2Key>, kConfigL2T2},
125 {"L2T2_KEY_SHIFT", Create<ScalabilityStructureL2T2KeyShift>, kConfigL2T2},
126 {"L2T3_KEY", Create<ScalabilityStructureL2T3Key>, kConfigL2T3},
127 {"L3T1", Create<ScalabilityStructureL3T1>, kConfigL3T1},
128 {"L3T3", Create<ScalabilityStructureL3T3>, kConfigL3T3},
129 {"L3T3_KEY", Create<ScalabilityStructureL3T3Key>, kConfigL3T3},
130 {"S2T1", Create<ScalabilityStructureS2T1>, kConfigS2T1},
131 {"S3T3", Create<ScalabilityStructureS3T3>, kConfigS3T3},
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200132};
133
134} // namespace
135
136std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
137 absl::string_view name) {
138 RTC_DCHECK(!name.empty());
139 for (const auto& entry : kFactories) {
140 if (entry.name == name) {
141 return entry.factory();
142 }
143 }
144 return nullptr;
145}
146
Danil Chapovalov5d3bf6a2021-09-06 15:41:54 +0200147absl::optional<ScalableVideoController::StreamLayersConfig>
148ScalabilityStructureConfig(absl::string_view name) {
149 RTC_DCHECK(!name.empty());
150 for (const auto& entry : kFactories) {
151 if (entry.name == name) {
152 return entry.config;
153 }
154 }
155 return absl::nullopt;
156}
157
Danil Chapovalova13e7a12020-07-14 12:34:36 +0200158} // namespace webrtc