obs-app.cpp 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/******************************************************************************
    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
    the Free Software Foundation, either version 3 of the License, or
    (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/>.
******************************************************************************/

18 19 20
#include <sstream>
using namespace std;

J
jp9000 已提交
21
#include <util/bmem.h>
22 23
#include <util/platform.h>

J
jp9000 已提交
24
#include "obs-app.hpp"
25
#include "window-obs-basic.hpp"
J
jp9000 已提交
26
#include "obs-wrappers.hpp"
J
jp9000 已提交
27
#include "wx-wrappers.hpp"
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
IMPLEMENT_APP(OBSApp);

OBSAppBase::~OBSAppBase()
{
	blog(LOG_INFO, "Number of memory leaks: %u", bnum_allocs());
}

static void do_log(enum log_type type, const char *msg, va_list args)
{
	char bla[4096];
	vsnprintf(bla, 4095, msg, args);

	OutputDebugStringA(bla);
	OutputDebugStringA("\n");

	if (type >= LOG_WARNING)
		__debugbreak();
}

void OBSApp::InitGlobalConfigDefaults()
{
	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);
}

static bool do_mkdir(const char *path)
{
	if (os_mkdir(path) == MKDIR_ERROR) {
		blog(LOG_ERROR, "Failed to create directory %s", path);
		return false;
	}

	return true;
}

static bool MakeUserDirs()
{
	BPtr<char*> homePath = os_get_home_path();
	stringstream str;

	str << homePath << "/obs-studio";
	if (!do_mkdir(str.str().c_str()))
		return false;

	return true;
}

bool OBSApp::InitGlobalConfig()
{
	BPtr<char*> homePath = os_get_home_path();
	stringstream str;

	if (!homePath) {
		blog(LOG_ERROR, "Failed to get home path");
		return false;
	}

	str << homePath << "/obs-studio/global.ini";
	string path = move(str.str());

	int errorcode = globalConfig.Open(path.c_str(), CONFIG_OPEN_ALWAYS);
	if (errorcode != CONFIG_SUCCESS) {
		blog(LOG_ERROR, "Failed to open global.ini: %d", errorcode);
		return false;
	}

	InitGlobalConfigDefaults();
	return true;
}
100 101 102

bool OBSApp::OnInit()
{
103 104
	base_set_log_handler(do_log);

105 106
	if (!wxApp::OnInit())
		return false;
107 108 109 110
	if (!MakeUserDirs())
		return false;
	if (!InitGlobalConfig())
		return false;
J
jp9000 已提交
111 112 113
	if (!obs_startup())
		return false;

114 115
	wxInitAllImageHandlers();

116
	dummyWindow = new wxFrame(NULL, wxID_ANY, "Dummy Window");
J
jp9000 已提交
117

118
	OBSBasic *mainWindow = new OBSBasic();
J
jp9000 已提交
119 120 121

	struct obs_video_info ovi;
	ovi.adapter         = 0;
122 123
	ovi.base_width      = 2;
	ovi.base_height     = 2;
J
jp9000 已提交
124 125 126 127
	ovi.fps_num         = 30000;
	ovi.fps_den         = 1001;
	ovi.graphics_module = "libobs-opengl";
	ovi.output_format   = VIDEO_FORMAT_RGBA;
128 129 130
	ovi.output_width    = 2;
	ovi.output_height   = 2;
	ovi.window          = WxToGSWindow(dummyWindow);
J
jp9000 已提交
131 132 133 134

	if (!obs_reset_video(&ovi))
		return false;

135 136 137
	mainWindow->Show();
	return true;
}
J
jp9000 已提交
138 139 140 141 142

int OBSApp::OnExit()
{
	obs_shutdown();

143 144 145 146 147 148 149 150 151
	delete dummyWindow;
	dummyWindow = NULL;

	return wxApp::OnExit();
}

void OBSApp::CleanUp()
{
	OBSAppBase::CleanUp();
J
jp9000 已提交
152
}