obs-cocoa.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /******************************************************************************
  2. Copyright (C) 2013 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "util/platform.h"
  15. #include "util/dstr.h"
  16. #include "obs.h"
  17. #include "obs-internal.h"
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <sys/sysctl.h>
  21. #include <objc/objc.h>
  22. const char *get_module_extension(void)
  23. {
  24. return ".so";
  25. }
  26. static const char *module_bin[] = {
  27. "../obs-plugins",
  28. OBS_INSTALL_PREFIX "obs-plugins",
  29. };
  30. static const char *module_data[] = {
  31. "../data/obs-plugins/%module%",
  32. OBS_INSTALL_DATA_PATH "obs-plugins/%module%",
  33. };
  34. static const int module_patterns_size =
  35. sizeof(module_bin)/sizeof(module_bin[0]);
  36. void add_default_module_paths(void)
  37. {
  38. char bin[512];
  39. char data[512];
  40. int ret;
  41. for (int i = 0; i < module_patterns_size; i++)
  42. obs_add_module_path(module_bin[i], module_data[i]);
  43. ret = os_get_config_path(bin, sizeof(bin), "obs-plugins/%module%");
  44. if (ret <= 0)
  45. return;
  46. strcpy(data, bin);
  47. strcat(data, "/data");
  48. strcat(bin, "/bin");
  49. obs_add_module_path(bin, data);
  50. }
  51. char *find_libobs_data_file(const char *file)
  52. {
  53. struct dstr path;
  54. dstr_init_copy(&path, OBS_INSTALL_DATA_PATH "/libobs/");
  55. dstr_cat(&path, file);
  56. return path.array;
  57. }
  58. static void log_processor_name(void)
  59. {
  60. char *name = NULL;
  61. size_t size;
  62. int ret;
  63. ret = sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0);
  64. if (ret != 0)
  65. return;
  66. name = malloc(size);
  67. ret = sysctlbyname("machdep.cpu.brand_string", name, &size, NULL, 0);
  68. if (ret == 0)
  69. blog(LOG_INFO, "CPU Name: %s", name);
  70. free(name);
  71. }
  72. static void log_processor_speed(void)
  73. {
  74. size_t size;
  75. long long freq;
  76. int ret;
  77. size = sizeof(freq);
  78. ret = sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0);
  79. if (ret == 0)
  80. blog(LOG_INFO, "CPU Speed: %lldMHz", freq / 1000000);
  81. }
  82. static void log_processor_cores(void)
  83. {
  84. size_t size;
  85. int physical_cores = 0, logical_cores = 0;
  86. int ret;
  87. size = sizeof(physical_cores);
  88. ret = sysctlbyname("machdep.cpu.core_count", &physical_cores,
  89. &size, NULL, 0);
  90. if (ret != 0)
  91. return;
  92. ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores,
  93. &size, NULL, 0);
  94. if (ret != 0)
  95. return;
  96. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  97. physical_cores, logical_cores);
  98. }
  99. static void log_available_memory(void)
  100. {
  101. size_t size;
  102. long long memory_available;
  103. int ret;
  104. size = sizeof(memory_available);
  105. ret = sysctlbyname("hw.memsize", &memory_available, &size, NULL, 0);
  106. if (ret == 0)
  107. blog(LOG_INFO, "Physical Memory: %lldMB Total",
  108. memory_available / 1024 / 1024);
  109. }
  110. static void log_os_name(id pi, SEL UTF8String)
  111. {
  112. unsigned long os_id = (unsigned long)objc_msgSend(pi,
  113. sel_registerName("operatingSystem"));
  114. id os = objc_msgSend(pi,
  115. sel_registerName("operatingSystemName"));
  116. const char *name = (const char*)objc_msgSend(os, UTF8String);
  117. if (os_id == 5 /*NSMACHOperatingSystem*/) {
  118. blog(LOG_INFO, "OS Name: Mac OS X (%s)", name);
  119. return;
  120. }
  121. blog(LOG_INFO, "OS Name: %s", name ? name : "Unknown");
  122. }
  123. static void log_os_version(id pi, SEL UTF8String)
  124. {
  125. id vs = objc_msgSend(pi,
  126. sel_registerName("operatingSystemVersionString"));
  127. const char *version = (const char*)objc_msgSend(vs, UTF8String);
  128. blog(LOG_INFO, "OS Version: %s", version ? version : "Unknown");
  129. }
  130. static void log_os(void)
  131. {
  132. Class NSProcessInfo = objc_getClass("NSProcessInfo");
  133. id pi = objc_msgSend((id)NSProcessInfo,
  134. sel_registerName("processInfo"));
  135. SEL UTF8String = sel_registerName("UTF8String");
  136. log_os_name(pi, UTF8String);
  137. log_os_version(pi, UTF8String);
  138. }
  139. static void log_kernel_version(void)
  140. {
  141. char kernel_version[1024];
  142. size_t size = sizeof(kernel_version);
  143. int ret;
  144. ret = sysctlbyname("kern.osrelease", kernel_version, &size,
  145. NULL, 0);
  146. if (ret == 0)
  147. blog(LOG_INFO, "Kernel Version: %s", kernel_version);
  148. }
  149. void log_system_info(void)
  150. {
  151. log_processor_name();
  152. log_processor_speed();
  153. log_processor_cores();
  154. log_available_memory();
  155. log_os();
  156. log_kernel_version();
  157. }