obs-cocoa.c 4.7 KB

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