window-basic-settings-stream.cpp 30 KB

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