obs-app.cpp 3.5 KB

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