obs-studio/libobs/obs-cocoa.c

185 lines
4.4 KiB
C
Raw Normal View History

2013-11-14 09:18:25 -08:00
/******************************************************************************
Copyright (C) 2013 by Ruwen Hahn <palana@stunned.de>
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
2013-11-14 09:18:25 -08:00
(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/>.
******************************************************************************/
#include "util/platform.h"
#include "util/dstr.h"
#include "obs.h"
#include "obs-internal.h"
2013-11-14 09:18:25 -08:00
#include <unistd.h>
2014-07-12 00:21:06 -07:00
#include <sys/types.h>
#include <sys/sysctl.h>
2013-11-14 09:18:25 -08:00
2014-07-12 11:32:13 -07:00
#include <objc/objc.h>
const char *get_module_extension(void)
{
return ".so";
}
(API Change) Refactor module handling Changed API: - char *obs_find_plugin_file(const char *sub_path); Changed to: char *obs_module_file(const char *file); Cahnge it so you no longer need to specify a sub-path such as: obs_find_plugin_file("module_name/file.ext") Instead, now automatically handle the module data path so all you need to do is: obs_module_file("file.ext") - int obs_load_module(const char *name); Changed to: int obs_open_module(obs_module_t *module, const char *path, const char *data_path); bool obs_init_module(obs_module_t module); Change the module loading API so that if the front-end chooses, it can load modules directly from a specified path, and associate a data directory with it on the spot. The module will not be initialized immediately; obs_init_module must be called on the module pointer in order to fully initialize the module. This is done so a module can be disabled by the front-end if the it so chooses. New API: - void obs_add_module_path(const char *bin, const char *data); These functions allow you to specify new module search paths to add, and allow you to search through them, or optionally just load all modules from them. If the string %module% is included, it will replace it with the module's name when that string is used as a lookup. Data paths are now directly added to the module's internal storage structure, and when obs_find_module_file is used, it will look up the pointer to the obs_module structure and get its data directory that way. Example: obs_add_module_path("/opt/obs/my-modules/%module%/bin", "/opt/obs/my-modules/%module%/data"); This would cause it to additionally look for the binary of a hypthetical module named "foo" at /opt/obs/my-modules/foo/bin/foo.so (or libfoo.so), and then look for the data in /opt/obs/my-modules/foo/data. This gives the front-end more flexibility for handling third-party plugin modules, or handling all plugin modules in a custom way. - void obs_find_modules(obs_find_module_callback_t callback, void *param); This searches the existing paths for modules and calls the callback function when any are found. Useful for plugin management and custom handling of the paths by the front-end if desired. - void obs_load_all_modules(void); Search through the paths and both loads and initializes all modules automatically without custom handling. - void obs_enum_modules(obs_enum_module_callback_t callback, void *param); Enumerates currently opened modules.
2014-07-27 12:00:11 -07:00
static const char *module_bin[] = {
"../obs-plugins",
OBS_INSTALL_PREFIX "obs-plugins",
2013-11-14 09:18:25 -08:00
};
2013-11-15 05:40:03 -08:00
(API Change) Refactor module handling Changed API: - char *obs_find_plugin_file(const char *sub_path); Changed to: char *obs_module_file(const char *file); Cahnge it so you no longer need to specify a sub-path such as: obs_find_plugin_file("module_name/file.ext") Instead, now automatically handle the module data path so all you need to do is: obs_module_file("file.ext") - int obs_load_module(const char *name); Changed to: int obs_open_module(obs_module_t *module, const char *path, const char *data_path); bool obs_init_module(obs_module_t module); Change the module loading API so that if the front-end chooses, it can load modules directly from a specified path, and associate a data directory with it on the spot. The module will not be initialized immediately; obs_init_module must be called on the module pointer in order to fully initialize the module. This is done so a module can be disabled by the front-end if the it so chooses. New API: - void obs_add_module_path(const char *bin, const char *data); These functions allow you to specify new module search paths to add, and allow you to search through them, or optionally just load all modules from them. If the string %module% is included, it will replace it with the module's name when that string is used as a lookup. Data paths are now directly added to the module's internal storage structure, and when obs_find_module_file is used, it will look up the pointer to the obs_module structure and get its data directory that way. Example: obs_add_module_path("/opt/obs/my-modules/%module%/bin", "/opt/obs/my-modules/%module%/data"); This would cause it to additionally look for the binary of a hypthetical module named "foo" at /opt/obs/my-modules/foo/bin/foo.so (or libfoo.so), and then look for the data in /opt/obs/my-modules/foo/data. This gives the front-end more flexibility for handling third-party plugin modules, or handling all plugin modules in a custom way. - void obs_find_modules(obs_find_module_callback_t callback, void *param); This searches the existing paths for modules and calls the callback function when any are found. Useful for plugin management and custom handling of the paths by the front-end if desired. - void obs_load_all_modules(void); Search through the paths and both loads and initializes all modules automatically without custom handling. - void obs_enum_modules(obs_enum_module_callback_t callback, void *param); Enumerates currently opened modules.
2014-07-27 12:00:11 -07:00
static const char *module_data[] = {
"../data/obs-plugins/%module%",
OBS_INSTALL_DATA_PATH "obs-plugins/%module%",
};
2013-11-14 09:18:25 -08:00
(API Change) Refactor module handling Changed API: - char *obs_find_plugin_file(const char *sub_path); Changed to: char *obs_module_file(const char *file); Cahnge it so you no longer need to specify a sub-path such as: obs_find_plugin_file("module_name/file.ext") Instead, now automatically handle the module data path so all you need to do is: obs_module_file("file.ext") - int obs_load_module(const char *name); Changed to: int obs_open_module(obs_module_t *module, const char *path, const char *data_path); bool obs_init_module(obs_module_t module); Change the module loading API so that if the front-end chooses, it can load modules directly from a specified path, and associate a data directory with it on the spot. The module will not be initialized immediately; obs_init_module must be called on the module pointer in order to fully initialize the module. This is done so a module can be disabled by the front-end if the it so chooses. New API: - void obs_add_module_path(const char *bin, const char *data); These functions allow you to specify new module search paths to add, and allow you to search through them, or optionally just load all modules from them. If the string %module% is included, it will replace it with the module's name when that string is used as a lookup. Data paths are now directly added to the module's internal storage structure, and when obs_find_module_file is used, it will look up the pointer to the obs_module structure and get its data directory that way. Example: obs_add_module_path("/opt/obs/my-modules/%module%/bin", "/opt/obs/my-modules/%module%/data"); This would cause it to additionally look for the binary of a hypthetical module named "foo" at /opt/obs/my-modules/foo/bin/foo.so (or libfoo.so), and then look for the data in /opt/obs/my-modules/foo/data. This gives the front-end more flexibility for handling third-party plugin modules, or handling all plugin modules in a custom way. - void obs_find_modules(obs_find_module_callback_t callback, void *param); This searches the existing paths for modules and calls the callback function when any are found. Useful for plugin management and custom handling of the paths by the front-end if desired. - void obs_load_all_modules(void); Search through the paths and both loads and initializes all modules automatically without custom handling. - void obs_enum_modules(obs_enum_module_callback_t callback, void *param); Enumerates currently opened modules.
2014-07-27 12:00:11 -07:00
static const int module_patterns_size =
sizeof(module_bin)/sizeof(module_bin[0]);
2013-11-14 09:18:25 -08:00
(API Change) Refactor module handling Changed API: - char *obs_find_plugin_file(const char *sub_path); Changed to: char *obs_module_file(const char *file); Cahnge it so you no longer need to specify a sub-path such as: obs_find_plugin_file("module_name/file.ext") Instead, now automatically handle the module data path so all you need to do is: obs_module_file("file.ext") - int obs_load_module(const char *name); Changed to: int obs_open_module(obs_module_t *module, const char *path, const char *data_path); bool obs_init_module(obs_module_t module); Change the module loading API so that if the front-end chooses, it can load modules directly from a specified path, and associate a data directory with it on the spot. The module will not be initialized immediately; obs_init_module must be called on the module pointer in order to fully initialize the module. This is done so a module can be disabled by the front-end if the it so chooses. New API: - void obs_add_module_path(const char *bin, const char *data); These functions allow you to specify new module search paths to add, and allow you to search through them, or optionally just load all modules from them. If the string %module% is included, it will replace it with the module's name when that string is used as a lookup. Data paths are now directly added to the module's internal storage structure, and when obs_find_module_file is used, it will look up the pointer to the obs_module structure and get its data directory that way. Example: obs_add_module_path("/opt/obs/my-modules/%module%/bin", "/opt/obs/my-modules/%module%/data"); This would cause it to additionally look for the binary of a hypthetical module named "foo" at /opt/obs/my-modules/foo/bin/foo.so (or libfoo.so), and then look for the data in /opt/obs/my-modules/foo/data. This gives the front-end more flexibility for handling third-party plugin modules, or handling all plugin modules in a custom way. - void obs_find_modules(obs_find_module_callback_t callback, void *param); This searches the existing paths for modules and calls the callback function when any are found. Useful for plugin management and custom handling of the paths by the front-end if desired. - void obs_load_all_modules(void); Search through the paths and both loads and initializes all modules automatically without custom handling. - void obs_enum_modules(obs_enum_module_callback_t callback, void *param); Enumerates currently opened modules.
2014-07-27 12:00:11 -07:00
void add_default_module_paths(void)
{
for (int i = 0; i < module_patterns_size; i++)
obs_add_module_path(module_bin[i], module_data[i]);
2013-11-14 09:18:25 -08:00
}
char *find_libobs_data_file(const char *file)
{
struct dstr path;
dstr_init_copy(&path, OBS_INSTALL_DATA_PATH "/libobs/");
2013-11-14 09:18:25 -08:00
dstr_cat(&path, file);
return path.array;
}
2014-07-12 00:21:06 -07:00
static void log_processor_name(void)
{
char *name = NULL;
size_t size;
int ret;
ret = sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0);
if (ret != 0)
return;
name = malloc(size);
ret = sysctlbyname("machdep.cpu.brand_string", name, &size, NULL, 0);
if (ret == 0)
blog(LOG_INFO, "CPU Name: %s", name);
free(name);
}
static void log_processor_speed(void)
{
size_t size;
long long freq;
int ret;
size = sizeof(freq);
ret = sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0);
if (ret == 0)
blog(LOG_INFO, "CPU Speed: %lldMHz", freq / 1000000);
}
static void log_processor_cores(void)
{
size_t size;
int physical_cores = 0, logical_cores = 0;
int ret;
size = sizeof(physical_cores);
ret = sysctlbyname("machdep.cpu.core_count", &physical_cores,
2014-07-12 00:21:06 -07:00
&size, NULL, 0);
if (ret != 0)
return;
ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores,
2014-07-12 00:21:06 -07:00
&size, NULL, 0);
if (ret != 0)
return;
blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
physical_cores, logical_cores);
}
static void log_available_memory(void)
{
size_t size;
long long memory_available;
int ret;
size = sizeof(memory_available);
ret = sysctlbyname("hw.memsize", &memory_available, &size, NULL, 0);
if (ret == 0)
blog(LOG_INFO, "Physical Memory: %lldMB Total",
memory_available / 1024 / 1024);
}
2014-07-12 11:32:13 -07:00
static void log_os_name(id pi, SEL UTF8String)
{
unsigned long os_id = (unsigned long)objc_msgSend(pi,
sel_registerName("operatingSystem"));
id os = objc_msgSend(pi,
sel_registerName("operatingSystemName"));
const char *name = (const char*)objc_msgSend(os, UTF8String);
if (os_id == 5 /*NSMACHOperatingSystem*/) {
blog(LOG_INFO, "OS Name: Mac OS X (%s)", name);
return;
}
blog(LOG_INFO, "OS Name: %s", name ? name : "Unknown");
}
static void log_os_version(id pi, SEL UTF8String)
{
id vs = objc_msgSend(pi,
sel_registerName("operatingSystemVersionString"));
const char *version = (const char*)objc_msgSend(vs, UTF8String);
blog(LOG_INFO, "OS Version: %s", version ? version : "Unknown");
}
static void log_os(void)
{
Class NSProcessInfo = objc_getClass("NSProcessInfo");
id pi = objc_msgSend((id)NSProcessInfo,
sel_registerName("processInfo"));
SEL UTF8String = sel_registerName("UTF8String");
log_os_name(pi, UTF8String);
log_os_version(pi, UTF8String);
}
2014-07-12 00:21:06 -07:00
static void log_kernel_version(void)
{
char kernel_version[1024];
size_t size = sizeof(kernel_version);
int ret;
ret = sysctlbyname("kern.osrelease", kernel_version, &size,
NULL, 0);
if (ret == 0)
blog(LOG_INFO, "Kernel Version: %s", kernel_version);
}
void log_system_info(void)
{
log_processor_name();
log_processor_speed();
log_processor_cores();
log_available_memory();
2014-07-12 11:32:13 -07:00
log_os();
2014-07-12 00:21:06 -07:00
log_kernel_version();
}