obs-app.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. using namespace std;
  22. IMPLEMENT_APP(OBSApp);
  23. OBSAppBase::~OBSAppBase()
  24. {
  25. blog(LOG_INFO, "Number of memory leaks: %zu", bnum_allocs());
  26. }
  27. static void do_log(enum log_type type, const char *msg, va_list args)
  28. {
  29. char bla[4096];
  30. vsnprintf(bla, 4095, msg, args);
  31. #ifdef _WIN32
  32. OutputDebugStringA(bla);
  33. OutputDebugStringA("\n");
  34. if (type >= LOG_WARNING)
  35. __debugbreak();
  36. #endif
  37. }
  38. void OBSApp::InitGlobalConfigDefaults()
  39. {
  40. config_set_default_int(globalConfig, "Window", "PosX", -1);
  41. config_set_default_int(globalConfig, "Window", "PosY", -1);
  42. config_set_default_int(globalConfig, "Window", "SizeX", -1);
  43. config_set_default_int(globalConfig, "Window", "SizeY", -1);
  44. }
  45. static bool do_mkdir(const char *path)
  46. {
  47. if (os_mkdir(path) == MKDIR_ERROR) {
  48. blog(LOG_ERROR, "Failed to create directory %s", path);
  49. return false;
  50. }
  51. return true;
  52. }
  53. static bool MakeUserDirs()
  54. {
  55. BPtr<char*> homePath = os_get_home_path();
  56. stringstream str;
  57. str << homePath << "/obs-studio";
  58. if (!do_mkdir(str.str().c_str()))
  59. return false;
  60. return true;
  61. }
  62. bool OBSApp::InitGlobalConfig()
  63. {
  64. BPtr<char*> homePath = os_get_home_path();
  65. stringstream str;
  66. if (!homePath) {
  67. blog(LOG_ERROR, "Failed to get home path");
  68. return false;
  69. }
  70. str << homePath << "/obs-studio/global.ini";
  71. string path = move(str.str());
  72. int errorcode = globalConfig.Open(path.c_str(), CONFIG_OPEN_ALWAYS);
  73. if (errorcode != CONFIG_SUCCESS) {
  74. blog(LOG_ERROR, "Failed to open global.ini: %d", errorcode);
  75. return false;
  76. }
  77. InitGlobalConfigDefaults();
  78. return true;
  79. }
  80. bool OBSApp::OnInit()
  81. {
  82. base_set_log_handler(do_log);
  83. if (!wxApp::OnInit())
  84. return false;
  85. if (!MakeUserDirs())
  86. return false;
  87. if (!InitGlobalConfig())
  88. return false;
  89. if (!obs_startup())
  90. return false;
  91. wxInitAllImageHandlers();
  92. dummyWindow = new wxFrame(NULL, wxID_ANY, "Dummy Window");
  93. OBSBasic *mainWindow = new OBSBasic();
  94. struct obs_video_info ovi;
  95. ovi.graphics_module = "libobs-opengl";
  96. ovi.fps_num = 30000;
  97. ovi.fps_den = 1001;
  98. ovi.window_width = 2;
  99. ovi.window_height = 2;
  100. ovi.base_width = 1920;
  101. ovi.base_height = 1080;
  102. ovi.output_width = 1280;
  103. ovi.output_height = 720;
  104. ovi.output_format = VIDEO_FORMAT_RGBA;
  105. ovi.adapter = 0;
  106. ovi.window = WxToGSWindow(dummyWindow);
  107. if (!obs_reset_video(&ovi))
  108. return false;
  109. mainWindow->Show();
  110. return true;
  111. }
  112. int OBSApp::OnExit()
  113. {
  114. obs_shutdown();
  115. delete dummyWindow;
  116. dummyWindow = NULL;
  117. return wxApp::OnExit();
  118. }
  119. void OBSApp::CleanUp()
  120. {
  121. wxApp::CleanUp();
  122. }