yolobs-studio/UI/window-basic-auto-config.cpp

1051 lines
28 KiB
C++
Raw Permalink Normal View History

2017-06-29 19:01:10 +00:00
#include <QMessageBox>
#include <QScreen>
#include <obs.hpp>
2020-03-25 08:07:22 +00:00
#include "window-basic-auto-config.hpp"
#include "window-basic-main.hpp"
#include "qt-wrappers.hpp"
#include "obs-app.hpp"
#include "url-push-button.hpp"
2017-06-29 19:01:10 +00:00
#include "ui_AutoConfigStartPage.h"
#include "ui_AutoConfigVideoPage.h"
#include "ui_AutoConfigStreamPage.h"
2019-07-27 12:47:10 +00:00
#ifdef BROWSER_AVAILABLE
#include <browser-panel.hpp>
#include "auth-oauth.hpp"
#endif
struct QCef;
struct QCefCookieManager;
2019-09-22 21:19:10 +00:00
extern QCef *cef;
2019-07-27 12:47:10 +00:00
extern QCefCookieManager *panel_cookies;
2019-09-22 21:19:10 +00:00
#define wiz reinterpret_cast<AutoConfig *>(wizard())
2017-06-29 19:01:10 +00:00
/* ------------------------------------------------------------------------- */
#define SERVICE_PATH "service.json"
static OBSData OpenServiceSettings(std::string &type)
{
char serviceJsonPath[512];
int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
2019-09-22 21:19:10 +00:00
SERVICE_PATH);
2017-06-29 19:01:10 +00:00
if (ret <= 0)
return OBSData();
2019-09-22 21:19:10 +00:00
OBSData data =
obs_data_create_from_json_file_safe(serviceJsonPath, "bak");
2017-06-29 19:01:10 +00:00
obs_data_release(data);
obs_data_set_default_string(data, "type", "rtmp_common");
type = obs_data_get_string(data, "type");
OBSData settings = obs_data_get_obj(data, "settings");
obs_data_release(settings);
return settings;
}
static void GetServiceInfo(std::string &type, std::string &service,
2019-09-22 21:19:10 +00:00
std::string &server, std::string &key)
2017-06-29 19:01:10 +00:00
{
OBSData settings = OpenServiceSettings(type);
service = obs_data_get_string(settings, "service");
server = obs_data_get_string(settings, "server");
key = obs_data_get_string(settings, "key");
}
/* ------------------------------------------------------------------------- */
AutoConfigStartPage::AutoConfigStartPage(QWidget *parent)
2019-09-22 21:19:10 +00:00
: QWizardPage(parent), ui(new Ui_AutoConfigStartPage)
2017-06-29 19:01:10 +00:00
{
ui->setupUi(this);
setTitle(QTStr("Basic.AutoConfig.StartPage"));
setSubTitle(QTStr("Basic.AutoConfig.StartPage.SubTitle"));
2020-10-01 20:15:25 +00:00
OBSBasic *main = OBSBasic::Get();
if (main->VCamEnabled()) {
QRadioButton *prioritizeVCam = new QRadioButton(
QTStr("Basic.AutoConfig.StartPage.PrioritizeVirtualCam"),
this);
QBoxLayout *box = reinterpret_cast<QBoxLayout *>(layout());
box->insertWidget(2, prioritizeVCam);
connect(prioritizeVCam, &QPushButton::clicked, this,
&AutoConfigStartPage::PrioritizeVCam);
}
2017-06-29 19:01:10 +00:00
}
AutoConfigStartPage::~AutoConfigStartPage()
{
delete ui;
}
int AutoConfigStartPage::nextId() const
{
2020-10-01 20:15:25 +00:00
return wiz->type == AutoConfig::Type::VirtualCam
? AutoConfig::TestPage
: AutoConfig::VideoPage;
2017-06-29 19:01:10 +00:00
}
void AutoConfigStartPage::on_prioritizeStreaming_clicked()
{
wiz->type = AutoConfig::Type::Streaming;
}
void AutoConfigStartPage::on_prioritizeRecording_clicked()
{
wiz->type = AutoConfig::Type::Recording;
}
2020-10-01 20:15:25 +00:00
void AutoConfigStartPage::PrioritizeVCam()
{
wiz->type = AutoConfig::Type::VirtualCam;
}
2017-06-29 19:01:10 +00:00
/* ------------------------------------------------------------------------- */
2019-09-22 21:19:10 +00:00
#define RES_TEXT(x) "Basic.AutoConfig.VideoPage." x
#define RES_USE_CURRENT RES_TEXT("BaseResolution.UseCurrent")
#define RES_USE_DISPLAY RES_TEXT("BaseResolution.Display")
#define FPS_USE_CURRENT RES_TEXT("FPS.UseCurrent")
#define FPS_PREFER_HIGH_FPS RES_TEXT("FPS.PreferHighFPS")
#define FPS_PREFER_HIGH_RES RES_TEXT("FPS.PreferHighRes")
2017-06-29 19:01:10 +00:00
AutoConfigVideoPage::AutoConfigVideoPage(QWidget *parent)
2019-09-22 21:19:10 +00:00
: QWizardPage(parent), ui(new Ui_AutoConfigVideoPage)
2017-06-29 19:01:10 +00:00
{
ui->setupUi(this);
setTitle(QTStr("Basic.AutoConfig.VideoPage"));
setSubTitle(QTStr("Basic.AutoConfig.VideoPage.SubTitle"));
obs_video_info ovi;
obs_get_video_info(&ovi);
long double fpsVal =
(long double)ovi.fps_num / (long double)ovi.fps_den;
2019-09-22 21:19:10 +00:00
QString fpsStr = (ovi.fps_den > 1) ? QString::number(fpsVal, 'f', 2)
: QString::number(fpsVal, 'g', 2);
2017-06-29 19:01:10 +00:00
ui->fps->addItem(QTStr(FPS_PREFER_HIGH_FPS),
2019-09-22 21:19:10 +00:00
(int)AutoConfig::FPSType::PreferHighFPS);
2017-06-29 19:01:10 +00:00
ui->fps->addItem(QTStr(FPS_PREFER_HIGH_RES),
2019-09-22 21:19:10 +00:00
(int)AutoConfig::FPSType::PreferHighRes);
2017-06-29 19:01:10 +00:00
ui->fps->addItem(QTStr(FPS_USE_CURRENT).arg(fpsStr),
2019-09-22 21:19:10 +00:00
(int)AutoConfig::FPSType::UseCurrent);
2017-06-29 19:01:10 +00:00
ui->fps->addItem(QStringLiteral("30"), (int)AutoConfig::FPSType::fps30);
ui->fps->addItem(QStringLiteral("60"), (int)AutoConfig::FPSType::fps60);
ui->fps->setCurrentIndex(0);
QString cxStr = QString::number(ovi.base_width);
QString cyStr = QString::number(ovi.base_height);
int encRes = int(ovi.base_width << 16) | int(ovi.base_height);
ui->canvasRes->addItem(QTStr(RES_USE_CURRENT).arg(cxStr, cyStr),
2019-09-22 21:19:10 +00:00
(int)encRes);
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
QList<QScreen *> screens = QGuiApplication::screens();
2017-06-29 19:01:10 +00:00
for (int i = 0; i < screens.size(); i++) {
QScreen *screen = screens[i];
QSize as = screen->size();
encRes = int(as.width() << 16) | int(as.height());
QString str = QTStr(RES_USE_DISPLAY)
2019-09-22 21:19:10 +00:00
.arg(QString::number(i + 1),
QString::number(as.width()),
QString::number(as.height()));
2017-06-29 19:01:10 +00:00
ui->canvasRes->addItem(str, encRes);
}
2019-09-22 21:19:10 +00:00
auto addRes = [&](int cx, int cy) {
2017-06-29 19:01:10 +00:00
encRes = (cx << 16) | cy;
2019-09-22 21:19:10 +00:00
QString str = QString("%1x%2").arg(QString::number(cx),
QString::number(cy));
2017-06-29 19:01:10 +00:00
ui->canvasRes->addItem(str, encRes);
};
addRes(1920, 1080);
addRes(1280, 720);
ui->canvasRes->setCurrentIndex(0);
}
AutoConfigVideoPage::~AutoConfigVideoPage()
{
delete ui;
}
int AutoConfigVideoPage::nextId() const
{
return wiz->type == AutoConfig::Type::Recording
2019-09-22 21:19:10 +00:00
? AutoConfig::TestPage
: AutoConfig::StreamPage;
2017-06-29 19:01:10 +00:00
}
bool AutoConfigVideoPage::validatePage()
{
int encRes = ui->canvasRes->currentData().toInt();
wiz->baseResolutionCX = encRes >> 16;
wiz->baseResolutionCY = encRes & 0xFFFF;
wiz->fpsType = (AutoConfig::FPSType)ui->fps->currentData().toInt();
obs_video_info ovi;
obs_get_video_info(&ovi);
switch (wiz->fpsType) {
case AutoConfig::FPSType::PreferHighFPS:
wiz->specificFPSNum = 0;
wiz->specificFPSDen = 0;
wiz->preferHighFPS = true;
break;
case AutoConfig::FPSType::PreferHighRes:
wiz->specificFPSNum = 0;
wiz->specificFPSDen = 0;
wiz->preferHighFPS = false;
break;
case AutoConfig::FPSType::UseCurrent:
wiz->specificFPSNum = ovi.fps_num;
wiz->specificFPSDen = ovi.fps_den;
wiz->preferHighFPS = false;
break;
case AutoConfig::FPSType::fps30:
wiz->specificFPSNum = 30;
wiz->specificFPSDen = 1;
wiz->preferHighFPS = false;
break;
case AutoConfig::FPSType::fps60:
wiz->specificFPSNum = 60;
wiz->specificFPSDen = 1;
wiz->preferHighFPS = false;
break;
}
return true;
}
/* ------------------------------------------------------------------------- */
2019-07-27 12:47:10 +00:00
enum class ListOpt : int {
ShowAll = 1,
2019-09-22 21:19:10 +00:00
Custom,
2019-07-27 12:47:10 +00:00
};
2017-06-29 19:01:10 +00:00
AutoConfigStreamPage::AutoConfigStreamPage(QWidget *parent)
2019-09-22 21:19:10 +00:00
: QWizardPage(parent), ui(new Ui_AutoConfigStreamPage)
2017-06-29 19:01:10 +00:00
{
ui->setupUi(this);
ui->bitrateLabel->setVisible(false);
ui->bitrate->setVisible(false);
2019-07-27 12:47:10 +00:00
ui->connectAccount2->setVisible(false);
ui->disconnectAccount->setVisible(false);
2017-06-29 19:01:10 +00:00
2019-07-27 12:47:10 +00:00
int vertSpacing = ui->topLayout->verticalSpacing();
QMargins m = ui->topLayout->contentsMargins();
m.setBottom(vertSpacing / 2);
ui->topLayout->setContentsMargins(m);
m = ui->loginPageLayout->contentsMargins();
m.setTop(vertSpacing / 2);
ui->loginPageLayout->setContentsMargins(m);
m = ui->streamkeyPageLayout->contentsMargins();
m.setTop(vertSpacing / 2);
ui->streamkeyPageLayout->setContentsMargins(m);
2017-06-29 19:01:10 +00:00
setTitle(QTStr("Basic.AutoConfig.StreamPage"));
setSubTitle(QTStr("Basic.AutoConfig.StreamPage.SubTitle"));
LoadServices(false);
2019-09-22 21:19:10 +00:00
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(ServiceChanged()));
connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
SLOT(ServiceChanged()));
2020-10-01 20:15:25 +00:00
connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
SLOT(UpdateKeyLink()));
connect(ui->customServer, SIGNAL(editingFinished()), this,
SLOT(UpdateKeyLink()));
2019-09-22 21:19:10 +00:00
connect(ui->doBandwidthTest, SIGNAL(toggled(bool)), this,
SLOT(ServiceChanged()));
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateServerList()));
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateKeyLink()));
2020-12-22 17:32:50 +00:00
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateMoreInfoLink()));
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
connect(ui->key, SIGNAL(textChanged(const QString &)), this,
SLOT(UpdateCompleted()));
connect(ui->regionUS, SIGNAL(toggled(bool)), this,
SLOT(UpdateCompleted()));
connect(ui->regionEU, SIGNAL(toggled(bool)), this,
SLOT(UpdateCompleted()));
connect(ui->regionAsia, SIGNAL(toggled(bool)), this,
SLOT(UpdateCompleted()));
connect(ui->regionOther, SIGNAL(toggled(bool)), this,
SLOT(UpdateCompleted()));
2017-06-29 19:01:10 +00:00
}
AutoConfigStreamPage::~AutoConfigStreamPage()
{
delete ui;
}
bool AutoConfigStreamPage::isComplete() const
{
return ready;
}
int AutoConfigStreamPage::nextId() const
{
return AutoConfig::TestPage;
}
2020-03-25 08:07:22 +00:00
inline bool AutoConfigStreamPage::IsCustomService() const
2019-07-27 12:47:10 +00:00
{
return ui->service->currentData().toInt() == (int)ListOpt::Custom;
}
2017-06-29 19:01:10 +00:00
bool AutoConfigStreamPage::validatePage()
{
OBSData service_settings = obs_data_create();
obs_data_release(service_settings);
2020-03-25 08:07:22 +00:00
wiz->customServer = IsCustomService();
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
const char *serverType = wiz->customServer ? "rtmp_custom"
: "rtmp_common";
2017-06-29 19:01:10 +00:00
if (!wiz->customServer) {
obs_data_set_string(service_settings, "service",
2019-09-22 21:19:10 +00:00
QT_TO_UTF8(ui->service->currentText()));
2017-06-29 19:01:10 +00:00
}
OBSService service = obs_service_create(serverType, "temp_service",
2019-09-22 21:19:10 +00:00
service_settings, nullptr);
2017-06-29 19:01:10 +00:00
obs_service_release(service);
int bitrate = 10000;
if (!ui->doBandwidthTest->isChecked()) {
bitrate = ui->bitrate->value();
wiz->idealBitrate = bitrate;
}
OBSData settings = obs_data_create();
obs_data_release(settings);
obs_data_set_int(settings, "bitrate", bitrate);
obs_service_apply_encoder_settings(service, settings, nullptr);
if (wiz->customServer) {
QString server = ui->customServer->text();
wiz->server = wiz->serverName = QT_TO_UTF8(server);
} else {
wiz->serverName = QT_TO_UTF8(ui->server->currentText());
wiz->server = QT_TO_UTF8(ui->server->currentData().toString());
}
wiz->bandwidthTest = ui->doBandwidthTest->isChecked();
wiz->startingBitrate = (int)obs_data_get_int(settings, "bitrate");
wiz->idealBitrate = wiz->startingBitrate;
wiz->regionUS = ui->regionUS->isChecked();
wiz->regionEU = ui->regionEU->isChecked();
wiz->regionAsia = ui->regionAsia->isChecked();
wiz->regionOther = ui->regionOther->isChecked();
wiz->serviceName = QT_TO_UTF8(ui->service->currentText());
if (ui->preferHardware)
wiz->preferHardware = ui->preferHardware->isChecked();
wiz->key = QT_TO_UTF8(ui->key->text());
if (!wiz->customServer) {
if (wiz->serviceName == "Twitch")
wiz->service = AutoConfig::Service::Twitch;
2018-02-19 19:54:37 +00:00
else if (wiz->serviceName == "Smashcast")
wiz->service = AutoConfig::Service::Smashcast;
2017-06-29 19:01:10 +00:00
else
wiz->service = AutoConfig::Service::Other;
} else {
wiz->service = AutoConfig::Service::Other;
}
if (wiz->service != AutoConfig::Service::Twitch && wiz->bandwidthTest) {
QMessageBox::StandardButton button;
#define WARNING_TEXT(x) QTStr("Basic.AutoConfig.StreamPage.StreamWarning." x)
2019-09-22 21:19:10 +00:00
button = OBSMessageBox::question(this, WARNING_TEXT("Title"),
WARNING_TEXT("Text"));
2017-06-29 19:01:10 +00:00
#undef WARNING_TEXT
if (button == QMessageBox::No)
return false;
}
return true;
}
void AutoConfigStreamPage::on_show_clicked()
{
if (ui->key->echoMode() == QLineEdit::Password) {
ui->key->setEchoMode(QLineEdit::Normal);
ui->show->setText(QTStr("Hide"));
} else {
ui->key->setEchoMode(QLineEdit::Password);
ui->show->setText(QTStr("Show"));
}
}
2019-07-27 12:47:10 +00:00
void AutoConfigStreamPage::OnOAuthStreamKeyConnected()
{
#ifdef BROWSER_AVAILABLE
2019-09-22 21:19:10 +00:00
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
2019-07-27 12:47:10 +00:00
if (a) {
bool validKey = !a->key().empty();
if (validKey)
ui->key->setText(QT_UTF8(a->key().c_str()));
ui->streamKeyWidget->setVisible(!validKey);
ui->streamKeyLabel->setVisible(!validKey);
ui->connectAccount2->setVisible(!validKey);
ui->disconnectAccount->setVisible(validKey);
}
ui->stackedWidget->setCurrentIndex((int)Section::StreamKey);
UpdateCompleted();
#endif
}
void AutoConfigStreamPage::OnAuthConnected()
{
std::string service = QT_TO_UTF8(ui->service->currentText());
Auth::Type type = Auth::AuthType(service);
if (type == Auth::Type::OAuth_StreamKey) {
OnOAuthStreamKeyConnected();
}
}
void AutoConfigStreamPage::on_connectAccount_clicked()
{
#ifdef BROWSER_AVAILABLE
std::string service = QT_TO_UTF8(ui->service->currentText());
2019-12-10 19:31:54 +00:00
OAuth::DeleteCookies(service);
2019-07-27 12:47:10 +00:00
auth = OAuthStreamKey::Login(this, service);
if (!!auth)
OnAuthConnected();
#endif
}
#define DISCONNECT_COMFIRM_TITLE \
"Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
#define DISCONNECT_COMFIRM_TEXT \
"Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
void AutoConfigStreamPage::on_disconnectAccount_clicked()
{
QMessageBox::StandardButton button;
2019-09-22 21:19:10 +00:00
button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
QTStr(DISCONNECT_COMFIRM_TEXT));
2019-07-27 12:47:10 +00:00
if (button == QMessageBox::No) {
return;
}
OBSBasic *main = OBSBasic::Get();
main->auth.reset();
auth.reset();
std::string service = QT_TO_UTF8(ui->service->currentText());
#ifdef BROWSER_AVAILABLE
OAuth::DeleteCookies(service);
#endif
ui->streamKeyWidget->setVisible(true);
ui->streamKeyLabel->setVisible(true);
ui->connectAccount2->setVisible(true);
ui->disconnectAccount->setVisible(false);
ui->key->setText("");
}
void AutoConfigStreamPage::on_useStreamKey_clicked()
{
ui->stackedWidget->setCurrentIndex((int)Section::StreamKey);
UpdateCompleted();
}
static inline bool is_auth_service(const std::string &service)
{
return Auth::AuthType(service) != Auth::Type::None;
}
2017-06-29 19:01:10 +00:00
void AutoConfigStreamPage::ServiceChanged()
{
2019-09-22 21:19:10 +00:00
bool showMore = ui->service->currentData().toInt() ==
(int)ListOpt::ShowAll;
2017-06-29 19:01:10 +00:00
if (showMore)
return;
std::string service = QT_TO_UTF8(ui->service->currentText());
2019-09-22 21:19:10 +00:00
bool regionBased = service == "Twitch" || service == "Smashcast";
2017-06-29 19:01:10 +00:00
bool testBandwidth = ui->doBandwidthTest->isChecked();
2020-03-25 08:07:22 +00:00
bool custom = IsCustomService();
2019-07-27 12:47:10 +00:00
ui->disconnectAccount->setVisible(false);
#ifdef BROWSER_AVAILABLE
if (cef) {
if (lastService != service.c_str()) {
bool can_auth = is_auth_service(service);
2019-09-22 21:19:10 +00:00
int page = can_auth ? (int)Section::Connect
: (int)Section::StreamKey;
2019-07-27 12:47:10 +00:00
ui->stackedWidget->setCurrentIndex(page);
ui->streamKeyWidget->setVisible(true);
ui->streamKeyLabel->setVisible(true);
ui->connectAccount2->setVisible(can_auth);
auth.reset();
if (lastService.isEmpty())
lastService = service.c_str();
}
} else {
ui->connectAccount2->setVisible(false);
}
#else
ui->connectAccount2->setVisible(false);
#endif
2017-06-29 19:01:10 +00:00
2018-02-19 19:54:37 +00:00
/* Test three closest servers if "Auto" is available for Twitch */
if (service == "Twitch" && wiz->twitchAuto)
regionBased = false;
2019-07-27 12:47:10 +00:00
ui->streamkeyPageLayout->removeWidget(ui->serverLabel);
ui->streamkeyPageLayout->removeWidget(ui->serverStackedWidget);
2017-06-29 19:01:10 +00:00
if (custom) {
2019-07-27 12:47:10 +00:00
ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
2019-09-22 21:19:10 +00:00
ui->serverStackedWidget);
2017-06-29 19:01:10 +00:00
ui->region->setVisible(false);
ui->serverStackedWidget->setCurrentIndex(1);
ui->serverStackedWidget->setVisible(true);
ui->serverLabel->setVisible(true);
} else {
if (!testBandwidth)
2019-09-22 21:19:10 +00:00
ui->streamkeyPageLayout->insertRow(
2, ui->serverLabel, ui->serverStackedWidget);
2017-06-29 19:01:10 +00:00
ui->region->setVisible(regionBased && testBandwidth);
ui->serverStackedWidget->setCurrentIndex(0);
ui->serverStackedWidget->setHidden(testBandwidth);
ui->serverLabel->setHidden(testBandwidth);
}
wiz->testRegions = regionBased && testBandwidth;
ui->bitrateLabel->setHidden(testBandwidth);
ui->bitrate->setHidden(testBandwidth);
2019-07-27 12:47:10 +00:00
#ifdef BROWSER_AVAILABLE
OBSBasic *main = OBSBasic::Get();
if (!!main->auth &&
service.find(main->auth->service()) != std::string::npos) {
auth = main->auth;
OnAuthConnected();
}
#endif
2017-06-29 19:01:10 +00:00
UpdateCompleted();
}
2020-12-22 17:32:50 +00:00
void AutoConfigStreamPage::UpdateMoreInfoLink()
{
if (IsCustomService()) {
ui->moreInfoButton->hide();
return;
}
QString serviceName = ui->service->currentText();
obs_properties_t *props = obs_get_service_properties("rtmp_common");
obs_property_t *services = obs_properties_get(props, "service");
OBSData settings = obs_data_create();
obs_data_release(settings);
obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
obs_property_modified(services, settings);
const char *more_info_link =
obs_data_get_string(settings, "more_info_link");
if (!more_info_link || (*more_info_link == '\0')) {
ui->moreInfoButton->hide();
} else {
ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
ui->moreInfoButton->show();
}
obs_properties_destroy(props);
}
2017-06-29 19:01:10 +00:00
void AutoConfigStreamPage::UpdateKeyLink()
{
QString serviceName = ui->service->currentText();
2020-10-01 20:15:25 +00:00
QString customServer = ui->customServer->text();
2018-02-19 19:54:37 +00:00
bool isYoutube = false;
2020-03-25 08:07:22 +00:00
QString streamKeyLink;
2017-06-29 19:01:10 +00:00
if (serviceName == "Twitch") {
2020-12-22 17:32:50 +00:00
streamKeyLink = "https://dashboard.twitch.tv/settings/stream";
} else if (serviceName.startsWith("YouTube")) {
2020-03-25 08:07:22 +00:00
streamKeyLink = "https://www.youtube.com/live_dashboard";
2018-02-19 19:54:37 +00:00
isYoutube = true;
2019-09-22 21:19:10 +00:00
} else if (serviceName.startsWith("Restream.io")) {
2020-03-25 08:07:22 +00:00
streamKeyLink =
"https://restream.io/settings/streaming-setup?from=OBS";
2020-10-01 20:15:25 +00:00
} else if (serviceName == "Facebook Live" ||
(customServer.contains("fbcdn.net") && IsCustomService())) {
streamKeyLink =
"https://www.facebook.com/live/producer?ref=OBS";
2020-03-25 08:07:22 +00:00
} else if (serviceName.startsWith("Twitter")) {
streamKeyLink = "https://www.pscp.tv/account/producer";
} else if (serviceName.startsWith("YouStreamer")) {
streamKeyLink = "https://www.app.youstreamer.com/stream/";
2020-10-01 20:15:25 +00:00
} else if (serviceName == "Trovo") {
streamKeyLink = "https://studio.trovo.live/mychannel/stream";
2020-03-25 08:07:22 +00:00
}
if (QString(streamKeyLink).isNull()) {
ui->streamKeyButton->hide();
} else {
ui->streamKeyButton->setTargetUrl(QUrl(streamKeyLink));
ui->streamKeyButton->show();
2018-02-19 19:54:37 +00:00
}
if (isYoutube) {
ui->doBandwidthTest->setChecked(false);
ui->doBandwidthTest->setEnabled(false);
} else {
ui->doBandwidthTest->setEnabled(true);
2017-06-29 19:01:10 +00:00
}
}
void AutoConfigStreamPage::LoadServices(bool showAll)
{
obs_properties_t *props = obs_get_service_properties("rtmp_common");
OBSData settings = obs_data_create();
obs_data_release(settings);
obs_data_set_bool(settings, "show_all", showAll);
obs_property_t *prop = obs_properties_get(props, "show_all");
obs_property_modified(prop, settings);
ui->service->blockSignals(true);
ui->service->clear();
QStringList names;
obs_property_t *services = obs_properties_get(props, "service");
size_t services_count = obs_property_list_item_count(services);
for (size_t i = 0; i < services_count; i++) {
const char *name = obs_property_list_item_string(services, i);
names.push_back(name);
}
if (showAll)
2020-10-01 20:15:25 +00:00
names.sort(Qt::CaseInsensitive);
2017-06-29 19:01:10 +00:00
for (QString &name : names)
ui->service->addItem(name);
2019-07-27 12:47:10 +00:00
if (!showAll) {
ui->service->addItem(
QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
QVariant((int)ListOpt::ShowAll));
}
2019-09-22 21:19:10 +00:00
ui->service->insertItem(
0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
QVariant((int)ListOpt::Custom));
2019-07-27 12:47:10 +00:00
2017-06-29 19:01:10 +00:00
if (!lastService.isEmpty()) {
int idx = ui->service->findText(lastService);
if (idx != -1)
ui->service->setCurrentIndex(idx);
}
obs_properties_destroy(props);
ui->service->blockSignals(false);
}
void AutoConfigStreamPage::UpdateServerList()
{
QString serviceName = ui->service->currentText();
2019-09-22 21:19:10 +00:00
bool showMore = ui->service->currentData().toInt() ==
(int)ListOpt::ShowAll;
2017-06-29 19:01:10 +00:00
if (showMore) {
LoadServices(true);
ui->service->showPopup();
return;
} else {
lastService = serviceName;
}
obs_properties_t *props = obs_get_service_properties("rtmp_common");
obs_property_t *services = obs_properties_get(props, "service");
OBSData settings = obs_data_create();
obs_data_release(settings);
obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
obs_property_modified(services, settings);
obs_property_t *servers = obs_properties_get(props, "server");
ui->server->clear();
size_t servers_count = obs_property_list_item_count(servers);
for (size_t i = 0; i < servers_count; i++) {
const char *name = obs_property_list_item_name(servers, i);
const char *server = obs_property_list_item_string(servers, i);
ui->server->addItem(name, server);
}
obs_properties_destroy(props);
}
void AutoConfigStreamPage::UpdateCompleted()
{
2019-07-27 12:47:10 +00:00
if (ui->stackedWidget->currentIndex() == (int)Section::Connect ||
(ui->key->text().isEmpty() && !auth)) {
2017-06-29 19:01:10 +00:00
ready = false;
} else {
2020-03-25 08:07:22 +00:00
bool custom = IsCustomService();
2017-06-29 19:01:10 +00:00
if (custom) {
ready = !ui->customServer->text().isEmpty();
} else {
ready = !wiz->testRegions ||
ui->regionUS->isChecked() ||
ui->regionEU->isChecked() ||
ui->regionAsia->isChecked() ||
ui->regionOther->isChecked();
}
}
emit completeChanged();
}
/* ------------------------------------------------------------------------- */
2019-09-22 21:19:10 +00:00
AutoConfig::AutoConfig(QWidget *parent) : QWizard(parent)
2017-06-29 19:01:10 +00:00
{
2019-07-27 12:47:10 +00:00
EnableThreadedMessageBoxes(true);
2018-02-19 19:54:37 +00:00
calldata_t cd = {0};
calldata_set_int(&cd, "seconds", 5);
proc_handler_t *ph = obs_get_proc_handler();
proc_handler_call(ph, "twitch_ingests_refresh", &cd);
calldata_free(&cd);
2019-09-22 21:19:10 +00:00
OBSBasic *main = reinterpret_cast<OBSBasic *>(parent);
2017-06-29 19:01:10 +00:00
main->EnableOutputs(false);
installEventFilter(CreateShortcutFilter());
std::string serviceType;
GetServiceInfo(serviceType, serviceName, server, key);
2020-10-01 20:15:25 +00:00
#if defined(_WIN32) || defined(__APPLE__)
2017-06-29 19:01:10 +00:00
setWizardStyle(QWizard::ModernStyle);
#endif
2019-07-27 12:47:10 +00:00
streamPage = new AutoConfigStreamPage();
2017-06-29 19:01:10 +00:00
setPage(StartPage, new AutoConfigStartPage());
setPage(VideoPage, new AutoConfigVideoPage());
setPage(StreamPage, streamPage);
setPage(TestPage, new AutoConfigTestPage());
2018-12-16 16:14:58 +00:00
setWindowTitle(QTStr("Basic.AutoConfig"));
2019-07-27 12:47:10 +00:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2017-06-29 19:01:10 +00:00
obs_video_info ovi;
obs_get_video_info(&ovi);
baseResolutionCX = ovi.base_width;
baseResolutionCY = ovi.base_height;
2018-02-19 19:54:37 +00:00
/* ----------------------------------------- */
/* check to see if Twitch's "auto" available */
OBSData twitchSettings = obs_data_create();
obs_data_release(twitchSettings);
obs_data_set_string(twitchSettings, "service", "Twitch");
obs_properties_t *props = obs_get_service_properties("rtmp_common");
obs_properties_apply_settings(props, twitchSettings);
obs_property_t *p = obs_properties_get(props, "server");
const char *first = obs_property_list_item_string(p, 0);
twitchAuto = strcmp(first, "auto") == 0;
obs_properties_destroy(props);
2017-06-29 19:01:10 +00:00
/* ----------------------------------------- */
/* load service/servers */
customServer = serviceType == "rtmp_custom";
QComboBox *serviceList = streamPage->ui->service;
if (!serviceName.empty()) {
serviceList->blockSignals(true);
int count = serviceList->count();
bool found = false;
for (int i = 0; i < count; i++) {
QString name = serviceList->itemText(i);
if (name == serviceName.c_str()) {
serviceList->setCurrentIndex(i);
found = true;
break;
}
}
if (!found) {
serviceList->insertItem(0, serviceName.c_str());
serviceList->setCurrentIndex(0);
}
serviceList->blockSignals(false);
}
streamPage->UpdateServerList();
streamPage->UpdateKeyLink();
2020-12-22 17:32:50 +00:00
streamPage->UpdateMoreInfoLink();
2019-07-27 12:47:10 +00:00
streamPage->lastService.clear();
2017-06-29 19:01:10 +00:00
if (!customServer) {
QComboBox *serverList = streamPage->ui->server;
int idx = serverList->findData(QString(server.c_str()));
if (idx == -1)
idx = 0;
serverList->setCurrentIndex(idx);
} else {
streamPage->ui->customServer->setText(server.c_str());
2019-07-27 12:47:10 +00:00
int idx = streamPage->ui->service->findData(
2019-09-22 21:19:10 +00:00
QVariant((int)ListOpt::Custom));
2019-07-27 12:47:10 +00:00
streamPage->ui->service->setCurrentIndex(idx);
2017-06-29 19:01:10 +00:00
}
if (!key.empty())
streamPage->ui->key->setText(key.c_str());
2019-09-22 21:19:10 +00:00
int bitrate =
config_get_int(main->Config(), "SimpleOutput", "VBitrate");
2017-06-29 19:01:10 +00:00
streamPage->ui->bitrate->setValue(bitrate);
streamPage->ServiceChanged();
TestHardwareEncoding();
if (!hardwareEncodingAvailable) {
delete streamPage->ui->preferHardware;
streamPage->ui->preferHardware = nullptr;
2019-07-27 12:47:10 +00:00
} else {
/* Newer generations of NVENC have a high enough quality to
* bitrate ratio that if NVENC is available, it makes sense to
* just always prefer hardware encoding by default */
bool preferHardware = nvencAvailable ||
2019-09-22 21:19:10 +00:00
os_get_physical_cores() <= 4;
2019-07-27 12:47:10 +00:00
streamPage->ui->preferHardware->setChecked(preferHardware);
2017-06-29 19:01:10 +00:00
}
2020-10-01 20:15:25 +00:00
setOptions(QWizard::WizardOptions());
2017-06-29 19:01:10 +00:00
setButtonText(QWizard::FinishButton,
2019-09-22 21:19:10 +00:00
QTStr("Basic.AutoConfig.ApplySettings"));
2017-06-29 19:01:10 +00:00
setButtonText(QWizard::BackButton, QTStr("Back"));
setButtonText(QWizard::NextButton, QTStr("Next"));
setButtonText(QWizard::CancelButton, QTStr("Cancel"));
}
AutoConfig::~AutoConfig()
{
2019-09-22 21:19:10 +00:00
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
2017-06-29 19:01:10 +00:00
main->EnableOutputs(true);
2019-07-27 12:47:10 +00:00
EnableThreadedMessageBoxes(false);
2017-06-29 19:01:10 +00:00
}
void AutoConfig::TestHardwareEncoding()
{
size_t idx = 0;
const char *id;
while (obs_enum_encoder_types(idx++, &id)) {
if (strcmp(id, "ffmpeg_nvenc") == 0)
hardwareEncodingAvailable = nvencAvailable = true;
else if (strcmp(id, "obs_qsv11") == 0)
hardwareEncodingAvailable = qsvAvailable = true;
else if (strcmp(id, "amd_amf_h264") == 0)
hardwareEncodingAvailable = vceAvailable = true;
}
}
bool AutoConfig::CanTestServer(const char *server)
{
if (!testRegions || (regionUS && regionEU && regionAsia && regionOther))
return true;
if (service == Service::Twitch) {
if (astrcmp_n(server, "US West:", 8) == 0 ||
astrcmp_n(server, "US East:", 8) == 0 ||
astrcmp_n(server, "US Central:", 11) == 0) {
return regionUS;
} else if (astrcmp_n(server, "EU:", 3) == 0) {
return regionEU;
} else if (astrcmp_n(server, "Asia:", 5) == 0) {
return regionAsia;
} else if (regionOther) {
return true;
}
2018-02-19 19:54:37 +00:00
} else if (service == Service::Smashcast) {
2017-06-29 19:01:10 +00:00
if (strcmp(server, "Default") == 0) {
return true;
} else if (astrcmp_n(server, "US-West:", 8) == 0 ||
2019-09-22 21:19:10 +00:00
astrcmp_n(server, "US-East:", 8) == 0) {
2017-06-29 19:01:10 +00:00
return regionUS;
} else if (astrcmp_n(server, "EU-", 3) == 0) {
return regionEU;
} else if (astrcmp_n(server, "South Korea:", 12) == 0 ||
2019-09-22 21:19:10 +00:00
astrcmp_n(server, "Asia:", 5) == 0 ||
astrcmp_n(server, "China:", 6) == 0) {
2017-06-29 19:01:10 +00:00
return regionAsia;
} else if (regionOther) {
return true;
}
} else {
return true;
}
return false;
}
void AutoConfig::done(int result)
{
QWizard::done(result);
if (result == QDialog::Accepted) {
if (type == Type::Streaming)
SaveStreamSettings();
SaveSettings();
}
}
inline const char *AutoConfig::GetEncoderId(Encoder enc)
{
switch (enc) {
case Encoder::NVENC:
return SIMPLE_ENCODER_NVENC;
case Encoder::QSV:
return SIMPLE_ENCODER_QSV;
case Encoder::AMD:
return SIMPLE_ENCODER_AMD;
default:
return SIMPLE_ENCODER_X264;
}
};
void AutoConfig::SaveStreamSettings()
{
2019-09-22 21:19:10 +00:00
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
2017-06-29 19:01:10 +00:00
/* ---------------------------------- */
/* save service */
2019-09-22 21:19:10 +00:00
const char *service_id = customServer ? "rtmp_custom" : "rtmp_common";
2017-06-29 19:01:10 +00:00
obs_service_t *oldService = main->GetService();
OBSData hotkeyData = obs_hotkeys_save_service(oldService);
obs_data_release(hotkeyData);
OBSData settings = obs_data_create();
obs_data_release(settings);
if (!customServer)
obs_data_set_string(settings, "service", serviceName.c_str());
obs_data_set_string(settings, "server", server.c_str());
obs_data_set_string(settings, "key", key.c_str());
2019-09-22 21:19:10 +00:00
OBSService newService = obs_service_create(
service_id, "default_service", settings, hotkeyData);
2017-06-29 19:01:10 +00:00
obs_service_release(newService);
if (!newService)
return;
main->SetService(newService);
main->SaveService();
2019-07-27 12:47:10 +00:00
main->auth = streamPage->auth;
if (!!main->auth)
main->auth->LoadUI();
2017-06-29 19:01:10 +00:00
/* ---------------------------------- */
/* save stream settings */
config_set_int(main->Config(), "SimpleOutput", "VBitrate",
2019-09-22 21:19:10 +00:00
idealBitrate);
2017-06-29 19:01:10 +00:00
config_set_string(main->Config(), "SimpleOutput", "StreamEncoder",
2019-09-22 21:19:10 +00:00
GetEncoderId(streamingEncoder));
2017-06-29 19:01:10 +00:00
config_remove_value(main->Config(), "SimpleOutput", "UseAdvanced");
}
void AutoConfig::SaveSettings()
{
2019-09-22 21:19:10 +00:00
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
2017-06-29 19:01:10 +00:00
if (recordingEncoder != Encoder::Stream)
config_set_string(main->Config(), "SimpleOutput", "RecEncoder",
2019-09-22 21:19:10 +00:00
GetEncoderId(recordingEncoder));
2017-06-29 19:01:10 +00:00
2019-09-22 21:19:10 +00:00
const char *quality = recordingQuality == Quality::High ? "Small"
: "Stream";
2017-06-29 19:01:10 +00:00
config_set_string(main->Config(), "Output", "Mode", "Simple");
2019-09-22 21:19:10 +00:00
config_set_string(main->Config(), "SimpleOutput", "RecQuality",
quality);
2017-06-29 19:01:10 +00:00
config_set_int(main->Config(), "Video", "BaseCX", baseResolutionCX);
config_set_int(main->Config(), "Video", "BaseCY", baseResolutionCY);
config_set_int(main->Config(), "Video", "OutputCX", idealResolutionCX);
config_set_int(main->Config(), "Video", "OutputCY", idealResolutionCY);
if (fpsType != FPSType::UseCurrent) {
config_set_uint(main->Config(), "Video", "FPSType", 0);
config_set_string(main->Config(), "Video", "FPSCommon",
2019-09-22 21:19:10 +00:00
std::to_string(idealFPSNum).c_str());
2017-06-29 19:01:10 +00:00
}
main->ResetVideo();
main->ResetOutputs();
config_save_safe(main->Config(), "tmp", nullptr);
}