window-basic-settings-stream.cpp 29 KB

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