window-basic-settings-stream.cpp 29 KB

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