obs-windows.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[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 <windows.h>
  19. const char *get_module_extension(void)
  20. {
  21. return ".dll";
  22. }
  23. #ifdef _WIN64
  24. #define BIT_STRING "64bit"
  25. #else
  26. #define BIT_STRING "32bit"
  27. #endif
  28. static const char *module_bin[] = {
  29. "obs-plugins/" BIT_STRING,
  30. "../../obs-plugins/" BIT_STRING,
  31. };
  32. static const char *module_data[] = {
  33. "data/%module%",
  34. "../../data/obs-plugins/%module%"
  35. };
  36. static const int module_patterns_size =
  37. sizeof(module_bin)/sizeof(module_bin[0]);
  38. void add_default_module_paths(void)
  39. {
  40. for (int i = 0; i < module_patterns_size; i++)
  41. obs_add_module_path(module_bin[i], module_data[i]);
  42. }
  43. /* on windows, points to [base directory]/data/libobs */
  44. char *find_libobs_data_file(const char *file)
  45. {
  46. struct dstr path;
  47. dstr_init(&path);
  48. if (check_path(file, "data/libobs/", &path))
  49. return path.array;
  50. if (check_path(file, "../../data/libobs/", &path))
  51. return path.array;
  52. dstr_free(&path);
  53. return NULL;
  54. }
  55. static void log_processor_info(void)
  56. {
  57. HKEY key;
  58. wchar_t data[1024];
  59. char *str = NULL;
  60. DWORD size, speed;
  61. LSTATUS status;
  62. memset(data, 0, 1024);
  63. status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
  64. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
  65. &key);
  66. if (status != ERROR_SUCCESS)
  67. return;
  68. size = 1024;
  69. status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
  70. (LPBYTE)data, &size);
  71. if (status == ERROR_SUCCESS) {
  72. os_wcs_to_utf8_ptr(data, 0, &str);
  73. blog(LOG_INFO, "CPU Name: %s", str);
  74. bfree(str);
  75. }
  76. size = sizeof(speed);
  77. status = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE)&speed,
  78. &size);
  79. if (status == ERROR_SUCCESS)
  80. blog(LOG_INFO, "CPU Speed: %ldMHz", speed);
  81. RegCloseKey(key);
  82. }
  83. static DWORD num_logical_cores(ULONG_PTR mask)
  84. {
  85. DWORD left_shift = sizeof(ULONG_PTR) * 8 - 1;
  86. DWORD bit_set_count = 0;
  87. ULONG_PTR bit_test = (ULONG_PTR)1 << left_shift;
  88. for (DWORD i = 0; i <= left_shift; ++i) {
  89. bit_set_count += ((mask & bit_test) ? 1 : 0);
  90. bit_test /= 2;
  91. }
  92. return bit_set_count;
  93. }
  94. static void log_processor_cores(void)
  95. {
  96. PSYSTEM_LOGICAL_PROCESSOR_INFORMATION info = NULL, temp = NULL;
  97. DWORD len = 0;
  98. GetLogicalProcessorInformation(info, &len);
  99. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
  100. return;
  101. info = malloc(len);
  102. if (GetLogicalProcessorInformation(info, &len)) {
  103. DWORD num = len / sizeof(*info);
  104. int physical_cores = 0;
  105. int logical_cores = 0;
  106. temp = info;
  107. for (DWORD i = 0; i < num; i++) {
  108. if (temp->Relationship == RelationProcessorCore) {
  109. ULONG_PTR mask = temp->ProcessorMask;
  110. physical_cores++;
  111. logical_cores += num_logical_cores(mask);
  112. }
  113. temp++;
  114. }
  115. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  116. physical_cores, logical_cores);
  117. }
  118. free(info);
  119. }
  120. static void log_available_memory(void)
  121. {
  122. MEMORYSTATUS ms;
  123. GlobalMemoryStatus(&ms);
  124. #ifdef _WIN64
  125. const char *note = "";
  126. #else
  127. const char *note = " (NOTE: 4 gigs max is normal for 32bit programs)";
  128. #endif
  129. blog(LOG_INFO, "Physical Memory: %luMB Total, %luMB Free%s",
  130. (DWORD)(ms.dwTotalPhys / 1048576),
  131. (DWORD)(ms.dwAvailPhys / 1048576),
  132. note);
  133. }
  134. static void log_windows_version(void)
  135. {
  136. OSVERSIONINFOW osvi;
  137. char *build = NULL;
  138. osvi.dwOSVersionInfoSize = sizeof(osvi);
  139. GetVersionExW(&osvi);
  140. os_wcs_to_utf8_ptr(osvi.szCSDVersion, 0, &build);
  141. blog(LOG_INFO, "Windows Version: %ld.%ld Build %ld %s",
  142. osvi.dwMajorVersion,
  143. osvi.dwMinorVersion,
  144. osvi.dwBuildNumber,
  145. build);
  146. bfree(build);
  147. }
  148. void log_system_info(void)
  149. {
  150. log_processor_info();
  151. log_processor_cores();
  152. log_available_memory();
  153. log_windows_version();
  154. }
  155. struct obs_hotkeys_platform {
  156. bool blank;
  157. };
  158. bool obs_hotkeys_platform_init(struct obs_core_hotkeys *hotkeys)
  159. {
  160. UNUSED_PARAMETER(hotkeys);
  161. return true;
  162. }
  163. void obs_hotkeys_platform_free(struct obs_core_hotkeys *hotkeys)
  164. {
  165. UNUSED_PARAMETER(hotkeys);
  166. }
  167. bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context,
  168. obs_key_t key)
  169. {
  170. UNUSED_PARAMETER(context);
  171. UNUSED_PARAMETER(key);
  172. return false;
  173. }
  174. void obs_key_to_str(obs_key_t key, struct dstr *str)
  175. {
  176. UNUSED_PARAMETER(key);
  177. UNUSED_PARAMETER(str);
  178. }
  179. void obs_key_combination_to_str(obs_key_combination_t key, struct dstr *str)
  180. {
  181. UNUSED_PARAMETER(key);
  182. UNUSED_PARAMETER(str);
  183. }
  184. obs_key_t obs_key_from_virtual_key(int code)
  185. {
  186. UNUSED_PARAMETER(code);
  187. return OBS_KEY_NONE;
  188. }
  189. int obs_key_to_virtual_key(obs_key_t key)
  190. {
  191. UNUSED_PARAMETER(key);
  192. return 0;
  193. }