diff --git a/src/media_server_app.cpp b/src/media_server_app.cpp index d879719..7d00a1a 100644 --- a/src/media_server_app.cpp +++ b/src/media_server_app.cpp @@ -3,6 +3,12 @@ #include #include #include +#include + +#if defined(__linux__) +#include +#include +#endif #include "graph_manager.h" #include "utils/simple_json.h" @@ -13,8 +19,28 @@ namespace { GraphManager* g_manager = nullptr; +std::string ResolvePluginDir() { + if (const char* env = std::getenv("RK_PLUGIN_DIR")) { + return std::string(env); + } + +#if defined(__linux__) + char path[PATH_MAX] = {0}; + ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1); + if (len > 0) { + std::string exe_path(path, static_cast(len)); + auto pos = exe_path.find_last_of('/'); + if (pos != std::string::npos) { + return exe_path.substr(0, pos) + "/plugins"; + } + } +#endif + + return std::string("plugins"); +} + GraphManager& GetManager() { - static GraphManager mgr; + static GraphManager mgr(ResolvePluginDir()); return mgr; }