blob: 337f94624e72ad7b005590689c2b8d64d8b97d3b [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 Chapovalovda7fe392020-10-15 15:57:17 +020018#include "modules/video_coding/svc/scalability_structure_s2t1.h"
19#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>},
57 {"L3T1", Create<ScalabilityStructureL3T1>},
58 {"L3T3", Create<ScalabilityStructureL3T3>},
Danil Chapovalov4b18e242020-10-16 16:14:58 +020059 {"L3T3_KEY", Create<ScalabilityStructureL3T3Key>},
Danil Chapovalova13e7a12020-07-14 12:34:36 +020060 {"S2T1", Create<ScalabilityStructureS2T1>},
61};
62
63} // namespace
64
65std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
66 absl::string_view name) {
67 RTC_DCHECK(!name.empty());
68 for (const auto& entry : kFactories) {
69 if (entry.name == name) {
70 return entry.factory();
71 }
72 }
73 return nullptr;
74}
75
76} // namespace webrtc