obs-app.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <sstream>
  15. #include <util/bmem.h>
  16. #include <util/platform.h>
  17. #include "obs-app.hpp"
  18. #include "window-main-basic.hpp"
  19. #include "obs-wrappers.hpp"
  20. #include "wx-wrappers.hpp"
  21. #include "platform.hpp"
  22. using namespace std;
  23. IMPLEMENT_APP(OBSApp);
  24. OBSAppBase::~OBSAppBase()
  25. {
  26. blog(LOG_INFO, "Number of memory leaks: %llu", bnum_allocs());
  27. }
  28. static void do_log(enum log_type type, const char *msg, va_list args)
  29. {
  30. char bla[4096];
  31. vsnprintf(bla, 4095, msg, args);
  32. #ifdef _WIN32
  33. OutputDebugStringA(bla);
  34. OutputDebugStringA("\n");
  35. if (type >= LOG_WARNING)
  36. __debugbreak();
  37. #endif
  38. }
  39. bool OBSApp::InitGlobalConfigDefaults()
  40. {
  41. config_set_default_string(globalConfig, "General", "Language", "en");
  42. config_set_default_int(globalConfig, "Window", "PosX", -1);
  43. config_set_default_int(globalConfig, "Window", "PosY", -1);
  44. config_set_default_int(globalConfig, "Window", "SizeX", -1);
  45. config_set_default_int(globalConfig, "Window", "SizeY", -1);
  46. vector<MonitorInfo> monitors;
  47. GetMonitors(monitors);
  48. if (!monitors.size()) {
  49. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  50. "technically shouldn't be possible.");
  51. return false;
  52. }
  53. uint32_t cx = monitors[0].cx;
  54. uint32_t cy = monitors[0].cy;
  55. config_set_default_uint(globalConfig, "Video", "BaseCX", cx);
  56. config_set_default_uint(globalConfig, "Video", "BaseCY", cy);
  57. cx = cx * 10 / 15;
  58. cy = cy * 10 / 15;
  59. config_set_default_uint(globalConfig, "Video", "OutputCX", cx);
  60. config_set_default_uint(globalConfig, "Video", "OutputCY", cy);
  61. config_set_default_string(globalConfig, "Video", "FPSType", "Common");
  62. config_set_default_string(globalConfig, "Video", "FPSCommon", "30");
  63. config_set_default_uint(globalConfig, "Video", "FPSInt", 30);
  64. config_set_default_uint(globalConfig, "Video", "FPSNum", 30);
  65. config_set_default_uint(globalConfig, "Video", "FPSDen", 1);
  66. config_set_default_uint(globalConfig, "Video", "FPSNS", 33333333);
  67. return true;
  68. }
  69. static bool do_mkdir(const char *path)
  70. {
  71. if (os_mkdir(path) == MKDIR_ERROR) {
  72. OBSErrorBox(NULL, "Failed to create directory %s", path);
  73. return false;
  74. }
  75. return true;
  76. }
  77. static bool MakeUserDirs()
  78. {
  79. BPtr<char> homePath(os_get_home_path());
  80. stringstream str;
  81. str << homePath << "/obs-studio";
  82. if (!do_mkdir(str.str().c_str()))
  83. return false;
  84. return true;
  85. }
  86. bool OBSApp::InitGlobalConfig()
  87. {
  88. BPtr<char> homePath(os_get_home_path());
  89. stringstream str;
  90. if (!homePath) {
  91. OBSErrorBox(NULL, "Failed to get home path");
  92. return false;
  93. }
  94. str << homePath << "/obs-studio/global.ini";
  95. string path = move(str.str());
  96. int errorcode = globalConfig.Open(path.c_str(), CONFIG_OPEN_ALWAYS);
  97. if (errorcode != CONFIG_SUCCESS) {
  98. OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
  99. return false;
  100. }
  101. if (!InitGlobalConfigDefaults())
  102. return false;
  103. return true;
  104. }
  105. bool OBSApp::InitLocale()
  106. {
  107. const char *lang = config_get_string(globalConfig, "General",
  108. "Language");
  109. stringstream file;
  110. file << "locale/" << lang << ".txt";
  111. string path;
  112. if (!GetDataFilePath(file.str().c_str(), path)) {
  113. /* use en-US by default if language file is not found */
  114. if (!GetDataFilePath("locale/en-US.txt", path)) {
  115. OBSErrorBox(NULL, "Failed to open locale file");
  116. return false;
  117. }
  118. }
  119. textLookup = text_lookup_create(path.c_str());
  120. return true;
  121. }
  122. bool OBSApp::OnInit()
  123. {
  124. base_set_log_handler(do_log);
  125. if (!wxApp::OnInit())
  126. return false;
  127. if (!MakeUserDirs())
  128. return false;
  129. if (!InitGlobalConfig())
  130. return false;
  131. if (!InitLocale())
  132. return false;
  133. if (!obs_startup())
  134. return false;
  135. wxInitAllImageHandlers();
  136. dummyWindow = new wxFrame(NULL, wxID_ANY, "Dummy Window");
  137. OBSBasic *mainWindow = new OBSBasic();
  138. /* this is a test */
  139. struct obs_video_info ovi;
  140. ovi.graphics_module = "libobs-opengl";
  141. ovi.fps_num = 30000;
  142. ovi.fps_den = 1001;
  143. ovi.window_width = 2;
  144. ovi.window_height = 2;
  145. ovi.base_width = 1920;
  146. ovi.base_height = 1080;
  147. ovi.output_width = 1280;
  148. ovi.output_height = 720;
  149. ovi.output_format = VIDEO_FORMAT_RGBA;
  150. ovi.adapter = 0;
  151. ovi.window = WxToGSWindow(dummyWindow);
  152. if (!obs_reset_video(&ovi))
  153. return false;
  154. mainWindow->Show();
  155. return true;
  156. }
  157. int OBSApp::OnExit()
  158. {
  159. obs_shutdown();
  160. delete dummyWindow;
  161. dummyWindow = NULL;
  162. return wxApp::OnExit();
  163. }
  164. void OBSApp::CleanUp()
  165. {
  166. wxApp::CleanUp();
  167. }