blob: 39710d82ffcc7004c62b0e3eb27c99f3ed4a4c36 [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)();
30};
31
32// Wrap std::make_unique function to have correct return type.
33template <typename T>
34std::unique_ptr<ScalableVideoController> Create() {
35 return std::make_unique<T>();
36}
37
Danil Chapovalovf91f8b52021-02-12 17:24:51 +010038template <typename T>
39std::unique_ptr<ScalableVideoController> CreateH() {
40 // 1.5:1 scaling, see https://w3c.github.io/webrtc-svc/#scalabilitymodes*
41 typename T::ScalingFactor factor;
42 factor.num = 2;
43 factor.den = 3;
44 return std::make_unique<T>(factor);
45}
46
Danil Chapovalova13e7a12020-07-14 12:34:36 +020047constexpr NamedStructureFactory kFactories[] = {
48 {"NONE", Create<ScalableVideoControllerNoLayering>},
49 {"L1T2", Create<ScalabilityStructureL1T2>},
50 {"L1T3", Create<ScalabilityStructureL1T3>},
51 {"L2T1", Create<ScalabilityStructureL2T1>},
Danil Chapovalovf91f8b52021-02-12 17:24:51 +010052 {"L2T1h", CreateH<ScalabilityStructureL2T1>},
Danil Chapovalova13e7a12020-07-14 12:34:36 +020053 {"L2T1_KEY", Create<ScalabilityStructureL2T1Key>},
54 {"L2T2", Create<ScalabilityStructureL2T2>},
55 {"L2T2_KEY", Create<ScalabilityStructureL2T2Key>},
56 {"L2T2_KEY_SHIFT", Create<ScalabilityStructureL2T2KeyShift>},
Emil Lundmarkc9b99302021-02-18 16:51:05 +010057 {"L2T3_KEY", Create<ScalabilityStructureL2T3Key>},
Danil Chapovalova13e7a12020-07-14 12:34:36 +020058 {"L3T1", Create<ScalabilityStructureL3T1>},
59 {"L3T3", Create<ScalabilityStructureL3T3>},
Danil Chapovalov4b18e242020-10-16 16:14:58 +020060 {"L3T3_KEY", Create<ScalabilityStructureL3T3Key>},
Danil Chapovalova13e7a12020-07-14 12:34:36 +020061 {"S2T1", Create<ScalabilityStructureS2T1>},
Danil Chapovalov735e33f2021-02-18 14:39:52 +010062 {"S3T3", Create<ScalabilityStructureS3T3>},
Danil Chapovalova13e7a12020-07-14 12:34:36 +020063};
64
65} // namespace
66
67std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
68 absl::string_view name) {
69 RTC_DCHECK(!name.empty());
70 for (const auto& entry : kFactories) {
71 if (entry.name == name) {
72 return entry.factory();
73 }
74 }
75 return nullptr;
76}
77
78} // namespace webrtc