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 #ifndef HISTREAMER_PLUGIN_MANAGER_H 17 #define HISTREAMER_PLUGIN_MANAGER_H 18 19 #include "plugin_info.h" 20 #include "plugin_register.h" 21 22 #include "audio_sink.h" 23 #include "codec.h" 24 #include "demuxer.h" 25 #include "muxer.h" 26 #include "output_sink.h" 27 #include "plugin/common/type_cast_ext.h" 28 #include "source.h" 29 #include "video_sink.h" 30 31 namespace OHOS { 32 namespace Media { 33 namespace Plugin { 34 class PluginManager { 35 public: 36 PluginManager(const PluginManager&) = delete; 37 PluginManager operator=(const PluginManager&) = delete; 38 ~PluginManager() = default; Instance()39 static PluginManager& Instance() 40 { 41 static PluginManager impl; 42 return impl; 43 } 44 45 std::set<std::string> ListPlugins(PluginType type); 46 47 std::shared_ptr<PluginInfo> GetPluginInfo(PluginType type, const std::string& name); 48 49 std::shared_ptr<Source> CreateSourcePlugin(const std::string& name); 50 51 std::shared_ptr<Demuxer> CreateDemuxerPlugin(const std::string& name); 52 53 std::shared_ptr<Muxer> CreateMuxerPlugin(const std::string& name); 54 55 std::shared_ptr<Codec> CreateCodecPlugin(const std::string& name); 56 57 std::shared_ptr<AudioSink> CreateAudioSinkPlugin(const std::string& name); 58 59 std::shared_ptr<VideoSink> CreateVideoSinkPlugin(const std::string& name); 60 61 std::shared_ptr<OutputSink> CreateOutputSinkPlugin(const std::string& name); 62 63 int32_t Sniffer(const std::string& name, std::shared_ptr<DataSourceHelper> source); 64 65 void EnablePackage(PluginType type, const std::string& name); 66 67 void DisablePackage(PluginType type, const std::string& name); 68 69 bool IsPackageExist(PluginType type, const std::string& name); 70 71 void PrintRegisteredPluginInfo(); 72 73 int GetAllRegisteredPluginCount(); 74 75 int GetRegisteredPluginCountByPackageName(std::string name); 76 77 private: 78 PluginManager(); 79 80 void Init(); 81 82 template<typename T, typename U> CreatePlugin(const std::string & name,PluginType pluginType)83 std::shared_ptr<T> CreatePlugin(const std::string& name, PluginType pluginType) 84 { 85 std::shared_ptr<PluginRegInfo> regInfo = pluginRegister_->GetPluginRegInfo(pluginType, name); 86 if (!regInfo) { 87 return {}; 88 } 89 auto plugin = ReinterpretPointerCast<U>(regInfo->creator(name)); 90 if (!plugin) { 91 return {}; 92 } 93 return std::shared_ptr<T>( 94 new T(regInfo->packageDef->pkgVersion, regInfo->info->apiVersion, plugin)); 95 } 96 97 private: 98 std::shared_ptr<PluginRegister> pluginRegister_; 99 }; 100 } // namespace Plugin 101 } // namespace Media 102 } // namespace OHOS 103 #endif // HISTREAMER_PLUGIN_MANAGER_H 104