window-basic-settings-stream.cpp 31 KB

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