2013-11-07 15:45:03 -08:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-11-07 15:45:03 -08:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-11-23 22:38:52 -08:00
|
|
|
#include <sstream>
|
|
|
|
|
2013-11-22 19:43:48 -08:00
|
|
|
#include <util/bmem.h>
|
2013-12-17 19:23:57 -08:00
|
|
|
#include <util/dstr.h>
|
2013-11-23 22:38:52 -08:00
|
|
|
#include <util/platform.h>
|
|
|
|
|
2013-12-22 16:42:02 -08:00
|
|
|
#include <obs.hpp>
|
|
|
|
|
2013-11-22 15:25:38 -08:00
|
|
|
#include "obs-app.hpp"
|
2013-12-28 20:51:18 -08:00
|
|
|
#include "window-basic-main.hpp"
|
2013-11-22 19:57:24 -08:00
|
|
|
#include "wx-wrappers.hpp"
|
2013-12-07 09:22:56 -08:00
|
|
|
#include "platform.hpp"
|
2013-12-06 08:16:33 -08:00
|
|
|
|
2013-11-28 11:48:00 -08:00
|
|
|
using namespace std;
|
2013-11-07 15:45:03 -08:00
|
|
|
|
2013-11-23 22:38:52 -08:00
|
|
|
IMPLEMENT_APP(OBSApp);
|
|
|
|
|
|
|
|
OBSAppBase::~OBSAppBase()
|
|
|
|
{
|
2013-12-07 08:39:43 -08:00
|
|
|
blog(LOG_INFO, "Number of memory leaks: %llu", bnum_allocs());
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_log(enum log_type type, const char *msg, va_list args)
|
|
|
|
{
|
2013-12-23 00:06:53 -08:00
|
|
|
#ifdef _WIN32
|
2013-11-23 22:38:52 -08:00
|
|
|
char bla[4096];
|
|
|
|
vsnprintf(bla, 4095, msg, args);
|
|
|
|
|
|
|
|
OutputDebugStringA(bla);
|
|
|
|
OutputDebugStringA("\n");
|
|
|
|
|
2014-01-12 21:04:41 -08:00
|
|
|
if (type >= LOG_WARNING && IsDebuggerPresent())
|
2013-11-23 22:38:52 -08:00
|
|
|
__debugbreak();
|
2013-12-23 00:06:53 -08:00
|
|
|
#else
|
|
|
|
vprintf(msg, args);
|
2013-12-29 18:26:09 -08:00
|
|
|
printf("\n");
|
2013-11-26 22:07:27 -08:00
|
|
|
#endif
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
|
|
|
|
2013-12-15 23:07:08 -08:00
|
|
|
bool OBSApp::InitGlobalConfigDefaults()
|
2013-11-23 22:38:52 -08:00
|
|
|
{
|
2013-12-12 20:47:42 -08:00
|
|
|
config_set_default_string(globalConfig, "General", "Language", "en");
|
2013-11-23 22:38:52 -08:00
|
|
|
config_set_default_int(globalConfig, "Window", "PosX", -1);
|
|
|
|
config_set_default_int(globalConfig, "Window", "PosY", -1);
|
|
|
|
config_set_default_int(globalConfig, "Window", "SizeX", -1);
|
|
|
|
config_set_default_int(globalConfig, "Window", "SizeY", -1);
|
2013-12-15 23:07:08 -08:00
|
|
|
|
|
|
|
vector<MonitorInfo> monitors;
|
|
|
|
GetMonitors(monitors);
|
|
|
|
|
|
|
|
if (!monitors.size()) {
|
|
|
|
OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
|
|
|
|
"technically shouldn't be possible.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t cx = monitors[0].cx;
|
|
|
|
uint32_t cy = monitors[0].cy;
|
|
|
|
|
2013-12-17 01:08:41 -08:00
|
|
|
#if _WIN32
|
|
|
|
config_set_default_string(globalConfig, "Video", "Renderer",
|
|
|
|
"Direct3D 11");
|
|
|
|
#else
|
|
|
|
config_set_default_string(globalConfig, "Video", "Renderer",
|
|
|
|
"OpenGL");
|
|
|
|
#endif
|
|
|
|
|
2013-12-15 23:07:08 -08:00
|
|
|
config_set_default_uint(globalConfig, "Video", "BaseCX", cx);
|
|
|
|
config_set_default_uint(globalConfig, "Video", "BaseCY", cy);
|
|
|
|
|
|
|
|
cx = cx * 10 / 15;
|
|
|
|
cy = cy * 10 / 15;
|
|
|
|
config_set_default_uint(globalConfig, "Video", "OutputCX", cx);
|
|
|
|
config_set_default_uint(globalConfig, "Video", "OutputCY", cy);
|
|
|
|
|
|
|
|
config_set_default_string(globalConfig, "Video", "FPSType", "Common");
|
|
|
|
config_set_default_string(globalConfig, "Video", "FPSCommon", "30");
|
|
|
|
config_set_default_uint(globalConfig, "Video", "FPSInt", 30);
|
|
|
|
config_set_default_uint(globalConfig, "Video", "FPSNum", 30);
|
|
|
|
config_set_default_uint(globalConfig, "Video", "FPSDen", 1);
|
|
|
|
config_set_default_uint(globalConfig, "Video", "FPSNS", 33333333);
|
|
|
|
|
|
|
|
return true;
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool do_mkdir(const char *path)
|
|
|
|
{
|
|
|
|
if (os_mkdir(path) == MKDIR_ERROR) {
|
2013-12-07 09:22:56 -08:00
|
|
|
OBSErrorBox(NULL, "Failed to create directory %s", path);
|
2013-11-23 22:38:52 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool MakeUserDirs()
|
|
|
|
{
|
2013-12-23 17:59:54 -08:00
|
|
|
BPtr<char> configPath(os_get_config_path("obs-studio"));
|
|
|
|
return do_mkdir(configPath);
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OBSApp::InitGlobalConfig()
|
|
|
|
{
|
2013-12-23 17:59:54 -08:00
|
|
|
BPtr<char> path(os_get_config_path("obs-studio/global.ini"));
|
2013-11-23 22:38:52 -08:00
|
|
|
|
2013-12-23 17:59:54 -08:00
|
|
|
int errorcode = globalConfig.Open(path, CONFIG_OPEN_ALWAYS);
|
2013-11-23 22:38:52 -08:00
|
|
|
if (errorcode != CONFIG_SUCCESS) {
|
2013-12-07 09:22:56 -08:00
|
|
|
OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
|
2013-11-23 22:38:52 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-23 17:59:54 -08:00
|
|
|
return InitGlobalConfigDefaults();
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
2013-11-07 15:45:03 -08:00
|
|
|
|
2013-12-17 12:56:28 -08:00
|
|
|
#define DEFAULT_LANG "en"
|
|
|
|
|
2013-12-07 09:22:56 -08:00
|
|
|
bool OBSApp::InitLocale()
|
|
|
|
{
|
|
|
|
const char *lang = config_get_string(globalConfig, "General",
|
|
|
|
"Language");
|
|
|
|
|
2013-12-30 05:56:39 -08:00
|
|
|
locale = lang;
|
|
|
|
|
2013-12-07 09:22:56 -08:00
|
|
|
stringstream file;
|
|
|
|
file << "locale/" << lang << ".txt";
|
|
|
|
|
2013-12-17 12:56:28 -08:00
|
|
|
string englishPath;
|
|
|
|
if (!GetDataFilePath("locale/" DEFAULT_LANG ".txt", englishPath)) {
|
|
|
|
OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".txt");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
textLookup = text_lookup_create(englishPath.c_str());
|
|
|
|
if (!textLookup) {
|
|
|
|
OBSErrorBox(NULL, "Failed to create locale from file '%s'",
|
|
|
|
englishPath.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-17 19:23:57 -08:00
|
|
|
if (astrcmpi(lang, DEFAULT_LANG) == 0)
|
2013-12-17 12:56:28 -08:00
|
|
|
return true;
|
|
|
|
|
2013-12-07 09:22:56 -08:00
|
|
|
string path;
|
2013-12-17 12:56:28 -08:00
|
|
|
if (GetDataFilePath(file.str().c_str(), path)) {
|
|
|
|
if (!text_lookup_add(textLookup, path.c_str()))
|
2013-12-17 17:19:24 -08:00
|
|
|
blog(LOG_WARNING, "Failed to add locale file '%s'",
|
2013-12-17 12:56:28 -08:00
|
|
|
path.c_str());
|
|
|
|
} else {
|
2013-12-17 17:19:24 -08:00
|
|
|
blog(LOG_WARNING, "Could not find locale file '%s'",
|
2013-12-17 12:56:28 -08:00
|
|
|
file.str().c_str());
|
2013-12-07 09:22:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
bool OBSApp::InitOBSBasic()
|
|
|
|
{
|
|
|
|
OBSBasic *obsBasic = new OBSBasic();
|
|
|
|
obsBasic->Show();
|
|
|
|
|
|
|
|
mainWindow = obsBasic;
|
|
|
|
return obsBasic->Init();
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:45:03 -08:00
|
|
|
bool OBSApp::OnInit()
|
|
|
|
{
|
2013-11-23 22:38:52 -08:00
|
|
|
base_set_log_handler(do_log);
|
|
|
|
|
2014-01-08 16:17:30 -08:00
|
|
|
if (!InitApplicationBundle())
|
|
|
|
return false;
|
|
|
|
|
2013-11-07 15:45:03 -08:00
|
|
|
if (!wxApp::OnInit())
|
|
|
|
return false;
|
2013-12-22 22:40:07 -08:00
|
|
|
wxInitAllImageHandlers();
|
|
|
|
|
2013-11-23 22:38:52 -08:00
|
|
|
if (!MakeUserDirs())
|
|
|
|
return false;
|
|
|
|
if (!InitGlobalConfig())
|
|
|
|
return false;
|
2013-12-07 09:22:56 -08:00
|
|
|
if (!InitLocale())
|
|
|
|
return false;
|
2013-12-22 22:40:07 -08:00
|
|
|
if (!InitOBSBasic())
|
2013-11-22 19:43:48 -08:00
|
|
|
return false;
|
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-19 00:00:00 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
int OBSApp::OnExit()
|
|
|
|
{
|
|
|
|
return wxApp::OnExit();
|
|
|
|
}
|
2013-11-22 19:43:48 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
void OBSApp::GetFPSCommon(uint32_t &num, uint32_t &den) const
|
|
|
|
{
|
|
|
|
const char *val = config_get_string(globalConfig, "Video", "FPSCommon");
|
|
|
|
|
|
|
|
if (strcmp(val, "10") == 0) {
|
|
|
|
num = 30;
|
|
|
|
den = 1;
|
|
|
|
} else if (strcmp(val, "20") == 0) {
|
|
|
|
num = 20;
|
|
|
|
den = 1;
|
2013-12-22 22:45:47 -08:00
|
|
|
} else if (strcmp(val, "25") == 0) {
|
|
|
|
num = 25;
|
|
|
|
den = 1;
|
2013-12-22 22:40:07 -08:00
|
|
|
} else if (strcmp(val, "29.97") == 0) {
|
|
|
|
num = 30000;
|
|
|
|
den = 1001;
|
|
|
|
} else if (strcmp(val, "48") == 0) {
|
|
|
|
num = 48;
|
|
|
|
den = 1;
|
|
|
|
} else if (strcmp(val, "59.94") == 0) {
|
|
|
|
num = 60000;
|
|
|
|
den = 1001;
|
|
|
|
} else if (strcmp(val, "60") == 0) {
|
|
|
|
num = 60;
|
|
|
|
den = 1;
|
|
|
|
} else {
|
|
|
|
num = 30;
|
|
|
|
den = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 14:10:09 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
void OBSApp::GetFPSInteger(uint32_t &num, uint32_t &den) const
|
|
|
|
{
|
|
|
|
num = (uint32_t)config_get_uint(globalConfig, "Video", "FPSInt");
|
|
|
|
den = 1;
|
|
|
|
}
|
2013-12-19 14:10:09 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
void OBSApp::GetFPSFraction(uint32_t &num, uint32_t &den) const
|
|
|
|
{
|
|
|
|
num = (uint32_t)config_get_uint(globalConfig, "Video", "FPSNum");
|
|
|
|
den = (uint32_t)config_get_uint(globalConfig, "Video", "FPSDen");
|
2013-11-07 15:45:03 -08:00
|
|
|
}
|
2013-11-22 19:43:48 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
void OBSApp::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
|
2013-11-22 19:43:48 -08:00
|
|
|
{
|
2013-12-22 22:40:07 -08:00
|
|
|
num = 1000000000;
|
|
|
|
den = (uint32_t)config_get_uint(globalConfig, "Video", "FPSNS");
|
|
|
|
}
|
2013-11-22 19:43:48 -08:00
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
void OBSApp::GetConfigFPS(uint32_t &num, uint32_t &den) const
|
|
|
|
{
|
|
|
|
const char *type = config_get_string(globalConfig, "Video", "FPSType");
|
|
|
|
|
|
|
|
if (astrcmpi(type, "Integer") == 0)
|
|
|
|
GetFPSInteger(num, den);
|
|
|
|
else if (astrcmpi(type, "Fraction") == 0)
|
|
|
|
GetFPSFraction(num, den);
|
|
|
|
else if (astrcmpi(type, "Nanoseconds") == 0)
|
|
|
|
GetFPSNanoseconds(num, den);
|
|
|
|
else
|
|
|
|
GetFPSCommon(num, den);
|
2013-11-23 22:38:52 -08:00
|
|
|
}
|
|
|
|
|
2013-12-22 22:40:07 -08:00
|
|
|
const char *OBSApp::GetRenderModule() const
|
2013-11-23 22:38:52 -08:00
|
|
|
{
|
2013-12-22 22:40:07 -08:00
|
|
|
const char *renderer = config_get_string(globalConfig, "Video",
|
|
|
|
"Renderer");
|
|
|
|
|
|
|
|
if (astrcmpi(renderer, "Direct3D 11") == 0)
|
|
|
|
return "libobs-d3d11";
|
|
|
|
else
|
|
|
|
return "libobs-opengl";
|
2013-11-22 19:43:48 -08:00
|
|
|
}
|