/* * Copyright (c) 2021-2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HISTREAMER_PLUGIN_REGISTER_H #define HISTREAMER_PLUGIN_REGISTER_H #include #include #include #include #include "plugin/common/any.h" #include "plugin/core/plugin_loader.h" #include "plugin/core/plugin_info.h" #include "plugin/interface/generic_plugin.h" namespace OHOS { namespace Media { namespace Plugin { struct DataSource; using DemuxerPluginSnifferFunc = int (*)(const std::string& name, std::shared_ptr dataSource); struct PluginRegInfo { std::shared_ptr packageDef; std::shared_ptr info; PluginCreatorFunc creator; DemuxerPluginSnifferFunc sniffer; std::shared_ptr loader; }; class PluginRegister { public: PluginRegister() = default; PluginRegister(const PluginRegister&) = delete; PluginRegister operator=(const PluginRegister&) = delete; ~PluginRegister(); std::vector ListPlugins(PluginType type, CodecMode preferredCodecMode = CodecMode::HARDWARE); int GetAllRegisteredPluginCount(); std::shared_ptr GetPluginRegInfo(PluginType type, const std::string& name); void RegisterPlugins(); void RegisterGenericPlugin(const GenericPluginDef& pluginDef); void RegisterGenericPlugins(const std::vector& vecPluginDef); private: void RegisterStaticPlugins(); void RegisterDynamicPlugins(); void RegisterPluginsFromPath(const char* libDirPath); void UnregisterAllPlugins(); void EraseRegisteredPluginsByLoader(const std::shared_ptr& loader); private: using REGISTERED_TABLE = std::map>>; struct RegisterData { std::map> registerNames; REGISTERED_TABLE registerTable; bool IsPluginExist(PluginType type, const std::string& name); }; struct RegisterImpl : PackageRegister { explicit RegisterImpl(std::shared_ptr data, std::shared_ptr loader = nullptr) : pluginLoader(std::move(loader)), registerData(std::move(data)) {} ~RegisterImpl() override = default; Status AddPlugin(const PluginDefBase& def) override; Status AddPackage(const PackageDef& def) override; Status SetPackageDef(const PackageDef& def); void UpdateRegisterTableAndRegisterNames(const PluginDefBase& def); void SetPluginInfo(std::shared_ptr& info, const PluginDefBase& def); Status InitSourceInfo(std::shared_ptr& reg, const PluginDefBase& def); static Status SourceCapabilityConvert(std::shared_ptr& info, const PluginDefBase& def); Status InitDemuxerInfo(std::shared_ptr& reg, const PluginDefBase& def); static Status DemuxerCapabilityConvert(std::shared_ptr& info, const PluginDefBase& def); Status InitMuxerInfo(std::shared_ptr& reg, const PluginDefBase& def); Status InitCodecInfo(std::shared_ptr& reg, const PluginDefBase& def); static Status CodecCapabilityConvert(std::shared_ptr& info, const PluginDefBase& def); Status InitAudioSinkInfo(std::shared_ptr& reg, const PluginDefBase& def); static Status AudioSinkCapabilityConvert(std::shared_ptr& info, const PluginDefBase& def); Status InitVideoSinkInfo(std::shared_ptr& reg, const PluginDefBase& def); static Status VideoSinkCapabilityConvert(std::shared_ptr& info, const PluginDefBase& def); Status InitOutputSinkInfo(std::shared_ptr& reg, const PluginDefBase& def); Status InitGenericPlugin(std::shared_ptr& reg, const PluginDefBase& def); bool Verification(const PluginDefBase& definition); bool VersionMatched(const PluginDefBase& definition); bool MoreAcceptable(std::shared_ptr& regInfo, const PluginDefBase& def); std::shared_ptr pluginLoader; std::shared_ptr registerData; std::shared_ptr packageDef {nullptr}; }; void DeletePlugin(std::map>& plugins, std::map>::iterator& info); std::shared_ptr registerData_ = std::make_shared(); std::vector> registeredLoaders_; std::shared_ptr staticPluginRegister_ = std::make_shared(registerData_); }; } // namespace Plugin } // namespace Media } // namespace OHOS #endif // HISTREAMER_PLUGIN_REGISTER_H