1
0

window-basic-settings-stream.cpp 31 KB

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