window-basic-settings-stream.cpp 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. }
  238. if (QString(streamKeyLink).isNull()) {
  239. ui->getStreamKeyButton->hide();
  240. } else {
  241. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  242. ui->getStreamKeyButton->show();
  243. }
  244. }
  245. void OBSBasicSettings::LoadServices(bool showAll)
  246. {
  247. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  248. OBSData settings = obs_data_create();
  249. obs_data_release(settings);
  250. obs_data_set_bool(settings, "show_all", showAll);
  251. obs_property_t *prop = obs_properties_get(props, "show_all");
  252. obs_property_modified(prop, settings);
  253. ui->service->blockSignals(true);
  254. ui->service->clear();
  255. QStringList names;
  256. obs_property_t *services = obs_properties_get(props, "service");
  257. size_t services_count = obs_property_list_item_count(services);
  258. for (size_t i = 0; i < services_count; i++) {
  259. const char *name = obs_property_list_item_string(services, i);
  260. names.push_back(name);
  261. }
  262. if (showAll)
  263. names.sort(Qt::CaseInsensitive);
  264. for (QString &name : names)
  265. ui->service->addItem(name);
  266. if (!showAll) {
  267. ui->service->addItem(
  268. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  269. QVariant((int)ListOpt::ShowAll));
  270. }
  271. ui->service->insertItem(
  272. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  273. QVariant((int)ListOpt::Custom));
  274. if (!lastService.isEmpty()) {
  275. int idx = ui->service->findText(lastService);
  276. if (idx != -1)
  277. ui->service->setCurrentIndex(idx);
  278. }
  279. obs_properties_destroy(props);
  280. ui->service->blockSignals(false);
  281. }
  282. static inline bool is_auth_service(const std::string &service)
  283. {
  284. return Auth::AuthType(service) != Auth::Type::None;
  285. }
  286. void OBSBasicSettings::on_service_currentIndexChanged(int)
  287. {
  288. bool showMore = ui->service->currentData().toInt() ==
  289. (int)ListOpt::ShowAll;
  290. if (showMore)
  291. return;
  292. std::string service = QT_TO_UTF8(ui->service->currentText());
  293. bool custom = IsCustomService();
  294. ui->disconnectAccount->setVisible(false);
  295. ui->bandwidthTestEnable->setVisible(false);
  296. ui->twitchAddonDropdown->setVisible(false);
  297. ui->twitchAddonLabel->setVisible(false);
  298. #ifdef BROWSER_AVAILABLE
  299. if (cef) {
  300. if (lastService != service.c_str()) {
  301. QString key = ui->key->text();
  302. bool can_auth = is_auth_service(service);
  303. int page = can_auth && (!loading || key.isEmpty())
  304. ? (int)Section::Connect
  305. : (int)Section::StreamKey;
  306. ui->streamStackWidget->setCurrentIndex(page);
  307. ui->streamKeyWidget->setVisible(true);
  308. ui->streamKeyLabel->setVisible(true);
  309. ui->connectAccount2->setVisible(can_auth);
  310. }
  311. } else {
  312. ui->connectAccount2->setVisible(false);
  313. }
  314. #else
  315. ui->connectAccount2->setVisible(false);
  316. #endif
  317. ui->useAuth->setVisible(custom);
  318. ui->authUsernameLabel->setVisible(custom);
  319. ui->authUsername->setVisible(custom);
  320. ui->authPwLabel->setVisible(custom);
  321. ui->authPwWidget->setVisible(custom);
  322. if (custom) {
  323. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  324. ui->serverStackedWidget);
  325. ui->serverStackedWidget->setCurrentIndex(1);
  326. ui->serverStackedWidget->setVisible(true);
  327. ui->serverLabel->setVisible(true);
  328. on_useAuth_toggled();
  329. } else {
  330. ui->serverStackedWidget->setCurrentIndex(0);
  331. }
  332. #ifdef BROWSER_AVAILABLE
  333. auth.reset();
  334. if (!!main->auth &&
  335. service.find(main->auth->service()) != std::string::npos) {
  336. auth = main->auth;
  337. OnAuthConnected();
  338. }
  339. #endif
  340. }
  341. void OBSBasicSettings::UpdateServerList()
  342. {
  343. QString serviceName = ui->service->currentText();
  344. bool showMore = ui->service->currentData().toInt() ==
  345. (int)ListOpt::ShowAll;
  346. if (showMore) {
  347. LoadServices(true);
  348. ui->service->showPopup();
  349. return;
  350. } else {
  351. lastService = serviceName;
  352. }
  353. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  354. obs_property_t *services = obs_properties_get(props, "service");
  355. OBSData settings = obs_data_create();
  356. obs_data_release(settings);
  357. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  358. obs_property_modified(services, settings);
  359. obs_property_t *servers = obs_properties_get(props, "server");
  360. ui->server->clear();
  361. size_t servers_count = obs_property_list_item_count(servers);
  362. for (size_t i = 0; i < servers_count; i++) {
  363. const char *name = obs_property_list_item_name(servers, i);
  364. const char *server = obs_property_list_item_string(servers, i);
  365. ui->server->addItem(name, server);
  366. }
  367. obs_properties_destroy(props);
  368. }
  369. void OBSBasicSettings::on_show_clicked()
  370. {
  371. if (ui->key->echoMode() == QLineEdit::Password) {
  372. ui->key->setEchoMode(QLineEdit::Normal);
  373. ui->show->setText(QTStr("Hide"));
  374. } else {
  375. ui->key->setEchoMode(QLineEdit::Password);
  376. ui->show->setText(QTStr("Show"));
  377. }
  378. }
  379. void OBSBasicSettings::on_authPwShow_clicked()
  380. {
  381. if (ui->authPw->echoMode() == QLineEdit::Password) {
  382. ui->authPw->setEchoMode(QLineEdit::Normal);
  383. ui->authPwShow->setText(QTStr("Hide"));
  384. } else {
  385. ui->authPw->setEchoMode(QLineEdit::Password);
  386. ui->authPwShow->setText(QTStr("Show"));
  387. }
  388. }
  389. OBSService OBSBasicSettings::SpawnTempService()
  390. {
  391. bool custom = IsCustomService();
  392. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  393. OBSData settings = obs_data_create();
  394. obs_data_release(settings);
  395. if (!custom) {
  396. obs_data_set_string(settings, "service",
  397. QT_TO_UTF8(ui->service->currentText()));
  398. obs_data_set_string(
  399. settings, "server",
  400. QT_TO_UTF8(ui->server->currentData().toString()));
  401. } else {
  402. obs_data_set_string(settings, "server",
  403. QT_TO_UTF8(ui->customServer->text()));
  404. }
  405. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  406. OBSService newService = obs_service_create(service_id, "temp_service",
  407. settings, nullptr);
  408. obs_service_release(newService);
  409. return newService;
  410. }
  411. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  412. {
  413. #ifdef BROWSER_AVAILABLE
  414. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  415. if (a) {
  416. bool validKey = !a->key().empty();
  417. if (validKey)
  418. ui->key->setText(QT_UTF8(a->key().c_str()));
  419. ui->streamKeyWidget->setVisible(false);
  420. ui->streamKeyLabel->setVisible(false);
  421. ui->connectAccount2->setVisible(false);
  422. ui->disconnectAccount->setVisible(true);
  423. if (strcmp(a->service(), "Twitch") == 0) {
  424. ui->bandwidthTestEnable->setVisible(true);
  425. ui->twitchAddonLabel->setVisible(true);
  426. ui->twitchAddonDropdown->setVisible(true);
  427. } else {
  428. ui->bandwidthTestEnable->setChecked(false);
  429. }
  430. }
  431. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  432. #endif
  433. }
  434. void OBSBasicSettings::OnAuthConnected()
  435. {
  436. std::string service = QT_TO_UTF8(ui->service->currentText());
  437. Auth::Type type = Auth::AuthType(service);
  438. if (type == Auth::Type::OAuth_StreamKey) {
  439. OnOAuthStreamKeyConnected();
  440. }
  441. if (!loading) {
  442. stream1Changed = true;
  443. EnableApplyButton(true);
  444. }
  445. }
  446. void OBSBasicSettings::on_connectAccount_clicked()
  447. {
  448. #ifdef BROWSER_AVAILABLE
  449. std::string service = QT_TO_UTF8(ui->service->currentText());
  450. OAuth::DeleteCookies(service);
  451. auth = OAuthStreamKey::Login(this, service);
  452. if (!!auth)
  453. OnAuthConnected();
  454. #endif
  455. }
  456. #define DISCONNECT_COMFIRM_TITLE \
  457. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  458. #define DISCONNECT_COMFIRM_TEXT \
  459. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  460. void OBSBasicSettings::on_disconnectAccount_clicked()
  461. {
  462. QMessageBox::StandardButton button;
  463. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  464. QTStr(DISCONNECT_COMFIRM_TEXT));
  465. if (button == QMessageBox::No) {
  466. return;
  467. }
  468. main->auth.reset();
  469. auth.reset();
  470. std::string service = QT_TO_UTF8(ui->service->currentText());
  471. #ifdef BROWSER_AVAILABLE
  472. OAuth::DeleteCookies(service);
  473. #endif
  474. ui->bandwidthTestEnable->setChecked(false);
  475. ui->streamKeyWidget->setVisible(true);
  476. ui->streamKeyLabel->setVisible(true);
  477. ui->connectAccount2->setVisible(true);
  478. ui->disconnectAccount->setVisible(false);
  479. ui->bandwidthTestEnable->setVisible(false);
  480. ui->twitchAddonDropdown->setVisible(false);
  481. ui->twitchAddonLabel->setVisible(false);
  482. ui->key->setText("");
  483. }
  484. void OBSBasicSettings::on_useStreamKey_clicked()
  485. {
  486. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  487. }
  488. void OBSBasicSettings::on_useAuth_toggled()
  489. {
  490. if (!IsCustomService())
  491. return;
  492. bool use_auth = ui->useAuth->isChecked();
  493. ui->authUsernameLabel->setVisible(use_auth);
  494. ui->authUsername->setVisible(use_auth);
  495. ui->authPwLabel->setVisible(use_auth);
  496. ui->authPwWidget->setVisible(use_auth);
  497. }
  498. void OBSBasicSettings::UpdateVodTrackSetting()
  499. {
  500. bool enableForCustomServer = config_get_bool(
  501. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  502. bool enableVodTrack = ui->service->currentText() == "Twitch";
  503. bool wasEnabled = !!vodTrackCheckbox;
  504. if (enableForCustomServer && IsCustomService())
  505. enableVodTrack = true;
  506. if (enableVodTrack == wasEnabled)
  507. return;
  508. if (!enableVodTrack) {
  509. delete vodTrackCheckbox;
  510. delete vodTrackContainer;
  511. delete simpleVodTrack;
  512. return;
  513. }
  514. /* -------------------------------------- */
  515. /* simple output mode vod track widgets */
  516. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  517. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  518. "VodTrackEnabled");
  519. simpleVodTrack = new QCheckBox(this);
  520. simpleVodTrack->setText(
  521. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  522. simpleVodTrack->setVisible(simpleAdv);
  523. simpleVodTrack->setChecked(vodTrackEnabled);
  524. int pos;
  525. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  526. &pos, nullptr);
  527. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  528. HookWidget(simpleVodTrack, SIGNAL(clicked(bool)),
  529. SLOT(OutputsChanged()));
  530. connect(ui->simpleOutAdvanced, SIGNAL(toggled(bool)),
  531. simpleVodTrack.data(), SLOT(setVisible(bool)));
  532. /* -------------------------------------- */
  533. /* advanced output mode vod track widgets */
  534. vodTrackCheckbox = new QCheckBox(this);
  535. vodTrackCheckbox->setText(
  536. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  537. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  538. vodTrackContainer = new QWidget(this);
  539. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  540. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  541. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  542. vodTrackLayout->addWidget(vodTrack[i]);
  543. HookWidget(vodTrack[i], SIGNAL(clicked(bool)),
  544. SLOT(OutputsChanged()));
  545. }
  546. HookWidget(vodTrackCheckbox, SIGNAL(clicked(bool)),
  547. SLOT(OutputsChanged()));
  548. vodTrackLayout->addStretch();
  549. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  550. vodTrackContainer->setLayout(vodTrackLayout);
  551. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  552. vodTrackEnabled =
  553. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  554. vodTrackCheckbox->setChecked(vodTrackEnabled);
  555. vodTrackContainer->setEnabled(vodTrackEnabled);
  556. connect(vodTrackCheckbox, SIGNAL(clicked(bool)), vodTrackContainer,
  557. SLOT(setEnabled(bool)));
  558. int trackIndex =
  559. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  560. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  561. vodTrack[i]->setChecked((i + 1) == trackIndex);
  562. }
  563. }
  564. OBSService OBSBasicSettings::GetStream1Service()
  565. {
  566. return stream1Changed ? SpawnTempService()
  567. : OBSService(main->GetService());
  568. }
  569. void OBSBasicSettings::UpdateServiceRecommendations()
  570. {
  571. bool customServer = IsCustomService();
  572. ui->ignoreRecommended->setVisible(!customServer);
  573. ui->enforceSettingsLabel->setVisible(!customServer);
  574. OBSService service = GetStream1Service();
  575. int vbitrate, abitrate;
  576. BPtr<obs_service_resolution> res_list;
  577. size_t res_count;
  578. int fps;
  579. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  580. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  581. obs_service_get_max_fps(service, &fps);
  582. QString text;
  583. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  584. if (vbitrate)
  585. text += ENFORCE_TEXT("MaxVideoBitrate")
  586. .arg(QString::number(vbitrate));
  587. if (abitrate) {
  588. if (!text.isEmpty())
  589. text += "\n";
  590. text += ENFORCE_TEXT("MaxAudioBitrate")
  591. .arg(QString::number(abitrate));
  592. }
  593. if (res_count) {
  594. if (!text.isEmpty())
  595. text += "\n";
  596. obs_service_resolution best_res = {};
  597. int best_res_pixels = 0;
  598. for (size_t i = 0; i < res_count; i++) {
  599. obs_service_resolution res = res_list[i];
  600. int res_pixels = res.cx + res.cy;
  601. if (res_pixels > best_res_pixels) {
  602. best_res = res;
  603. best_res_pixels = res_pixels;
  604. }
  605. }
  606. QString res_str =
  607. QString("%1x%2").arg(QString::number(best_res.cx),
  608. QString::number(best_res.cy));
  609. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  610. }
  611. if (fps) {
  612. if (!text.isEmpty())
  613. text += "\n";
  614. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  615. }
  616. #undef ENFORCE_TEXT
  617. ui->enforceSettingsLabel->setText(text);
  618. }
  619. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  620. {
  621. if (IsCustomService())
  622. return;
  623. if (!checked) {
  624. SimpleRecordingEncoderChanged();
  625. return;
  626. }
  627. QMessageBox::StandardButton button;
  628. #define ENFORCE_WARNING(x) \
  629. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  630. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  631. ENFORCE_WARNING("Text"));
  632. #undef ENFORCE_WARNING
  633. if (button == QMessageBox::No) {
  634. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  635. Qt::QueuedConnection,
  636. Q_ARG(bool, false));
  637. return;
  638. }
  639. SimpleRecordingEncoderChanged();
  640. }
  641. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  642. size_t res_count, int max_fps)
  643. {
  644. if (!res_count && !max_fps)
  645. return true;
  646. if (res_count) {
  647. QString res = ui->outputResolution->currentText();
  648. bool found_res = false;
  649. int cx, cy;
  650. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  651. return false;
  652. for (size_t i = 0; i < res_count; i++) {
  653. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  654. found_res = true;
  655. break;
  656. }
  657. }
  658. if (!found_res)
  659. return false;
  660. }
  661. if (max_fps) {
  662. int fpsType = ui->fpsType->currentIndex();
  663. if (fpsType != 0)
  664. return false;
  665. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  666. float fps;
  667. sscanf(fps_str.c_str(), "%f", &fps);
  668. if (fps > (float)max_fps)
  669. return false;
  670. }
  671. return true;
  672. }
  673. extern void set_closest_res(int &cx, int &cy,
  674. struct obs_service_resolution *res_list,
  675. size_t count);
  676. /* Checks for and updates the resolution and FPS limits of a service, if any.
  677. *
  678. * If the service has a resolution and/or FPS limit, this will enforce those
  679. * limitations in the UI itself, preventing the user from selecting a
  680. * resolution or FPS that's not supported.
  681. *
  682. * This is an unpleasant thing to have to do to users, but there is no other
  683. * way to ensure that a service's restricted resolution/framerate values are
  684. * properly enforced, otherwise users will just be confused when things aren't
  685. * working correctly. The user can turn it off if they're partner (or if they
  686. * want to risk getting in trouble with their service) by selecting the "Ignore
  687. * recommended settings" option in the stream section of settings.
  688. *
  689. * This only affects services that have a resolution and/or framerate limit, of
  690. * which as of this writing, and hopefully for the foreseeable future, there is
  691. * only one.
  692. */
  693. void OBSBasicSettings::UpdateResFPSLimits()
  694. {
  695. if (loading)
  696. return;
  697. int idx = ui->service->currentIndex();
  698. if (idx == -1)
  699. return;
  700. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  701. BPtr<obs_service_resolution> res_list;
  702. size_t res_count = 0;
  703. int max_fps = 0;
  704. if (!IsCustomService() && !ignoreRecommended) {
  705. OBSService service = GetStream1Service();
  706. obs_service_get_supported_resolutions(service, &res_list,
  707. &res_count);
  708. obs_service_get_max_fps(service, &max_fps);
  709. }
  710. /* ------------------------------------ */
  711. /* Check for enforced res/FPS */
  712. QString res = ui->outputResolution->currentText();
  713. QString fps_str;
  714. int cx = 0, cy = 0;
  715. double max_fpsd = (double)max_fps;
  716. int closest_fps_index = -1;
  717. double fpsd;
  718. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  719. if (res_count)
  720. set_closest_res(cx, cy, res_list, res_count);
  721. if (max_fps) {
  722. int fpsType = ui->fpsType->currentIndex();
  723. if (fpsType == 1) { //Integer
  724. fpsd = (double)ui->fpsInteger->value();
  725. } else if (fpsType == 2) { //Fractional
  726. fpsd = (double)ui->fpsNumerator->value() /
  727. (double)ui->fpsDenominator->value();
  728. } else { //Common
  729. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  730. &fpsd);
  731. }
  732. double closest_diff = 1000000000000.0;
  733. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  734. double com_fpsd;
  735. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  736. &com_fpsd);
  737. if (com_fpsd > max_fpsd) {
  738. continue;
  739. }
  740. double diff = fabs(com_fpsd - fpsd);
  741. if (diff < closest_diff) {
  742. closest_diff = diff;
  743. closest_fps_index = i;
  744. fps_str = ui->fpsCommon->itemText(i);
  745. }
  746. }
  747. }
  748. QString res_str =
  749. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  750. /* ------------------------------------ */
  751. /* Display message box if res/FPS bad */
  752. bool valid = ResFPSValid(res_list, res_count, max_fps);
  753. if (!valid) {
  754. /* if the user was already on facebook with an incompatible
  755. * resolution, assume it's an upgrade */
  756. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  757. ui->ignoreRecommended->setChecked(true);
  758. ui->ignoreRecommended->setProperty("changed", true);
  759. stream1Changed = true;
  760. EnableApplyButton(true);
  761. UpdateResFPSLimits();
  762. return;
  763. }
  764. QMessageBox::StandardButton button;
  765. #define WARNING_VAL(x) \
  766. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  767. QString str;
  768. if (res_count)
  769. str += WARNING_VAL("Resolution").arg(res_str);
  770. if (max_fps) {
  771. if (!str.isEmpty())
  772. str += "\n";
  773. str += WARNING_VAL("FPS").arg(fps_str);
  774. }
  775. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  776. WARNING_VAL("Msg").arg(str));
  777. #undef WARNING_VAL
  778. if (button == QMessageBox::No) {
  779. if (idx != lastServiceIdx)
  780. QMetaObject::invokeMethod(
  781. ui->service, "setCurrentIndex",
  782. Qt::QueuedConnection,
  783. Q_ARG(int, lastServiceIdx));
  784. else
  785. QMetaObject::invokeMethod(ui->ignoreRecommended,
  786. "setChecked",
  787. Qt::QueuedConnection,
  788. Q_ARG(bool, true));
  789. return;
  790. }
  791. }
  792. /* ------------------------------------ */
  793. /* Update widgets/values if switching */
  794. /* to/from enforced resolution/FPS */
  795. ui->outputResolution->blockSignals(true);
  796. if (res_count) {
  797. ui->outputResolution->clear();
  798. ui->outputResolution->setEditable(false);
  799. int new_res_index = -1;
  800. for (size_t i = 0; i < res_count; i++) {
  801. obs_service_resolution val = res_list[i];
  802. QString str =
  803. QString("%1x%2").arg(QString::number(val.cx),
  804. QString::number(val.cy));
  805. ui->outputResolution->addItem(str);
  806. if (val.cx == cx && val.cy == cy)
  807. new_res_index = (int)i;
  808. }
  809. ui->outputResolution->setCurrentIndex(new_res_index);
  810. if (!valid) {
  811. ui->outputResolution->setProperty("changed", true);
  812. videoChanged = true;
  813. EnableApplyButton(true);
  814. }
  815. } else {
  816. QString baseRes = ui->baseResolution->currentText();
  817. int baseCX, baseCY;
  818. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  819. if (!ui->outputResolution->isEditable()) {
  820. RecreateOutputResolutionWidget();
  821. ui->outputResolution->blockSignals(true);
  822. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  823. true);
  824. ui->outputResolution->setCurrentText(res);
  825. }
  826. }
  827. ui->outputResolution->blockSignals(false);
  828. if (max_fps) {
  829. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  830. double com_fpsd;
  831. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  832. &com_fpsd);
  833. if (com_fpsd > max_fpsd) {
  834. SetComboItemEnabled(ui->fpsCommon, i, false);
  835. continue;
  836. }
  837. }
  838. ui->fpsType->setCurrentIndex(0);
  839. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  840. if (!valid) {
  841. ui->fpsType->setProperty("changed", true);
  842. ui->fpsCommon->setProperty("changed", true);
  843. videoChanged = true;
  844. EnableApplyButton(true);
  845. }
  846. } else {
  847. for (int i = 0; i < ui->fpsCommon->count(); i++)
  848. SetComboItemEnabled(ui->fpsCommon, i, true);
  849. }
  850. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  851. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  852. /* ------------------------------------ */
  853. lastIgnoreRecommended = (int)ignoreRecommended;
  854. lastServiceIdx = idx;
  855. }