• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 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_manager.h"
17 #include "interface/audio_sink_plugin.h"
18 #include "interface/codec_plugin.h"
19 #include "interface/demuxer_plugin.h"
20 #include "interface/source_plugin.h"
21 #include "interface/video_sink_plugin.h"
22 #include "plugin_register.h"
23 #include "plugin_wrapper.h"
24 
25 #include <utility>
26 
27 namespace OHOS {
28 namespace Media {
29 namespace Plugin {
PluginManager()30 PluginManager::PluginManager()
31 {
32     Init();
33 }
34 
ListPlugins(PluginType type)35 std::set<std::string> PluginManager::ListPlugins(PluginType type)
36 {
37     return pluginRegister_->ListPlugins(type);
38 }
39 
GetPluginInfo(PluginType type,const std::string & name)40 std::shared_ptr<PluginInfo> PluginManager::GetPluginInfo(PluginType type, const std::string& name)
41 {
42     std::shared_ptr<PluginRegInfo> regInfo = pluginRegister_->GetPluginRegInfo(type, name);
43     if (regInfo && regInfo->info && regInfo->info->pluginType == type) {
44         return regInfo->info;
45     }
46     return {};
47 }
48 
Sniffer(const std::string & name,std::shared_ptr<DataSourceHelper> source)49 int32_t PluginManager::Sniffer(const std::string& name, std::shared_ptr<DataSourceHelper> source)
50 {
51     if (source == nullptr) {
52         return 0;
53     }
54     std::shared_ptr<PluginRegInfo> regInfo = pluginRegister_->GetPluginRegInfo(PluginType::DEMUXER, name);
55     if (!regInfo) {
56         return 0;
57     }
58     if (regInfo->info->pluginType == PluginType::DEMUXER) {
59         return regInfo->sniffer(name, std::make_shared<DataSourceWrapper>(regInfo->packageDef->pkgVersion, source));
60     }
61     return 0;
62 }
63 
EnablePackage(PluginType type,const std::string & name)64 void PluginManager::EnablePackage(PluginType type, const std::string& name)
65 {
66     return pluginRegister_->EnablePackage(type, name);
67 }
68 
DisablePackage(PluginType type,const std::string & name)69 void PluginManager::DisablePackage(PluginType type, const std::string& name)
70 {
71     return pluginRegister_->DisablePackage(type, name);
72 }
73 
IsPackageExist(PluginType type,const std::string & name)74 bool PluginManager::IsPackageExist(PluginType type, const std::string& name)
75 {
76     return pluginRegister_->IsPackageExist(type, name);
77 }
78 
PrintRegisteredPluginInfo()79 void PluginManager::PrintRegisteredPluginInfo()
80 {
81     pluginRegister_->PrintRegisteredPluginInfo();
82 }
83 
GetAllRegisteredPluginCount()84 int PluginManager::GetAllRegisteredPluginCount()
85 {
86     return pluginRegister_->GetAllRegisteredPluginCount();
87 }
88 
GetRegisteredPluginCountByPackageName(std::string name)89 int PluginManager::GetRegisteredPluginCountByPackageName(std::string name)
90 {
91     return pluginRegister_->GetRegisteredPluginCountByPackageName(name);
92 }
93 
Init()94 void PluginManager::Init()
95 {
96     pluginRegister_ = std::make_shared<PluginRegister>();
97     pluginRegister_->RegisterPlugins();
98 }
99 
CreateDemuxerPlugin(const std::string & name)100 std::shared_ptr<Demuxer> PluginManager::CreateDemuxerPlugin(const std::string& name)
101 {
102     return CreatePlugin<Demuxer, DemuxerPlugin>(name, PluginType::DEMUXER);
103 }
104 
CreateMuxerPlugin(const std::string & name)105 std::shared_ptr<Muxer> PluginManager::CreateMuxerPlugin(const std::string& name)
106 {
107     return CreatePlugin<Muxer, MuxerPlugin>(name, PluginType::MUXER);
108 }
109 
CreateSourcePlugin(const std::string & name)110 std::shared_ptr<Source> PluginManager::CreateSourcePlugin(const std::string& name)
111 {
112     return CreatePlugin<Source, SourcePlugin>(name, PluginType::SOURCE);
113 }
114 
CreateCodecPlugin(const std::string & name)115 std::shared_ptr<Codec> PluginManager::CreateCodecPlugin(const std::string& name)
116 {
117     return CreatePlugin<Codec, CodecPlugin>(name, PluginType::CODEC);
118 }
119 
CreateAudioSinkPlugin(const std::string & name)120 std::shared_ptr<AudioSink> PluginManager::CreateAudioSinkPlugin(const std::string& name)
121 {
122     return CreatePlugin<AudioSink, AudioSinkPlugin>(name, PluginType::AUDIO_SINK);
123 }
124 
CreateVideoSinkPlugin(const std::string & name)125 std::shared_ptr<VideoSink> PluginManager::CreateVideoSinkPlugin(const std::string& name)
126 {
127     return CreatePlugin<VideoSink, VideoSinkPlugin>(name, PluginType::VIDEO_SINK);
128 }
CreateOutputSinkPlugin(const std::string & name)129 std::shared_ptr<OutputSink> PluginManager::CreateOutputSinkPlugin(const std::string& name)
130 {
131     return CreatePlugin<OutputSink, OutputSinkPlugin>(name, PluginType::OUTPUT_SINK);
132 }
133 } // namespace Plugin
134 } // namespace Media
135 } // namespace OHOS