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/core/plugin_manager.h"
17 #include <utility>
18 #include "plugin/core/plugin_wrapper.h"
19
20 namespace OHOS {
21 namespace Media {
22 namespace Plugin {
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<DataSourceHelper> source)42 int32_t PluginManager::Sniffer(const std::string& name, std::shared_ptr<DataSourceHelper> 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, std::make_shared<DataSourceWrapper>(regInfo->packageDef->pkgVersion, source));
53 }
54 return 0;
55 }
56
Init()57 void PluginManager::Init()
58 {
59 pluginRegister_ = std::make_shared<PluginRegister>();
60 pluginRegister_->RegisterPlugins();
61 }
62
CreateDemuxerPlugin(const std::string & name)63 std::shared_ptr<Demuxer> PluginManager::CreateDemuxerPlugin(const std::string& name)
64 {
65 return CreatePlugin<Demuxer, DemuxerPlugin>(name, PluginType::DEMUXER);
66 }
67
CreateMuxerPlugin(const std::string & name)68 std::shared_ptr<Muxer> PluginManager::CreateMuxerPlugin(const std::string& name)
69 {
70 return CreatePlugin<Muxer, MuxerPlugin>(name, PluginType::MUXER);
71 }
72
CreateSourcePlugin(const std::string & name)73 std::shared_ptr<Source> PluginManager::CreateSourcePlugin(const std::string& name)
74 {
75 return CreatePlugin<Source, SourcePlugin>(name, PluginType::SOURCE);
76 }
77
CreateCodecPlugin(const std::string & name,PluginType type)78 std::shared_ptr<Codec> PluginManager::CreateCodecPlugin(const std::string& name, PluginType type)
79 {
80 return CreatePlugin<Codec, CodecPlugin>(name, type);
81 }
82
CreateAudioSinkPlugin(const std::string & name)83 std::shared_ptr<AudioSink> PluginManager::CreateAudioSinkPlugin(const std::string& name)
84 {
85 return CreatePlugin<AudioSink, AudioSinkPlugin>(name, PluginType::AUDIO_SINK);
86 }
87
CreateVideoSinkPlugin(const std::string & name)88 std::shared_ptr<VideoSink> PluginManager::CreateVideoSinkPlugin(const std::string& name)
89 {
90 return CreatePlugin<VideoSink, VideoSinkPlugin>(name, PluginType::VIDEO_SINK);
91 }
CreateOutputSinkPlugin(const std::string & name)92 std::shared_ptr<OutputSink> PluginManager::CreateOutputSinkPlugin(const std::string& name)
93 {
94 return CreatePlugin<OutputSink, OutputSinkPlugin>(name, PluginType::OUTPUT_SINK);
95 }
96
RegisterGenericPlugin(const GenericPluginDef & pluginDef)97 void PluginManager::RegisterGenericPlugin(const GenericPluginDef& pluginDef)
98 {
99 pluginRegister_->RegisterGenericPlugin(pluginDef);
100 }
101
RegisterGenericPlugins(const std::vector<GenericPluginDef> & vecPluginDef)102 void PluginManager::RegisterGenericPlugins(const std::vector<GenericPluginDef>& vecPluginDef)
103 {
104 pluginRegister_->RegisterGenericPlugins(vecPluginDef);
105 }
106 } // namespace Plugin
107 } // namespace Media
108 } // namespace OHOS