window-basic-settings-stream.cpp 31 KB

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