window-basic-settings-stream.cpp 29 KB

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