• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HISTREAMER_PLUGIN_MANAGER_H
17 #define HISTREAMER_PLUGIN_MANAGER_H
18 
19 #include "cpp_ext/type_cast_ext.h"
20 #include "plugin_info.h"
21 #include "plugin/plugin_register.h"
22 #include "generic_plugin.h"
23 
24 namespace OHOS {
25 namespace Media {
26 namespace Plugins {
27 class PluginManager {
28 public:
29     PluginManager(const PluginManager&) = delete;
30     PluginManager operator=(const PluginManager&) = delete;
31     ~PluginManager() = default;
Instance()32     static PluginManager& Instance()
33     {
34         static PluginManager impl;
35         return impl;
36     }
GetPluginRegister()37     std::shared_ptr<PluginRegister> GetPluginRegister()
38     {
39         return pluginRegister_;
40     }
41 
42     std::vector<std::string> ListPlugins(PluginType pluginType, CodecMode preferredCodecMode = CodecMode::HARDWARE);
43 
44     std::shared_ptr<PluginInfo> GetPluginInfo(PluginType type, const std::string& name);
45 
46     std::shared_ptr<PluginBase> CreatePlugin(const std::string& name, PluginType type);
47 
48     template<typename T, typename U>
CreateGenericPlugin(const std::string & name)49     std::shared_ptr<T> CreateGenericPlugin(const std::string& name)
50     {
51         return CreatePlugin<T, U>(name, PluginType::GENERIC_PLUGIN);
52     }
53 
54     int32_t Sniffer(const std::string& name, std::shared_ptr<DataSource> source);
55 
56     void RegisterGenericPlugin(const GenericPluginDef& pluginDef);
57 
58     void RegisterGenericPlugins(const std::vector<GenericPluginDef>& vecPluginDef);
59 private:
60     PluginManager();
61 
62     void Init();
63 
64     template<typename T, typename U>
CreatePlugin(const std::string & name,PluginType pluginType)65     std::shared_ptr<T> CreatePlugin(const std::string& name, PluginType pluginType)
66     {
67         auto regInfo = pluginRegister_->GetPluginRegInfo(pluginType, name);
68         if (!regInfo) {
69             return {};
70         }
71         auto plugin = regInfo->creator(name);
72         if (!plugin) {
73             return {};
74         }
75         return std::shared_ptr<T>(plugin);
76     }
77 
78 private:
79     std::shared_ptr<PluginRegister> pluginRegister_;
80 };
81 } // namespace Plugins
82 } // namespace Media
83 } // namespace OHOS
84 #endif // HISTREAMER_PLUGIN_MANAGER_H
85