Danil Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 1 | /* |
| 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 Chapovalov | da7fe39 | 2020-10-15 15:57:17 +0200 | [diff] [blame] | 10 | #include "modules/video_coding/svc/create_scalability_structure.h" |
Danil Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | #include "absl/strings/string_view.h" |
Danil Chapovalov | f91f8b5 | 2021-02-12 17:24:51 +0100 | [diff] [blame^] | 15 | #include "modules/video_coding/svc/scalability_structure_full_svc.h" |
Danil Chapovalov | 4b18e24 | 2020-10-16 16:14:58 +0200 | [diff] [blame] | 16 | #include "modules/video_coding/svc/scalability_structure_key_svc.h" |
Danil Chapovalov | da7fe39 | 2020-10-15 15:57:17 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/svc/scalability_structure_l2t2_key_shift.h" |
Danil Chapovalov | da7fe39 | 2020-10-15 15:57:17 +0200 | [diff] [blame] | 18 | #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 Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | namespace { |
| 25 | |
| 26 | struct 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. |
| 33 | template <typename T> |
| 34 | std::unique_ptr<ScalableVideoController> Create() { |
| 35 | return std::make_unique<T>(); |
| 36 | } |
| 37 | |
Danil Chapovalov | f91f8b5 | 2021-02-12 17:24:51 +0100 | [diff] [blame^] | 38 | template <typename T> |
| 39 | std::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 Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 47 | constexpr NamedStructureFactory kFactories[] = { |
| 48 | {"NONE", Create<ScalableVideoControllerNoLayering>}, |
| 49 | {"L1T2", Create<ScalabilityStructureL1T2>}, |
| 50 | {"L1T3", Create<ScalabilityStructureL1T3>}, |
| 51 | {"L2T1", Create<ScalabilityStructureL2T1>}, |
Danil Chapovalov | f91f8b5 | 2021-02-12 17:24:51 +0100 | [diff] [blame^] | 52 | {"L2T1h", CreateH<ScalabilityStructureL2T1>}, |
Danil Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 53 | {"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 Chapovalov | 4b18e24 | 2020-10-16 16:14:58 +0200 | [diff] [blame] | 59 | {"L3T3_KEY", Create<ScalabilityStructureL3T3Key>}, |
Danil Chapovalov | a13e7a1 | 2020-07-14 12:34:36 +0200 | [diff] [blame] | 60 | {"S2T1", Create<ScalabilityStructureS2T1>}, |
| 61 | }; |
| 62 | |
| 63 | } // namespace |
| 64 | |
| 65 | std::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 |