window-basic-settings-stream.cpp 29 KB

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