obs-cocoa.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. for (int i = 0; i < module_patterns_size; i++)
  39. obs_add_module_path(module_bin[i], module_data[i]);
  40. }
  41. char *find_libobs_data_file(const char *file)
  42. {
  43. struct dstr path;
  44. dstr_init_copy(&path, OBS_INSTALL_DATA_PATH "/libobs/");
  45. dstr_cat(&path, file);
  46. return path.array;
  47. }
  48. static void log_processor_name(void)
  49. {
  50. char *name = NULL;
  51. size_t size;
  52. int ret;
  53. ret = sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0);
  54. if (ret != 0)
  55. return;
  56. name = malloc(size);
  57. ret = sysctlbyname("machdep.cpu.brand_string", name, &size, NULL, 0);
  58. if (ret == 0)
  59. blog(LOG_INFO, "CPU Name: %s", name);
  60. free(name);
  61. }
  62. static void log_processor_speed(void)
  63. {
  64. size_t size;
  65. long long freq;
  66. int ret;
  67. size = sizeof(freq);
  68. ret = sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0);
  69. if (ret == 0)
  70. blog(LOG_INFO, "CPU Speed: %lldMHz", freq / 1000000);
  71. }
  72. static void log_processor_cores(void)
  73. {
  74. size_t size;
  75. int physical_cores = 0, logical_cores = 0;
  76. int ret;
  77. size = sizeof(physical_cores);
  78. ret = sysctlbyname("machdep.cpu.core_count", &physical_cores,
  79. &size, NULL, 0);
  80. if (ret != 0)
  81. return;
  82. ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores,
  83. &size, NULL, 0);
  84. if (ret != 0)
  85. return;
  86. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  87. physical_cores, logical_cores);
  88. }
  89. static void log_available_memory(void)
  90. {
  91. size_t size;
  92. long long memory_available;
  93. int ret;
  94. size = sizeof(memory_available);
  95. ret = sysctlbyname("hw.memsize", &memory_available, &size, NULL, 0);
  96. if (ret == 0)
  97. blog(LOG_INFO, "Physical Memory: %lldMB Total",
  98. memory_available / 1024 / 1024);
  99. }
  100. static void log_os_name(id pi, SEL UTF8String)
  101. {
  102. unsigned long os_id = (unsigned long)objc_msgSend(pi,
  103. sel_registerName("operatingSystem"));
  104. id os = objc_msgSend(pi,
  105. sel_registerName("operatingSystemName"));
  106. const char *name = (const char*)objc_msgSend(os, UTF8String);
  107. if (os_id == 5 /*NSMACHOperatingSystem*/) {
  108. blog(LOG_INFO, "OS Name: Mac OS X (%s)", name);
  109. return;
  110. }
  111. blog(LOG_INFO, "OS Name: %s", name ? name : "Unknown");
  112. }
  113. static void log_os_version(id pi, SEL UTF8String)
  114. {
  115. id vs = objc_msgSend(pi,
  116. sel_registerName("operatingSystemVersionString"));
  117. const char *version = (const char*)objc_msgSend(vs, UTF8String);
  118. blog(LOG_INFO, "OS Version: %s", version ? version : "Unknown");
  119. }
  120. static void log_os(void)
  121. {
  122. Class NSProcessInfo = objc_getClass("NSProcessInfo");
  123. id pi = objc_msgSend((id)NSProcessInfo,
  124. sel_registerName("processInfo"));
  125. SEL UTF8String = sel_registerName("UTF8String");
  126. log_os_name(pi, UTF8String);
  127. log_os_version(pi, UTF8String);
  128. }
  129. static void log_kernel_version(void)
  130. {
  131. char kernel_version[1024];
  132. size_t size = sizeof(kernel_version);
  133. int ret;
  134. ret = sysctlbyname("kern.osrelease", kernel_version, &size,
  135. NULL, 0);
  136. if (ret == 0)
  137. blog(LOG_INFO, "Kernel Version: %s", kernel_version);
  138. }
  139. void log_system_info(void)
  140. {
  141. log_processor_name();
  142. log_processor_speed();
  143. log_processor_cores();
  144. log_available_memory();
  145. log_os();
  146. log_kernel_version();
  147. }