mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-11-02 18:25:29 -05:00
With this change module loading in the application is managed by the plugin manager and allows the application to explicitly load core modules independantly from 3rd party (plugin) modules. The implementation is split into separate files for different platforms to allow for cleaner code handling the different possible locations and path schemes used, including all possible legacy locations and plugin bundle formats. This change introduces new locations and directory formats for plugins: * WINDOWS: Portable plugins need to be placed in a directory called "plugins" adjacent to the "bin" directory of an OBS Studio installation. * WINDOWS: Plugins need to be packaged into their own directory "bundles", with the associated DLL in the root of the bundle and the associated "data" directory next to it. * WINDOWS: The "obs-plugins" directory adjacent to the "bin" directory is deprecated and considered a legacy location for all plugins. * MACOS: No changes in locations or formats. * LINUX: Plugins distributed via system package managers now need to use the "obs-modules/plugins" directory in the system library directory for binaries, and the "obs/obs-modules/plugins" directory in the system data directory for resources. * LINUX: The "obs-plugins" directories in the system library and system data directories are deprecated. * LINUX: Plugins distributed outside of system packages need to use the same directory format as plugins for Windows (see above). * LINUX: A "portable" plugin location like on Windows is not supported. * LINUX: Proper XDG directory locations are scanned for plugins, using XDG_CONFIG_HOME for the legacy plugin format and XDG_DATA_HOME for the new plugin structure. * LINUX: Changes Flatpak plugin loading to use the new plugin structure (while still supporting the legacy structure), and moves Flatpak specific plugin loading to its own source files. * ALL PLATFORMS: A single environment variable "OBS_PLUGINS_PATH" can now be used to provide a highest-priority location from which to load plugins. This directory needs to contain plugin bundles per the new format. The one exception is Flatpak which does not support loading plugins from an env provided location. * ALL PLATFORMS: A custom legacy plugin locations can still be provided via the "OBS_LEGACY_PLUGINS_PATH" and "OBS_LEGACY_PLUGINS_DATA_PATH" environment variables. These are only compatible with plugins using the legacy format and are considered deprecated. The one exception is Flatpak which does not support loading plugins from an env provided location. Co-authored-by: PatTheMav <PatTheMav@users.noreply.github.com>
106 lines
3.3 KiB
C++
106 lines
3.3 KiB
C++
/******************************************************************************
|
|
Copyright (C) 2025 by FiniteSingularity <finitesingularityttv@gmail.com>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <obs-module.h>
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace OBS {
|
|
|
|
struct ModuleInfo {
|
|
std::string display_name;
|
|
std::string module_name;
|
|
std::string id;
|
|
std::string version;
|
|
bool enabled;
|
|
bool enabledAtLaunch;
|
|
std::vector<std::string> sources;
|
|
std::vector<std::string> outputs;
|
|
std::vector<std::string> encoders;
|
|
std::vector<std::string> services;
|
|
std::vector<std::string> sourcesLoaded;
|
|
std::vector<std::string> outputsLoaded;
|
|
std::vector<std::string> encodersLoaded;
|
|
std::vector<std::string> servicesLoaded;
|
|
};
|
|
|
|
class PluginManager {
|
|
public:
|
|
using ModuleList = std::vector<std::string>;
|
|
enum class Mode { CoreOnly, Full };
|
|
enum class State { Failure, PartialFailure, Success };
|
|
|
|
private:
|
|
Mode loadMode_{Mode::Full};
|
|
State loadState_{State::Failure};
|
|
|
|
std::vector<ModuleInfo> modules_ = {};
|
|
ModuleList failedModules_ = {};
|
|
ModuleList disabledSources_ = {};
|
|
ModuleList disabledOutputs_ = {};
|
|
ModuleList disabledServices_ = {};
|
|
ModuleList disabledEncoders_ = {};
|
|
std::filesystem::path getConfigFilePath_();
|
|
void loadModuleConfiguration_();
|
|
void saveModules_();
|
|
void disableModules_();
|
|
void addModuleTypes_();
|
|
void linkUnloadedModules_();
|
|
|
|
State loadPlugins(bool usePortableMode);
|
|
State loadLegacyPlugins(bool usePortableMode);
|
|
|
|
public:
|
|
Mode pluginMode() { return loadMode_; }
|
|
void setPluginMode(Mode mode) { loadMode_ = mode; }
|
|
|
|
State loadState() { return loadState_; }
|
|
|
|
void disablePlugins();
|
|
void preLoad();
|
|
void postLoad();
|
|
void loadAllPlugins(bool usePortableMode);
|
|
void open();
|
|
|
|
friend void addModuleToPluginManagerImpl(void *param, obs_module_t *newModule);
|
|
};
|
|
|
|
void addModuleToPluginManagerImpl(void *param, obs_module_t *newModule);
|
|
|
|
}; // namespace OBS
|
|
|
|
bool operator&&(const OBS::PluginManager::State &lhs, const OBS::PluginManager::State &rhs);
|
|
bool operator&&(const OBS::PluginManager::State &lhs, bool rhs);
|
|
bool operator&&(bool lhs, const OBS::PluginManager::State &rhs);
|
|
|
|
bool operator||(const OBS::PluginManager::State &lhs, const OBS::PluginManager::State &rhs);
|
|
bool operator||(const OBS::PluginManager::State &lhs, bool rhs);
|
|
bool operator||(bool lhs, const OBS::PluginManager::State &rhs);
|
|
|
|
// Anonymous namespace function to add module to plugin manager
|
|
// via libobs's module enumeration.
|
|
namespace {
|
|
inline void addModuleToPluginManager(void *param, obs_module_t *newModule)
|
|
{
|
|
OBS::addModuleToPluginManagerImpl(param, newModule);
|
|
}
|
|
} // namespace
|