window-basic-settings-stream.cpp 29 KB

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