apply configure video settings on startup

This commit is contained in:
jp9000 2013-12-22 23:40:07 -07:00
parent 991b5739d6
commit 399b0c8d10
9 changed files with 199 additions and 61 deletions

View file

@ -23,13 +23,12 @@ MainWindow.Volume="Volume:"
Settings="Settings"
Settings.StreamRestart="All streaming/recording must be stopped in order for these changes to take effect"
Settings.ProgramRestart="The program must be restarted for these settings to take effect."
Settings.ConfirmTitle="Confirm Changes"
Settings.Confirm="You have unsaved changes. Save changes?"
Settings.General="General"
Settings.General.Language="Language:"
Settings.General.LanguageChanged="The program must be restarted in order to change the language"
Settings.Outputs="Outputs"

View file

@ -343,7 +343,7 @@ bool obs_get_video_info(struct obs_video_info *ovi)
struct obs_video *video = &obs->video;
const struct video_info *info;
if (!video->graphics)
if (!obs || !video->graphics)
return false;
info = video_output_getinfo(video->video);
@ -365,7 +365,7 @@ bool obs_get_audio_info(struct audio_info *ai)
struct obs_audio *audio = &obs->audio;
const struct audio_info *info;
if (!audio->audio)
if (!obs || !audio->audio)
return false;
info = audio_output_getinfo(audio->audio);

View file

@ -89,7 +89,7 @@ public:
config = NULL;
}
inline operator config_t() {return config;}
inline operator config_t() const {return config;}
};
class TextLookup {
@ -114,9 +114,9 @@ public:
return *this;
}
inline operator lookup_t() {return lookup;}
inline operator lookup_t() const {return lookup;}
inline const char *GetString(const char *lookupVal)
inline const char *GetString(const char *lookupVal) const
{
const char *out;
if (!text_lookup_getstr(lookup, lookupVal, &out))

View file

@ -183,61 +183,107 @@ bool OBSApp::InitLocale()
return true;
}
bool OBSApp::InitOBSBasic()
{
OBSBasic *obsBasic = new OBSBasic();
obsBasic->Show();
mainWindow = obsBasic;
return obsBasic->Init();
}
bool OBSApp::OnInit()
{
base_set_log_handler(do_log);
if (!wxApp::OnInit())
return false;
wxInitAllImageHandlers();
if (!MakeUserDirs())
return false;
if (!InitGlobalConfig())
return false;
if (!InitLocale())
return false;
if (!obs_startup())
if (!InitOBSBasic())
return false;
wxInitAllImageHandlers();
OBSBasic *mainWindow = new OBSBasic();
wxSize size = mainWindow->GetPreviewPanel()->GetClientSize();
mainWindow->Show();
/* this is a test */
struct obs_video_info ovi;
ovi.graphics_module = "libobs-opengl";
ovi.fps_num = 30000;
ovi.fps_den = 1001;
ovi.window_width = size.x;
ovi.window_height = size.y;
ovi.base_width = 1920;
ovi.base_height = 1080;
ovi.output_width = 1280;
ovi.output_height = 720;
ovi.output_format = VIDEO_FORMAT_RGBA;
ovi.adapter = 0;
ovi.window = WxToGSWindow(mainWindow->GetPreviewPanel());
if (!obs_reset_video(&ovi))
return false;
//required to make opengl display stuff on osx(?)
mainWindow->SendSizeEvent();
return true;
}
int OBSApp::OnExit()
{
obs_shutdown();
return wxApp::OnExit();
}
void OBSApp::CleanUp()
void OBSApp::GetFPSCommon(uint32_t &num, uint32_t &den) const
{
wxApp::CleanUp();
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;
} 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;
}
}
void OBSApp::GetFPSInteger(uint32_t &num, uint32_t &den) const
{
num = (uint32_t)config_get_uint(globalConfig, "Video", "FPSInt");
den = 1;
}
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");
}
void OBSApp::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
{
num = 1000000000;
den = (uint32_t)config_get_uint(globalConfig, "Video", "FPSNS");
}
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);
}
const char *OBSApp::GetRenderModule() const
{
const char *renderer = config_get_string(globalConfig, "Video",
"Renderer");
if (astrcmpi(renderer, "Direct3D 11") == 0)
return "libobs-d3d11";
else
return "libobs-opengl";
}

View file

@ -18,6 +18,7 @@
#pragma once
#include <wx/app.h>
#include <wx/window.h>
#include <util/util.hpp>
@ -29,23 +30,34 @@ public:
class OBSApp : public OBSAppBase {
ConfigFile globalConfig;
TextLookup textLookup;
wxWindow *mainWindow;
bool InitGlobalConfig();
bool InitGlobalConfigDefaults();
bool InitConfigDefaults();
bool InitLocale();
bool InitOBSBasic();
void GetFPSCommon(uint32_t &num, uint32_t &den) const;
void GetFPSInteger(uint32_t &num, uint32_t &den) const;
void GetFPSFraction(uint32_t &num, uint32_t &den) const;
void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
public:
virtual bool OnInit();
virtual int OnExit();
virtual void CleanUp();
inline config_t GlobalConfig() {return globalConfig;}
inline wxWindow *GetMainWindow() const {return mainWindow;}
inline const char *GetString(const char *lookupVal)
inline config_t GlobalConfig() const {return globalConfig;}
inline const char *GetString(const char *lookupVal) const
{
return textLookup.GetString(lookupVal);
}
void GetConfigFPS(uint32_t &num, uint32_t &den) const;
const char *GetRenderModule() const;
};
wxDECLARE_APP(OBSApp);

View file

@ -103,7 +103,7 @@ void BasicGenData::LanguageChanged(wxCommandEvent &event)
{
SetChanged();
window->generalChangedText->SetLabel(
WXStr("Settings.General.LanguageChanged"));
WXStr("Settings.General.ProgramRestart"));
window->generalChangedText->Show();
}

View file

@ -40,8 +40,10 @@ class BasicVideoData : public BasicSettingsData {
void LoadFPSNanoseconds();
void ResetScaleList(uint32_t cx, uint32_t cy);
void BaseResListChanged(wxCommandEvent &event);
void OutputResListChanged(wxCommandEvent &event);
void RendererChanged(wxCommandEvent &event);
void BaseResChanged(wxCommandEvent &event);
void OutputResChanged(wxCommandEvent &event);
void FPSChanged(wxCommandEvent &event);
void SaveOther();
void SaveFPSData();
@ -280,6 +282,11 @@ void BasicVideoData::ResetScaleList(uint32_t cx, uint32_t cy)
}
}
#define ADD_CONNECT(control, event, func) \
connections.Add(window->control, event, \
wxCommandEventHandler(BasicVideoData::func), \
NULL, this)
BasicVideoData::BasicVideoData(OBSBasicSettings *window)
: BasicSettingsData(window)
{
@ -288,19 +295,37 @@ BasicVideoData::BasicVideoData(OBSBasicSettings *window)
LoadOther();
/* load connectors after loading data to prevent them from triggering */
connections.Add(window->baseResList, wxEVT_TEXT,
wxCommandEventHandler(
BasicVideoData::BaseResListChanged),
NULL, this);
connections.Add(window->outputResList, wxEVT_TEXT,
wxCommandEventHandler(
BasicVideoData::OutputResListChanged),
NULL, this);
ADD_CONNECT(baseResList, wxEVT_TEXT, BaseResChanged);
ADD_CONNECT(outputResList, wxEVT_TEXT, OutputResChanged);
ADD_CONNECT(rendererList, wxEVT_COMBOBOX, RendererChanged);
ADD_CONNECT(fpsCommonList, wxEVT_COMBOBOX, FPSChanged);
ADD_CONNECT(fpsIntegerScroller, wxEVT_SPINCTRL, FPSChanged);
ADD_CONNECT(fpsNumeratorScroller, wxEVT_SPINCTRL, FPSChanged);
ADD_CONNECT(fpsDenominatorScroller, wxEVT_SPINCTRL, FPSChanged);
ADD_CONNECT(fpsNanosecondsScroller, wxEVT_SPINCTRL, FPSChanged);
ADD_CONNECT(fpsIntegerScroller, wxEVT_TEXT, FPSChanged);
ADD_CONNECT(fpsNumeratorScroller, wxEVT_TEXT, FPSChanged);
ADD_CONNECT(fpsDenominatorScroller, wxEVT_TEXT, FPSChanged);
ADD_CONNECT(fpsNanosecondsScroller, wxEVT_TEXT, FPSChanged);
ADD_CONNECT(fpsTypeList, wxEVT_CHOICEBOOK_PAGE_CHANGED,
FPSChanged);
window->videoChangedText->Hide();
}
void BasicVideoData::BaseResListChanged(wxCommandEvent &event)
void BasicVideoData::RendererChanged(wxCommandEvent &event)
{
SetChanged();
window->videoChangedText->SetLabel(WXStr("Settings.ProgramRestart"));
window->videoChangedText->Show();
}
void BasicVideoData::FPSChanged(wxCommandEvent &event)
{
SetChanged();
}
void BasicVideoData::BaseResChanged(wxCommandEvent &event)
{
uint32_t cx, cy;
if (!ConvertTextRes(window->baseResList, cx, cy)) {
@ -311,13 +336,11 @@ void BasicVideoData::BaseResListChanged(wxCommandEvent &event)
}
SetChanged();
window->videoChangedText->SetLabel(WXStr("Settings.StreamRestart"));
window->videoChangedText->Show();
ResetScaleList(cx, cy);
}
void BasicVideoData::OutputResListChanged(wxCommandEvent &event)
void BasicVideoData::OutputResChanged(wxCommandEvent &event)
{
uint32_t cx, cy;
if (!ConvertTextRes(window->outputResList, cx, cy)) {
@ -328,8 +351,6 @@ void BasicVideoData::OutputResListChanged(wxCommandEvent &event)
}
SetChanged();
window->videoChangedText->SetLabel(WXStr("Settings.StreamRestart"));
window->videoChangedText->Show();
}
void BasicVideoData::SaveOther()
@ -412,6 +433,8 @@ void BasicVideoData::Apply()
config_save(GetGlobalConfig());
/* TODO: If resolutiosn/fps were chaned, reset video */
SetSaved();
}

View file

@ -18,9 +18,55 @@
#include <obs.hpp>
#include "obs-app.hpp"
#include "wx-wrappers.hpp"
#include "window-settings-basic.hpp"
#include "window-main-basic.hpp"
bool OBSBasic::Init()
{
if (!obs_startup())
return false;
if (!InitGraphics())
return false;
return true;
}
OBSBasic::~OBSBasic()
{
obs_shutdown();
}
bool OBSBasic::InitGraphics()
{
wxSize size = previewPanel->GetClientSize();
struct obs_video_info ovi;
wxGetApp().GetConfigFPS(ovi.fps_num, ovi.fps_den);
ovi.graphics_module = wxGetApp().GetRenderModule();
ovi.window_width = size.x;
ovi.window_height = size.y;
ovi.base_width = (uint32_t)config_get_uint(GetGlobalConfig(),
"Video", "BaseCX");
ovi.base_height = (uint32_t)config_get_uint(GetGlobalConfig(),
"Video", "BaseCY");
ovi.output_width = (uint32_t)config_get_uint(GetGlobalConfig(),
"Video", "OutputCX");
ovi.output_height = (uint32_t)config_get_uint(GetGlobalConfig(),
"Video", "OutputCY");
ovi.output_format = VIDEO_FORMAT_RGBA;
ovi.adapter = 0;
ovi.window = WxToGSWindow(previewPanel);
if (!obs_reset_video(&ovi))
return false;
//required to make opengl display stuff on osx(?)
SendSizeEvent();
return true;
}
void OBSBasic::OnClose(wxCloseEvent &event)
{
wxGetApp().ExitMainLoop();

View file

@ -19,7 +19,16 @@
#include "forms/OBSWindows.h"
#include <obs.hpp>
#include <vector>
using namespace std;
class OBSBasic : public OBSBasicBase {
vector<OBSSource> scenes;
bool InitGraphics();
void NewProject();
void SaveProject();
void LoadProject();
@ -49,6 +58,9 @@ protected:
public:
inline OBSBasic() : OBSBasicBase(NULL) {}
virtual ~OBSBasic();
bool Init();
inline wxPanel *GetPreviewPanel() {return previewPanel;}
inline wxSizer *GetPreviewContainer() {return previewContainer;}