obs-app.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. void 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. }
  47. static bool do_mkdir(const char *path)
  48. {
  49. if (os_mkdir(path) == MKDIR_ERROR) {
  50. OBSErrorBox(NULL, "Failed to create directory %s", path);
  51. return false;
  52. }
  53. return true;
  54. }
  55. static bool MakeUserDirs()
  56. {
  57. BPtr<char*> homePath = os_get_home_path();
  58. stringstream str;
  59. str << homePath << "/obs-studio";
  60. if (!do_mkdir(str.str().c_str()))
  61. return false;
  62. return true;
  63. }
  64. bool OBSApp::InitGlobalConfig()
  65. {
  66. BPtr<char*> homePath = os_get_home_path();
  67. stringstream str;
  68. if (!homePath) {
  69. OBSErrorBox(NULL, "Failed to get home path");
  70. return false;
  71. }
  72. str << homePath << "/obs-studio/global.ini";
  73. string path = move(str.str());
  74. int errorcode = globalConfig.Open(path.c_str(), CONFIG_OPEN_ALWAYS);
  75. if (errorcode != CONFIG_SUCCESS) {
  76. OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
  77. return false;
  78. }
  79. InitGlobalConfigDefaults();
  80. return true;
  81. }
  82. bool OBSApp::InitLocale()
  83. {
  84. const char *lang = config_get_string(globalConfig, "General",
  85. "Language");
  86. stringstream file;
  87. file << "locale/" << lang << ".txt";
  88. string path;
  89. if (!GetDataFilePath(file.str().c_str(), path)) {
  90. /* use en-US by default if language file is not found */
  91. if (!GetDataFilePath("locale/en-US.txt", path)) {
  92. OBSErrorBox(NULL, "Failed to open locale file");
  93. return false;
  94. }
  95. }
  96. textLookup = text_lookup_create(path.c_str());
  97. return true;
  98. }
  99. bool OBSApp::OnInit()
  100. {
  101. base_set_log_handler(do_log);
  102. if (!wxApp::OnInit())
  103. return false;
  104. if (!MakeUserDirs())
  105. return false;
  106. if (!InitGlobalConfig())
  107. return false;
  108. if (!InitLocale())
  109. return false;
  110. if (!obs_startup())
  111. return false;
  112. wxInitAllImageHandlers();
  113. dummyWindow = new wxFrame(NULL, wxID_ANY, "Dummy Window");
  114. OBSBasic *mainWindow = new OBSBasic();
  115. /* this is a test */
  116. struct obs_video_info ovi;
  117. ovi.graphics_module = "libobs-opengl";
  118. ovi.fps_num = 30000;
  119. ovi.fps_den = 1001;
  120. ovi.window_width = 2;
  121. ovi.window_height = 2;
  122. ovi.base_width = 1920;
  123. ovi.base_height = 1080;
  124. ovi.output_width = 1280;
  125. ovi.output_height = 720;
  126. ovi.output_format = VIDEO_FORMAT_RGBA;
  127. ovi.adapter = 0;
  128. ovi.window = WxToGSWindow(dummyWindow);
  129. if (!obs_reset_video(&ovi))
  130. return false;
  131. mainWindow->Show();
  132. return true;
  133. }
  134. int OBSApp::OnExit()
  135. {
  136. obs_shutdown();
  137. delete dummyWindow;
  138. dummyWindow = NULL;
  139. return wxApp::OnExit();
  140. }
  141. void OBSApp::CleanUp()
  142. {
  143. wxApp::CleanUp();
  144. }