window-basic-settings-stream.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. #include <QMessageBox>
  2. #include <QUrl>
  3. #include "window-basic-settings.hpp"
  4. #include "obs-frontend-api.h"
  5. #include "obs-app.hpp"
  6. #include "window-basic-main.hpp"
  7. #include "qt-wrappers.hpp"
  8. #include "url-push-button.hpp"
  9. #ifdef BROWSER_AVAILABLE
  10. #include <browser-panel.hpp>
  11. #include "auth-oauth.hpp"
  12. #endif
  13. struct QCef;
  14. struct QCefCookieManager;
  15. extern QCef *cef;
  16. extern QCefCookieManager *panel_cookies;
  17. enum class ListOpt : int {
  18. ShowAll = 1,
  19. Custom,
  20. };
  21. enum class Section : int {
  22. Connect,
  23. StreamKey,
  24. };
  25. inline bool OBSBasicSettings::IsCustomService() const
  26. {
  27. return ui->service->currentData().toInt() == (int)ListOpt::Custom;
  28. }
  29. void OBSBasicSettings::InitStreamPage()
  30. {
  31. ui->connectAccount2->setVisible(false);
  32. ui->disconnectAccount->setVisible(false);
  33. ui->bandwidthTestEnable->setVisible(false);
  34. ui->twitchAddonDropdown->setVisible(false);
  35. ui->twitchAddonLabel->setVisible(false);
  36. int vertSpacing = ui->topStreamLayout->verticalSpacing();
  37. QMargins m = ui->topStreamLayout->contentsMargins();
  38. m.setBottom(vertSpacing / 2);
  39. ui->topStreamLayout->setContentsMargins(m);
  40. m = ui->loginPageLayout->contentsMargins();
  41. m.setTop(vertSpacing / 2);
  42. ui->loginPageLayout->setContentsMargins(m);
  43. m = ui->streamkeyPageLayout->contentsMargins();
  44. m.setTop(vertSpacing / 2);
  45. ui->streamkeyPageLayout->setContentsMargins(m);
  46. LoadServices(false);
  47. ui->twitchAddonDropdown->addItem(
  48. QTStr("Basic.Settings.Stream.TTVAddon.None"));
  49. ui->twitchAddonDropdown->addItem(
  50. QTStr("Basic.Settings.Stream.TTVAddon.BTTV"));
  51. ui->twitchAddonDropdown->addItem(
  52. QTStr("Basic.Settings.Stream.TTVAddon.FFZ"));
  53. ui->twitchAddonDropdown->addItem(
  54. QTStr("Basic.Settings.Stream.TTVAddon.Both"));
  55. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  56. SLOT(UpdateServerList()));
  57. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  58. SLOT(UpdateKeyLink()));
  59. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  60. SLOT(UpdateVodTrackSetting()));
  61. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  62. SLOT(UpdateServiceRecommendations()));
  63. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  64. SLOT(UpdateResFPSLimits()));
  65. connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
  66. SLOT(UpdateKeyLink()));
  67. connect(ui->ignoreRecommended, SIGNAL(clicked(bool)), this,
  68. SLOT(DisplayEnforceWarning(bool)));
  69. connect(ui->ignoreRecommended, SIGNAL(toggled(bool)), this,
  70. SLOT(UpdateResFPSLimits()));
  71. connect(ui->customServer, SIGNAL(editingFinished(const QString &)),
  72. this, SLOT(UpdateKeyLink()));
  73. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  74. SLOT(UpdateMoreInfoLink()));
  75. }
  76. void OBSBasicSettings::LoadStream1Settings()
  77. {
  78. bool ignoreRecommended =
  79. config_get_bool(main->Config(), "Stream1", "IgnoreRecommended");
  80. obs_service_t *service_obj = main->GetService();
  81. const char *type = obs_service_get_type(service_obj);
  82. loading = true;
  83. obs_data_t *settings = obs_service_get_settings(service_obj);
  84. const char *service = obs_data_get_string(settings, "service");
  85. const char *server = obs_data_get_string(settings, "server");
  86. const char *key = obs_data_get_string(settings, "key");
  87. if (strcmp(type, "rtmp_custom") == 0) {
  88. ui->service->setCurrentIndex(0);
  89. ui->customServer->setText(server);
  90. bool use_auth = obs_data_get_bool(settings, "use_auth");
  91. const char *username =
  92. obs_data_get_string(settings, "username");
  93. const char *password =
  94. obs_data_get_string(settings, "password");
  95. ui->authUsername->setText(QT_UTF8(username));
  96. ui->authPw->setText(QT_UTF8(password));
  97. ui->useAuth->setChecked(use_auth);
  98. } else {
  99. int idx = ui->service->findText(service);
  100. if (idx == -1) {
  101. if (service && *service)
  102. ui->service->insertItem(1, service);
  103. idx = 1;
  104. }
  105. ui->service->setCurrentIndex(idx);
  106. bool bw_test = obs_data_get_bool(settings, "bwtest");
  107. ui->bandwidthTestEnable->setChecked(bw_test);
  108. idx = config_get_int(main->Config(), "Twitch", "AddonChoice");
  109. ui->twitchAddonDropdown->setCurrentIndex(idx);
  110. }
  111. UpdateServerList();
  112. if (strcmp(type, "rtmp_common") == 0) {
  113. int idx = ui->server->findData(server);
  114. if (idx == -1) {
  115. if (server && *server)
  116. ui->server->insertItem(0, server, server);
  117. idx = 0;
  118. }
  119. ui->server->setCurrentIndex(idx);
  120. }
  121. ui->key->setText(key);
  122. lastService.clear();
  123. on_service_currentIndexChanged(0);
  124. obs_data_release(settings);
  125. UpdateKeyLink();
  126. UpdateMoreInfoLink();
  127. UpdateVodTrackSetting();
  128. UpdateServiceRecommendations();
  129. bool streamActive = obs_frontend_streaming_active();
  130. ui->streamPage->setEnabled(!streamActive);
  131. ui->ignoreRecommended->setChecked(ignoreRecommended);
  132. loading = false;
  133. QMetaObject::invokeMethod(this, "UpdateResFPSLimits",
  134. Qt::QueuedConnection);
  135. }
  136. void OBSBasicSettings::SaveStream1Settings()
  137. {
  138. bool customServer = IsCustomService();
  139. const char *service_id = customServer ? "rtmp_custom" : "rtmp_common";
  140. obs_service_t *oldService = main->GetService();
  141. OBSData hotkeyData = obs_hotkeys_save_service(oldService);
  142. obs_data_release(hotkeyData);
  143. OBSData settings = obs_data_create();
  144. obs_data_release(settings);
  145. if (!customServer) {
  146. obs_data_set_string(settings, "service",
  147. QT_TO_UTF8(ui->service->currentText()));
  148. obs_data_set_string(
  149. settings, "server",
  150. QT_TO_UTF8(ui->server->currentData().toString()));
  151. } else {
  152. obs_data_set_string(settings, "server",
  153. QT_TO_UTF8(ui->customServer->text()));
  154. obs_data_set_bool(settings, "use_auth",
  155. ui->useAuth->isChecked());
  156. if (ui->useAuth->isChecked()) {
  157. obs_data_set_string(
  158. settings, "username",
  159. QT_TO_UTF8(ui->authUsername->text()));
  160. obs_data_set_string(settings, "password",
  161. QT_TO_UTF8(ui->authPw->text()));
  162. }
  163. }
  164. if (!!auth && strcmp(auth->service(), "Twitch") == 0) {
  165. bool choiceExists = config_has_user_value(
  166. main->Config(), "Twitch", "AddonChoice");
  167. int currentChoice =
  168. config_get_int(main->Config(), "Twitch", "AddonChoice");
  169. int newChoice = ui->twitchAddonDropdown->currentIndex();
  170. config_set_int(main->Config(), "Twitch", "AddonChoice",
  171. newChoice);
  172. if (choiceExists && currentChoice != newChoice)
  173. forceAuthReload = true;
  174. obs_data_set_bool(settings, "bwtest",
  175. ui->bandwidthTestEnable->isChecked());
  176. } else {
  177. obs_data_set_bool(settings, "bwtest", false);
  178. }
  179. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  180. OBSService newService = obs_service_create(
  181. service_id, "default_service", settings, hotkeyData);
  182. obs_service_release(newService);
  183. if (!newService)
  184. return;
  185. main->SetService(newService);
  186. main->SaveService();
  187. main->auth = auth;
  188. if (!!main->auth)
  189. main->auth->LoadUI();
  190. SaveCheckBox(ui->ignoreRecommended, "Stream1", "IgnoreRecommended");
  191. }
  192. void OBSBasicSettings::UpdateMoreInfoLink()
  193. {
  194. if (IsCustomService()) {
  195. ui->moreInfoButton->hide();
  196. return;
  197. }
  198. QString serviceName = ui->service->currentText();
  199. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  200. obs_property_t *services = obs_properties_get(props, "service");
  201. OBSData settings = obs_data_create();
  202. obs_data_release(settings);
  203. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  204. obs_property_modified(services, settings);
  205. const char *more_info_link =
  206. obs_data_get_string(settings, "more_info_link");
  207. if (!more_info_link || (*more_info_link == '\0')) {
  208. ui->moreInfoButton->hide();
  209. } else {
  210. ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
  211. ui->moreInfoButton->show();
  212. }
  213. obs_properties_destroy(props);
  214. }
  215. void OBSBasicSettings::UpdateKeyLink()
  216. {
  217. QString serviceName = ui->service->currentText();
  218. QString customServer = ui->customServer->text();
  219. QString streamKeyLink;
  220. if (serviceName == "Twitch") {
  221. streamKeyLink = "https://dashboard.twitch.tv/settings/stream";
  222. } else if (serviceName.startsWith("YouTube")) {
  223. streamKeyLink = "https://www.youtube.com/live_dashboard";
  224. } else if (serviceName.startsWith("Restream.io")) {
  225. streamKeyLink =
  226. "https://restream.io/settings/streaming-setup?from=OBS";
  227. } else if (serviceName == "Facebook Live" ||
  228. (customServer.contains("fbcdn.net") && IsCustomService())) {
  229. streamKeyLink =
  230. "https://www.facebook.com/live/producer?ref=OBS";
  231. } else if (serviceName.startsWith("Twitter")) {
  232. streamKeyLink = "https://www.pscp.tv/account/producer";
  233. } else if (serviceName.startsWith("YouStreamer")) {
  234. streamKeyLink = "https://app.youstreamer.com/stream/";
  235. } else if (serviceName == "Trovo") {
  236. streamKeyLink = "https://studio.trovo.live/mychannel/stream";
  237. } else if (serviceName == "Glimesh") {
  238. streamKeyLink = "https://glimesh.tv/users/settings/stream";
  239. }
  240. if (QString(streamKeyLink).isNull()) {
  241. ui->getStreamKeyButton->hide();
  242. } else {
  243. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  244. ui->getStreamKeyButton->show();
  245. }
  246. }
  247. void OBSBasicSettings::LoadServices(bool showAll)
  248. {
  249. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  250. OBSData settings = obs_data_create();
  251. obs_data_release(settings);
  252. obs_data_set_bool(settings, "show_all", showAll);
  253. obs_property_t *prop = obs_properties_get(props, "show_all");
  254. obs_property_modified(prop, settings);
  255. ui->service->blockSignals(true);
  256. ui->service->clear();
  257. QStringList names;
  258. obs_property_t *services = obs_properties_get(props, "service");
  259. size_t services_count = obs_property_list_item_count(services);
  260. for (size_t i = 0; i < services_count; i++) {
  261. const char *name = obs_property_list_item_string(services, i);
  262. names.push_back(name);
  263. }
  264. if (showAll)
  265. names.sort(Qt::CaseInsensitive);
  266. for (QString &name : names)
  267. ui->service->addItem(name);
  268. if (!showAll) {
  269. ui->service->addItem(
  270. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  271. QVariant((int)ListOpt::ShowAll));
  272. }
  273. ui->service->insertItem(
  274. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  275. QVariant((int)ListOpt::Custom));
  276. if (!lastService.isEmpty()) {
  277. int idx = ui->service->findText(lastService);
  278. if (idx != -1)
  279. ui->service->setCurrentIndex(idx);
  280. }
  281. obs_properties_destroy(props);
  282. ui->service->blockSignals(false);
  283. }
  284. static inline bool is_auth_service(const std::string &service)
  285. {
  286. return Auth::AuthType(service) != Auth::Type::None;
  287. }
  288. void OBSBasicSettings::on_service_currentIndexChanged(int)
  289. {
  290. bool showMore = ui->service->currentData().toInt() ==
  291. (int)ListOpt::ShowAll;
  292. if (showMore)
  293. return;
  294. std::string service = QT_TO_UTF8(ui->service->currentText());
  295. bool custom = IsCustomService();
  296. ui->disconnectAccount->setVisible(false);
  297. ui->bandwidthTestEnable->setVisible(false);
  298. ui->twitchAddonDropdown->setVisible(false);
  299. ui->twitchAddonLabel->setVisible(false);
  300. #ifdef BROWSER_AVAILABLE
  301. if (cef) {
  302. if (lastService != service.c_str()) {
  303. QString key = ui->key->text();
  304. bool can_auth = is_auth_service(service);
  305. int page = can_auth && (!loading || key.isEmpty())
  306. ? (int)Section::Connect
  307. : (int)Section::StreamKey;
  308. ui->streamStackWidget->setCurrentIndex(page);
  309. ui->streamKeyWidget->setVisible(true);
  310. ui->streamKeyLabel->setVisible(true);
  311. ui->connectAccount2->setVisible(can_auth);
  312. }
  313. } else {
  314. ui->connectAccount2->setVisible(false);
  315. }
  316. #else
  317. ui->connectAccount2->setVisible(false);
  318. #endif
  319. ui->useAuth->setVisible(custom);
  320. ui->authUsernameLabel->setVisible(custom);
  321. ui->authUsername->setVisible(custom);
  322. ui->authPwLabel->setVisible(custom);
  323. ui->authPwWidget->setVisible(custom);
  324. if (custom) {
  325. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  326. ui->serverStackedWidget);
  327. ui->serverStackedWidget->setCurrentIndex(1);
  328. ui->serverStackedWidget->setVisible(true);
  329. ui->serverLabel->setVisible(true);
  330. on_useAuth_toggled();
  331. } else {
  332. ui->serverStackedWidget->setCurrentIndex(0);
  333. }
  334. #ifdef BROWSER_AVAILABLE
  335. auth.reset();
  336. if (!!main->auth &&
  337. service.find(main->auth->service()) != std::string::npos) {
  338. auth = main->auth;
  339. OnAuthConnected();
  340. }
  341. #endif
  342. }
  343. void OBSBasicSettings::UpdateServerList()
  344. {
  345. QString serviceName = ui->service->currentText();
  346. bool showMore = ui->service->currentData().toInt() ==
  347. (int)ListOpt::ShowAll;
  348. if (showMore) {
  349. LoadServices(true);
  350. ui->service->showPopup();
  351. return;
  352. } else {
  353. lastService = serviceName;
  354. }
  355. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  356. obs_property_t *services = obs_properties_get(props, "service");
  357. OBSData settings = obs_data_create();
  358. obs_data_release(settings);
  359. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  360. obs_property_modified(services, settings);
  361. obs_property_t *servers = obs_properties_get(props, "server");
  362. ui->server->clear();
  363. size_t servers_count = obs_property_list_item_count(servers);
  364. for (size_t i = 0; i < servers_count; i++) {
  365. const char *name = obs_property_list_item_name(servers, i);
  366. const char *server = obs_property_list_item_string(servers, i);
  367. ui->server->addItem(name, server);
  368. }
  369. obs_properties_destroy(props);
  370. }
  371. void OBSBasicSettings::on_show_clicked()
  372. {
  373. if (ui->key->echoMode() == QLineEdit::Password) {
  374. ui->key->setEchoMode(QLineEdit::Normal);
  375. ui->show->setText(QTStr("Hide"));
  376. } else {
  377. ui->key->setEchoMode(QLineEdit::Password);
  378. ui->show->setText(QTStr("Show"));
  379. }
  380. }
  381. void OBSBasicSettings::on_authPwShow_clicked()
  382. {
  383. if (ui->authPw->echoMode() == QLineEdit::Password) {
  384. ui->authPw->setEchoMode(QLineEdit::Normal);
  385. ui->authPwShow->setText(QTStr("Hide"));
  386. } else {
  387. ui->authPw->setEchoMode(QLineEdit::Password);
  388. ui->authPwShow->setText(QTStr("Show"));
  389. }
  390. }
  391. OBSService OBSBasicSettings::SpawnTempService()
  392. {
  393. bool custom = IsCustomService();
  394. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  395. OBSData settings = obs_data_create();
  396. obs_data_release(settings);
  397. if (!custom) {
  398. obs_data_set_string(settings, "service",
  399. QT_TO_UTF8(ui->service->currentText()));
  400. obs_data_set_string(
  401. settings, "server",
  402. QT_TO_UTF8(ui->server->currentData().toString()));
  403. } else {
  404. obs_data_set_string(settings, "server",
  405. QT_TO_UTF8(ui->customServer->text()));
  406. }
  407. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  408. OBSService newService = obs_service_create(service_id, "temp_service",
  409. settings, nullptr);
  410. obs_service_release(newService);
  411. return newService;
  412. }
  413. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  414. {
  415. #ifdef BROWSER_AVAILABLE
  416. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  417. if (a) {
  418. bool validKey = !a->key().empty();
  419. if (validKey)
  420. ui->key->setText(QT_UTF8(a->key().c_str()));
  421. ui->streamKeyWidget->setVisible(false);
  422. ui->streamKeyLabel->setVisible(false);
  423. ui->connectAccount2->setVisible(false);
  424. ui->disconnectAccount->setVisible(true);
  425. if (strcmp(a->service(), "Twitch") == 0) {
  426. ui->bandwidthTestEnable->setVisible(true);
  427. ui->twitchAddonLabel->setVisible(true);
  428. ui->twitchAddonDropdown->setVisible(true);
  429. } else {
  430. ui->bandwidthTestEnable->setChecked(false);
  431. }
  432. }
  433. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  434. #endif
  435. }
  436. void OBSBasicSettings::OnAuthConnected()
  437. {
  438. std::string service = QT_TO_UTF8(ui->service->currentText());
  439. Auth::Type type = Auth::AuthType(service);
  440. if (type == Auth::Type::OAuth_StreamKey) {
  441. OnOAuthStreamKeyConnected();
  442. }
  443. if (!loading) {
  444. stream1Changed = true;
  445. EnableApplyButton(true);
  446. }
  447. }
  448. void OBSBasicSettings::on_connectAccount_clicked()
  449. {
  450. #ifdef BROWSER_AVAILABLE
  451. std::string service = QT_TO_UTF8(ui->service->currentText());
  452. OAuth::DeleteCookies(service);
  453. auth = OAuthStreamKey::Login(this, service);
  454. if (!!auth)
  455. OnAuthConnected();
  456. #endif
  457. }
  458. #define DISCONNECT_COMFIRM_TITLE \
  459. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  460. #define DISCONNECT_COMFIRM_TEXT \
  461. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  462. void OBSBasicSettings::on_disconnectAccount_clicked()
  463. {
  464. QMessageBox::StandardButton button;
  465. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  466. QTStr(DISCONNECT_COMFIRM_TEXT));
  467. if (button == QMessageBox::No) {
  468. return;
  469. }
  470. main->auth.reset();
  471. auth.reset();
  472. std::string service = QT_TO_UTF8(ui->service->currentText());
  473. #ifdef BROWSER_AVAILABLE
  474. OAuth::DeleteCookies(service);
  475. #endif
  476. ui->bandwidthTestEnable->setChecked(false);
  477. ui->streamKeyWidget->setVisible(true);
  478. ui->streamKeyLabel->setVisible(true);
  479. ui->connectAccount2->setVisible(true);
  480. ui->disconnectAccount->setVisible(false);
  481. ui->bandwidthTestEnable->setVisible(false);
  482. ui->twitchAddonDropdown->setVisible(false);
  483. ui->twitchAddonLabel->setVisible(false);
  484. ui->key->setText("");
  485. }
  486. void OBSBasicSettings::on_useStreamKey_clicked()
  487. {
  488. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  489. }
  490. void OBSBasicSettings::on_useAuth_toggled()
  491. {
  492. if (!IsCustomService())
  493. return;
  494. bool use_auth = ui->useAuth->isChecked();
  495. ui->authUsernameLabel->setVisible(use_auth);
  496. ui->authUsername->setVisible(use_auth);
  497. ui->authPwLabel->setVisible(use_auth);
  498. ui->authPwWidget->setVisible(use_auth);
  499. }
  500. void OBSBasicSettings::UpdateVodTrackSetting()
  501. {
  502. bool enableForCustomServer = config_get_bool(
  503. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  504. bool enableVodTrack = ui->service->currentText() == "Twitch";
  505. bool wasEnabled = !!vodTrackCheckbox;
  506. if (enableForCustomServer && IsCustomService())
  507. enableVodTrack = true;
  508. if (enableVodTrack == wasEnabled)
  509. return;
  510. if (!enableVodTrack) {
  511. delete vodTrackCheckbox;
  512. delete vodTrackContainer;
  513. delete simpleVodTrack;
  514. return;
  515. }
  516. /* -------------------------------------- */
  517. /* simple output mode vod track widgets */
  518. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  519. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  520. "VodTrackEnabled");
  521. simpleVodTrack = new QCheckBox(this);
  522. simpleVodTrack->setText(
  523. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  524. simpleVodTrack->setVisible(simpleAdv);
  525. simpleVodTrack->setChecked(vodTrackEnabled);
  526. int pos;
  527. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  528. &pos, nullptr);
  529. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  530. HookWidget(simpleVodTrack, SIGNAL(clicked(bool)),
  531. SLOT(OutputsChanged()));
  532. connect(ui->simpleOutAdvanced, SIGNAL(toggled(bool)),
  533. simpleVodTrack.data(), SLOT(setVisible(bool)));
  534. /* -------------------------------------- */
  535. /* advanced output mode vod track widgets */
  536. vodTrackCheckbox = new QCheckBox(this);
  537. vodTrackCheckbox->setText(
  538. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  539. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  540. vodTrackContainer = new QWidget(this);
  541. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  542. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  543. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  544. vodTrackLayout->addWidget(vodTrack[i]);
  545. HookWidget(vodTrack[i], SIGNAL(clicked(bool)),
  546. SLOT(OutputsChanged()));
  547. }
  548. HookWidget(vodTrackCheckbox, SIGNAL(clicked(bool)),
  549. SLOT(OutputsChanged()));
  550. vodTrackLayout->addStretch();
  551. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  552. vodTrackContainer->setLayout(vodTrackLayout);
  553. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  554. vodTrackEnabled =
  555. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  556. vodTrackCheckbox->setChecked(vodTrackEnabled);
  557. vodTrackContainer->setEnabled(vodTrackEnabled);
  558. connect(vodTrackCheckbox, SIGNAL(clicked(bool)), vodTrackContainer,
  559. SLOT(setEnabled(bool)));
  560. int trackIndex =
  561. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  562. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  563. vodTrack[i]->setChecked((i + 1) == trackIndex);
  564. }
  565. }
  566. OBSService OBSBasicSettings::GetStream1Service()
  567. {
  568. return stream1Changed ? SpawnTempService()
  569. : OBSService(main->GetService());
  570. }
  571. void OBSBasicSettings::UpdateServiceRecommendations()
  572. {
  573. bool customServer = IsCustomService();
  574. ui->ignoreRecommended->setVisible(!customServer);
  575. ui->enforceSettingsLabel->setVisible(!customServer);
  576. OBSService service = GetStream1Service();
  577. int vbitrate, abitrate;
  578. BPtr<obs_service_resolution> res_list;
  579. size_t res_count;
  580. int fps;
  581. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  582. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  583. obs_service_get_max_fps(service, &fps);
  584. QString text;
  585. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  586. if (vbitrate)
  587. text += ENFORCE_TEXT("MaxVideoBitrate")
  588. .arg(QString::number(vbitrate));
  589. if (abitrate) {
  590. if (!text.isEmpty())
  591. text += "\n";
  592. text += ENFORCE_TEXT("MaxAudioBitrate")
  593. .arg(QString::number(abitrate));
  594. }
  595. if (res_count) {
  596. if (!text.isEmpty())
  597. text += "\n";
  598. obs_service_resolution best_res = {};
  599. int best_res_pixels = 0;
  600. for (size_t i = 0; i < res_count; i++) {
  601. obs_service_resolution res = res_list[i];
  602. int res_pixels = res.cx + res.cy;
  603. if (res_pixels > best_res_pixels) {
  604. best_res = res;
  605. best_res_pixels = res_pixels;
  606. }
  607. }
  608. QString res_str =
  609. QString("%1x%2").arg(QString::number(best_res.cx),
  610. QString::number(best_res.cy));
  611. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  612. }
  613. if (fps) {
  614. if (!text.isEmpty())
  615. text += "\n";
  616. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  617. }
  618. #undef ENFORCE_TEXT
  619. ui->enforceSettingsLabel->setText(text);
  620. }
  621. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  622. {
  623. if (IsCustomService())
  624. return;
  625. if (!checked) {
  626. SimpleRecordingEncoderChanged();
  627. return;
  628. }
  629. QMessageBox::StandardButton button;
  630. #define ENFORCE_WARNING(x) \
  631. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  632. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  633. ENFORCE_WARNING("Text"));
  634. #undef ENFORCE_WARNING
  635. if (button == QMessageBox::No) {
  636. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  637. Qt::QueuedConnection,
  638. Q_ARG(bool, false));
  639. return;
  640. }
  641. SimpleRecordingEncoderChanged();
  642. }
  643. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  644. size_t res_count, int max_fps)
  645. {
  646. if (!res_count && !max_fps)
  647. return true;
  648. if (res_count) {
  649. QString res = ui->outputResolution->currentText();
  650. bool found_res = false;
  651. int cx, cy;
  652. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  653. return false;
  654. for (size_t i = 0; i < res_count; i++) {
  655. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  656. found_res = true;
  657. break;
  658. }
  659. }
  660. if (!found_res)
  661. return false;
  662. }
  663. if (max_fps) {
  664. int fpsType = ui->fpsType->currentIndex();
  665. if (fpsType != 0)
  666. return false;
  667. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  668. float fps;
  669. sscanf(fps_str.c_str(), "%f", &fps);
  670. if (fps > (float)max_fps)
  671. return false;
  672. }
  673. return true;
  674. }
  675. extern void set_closest_res(int &cx, int &cy,
  676. struct obs_service_resolution *res_list,
  677. size_t count);
  678. /* Checks for and updates the resolution and FPS limits of a service, if any.
  679. *
  680. * If the service has a resolution and/or FPS limit, this will enforce those
  681. * limitations in the UI itself, preventing the user from selecting a
  682. * resolution or FPS that's not supported.
  683. *
  684. * This is an unpleasant thing to have to do to users, but there is no other
  685. * way to ensure that a service's restricted resolution/framerate values are
  686. * properly enforced, otherwise users will just be confused when things aren't
  687. * working correctly. The user can turn it off if they're partner (or if they
  688. * want to risk getting in trouble with their service) by selecting the "Ignore
  689. * recommended settings" option in the stream section of settings.
  690. *
  691. * This only affects services that have a resolution and/or framerate limit, of
  692. * which as of this writing, and hopefully for the foreseeable future, there is
  693. * only one.
  694. */
  695. void OBSBasicSettings::UpdateResFPSLimits()
  696. {
  697. if (loading)
  698. return;
  699. int idx = ui->service->currentIndex();
  700. if (idx == -1)
  701. return;
  702. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  703. BPtr<obs_service_resolution> res_list;
  704. size_t res_count = 0;
  705. int max_fps = 0;
  706. if (!IsCustomService() && !ignoreRecommended) {
  707. OBSService service = GetStream1Service();
  708. obs_service_get_supported_resolutions(service, &res_list,
  709. &res_count);
  710. obs_service_get_max_fps(service, &max_fps);
  711. }
  712. /* ------------------------------------ */
  713. /* Check for enforced res/FPS */
  714. QString res = ui->outputResolution->currentText();
  715. QString fps_str;
  716. int cx = 0, cy = 0;
  717. double max_fpsd = (double)max_fps;
  718. int closest_fps_index = -1;
  719. double fpsd;
  720. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  721. if (res_count)
  722. set_closest_res(cx, cy, res_list, res_count);
  723. if (max_fps) {
  724. int fpsType = ui->fpsType->currentIndex();
  725. if (fpsType == 1) { //Integer
  726. fpsd = (double)ui->fpsInteger->value();
  727. } else if (fpsType == 2) { //Fractional
  728. fpsd = (double)ui->fpsNumerator->value() /
  729. (double)ui->fpsDenominator->value();
  730. } else { //Common
  731. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  732. &fpsd);
  733. }
  734. double closest_diff = 1000000000000.0;
  735. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  736. double com_fpsd;
  737. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  738. &com_fpsd);
  739. if (com_fpsd > max_fpsd) {
  740. continue;
  741. }
  742. double diff = fabs(com_fpsd - fpsd);
  743. if (diff < closest_diff) {
  744. closest_diff = diff;
  745. closest_fps_index = i;
  746. fps_str = ui->fpsCommon->itemText(i);
  747. }
  748. }
  749. }
  750. QString res_str =
  751. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  752. /* ------------------------------------ */
  753. /* Display message box if res/FPS bad */
  754. bool valid = ResFPSValid(res_list, res_count, max_fps);
  755. if (!valid) {
  756. /* if the user was already on facebook with an incompatible
  757. * resolution, assume it's an upgrade */
  758. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  759. ui->ignoreRecommended->setChecked(true);
  760. ui->ignoreRecommended->setProperty("changed", true);
  761. stream1Changed = true;
  762. EnableApplyButton(true);
  763. UpdateResFPSLimits();
  764. return;
  765. }
  766. QMessageBox::StandardButton button;
  767. #define WARNING_VAL(x) \
  768. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  769. QString str;
  770. if (res_count)
  771. str += WARNING_VAL("Resolution").arg(res_str);
  772. if (max_fps) {
  773. if (!str.isEmpty())
  774. str += "\n";
  775. str += WARNING_VAL("FPS").arg(fps_str);
  776. }
  777. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  778. WARNING_VAL("Msg").arg(str));
  779. #undef WARNING_VAL
  780. if (button == QMessageBox::No) {
  781. if (idx != lastServiceIdx)
  782. QMetaObject::invokeMethod(
  783. ui->service, "setCurrentIndex",
  784. Qt::QueuedConnection,
  785. Q_ARG(int, lastServiceIdx));
  786. else
  787. QMetaObject::invokeMethod(ui->ignoreRecommended,
  788. "setChecked",
  789. Qt::QueuedConnection,
  790. Q_ARG(bool, true));
  791. return;
  792. }
  793. }
  794. /* ------------------------------------ */
  795. /* Update widgets/values if switching */
  796. /* to/from enforced resolution/FPS */
  797. ui->outputResolution->blockSignals(true);
  798. if (res_count) {
  799. ui->outputResolution->clear();
  800. ui->outputResolution->setEditable(false);
  801. int new_res_index = -1;
  802. for (size_t i = 0; i < res_count; i++) {
  803. obs_service_resolution val = res_list[i];
  804. QString str =
  805. QString("%1x%2").arg(QString::number(val.cx),
  806. QString::number(val.cy));
  807. ui->outputResolution->addItem(str);
  808. if (val.cx == cx && val.cy == cy)
  809. new_res_index = (int)i;
  810. }
  811. ui->outputResolution->setCurrentIndex(new_res_index);
  812. if (!valid) {
  813. ui->outputResolution->setProperty("changed", true);
  814. videoChanged = true;
  815. EnableApplyButton(true);
  816. }
  817. } else {
  818. QString baseRes = ui->baseResolution->currentText();
  819. int baseCX, baseCY;
  820. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  821. if (!ui->outputResolution->isEditable()) {
  822. RecreateOutputResolutionWidget();
  823. ui->outputResolution->blockSignals(true);
  824. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  825. true);
  826. ui->outputResolution->setCurrentText(res);
  827. }
  828. }
  829. ui->outputResolution->blockSignals(false);
  830. if (max_fps) {
  831. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  832. double com_fpsd;
  833. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  834. &com_fpsd);
  835. if (com_fpsd > max_fpsd) {
  836. SetComboItemEnabled(ui->fpsCommon, i, false);
  837. continue;
  838. }
  839. }
  840. ui->fpsType->setCurrentIndex(0);
  841. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  842. if (!valid) {
  843. ui->fpsType->setProperty("changed", true);
  844. ui->fpsCommon->setProperty("changed", true);
  845. videoChanged = true;
  846. EnableApplyButton(true);
  847. }
  848. } else {
  849. for (int i = 0; i < ui->fpsCommon->count(); i++)
  850. SetComboItemEnabled(ui->fpsCommon, i, true);
  851. }
  852. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  853. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  854. /* ------------------------------------ */
  855. lastIgnoreRecommended = (int)ignoreRecommended;
  856. lastServiceIdx = idx;
  857. }