• 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 #include "plugin/plugin_manager.h"
17 #include <utility>
18 #include "plugin/plugin_register.h"
19 
20 namespace OHOS {
21 namespace Media {
22 namespace Plugins {
PluginManager()23 PluginManager::PluginManager()
24 {
25     Init();
26 }
27 
ListPlugins(PluginType pluginType,CodecMode preferredCodecMode)28 std::vector<std::string> PluginManager::ListPlugins(PluginType pluginType, CodecMode preferredCodecMode)
29 {
30     return pluginRegister_->ListPlugins(pluginType, preferredCodecMode);
31 }
32 
GetPluginInfo(PluginType type,const std::string & name)33 std::shared_ptr<PluginInfo> PluginManager::GetPluginInfo(PluginType type, const std::string& name)
34 {
35     auto regInfo = pluginRegister_->GetPluginRegInfo(type, name);
36     if (regInfo && regInfo->info && regInfo->info->pluginType == type) {
37         return regInfo->info;
38     }
39     return {};
40 }
41 
Sniffer(const std::string & name,std::shared_ptr<DataSource> source)42 int32_t PluginManager::Sniffer(const std::string& name, std::shared_ptr<DataSource> source)
43 {
44     if (!source) {
45         return 0;
46     }
47     auto regInfo = pluginRegister_->GetPluginRegInfo(PluginType::DEMUXER, name);
48     if (!regInfo) {
49         return 0;
50     }
51     if (regInfo->info->pluginType == PluginType::DEMUXER) {
52         return regInfo->sniffer(name, source);
53     }
54     return 0;
55 }
56 
Init()57 void PluginManager::Init()
58 {
59     pluginRegister_ = std::make_shared<PluginRegister>();
60     pluginRegister_->RegisterPlugins();
61 }
62 
CreatePlugin(const std::string & name,PluginType type)63 std::shared_ptr<PluginBase> PluginManager::CreatePlugin(const std::string& name, PluginType type)
64 {
65     return CreatePlugin<PluginBase, PluginBase>(name, type);
66 }
67 
RegisterGenericPlugin(const GenericPluginDef & pluginDef)68 void PluginManager::RegisterGenericPlugin(const GenericPluginDef& pluginDef)
69 {
70     pluginRegister_->RegisterGenericPlugin(pluginDef);
71 }
72 
RegisterGenericPlugins(const std::vector<GenericPluginDef> & vecPluginDef)73 void PluginManager::RegisterGenericPlugins(const std::vector<GenericPluginDef>& vecPluginDef)
74 {
75     pluginRegister_->RegisterGenericPlugins(vecPluginDef);
76 }
77 } // namespace Plugins
78 } // namespace Media
79 } // namespace OHOS