window-basic-settings-stream.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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. {
  331. const char *name = config_get_string(OBSBasic::Get()->Config(),
  332. "YouTube", "ChannelName");
  333. if (name) {
  334. ui->connectedAccountText->setText(name);
  335. } else {
  336. // if we still not changed the service page
  337. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  338. ui->connectedAccountText->setText(
  339. QTStr("Auth.LoadingChannel.Error"));
  340. }
  341. }
  342. }
  343. #endif
  344. void OBSBasicSettings::UseStreamKeyAdvClicked()
  345. {
  346. ui->streamKeyWidget->setVisible(true);
  347. }
  348. void OBSBasicSettings::on_service_currentIndexChanged(int)
  349. {
  350. bool showMore = ui->service->currentData().toInt() ==
  351. (int)ListOpt::ShowAll;
  352. if (showMore)
  353. return;
  354. std::string service = QT_TO_UTF8(ui->service->currentText());
  355. bool custom = IsCustomService();
  356. ui->disconnectAccount->setVisible(false);
  357. ui->bandwidthTestEnable->setVisible(false);
  358. ui->twitchAddonDropdown->setVisible(false);
  359. ui->twitchAddonLabel->setVisible(false);
  360. if (lastService != service.c_str()) {
  361. reset_service_ui_fields(ui.get(), service, loading);
  362. }
  363. ui->useAuth->setVisible(custom);
  364. ui->authUsernameLabel->setVisible(custom);
  365. ui->authUsername->setVisible(custom);
  366. ui->authPwLabel->setVisible(custom);
  367. ui->authPwWidget->setVisible(custom);
  368. if (custom) {
  369. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  370. ui->serverStackedWidget);
  371. ui->serverStackedWidget->setCurrentIndex(1);
  372. ui->serverStackedWidget->setVisible(true);
  373. ui->serverLabel->setVisible(true);
  374. on_useAuth_toggled();
  375. } else {
  376. ui->serverStackedWidget->setCurrentIndex(0);
  377. }
  378. if (!main->auth) {
  379. return;
  380. }
  381. auto system_auth_service = main->auth->service();
  382. bool service_check = service == system_auth_service;
  383. #if YOUTUBE_ENABLED
  384. service_check = service_check ? service_check
  385. : IsYouTubeService(system_auth_service) &&
  386. IsYouTubeService(service);
  387. #endif
  388. if (service_check) {
  389. auth.reset();
  390. auth = main->auth;
  391. OnAuthConnected();
  392. }
  393. }
  394. void OBSBasicSettings::UpdateServerList()
  395. {
  396. QString serviceName = ui->service->currentText();
  397. bool showMore = ui->service->currentData().toInt() ==
  398. (int)ListOpt::ShowAll;
  399. if (showMore) {
  400. LoadServices(true);
  401. ui->service->showPopup();
  402. return;
  403. } else {
  404. lastService = serviceName;
  405. }
  406. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  407. obs_property_t *services = obs_properties_get(props, "service");
  408. OBSData settings = obs_data_create();
  409. obs_data_release(settings);
  410. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  411. obs_property_modified(services, settings);
  412. obs_property_t *servers = obs_properties_get(props, "server");
  413. ui->server->clear();
  414. size_t servers_count = obs_property_list_item_count(servers);
  415. for (size_t i = 0; i < servers_count; i++) {
  416. const char *name = obs_property_list_item_name(servers, i);
  417. const char *server = obs_property_list_item_string(servers, i);
  418. ui->server->addItem(name, server);
  419. }
  420. obs_properties_destroy(props);
  421. }
  422. void OBSBasicSettings::on_show_clicked()
  423. {
  424. if (ui->key->echoMode() == QLineEdit::Password) {
  425. ui->key->setEchoMode(QLineEdit::Normal);
  426. ui->show->setText(QTStr("Hide"));
  427. } else {
  428. ui->key->setEchoMode(QLineEdit::Password);
  429. ui->show->setText(QTStr("Show"));
  430. }
  431. }
  432. void OBSBasicSettings::on_authPwShow_clicked()
  433. {
  434. if (ui->authPw->echoMode() == QLineEdit::Password) {
  435. ui->authPw->setEchoMode(QLineEdit::Normal);
  436. ui->authPwShow->setText(QTStr("Hide"));
  437. } else {
  438. ui->authPw->setEchoMode(QLineEdit::Password);
  439. ui->authPwShow->setText(QTStr("Show"));
  440. }
  441. }
  442. OBSService OBSBasicSettings::SpawnTempService()
  443. {
  444. bool custom = IsCustomService();
  445. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  446. OBSData settings = obs_data_create();
  447. obs_data_release(settings);
  448. if (!custom) {
  449. obs_data_set_string(settings, "service",
  450. QT_TO_UTF8(ui->service->currentText()));
  451. obs_data_set_string(
  452. settings, "server",
  453. QT_TO_UTF8(ui->server->currentData().toString()));
  454. } else {
  455. obs_data_set_string(
  456. settings, "server",
  457. QT_TO_UTF8(ui->customServer->text().trimmed()));
  458. }
  459. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  460. OBSService newService = obs_service_create(service_id, "temp_service",
  461. settings, nullptr);
  462. obs_service_release(newService);
  463. return newService;
  464. }
  465. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  466. {
  467. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  468. if (a) {
  469. bool validKey = !a->key().empty();
  470. if (validKey)
  471. ui->key->setText(QT_UTF8(a->key().c_str()));
  472. ui->streamKeyWidget->setVisible(false);
  473. ui->streamKeyLabel->setVisible(false);
  474. ui->connectAccount2->setVisible(false);
  475. ui->disconnectAccount->setVisible(true);
  476. ui->useStreamKeyAdv->setVisible(false);
  477. ui->connectedAccountLabel->setVisible(false);
  478. ui->connectedAccountText->setVisible(false);
  479. if (strcmp(a->service(), "Twitch") == 0) {
  480. ui->bandwidthTestEnable->setVisible(true);
  481. ui->twitchAddonLabel->setVisible(true);
  482. ui->twitchAddonDropdown->setVisible(true);
  483. }
  484. #if YOUTUBE_ENABLED
  485. if (IsYouTubeService(a->service())) {
  486. ui->key->clear();
  487. ui->connectedAccountLabel->setVisible(true);
  488. ui->connectedAccountText->setVisible(true);
  489. ui->connectedAccountText->setText(
  490. QTStr("Auth.LoadingChannel.Title"));
  491. get_yt_ch_title(ui.get());
  492. }
  493. #endif
  494. ui->bandwidthTestEnable->setChecked(false);
  495. }
  496. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  497. }
  498. void OBSBasicSettings::OnAuthConnected()
  499. {
  500. std::string service = QT_TO_UTF8(ui->service->currentText());
  501. Auth::Type type = Auth::AuthType(service);
  502. if (type == Auth::Type::OAuth_StreamKey ||
  503. type == Auth::Type::OAuth_LinkedAccount) {
  504. OnOAuthStreamKeyConnected();
  505. }
  506. if (!loading) {
  507. stream1Changed = true;
  508. EnableApplyButton(true);
  509. }
  510. }
  511. void OBSBasicSettings::on_connectAccount_clicked()
  512. {
  513. std::string service = QT_TO_UTF8(ui->service->currentText());
  514. OAuth::DeleteCookies(service);
  515. auth = OAuthStreamKey::Login(this, service);
  516. if (!!auth) {
  517. OnAuthConnected();
  518. ui->useStreamKeyAdv->setVisible(false);
  519. }
  520. }
  521. #define DISCONNECT_COMFIRM_TITLE \
  522. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  523. #define DISCONNECT_COMFIRM_TEXT \
  524. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  525. void OBSBasicSettings::on_disconnectAccount_clicked()
  526. {
  527. QMessageBox::StandardButton button;
  528. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  529. QTStr(DISCONNECT_COMFIRM_TEXT));
  530. if (button == QMessageBox::No) {
  531. return;
  532. }
  533. main->auth.reset();
  534. auth.reset();
  535. std::string service = QT_TO_UTF8(ui->service->currentText());
  536. #ifdef BROWSER_AVAILABLE
  537. OAuth::DeleteCookies(service);
  538. #endif
  539. ui->bandwidthTestEnable->setChecked(false);
  540. reset_service_ui_fields(ui.get(), service, loading);
  541. ui->bandwidthTestEnable->setVisible(false);
  542. ui->twitchAddonDropdown->setVisible(false);
  543. ui->twitchAddonLabel->setVisible(false);
  544. ui->key->setText("");
  545. ui->connectedAccountLabel->setVisible(false);
  546. ui->connectedAccountText->setVisible(false);
  547. }
  548. void OBSBasicSettings::on_useStreamKey_clicked()
  549. {
  550. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  551. }
  552. void OBSBasicSettings::on_useAuth_toggled()
  553. {
  554. if (!IsCustomService())
  555. return;
  556. bool use_auth = ui->useAuth->isChecked();
  557. ui->authUsernameLabel->setVisible(use_auth);
  558. ui->authUsername->setVisible(use_auth);
  559. ui->authPwLabel->setVisible(use_auth);
  560. ui->authPwWidget->setVisible(use_auth);
  561. }
  562. void OBSBasicSettings::UpdateVodTrackSetting()
  563. {
  564. bool enableForCustomServer = config_get_bool(
  565. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  566. bool enableVodTrack = ui->service->currentText() == "Twitch";
  567. bool wasEnabled = !!vodTrackCheckbox;
  568. if (enableForCustomServer && IsCustomService())
  569. enableVodTrack = true;
  570. if (enableVodTrack == wasEnabled)
  571. return;
  572. if (!enableVodTrack) {
  573. delete vodTrackCheckbox;
  574. delete vodTrackContainer;
  575. delete simpleVodTrack;
  576. return;
  577. }
  578. /* -------------------------------------- */
  579. /* simple output mode vod track widgets */
  580. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  581. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  582. "VodTrackEnabled");
  583. simpleVodTrack = new QCheckBox(this);
  584. simpleVodTrack->setText(
  585. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  586. simpleVodTrack->setVisible(simpleAdv);
  587. simpleVodTrack->setChecked(vodTrackEnabled);
  588. int pos;
  589. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  590. &pos, nullptr);
  591. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  592. HookWidget(simpleVodTrack, SIGNAL(clicked(bool)),
  593. SLOT(OutputsChanged()));
  594. connect(ui->simpleOutAdvanced, SIGNAL(toggled(bool)),
  595. simpleVodTrack.data(), SLOT(setVisible(bool)));
  596. /* -------------------------------------- */
  597. /* advanced output mode vod track widgets */
  598. vodTrackCheckbox = new QCheckBox(this);
  599. vodTrackCheckbox->setText(
  600. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  601. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  602. vodTrackContainer = new QWidget(this);
  603. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  604. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  605. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  606. vodTrackLayout->addWidget(vodTrack[i]);
  607. HookWidget(vodTrack[i], SIGNAL(clicked(bool)),
  608. SLOT(OutputsChanged()));
  609. }
  610. HookWidget(vodTrackCheckbox, SIGNAL(clicked(bool)),
  611. SLOT(OutputsChanged()));
  612. vodTrackLayout->addStretch();
  613. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  614. vodTrackContainer->setLayout(vodTrackLayout);
  615. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  616. vodTrackEnabled =
  617. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  618. vodTrackCheckbox->setChecked(vodTrackEnabled);
  619. vodTrackContainer->setEnabled(vodTrackEnabled);
  620. connect(vodTrackCheckbox, SIGNAL(clicked(bool)), vodTrackContainer,
  621. SLOT(setEnabled(bool)));
  622. int trackIndex =
  623. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  624. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  625. vodTrack[i]->setChecked((i + 1) == trackIndex);
  626. }
  627. }
  628. OBSService OBSBasicSettings::GetStream1Service()
  629. {
  630. return stream1Changed ? SpawnTempService()
  631. : OBSService(main->GetService());
  632. }
  633. void OBSBasicSettings::UpdateServiceRecommendations()
  634. {
  635. bool customServer = IsCustomService();
  636. ui->ignoreRecommended->setVisible(!customServer);
  637. ui->enforceSettingsLabel->setVisible(!customServer);
  638. OBSService service = GetStream1Service();
  639. int vbitrate, abitrate;
  640. BPtr<obs_service_resolution> res_list;
  641. size_t res_count;
  642. int fps;
  643. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  644. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  645. obs_service_get_max_fps(service, &fps);
  646. QString text;
  647. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  648. if (vbitrate)
  649. text += ENFORCE_TEXT("MaxVideoBitrate")
  650. .arg(QString::number(vbitrate));
  651. if (abitrate) {
  652. if (!text.isEmpty())
  653. text += "<br>";
  654. text += ENFORCE_TEXT("MaxAudioBitrate")
  655. .arg(QString::number(abitrate));
  656. }
  657. if (res_count) {
  658. if (!text.isEmpty())
  659. text += "<br>";
  660. obs_service_resolution best_res = {};
  661. int best_res_pixels = 0;
  662. for (size_t i = 0; i < res_count; i++) {
  663. obs_service_resolution res = res_list[i];
  664. int res_pixels = res.cx + res.cy;
  665. if (res_pixels > best_res_pixels) {
  666. best_res = res;
  667. best_res_pixels = res_pixels;
  668. }
  669. }
  670. QString res_str =
  671. QString("%1x%2").arg(QString::number(best_res.cx),
  672. QString::number(best_res.cy));
  673. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  674. }
  675. if (fps) {
  676. if (!text.isEmpty())
  677. text += "<br>";
  678. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  679. }
  680. #undef ENFORCE_TEXT
  681. #if YOUTUBE_ENABLED
  682. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  683. if (!text.isEmpty())
  684. text += "<br><br>";
  685. text += "<a href=\"https://www.youtube.com/t/terms\">"
  686. "YouTube Terms of Service</a><br>"
  687. "<a href=\"http://www.google.com/policies/privacy\">"
  688. "Google Privacy Policy</a><br>"
  689. "<a href=\"https://security.google.com/settings/security/permissions\">"
  690. "Google Third-Party Permissions</a>";
  691. }
  692. #endif
  693. ui->enforceSettingsLabel->setText(text);
  694. }
  695. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  696. {
  697. if (IsCustomService())
  698. return;
  699. if (!checked) {
  700. SimpleRecordingEncoderChanged();
  701. return;
  702. }
  703. QMessageBox::StandardButton button;
  704. #define ENFORCE_WARNING(x) \
  705. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  706. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  707. ENFORCE_WARNING("Text"));
  708. #undef ENFORCE_WARNING
  709. if (button == QMessageBox::No) {
  710. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  711. Qt::QueuedConnection,
  712. Q_ARG(bool, false));
  713. return;
  714. }
  715. SimpleRecordingEncoderChanged();
  716. }
  717. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  718. size_t res_count, int max_fps)
  719. {
  720. if (!res_count && !max_fps)
  721. return true;
  722. if (res_count) {
  723. QString res = ui->outputResolution->currentText();
  724. bool found_res = false;
  725. int cx, cy;
  726. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  727. return false;
  728. for (size_t i = 0; i < res_count; i++) {
  729. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  730. found_res = true;
  731. break;
  732. }
  733. }
  734. if (!found_res)
  735. return false;
  736. }
  737. if (max_fps) {
  738. int fpsType = ui->fpsType->currentIndex();
  739. if (fpsType != 0)
  740. return false;
  741. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  742. float fps;
  743. sscanf(fps_str.c_str(), "%f", &fps);
  744. if (fps > (float)max_fps)
  745. return false;
  746. }
  747. return true;
  748. }
  749. extern void set_closest_res(int &cx, int &cy,
  750. struct obs_service_resolution *res_list,
  751. size_t count);
  752. /* Checks for and updates the resolution and FPS limits of a service, if any.
  753. *
  754. * If the service has a resolution and/or FPS limit, this will enforce those
  755. * limitations in the UI itself, preventing the user from selecting a
  756. * resolution or FPS that's not supported.
  757. *
  758. * This is an unpleasant thing to have to do to users, but there is no other
  759. * way to ensure that a service's restricted resolution/framerate values are
  760. * properly enforced, otherwise users will just be confused when things aren't
  761. * working correctly. The user can turn it off if they're partner (or if they
  762. * want to risk getting in trouble with their service) by selecting the "Ignore
  763. * recommended settings" option in the stream section of settings.
  764. *
  765. * This only affects services that have a resolution and/or framerate limit, of
  766. * which as of this writing, and hopefully for the foreseeable future, there is
  767. * only one.
  768. */
  769. void OBSBasicSettings::UpdateResFPSLimits()
  770. {
  771. if (loading)
  772. return;
  773. int idx = ui->service->currentIndex();
  774. if (idx == -1)
  775. return;
  776. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  777. BPtr<obs_service_resolution> res_list;
  778. size_t res_count = 0;
  779. int max_fps = 0;
  780. if (!IsCustomService() && !ignoreRecommended) {
  781. OBSService service = GetStream1Service();
  782. obs_service_get_supported_resolutions(service, &res_list,
  783. &res_count);
  784. obs_service_get_max_fps(service, &max_fps);
  785. }
  786. /* ------------------------------------ */
  787. /* Check for enforced res/FPS */
  788. QString res = ui->outputResolution->currentText();
  789. QString fps_str;
  790. int cx = 0, cy = 0;
  791. double max_fpsd = (double)max_fps;
  792. int closest_fps_index = -1;
  793. double fpsd;
  794. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  795. if (res_count)
  796. set_closest_res(cx, cy, res_list, res_count);
  797. if (max_fps) {
  798. int fpsType = ui->fpsType->currentIndex();
  799. if (fpsType == 1) { //Integer
  800. fpsd = (double)ui->fpsInteger->value();
  801. } else if (fpsType == 2) { //Fractional
  802. fpsd = (double)ui->fpsNumerator->value() /
  803. (double)ui->fpsDenominator->value();
  804. } else { //Common
  805. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  806. &fpsd);
  807. }
  808. double closest_diff = 1000000000000.0;
  809. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  810. double com_fpsd;
  811. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  812. &com_fpsd);
  813. if (com_fpsd > max_fpsd) {
  814. continue;
  815. }
  816. double diff = fabs(com_fpsd - fpsd);
  817. if (diff < closest_diff) {
  818. closest_diff = diff;
  819. closest_fps_index = i;
  820. fps_str = ui->fpsCommon->itemText(i);
  821. }
  822. }
  823. }
  824. QString res_str =
  825. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  826. /* ------------------------------------ */
  827. /* Display message box if res/FPS bad */
  828. bool valid = ResFPSValid(res_list, res_count, max_fps);
  829. if (!valid) {
  830. /* if the user was already on facebook with an incompatible
  831. * resolution, assume it's an upgrade */
  832. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  833. ui->ignoreRecommended->setChecked(true);
  834. ui->ignoreRecommended->setProperty("changed", true);
  835. stream1Changed = true;
  836. EnableApplyButton(true);
  837. UpdateResFPSLimits();
  838. return;
  839. }
  840. QMessageBox::StandardButton button;
  841. #define WARNING_VAL(x) \
  842. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  843. QString str;
  844. if (res_count)
  845. str += WARNING_VAL("Resolution").arg(res_str);
  846. if (max_fps) {
  847. if (!str.isEmpty())
  848. str += "\n";
  849. str += WARNING_VAL("FPS").arg(fps_str);
  850. }
  851. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  852. WARNING_VAL("Msg").arg(str));
  853. #undef WARNING_VAL
  854. if (button == QMessageBox::No) {
  855. if (idx != lastServiceIdx)
  856. QMetaObject::invokeMethod(
  857. ui->service, "setCurrentIndex",
  858. Qt::QueuedConnection,
  859. Q_ARG(int, lastServiceIdx));
  860. else
  861. QMetaObject::invokeMethod(ui->ignoreRecommended,
  862. "setChecked",
  863. Qt::QueuedConnection,
  864. Q_ARG(bool, true));
  865. return;
  866. }
  867. }
  868. /* ------------------------------------ */
  869. /* Update widgets/values if switching */
  870. /* to/from enforced resolution/FPS */
  871. ui->outputResolution->blockSignals(true);
  872. if (res_count) {
  873. ui->outputResolution->clear();
  874. ui->outputResolution->setEditable(false);
  875. HookWidget(ui->outputResolution,
  876. SIGNAL(currentIndexChanged(int)),
  877. SLOT(VideoChangedResolution()));
  878. int new_res_index = -1;
  879. for (size_t i = 0; i < res_count; i++) {
  880. obs_service_resolution val = res_list[i];
  881. QString str =
  882. QString("%1x%2").arg(QString::number(val.cx),
  883. QString::number(val.cy));
  884. ui->outputResolution->addItem(str);
  885. if (val.cx == cx && val.cy == cy)
  886. new_res_index = (int)i;
  887. }
  888. ui->outputResolution->setCurrentIndex(new_res_index);
  889. if (!valid) {
  890. ui->outputResolution->setProperty("changed", true);
  891. videoChanged = true;
  892. EnableApplyButton(true);
  893. }
  894. } else {
  895. QString baseRes = ui->baseResolution->currentText();
  896. int baseCX, baseCY;
  897. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  898. if (!ui->outputResolution->isEditable()) {
  899. RecreateOutputResolutionWidget();
  900. ui->outputResolution->blockSignals(true);
  901. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  902. true);
  903. ui->outputResolution->setCurrentText(res);
  904. }
  905. }
  906. ui->outputResolution->blockSignals(false);
  907. if (max_fps) {
  908. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  909. double com_fpsd;
  910. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  911. &com_fpsd);
  912. if (com_fpsd > max_fpsd) {
  913. SetComboItemEnabled(ui->fpsCommon, i, false);
  914. continue;
  915. }
  916. }
  917. ui->fpsType->setCurrentIndex(0);
  918. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  919. if (!valid) {
  920. ui->fpsType->setProperty("changed", true);
  921. ui->fpsCommon->setProperty("changed", true);
  922. videoChanged = true;
  923. EnableApplyButton(true);
  924. }
  925. } else {
  926. for (int i = 0; i < ui->fpsCommon->count(); i++)
  927. SetComboItemEnabled(ui->fpsCommon, i, true);
  928. }
  929. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  930. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  931. /* ------------------------------------ */
  932. lastIgnoreRecommended = (int)ignoreRecommended;
  933. lastServiceIdx = idx;
  934. }