obs-nix.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Copyright (C) 2014 by Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #if defined(__FreeBSD__)
  19. #include <sys/sysctl.h>
  20. #endif
  21. #include <sys/sysinfo.h>
  22. #include <sys/utsname.h>
  23. #include <inttypes.h>
  24. #include "util/dstr.h"
  25. #include "obs-internal.h"
  26. const char *get_module_extension(void)
  27. {
  28. return ".so";
  29. }
  30. #ifdef __LP64__
  31. #define BIT_STRING "64bit"
  32. #else
  33. #define BIT_STRING "32bit"
  34. #endif
  35. static const char *module_bin[] = {
  36. "../../obs-plugins/" BIT_STRING,
  37. OBS_INSTALL_PREFIX "/" OBS_PLUGIN_DESTINATION
  38. };
  39. static const char *module_data[] = {
  40. OBS_DATA_PATH "/obs-plugins/%module%",
  41. OBS_INSTALL_DATA_PATH "/obs-plugins/%module%",
  42. };
  43. static const int module_patterns_size =
  44. sizeof(module_bin)/sizeof(module_bin[0]);
  45. void add_default_module_paths(void)
  46. {
  47. for (int i = 0; i < module_patterns_size; i++)
  48. obs_add_module_path(module_bin[i], module_data[i]);
  49. }
  50. /*
  51. * /usr/local/share/libobs
  52. * /usr/share/libobs
  53. */
  54. char *find_libobs_data_file(const char *file)
  55. {
  56. struct dstr output;
  57. dstr_init(&output);
  58. if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
  59. return output.array;
  60. if (OBS_INSTALL_PREFIX [0] != 0) {
  61. if (check_path(file, OBS_INSTALL_DATA_PATH "/libobs/",
  62. &output))
  63. return output.array;
  64. }
  65. dstr_free(&output);
  66. return NULL;
  67. }
  68. static void log_processor_cores(void)
  69. {
  70. blog(LOG_INFO, "Processor: %lu logical cores",
  71. sysconf(_SC_NPROCESSORS_ONLN));
  72. }
  73. #if defined(__linux__)
  74. static void log_processor_info(void)
  75. {
  76. FILE *fp;
  77. int physical_id = -1;
  78. int last_physical_id = -1;
  79. char *line = NULL;
  80. size_t linecap = 0;
  81. struct dstr processor;
  82. fp = fopen("/proc/cpuinfo", "r");
  83. if (!fp)
  84. return;
  85. dstr_init(&processor);
  86. while (getline(&line, &linecap, fp) != -1) {
  87. if (!strncmp(line, "model name", 10)) {
  88. char *start = strchr(line, ':');
  89. if (!start || *(++start) == '\0')
  90. continue;
  91. dstr_copy(&processor, start);
  92. dstr_resize(&processor, processor.len - 1);
  93. dstr_depad(&processor);
  94. }
  95. if (!strncmp(line, "physical id", 11)) {
  96. char *start = strchr(line, ':');
  97. if (!start || *(++start) == '\0')
  98. continue;
  99. physical_id = atoi(start);
  100. }
  101. if (*line == '\n' && physical_id != last_physical_id) {
  102. last_physical_id = physical_id;
  103. blog(LOG_INFO, "Processor: %s", processor.array);
  104. }
  105. }
  106. fclose(fp);
  107. dstr_free(&processor);
  108. free(line);
  109. }
  110. #elif defined(__FreeBSD__)
  111. static void log_processor_info(void)
  112. {
  113. int mib[2];
  114. size_t len;
  115. char *proc;
  116. mib[0] = CTL_HW;
  117. mib[1] = HW_MODEL;
  118. sysctl(mib, 2, NULL, &len, NULL, 0);
  119. proc = bmalloc(len);
  120. if (!proc)
  121. return;
  122. sysctl(mib, 2, proc, &len, NULL, 0);
  123. blog(LOG_INFO, "Processor: %s", proc);
  124. bfree(proc);
  125. }
  126. #endif
  127. static void log_memory_info(void)
  128. {
  129. struct sysinfo info;
  130. if (sysinfo(&info) < 0)
  131. return;
  132. blog(LOG_INFO, "Physical Memory: %"PRIu64"MB Total",
  133. (uint64_t)info.totalram * info.mem_unit / 1024 / 1024);
  134. }
  135. static void log_kernel_version(void)
  136. {
  137. struct utsname info;
  138. if (uname(&info) < 0)
  139. return;
  140. blog(LOG_INFO, "Kernel Version: %s %s", info.sysname, info.release);
  141. }
  142. #if defined(__linux__)
  143. static void log_distribution_info(void)
  144. {
  145. FILE *fp;
  146. char *line = NULL;
  147. size_t linecap = 0;
  148. struct dstr distro;
  149. struct dstr version;
  150. fp = fopen("/etc/os-release", "r");
  151. if (!fp) {
  152. blog(LOG_INFO, "Distribution: Missing /etc/os-release !");
  153. return;
  154. }
  155. dstr_init_copy(&distro, "Unknown");
  156. dstr_init_copy(&version, "Unknown");
  157. while (getline(&line, &linecap, fp) != -1) {
  158. if (!strncmp(line, "NAME", 4)) {
  159. char *start = strchr(line, '=');
  160. if (!start || *(++start) == '\0')
  161. continue;
  162. dstr_copy(&distro, start);
  163. dstr_resize(&distro, distro.len - 1);
  164. }
  165. if (!strncmp(line, "VERSION_ID", 10)) {
  166. char *start = strchr(line, '=');
  167. if (!start || *(++start) == '\0')
  168. continue;
  169. dstr_copy(&version, start);
  170. dstr_resize(&version, version.len - 1);
  171. }
  172. }
  173. blog(LOG_INFO, "Distribution: %s %s", distro.array, version.array);
  174. fclose(fp);
  175. dstr_free(&version);
  176. dstr_free(&distro);
  177. free(line);
  178. }
  179. #endif
  180. void log_system_info(void)
  181. {
  182. log_processor_cores();
  183. #if defined(__linux__) || defined(__FreeBSD__)
  184. log_processor_info();
  185. #endif
  186. log_memory_info();
  187. log_kernel_version();
  188. #if defined(__linux__)
  189. log_distribution_info();
  190. #endif
  191. }
  192. struct obs_hotkeys_platform {
  193. };
  194. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
  195. {
  196. UNUSED_PARAMETER(hotkeys);
  197. return true;
  198. }
  199. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys)
  200. {
  201. UNUSED_PARAMETER(hotkeys);
  202. }
  203. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  204. obs_key_t key)
  205. {
  206. UNUSED_PARAMETER(context);
  207. UNUSED_PARAMETER(key);
  208. return false;
  209. }
  210. void obs_key_to_str(obs_key_t key, struct dstr *str)
  211. {
  212. UNUSED_PARAMETER(key);
  213. UNUSED_PARAMETER(str);
  214. }
  215. void obs_key_combination_to_str(obs_key_combination_t key, struct dstr *str)
  216. {
  217. UNUSED_PARAMETER(key);
  218. UNUSED_PARAMETER(str);
  219. }
  220. obs_key_t obs_key_from_virtual_key(int code)
  221. {
  222. UNUSED_PARAMETER(code);
  223. return OBS_KEY_NONE;
  224. }
  225. int obs_key_to_virtual_key(obs_key_t key)
  226. {
  227. UNUSED_PARAMETER(key);
  228. return 0;
  229. }