bool load_nvenc_lib(void)
{
	if (sizeof(void*) == 8) {
		nvenc_lib = os_dlopen("nvEncodeAPI64.dll");
	} else {
		nvenc_lib = os_dlopen("nvEncodeAPI.dll");
	}

	return !!nvenc_lib;
}
Beispiel #2
0
int gs_create(graphics_t *pgraphics, const char *module,
		struct gs_init_data *data)
{
	int errcode = GS_ERROR_FAIL;

	graphics_t graphics = bmalloc(sizeof(struct graphics_subsystem));
	memset(graphics, 0, sizeof(struct graphics_subsystem));
	pthread_mutex_init_value(&graphics->mutex);

	graphics->module = os_dlopen(module);
	if (!graphics->module) {
		errcode = GS_ERROR_MODULENOTFOUND;
		goto error;
	}

	if (!load_graphics_imports(&graphics->exports, graphics->module,
	                           module))
		goto error;

	graphics->device = graphics->exports.device_create(data);
	if (!graphics->device)
		goto error;

	if (!graphics_init(graphics))
		goto error;

	*pgraphics = graphics;
	return GS_SUCCESS;

error:
	gs_destroy(graphics);
	return errcode;
}
Beispiel #3
0
int obs_open_module(obs_module_t *module, const char *path,
                    const char *data_path)
{
    struct obs_module mod = {0};
    int errorcode;

    if (!module || !path || !obs)
        return MODULE_ERROR;

    mod.module = os_dlopen(path);
    if (!mod.module) {
        blog(LOG_WARNING, "Module '%s' not found", path);
        return MODULE_FILE_NOT_FOUND;
    }

    errorcode = load_module_exports(&mod, path);
    if (errorcode != MODULE_SUCCESS)
        return errorcode;

    mod.bin_path  = bstrdup(path);
    mod.file      = strrchr(mod.bin_path, '/');
    mod.file      = (!mod.file) ? mod.bin_path : (mod.file + 1);
    mod.data_path = bstrdup(data_path);
    mod.next      = obs->first_module;

    *module = bmemdup(&mod, sizeof(mod));
    obs->first_module = (*module);
    mod.set_pointer(*module);

    if (mod.set_locale)
        mod.set_locale(obs->locale);

    return MODULE_SUCCESS;
}
Beispiel #4
0
int obs_load_module(const char *path)
{
	struct obs_module mod;
	bool (*module_load)(void) = NULL;

	mod.module = os_dlopen(path);
	if (!mod.module)
		return MODULE_FILENOTFOUND;

	module_load = os_dlsym(mod.module, "module_load");
	if (module_load) {
		if (!module_load()) {
			os_dlclose(mod.module);
			return MODULE_ERROR;
		}
	}

	mod.name = bstrdup(path);
	module_load_exports(&mod, &obs->input_types.da, "inputs",
			sizeof(struct source_info), get_source_info);
	module_load_exports(&mod, &obs->filter_types.da, "filters",
			sizeof(struct source_info), get_source_info);
	module_load_exports(&mod, &obs->transition_types.da, "transitions",
			sizeof(struct source_info), get_source_info);
	module_load_exports(&mod, &obs->output_types.da, "outputs",
			sizeof(struct output_info), get_output_info);

	da_push_back(obs->modules, &mod);
	return MODULE_SUCCESS;
}
static bool load_libvlc_module(void)
{
#ifdef _WIN32
	char    *path_utf8 = NULL;
	wchar_t path[1024];
	LSTATUS status;
	DWORD   size;
	HKEY    key;

	memset(path, 0, 1024 * sizeof(wchar_t));

	status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
			L"SOFTWARE\\VideoLAN\\VLC",
			&key);
	if (status != ERROR_SUCCESS)
		return false;

	size = 1024;
	status = RegQueryValueExW(key, L"InstallDir", NULL, NULL,
			(LPBYTE)path, &size);
	if (status == ERROR_SUCCESS) {
		wcscat(path, L"\\libvlc.dll");
		os_wcs_to_utf8_ptr(path, 0, &path_utf8);
		libvlc_module = os_dlopen(path_utf8);
		bfree(path_utf8);
	}

	RegCloseKey(key);
#else

#ifdef __APPLE__
#define LIBVLC_DIR "/Applications/VLC.app/Contents/MacOS/"
#define LIBVLC_FILE LIBVLC_DIR "lib/libvlc.5.dylib"
	setenv("VLC_PLUGIN_PATH", LIBVLC_DIR "plugins", false);
#else
#define LIBVLC_FILE "libvlc.5.so"
#endif
	libvlc_module = os_dlopen(LIBVLC_FILE);

#endif

	return libvlc_module != NULL;
}
Beispiel #6
0
static inline QCef *obs_browser_init_panel(void)
{
#ifdef _WIN32
	void *lib = os_dlopen("obs-browser");
#else
	void *lib = os_dlopen("../obs-plugins/obs-browser");
#endif
	QCef *(*create_qcef)(void) = nullptr;

	if (!lib) {
		return nullptr;
	}

	create_qcef = (decltype(create_qcef))
		os_dlsym(lib, "obs_browser_create_qcef");
	if (!create_qcef)
		return nullptr;

	return create_qcef();
}
Beispiel #7
0
bool
obs_module_load(void)
{
	obs_so = NULL;
	
	bool success;
	char *obs_browser_path = obs_module_file("obs-browser");
	if (obs_browser_path) {
		obs_so = os_dlopen(obs_browser_path);
		if (obs_so) {
			obs_actual_load = os_dlsym(obs_so, "obs_module_load");
			obs_actual_unload = os_dlsym(obs_so, 
				"obs_module_unload");
			obs_actual_module_set_pointer = os_dlsym(obs_so,
				"obs_actual_module_so");

			if (obs_actual_load && obs_actual_unload 
				&& obs_actual_module_set_pointer) 
			{
				obs_actual_module_set_pointer(
					obs_module_pointer);
				if (obs_actual_load()) {
					goto success;
				}
			}

		}
	}

error:
	success = false;
	if (obs_so)
		os_dlclose(obs_so);
success:
	if (obs_browser_path)
		bfree(obs_browser_path);
	return success;
}
Beispiel #8
0
int obs_load_module(const char *path)
{
	struct obs_module mod;
	char *plugin_path = find_plugin(path);
	int errorcode;

	mod.module = os_dlopen(plugin_path);
	bfree(plugin_path);
	if (!mod.module) {
		blog(LOG_DEBUG, "Module '%s' not found", path);
		return MODULE_FILE_NOT_FOUND;
	}

	errorcode = call_module_load(mod.module, path);
	if (errorcode != MODULE_SUCCESS) {
		os_dlclose(mod.module);
		return errorcode;
	}

	mod.name = bstrdup(path);
	da_push_back(obs->modules, &mod);
	return MODULE_SUCCESS;
}
bool obs_module_load()
{
    blog(LOG_INFO, "obs_module_load");

    if(!is_python_on_path()){
      blog(LOG_WARNING,
	   "%s:l%i \"Warning could not detect python environment variables attempting to load shared library anyway\"",
	   __func__,
	   __LINE__
	   );      
    }

    // Manually force python to be loaded
#if __GNUC__
    if(!os_dlopen_global(PYTHON_SHARED_LIBRARY_NAME)){
#else
      if(!os_dlopen(PYTHON_SHARED_LIBRARY_NAME)){
#endif
	blog(LOG_ERROR,
	    "%s:l%i \"Error Could not load python shared library %s aborting!\"",
	    __func__,
	    __LINE__,
	    PYTHON_SHARED_LIBRARY_NAME
	    );      
	return false;
    }


    Py_Initialize();
    PyEval_InitThreads();
 

    /*Must set arguments for guis to work*/
    wchar_t* argv[] = { L"", NULL };
    int argc = sizeof(argv) / sizeof(wchar_t*) - 1;
  

    PySys_SetArgv(argc, argv);

    /* Setup logs to a safe place can be changed by user in OBSPythonManager.py register function*/
    PyRun_SimpleString("import os");
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("os.environ['PYTHONUNBUFFERED'] = '1'");
    /* TODO  change to non platform specific */
    PyRun_SimpleString("sys.stdout = open('./stdOut.txt','w',1)");
    PyRun_SimpleString("sys.stderr = open('./stdErr.txt','w',1)");
    PyRun_SimpleString("print(sys.version)");

    
    /*Load manager from file*/    
    PyObject* pName = NULL;
    PyObject* pModule = NULL;
    PyObject* pFunc = NULL;
    PyObject* argList = NULL;

    bool ret = false;

    char script[] = "/scripts";
    char arch[] = PLUGINARCH;
    const char *data_path = obs_get_module_data_path(obs_current_module());
    char *scripts_path = bzalloc(strlen(data_path)+strlen(script));
    
    strcpy(scripts_path,data_path);
    strcat(scripts_path,script);


    //Add the scripts path to env
    add_to_python_path(scripts_path);

    bfree(scripts_path);
    

    scripts_path = bzalloc(strlen(data_path)+strlen(arch));
    strcpy(scripts_path,data_path);
    strcat(scripts_path,arch);

    //Add the plugin obspython arch path to env
    add_to_python_path(scripts_path);


    /* load the obspython library and extend with manually written functions/objects  */
    PyObject *py_libobs = PyImport_ImportModule("obspython");
    ret = pyHasError();
    if (ret){
      blog(LOG_INFO,
	   "%s:l%i \"Error importing '%s/obspython.py' unloading obs-python\"",
	   __func__,
	   __LINE__,
	   scripts_path
	   );
      goto out;
    }

    extend_swig_libobs(py_libobs);


    //Import the manager script
    pName = PyUnicode_FromString("OBSPythonManager");
    pModule = PyImport_Import(pName);

    ret = pyHasError();
    if (ret){
      blog(LOG_INFO,
	     "%s:l%i \"Error loading '%s/OBSPythonManager.py' unloading obs-python\"",
	     __func__,
	     __LINE__,
	     scripts_path
	     );
      goto out;
    }
    
    //get the function by name
    if(pModule != NULL) {
      PyModule_AddObject(pModule,"obspython",py_libobs);
      pFunc = PyObject_GetAttr(pModule, PyUnicode_FromString("obs_module_load"));
        if(pFunc != NULL) {
	  argList = Py_BuildValue("()");
            PyObject_CallObject(pFunc,argList);
	    ret = pyHasError();
	    if (ret){
	      blog(LOG_INFO,
		   "%s:l%i \"Error running 'register' function in '%s/OBSPythonManager.py' unloading obs-python\"",
		   __func__,
		   __LINE__,
		   scripts_path
		   );
	      goto out;
	    }
	}else{
	  ret = pyHasError();
	  blog(LOG_INFO,
	       "%s:l%i \"Could not find register function in '%s/OBSPythonManager.py' unloading obs-python\"",
	       __func__,
	       __LINE__,
	       scripts_path
	       );
	}
	goto out;
    }

 out:
    bfree(scripts_path);    
    Py_XDECREF(pFunc);
    Py_XDECREF(argList);
    Py_XDECREF(pModule);
    Py_XDECREF(pName); 
    //Release the thread GIL
    PyThreadState* pts = PyGILState_GetThisThreadState();
    PyEval_ReleaseThread(pts);
    if(!ret){    
       return true;
    }else{    
        obs_module_unload();
        return false;
    }
}

void obs_module_unload()
{
    //Shutdown python and call shutdown functions
    blog(LOG_INFO, "obs_module_unload");

    PyGILState_STATE gstate;
    gstate = PyGILState_Ensure();

    UNUSED_PARAMETER(gstate);

    if (Py_IsInitialized()) {
        Py_Finalize();
    }

}