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. YoutubeApiWrappers *ytAuth)
  331. {
  332. if (ytAuth) {
  333. ChannelDescription cd;
  334. if (ytAuth->GetChannelDescription(cd)) {
  335. ui->connectedAccountText->setText(cd.title);
  336. } else {
  337. // if we still not changed the service page
  338. if (IsYouTubeService(
  339. QT_TO_UTF8(ui->service->currentText()))) {
  340. ui->connectedAccountText->setText(
  341. QTStr("Auth.LoadingChannel.Error"));
  342. }
  343. }
  344. }
  345. }
  346. #endif
  347. void OBSBasicSettings::UseStreamKeyAdvClicked()
  348. {
  349. ui->streamKeyWidget->setVisible(true);
  350. }
  351. void OBSBasicSettings::on_service_currentIndexChanged(int)
  352. {
  353. bool showMore = ui->service->currentData().toInt() ==
  354. (int)ListOpt::ShowAll;
  355. if (showMore)
  356. return;
  357. std::string service = QT_TO_UTF8(ui->service->currentText());
  358. bool custom = IsCustomService();
  359. ui->disconnectAccount->setVisible(false);
  360. ui->bandwidthTestEnable->setVisible(false);
  361. ui->twitchAddonDropdown->setVisible(false);
  362. ui->twitchAddonLabel->setVisible(false);
  363. if (lastService != service.c_str()) {
  364. reset_service_ui_fields(ui.get(), service, loading);
  365. }
  366. ui->useAuth->setVisible(custom);
  367. ui->authUsernameLabel->setVisible(custom);
  368. ui->authUsername->setVisible(custom);
  369. ui->authPwLabel->setVisible(custom);
  370. ui->authPwWidget->setVisible(custom);
  371. if (custom) {
  372. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  373. ui->serverStackedWidget);
  374. ui->serverStackedWidget->setCurrentIndex(1);
  375. ui->serverStackedWidget->setVisible(true);
  376. ui->serverLabel->setVisible(true);
  377. on_useAuth_toggled();
  378. } else {
  379. ui->serverStackedWidget->setCurrentIndex(0);
  380. }
  381. if (!main->auth) {
  382. return;
  383. }
  384. auto system_auth_service = main->auth->service();
  385. bool service_check = service == system_auth_service;
  386. #if YOUTUBE_ENABLED
  387. service_check = service_check ? service_check
  388. : IsYouTubeService(system_auth_service) &&
  389. IsYouTubeService(service);
  390. #endif
  391. if (service_check) {
  392. auth.reset();
  393. auth = main->auth;
  394. OnAuthConnected();
  395. }
  396. }
  397. void OBSBasicSettings::UpdateServerList()
  398. {
  399. QString serviceName = ui->service->currentText();
  400. bool showMore = ui->service->currentData().toInt() ==
  401. (int)ListOpt::ShowAll;
  402. if (showMore) {
  403. LoadServices(true);
  404. ui->service->showPopup();
  405. return;
  406. } else {
  407. lastService = serviceName;
  408. }
  409. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  410. obs_property_t *services = obs_properties_get(props, "service");
  411. OBSData settings = obs_data_create();
  412. obs_data_release(settings);
  413. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  414. obs_property_modified(services, settings);
  415. obs_property_t *servers = obs_properties_get(props, "server");
  416. ui->server->clear();
  417. size_t servers_count = obs_property_list_item_count(servers);
  418. for (size_t i = 0; i < servers_count; i++) {
  419. const char *name = obs_property_list_item_name(servers, i);
  420. const char *server = obs_property_list_item_string(servers, i);
  421. ui->server->addItem(name, server);
  422. }
  423. obs_properties_destroy(props);
  424. }
  425. void OBSBasicSettings::on_show_clicked()
  426. {
  427. if (ui->key->echoMode() == QLineEdit::Password) {
  428. ui->key->setEchoMode(QLineEdit::Normal);
  429. ui->show->setText(QTStr("Hide"));
  430. } else {
  431. ui->key->setEchoMode(QLineEdit::Password);
  432. ui->show->setText(QTStr("Show"));
  433. }
  434. }
  435. void OBSBasicSettings::on_authPwShow_clicked()
  436. {
  437. if (ui->authPw->echoMode() == QLineEdit::Password) {
  438. ui->authPw->setEchoMode(QLineEdit::Normal);
  439. ui->authPwShow->setText(QTStr("Hide"));
  440. } else {
  441. ui->authPw->setEchoMode(QLineEdit::Password);
  442. ui->authPwShow->setText(QTStr("Show"));
  443. }
  444. }
  445. OBSService OBSBasicSettings::SpawnTempService()
  446. {
  447. bool custom = IsCustomService();
  448. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  449. OBSData settings = obs_data_create();
  450. obs_data_release(settings);
  451. if (!custom) {
  452. obs_data_set_string(settings, "service",
  453. QT_TO_UTF8(ui->service->currentText()));
  454. obs_data_set_string(
  455. settings, "server",
  456. QT_TO_UTF8(ui->server->currentData().toString()));
  457. } else {
  458. obs_data_set_string(
  459. settings, "server",
  460. QT_TO_UTF8(ui->customServer->text().trimmed()));
  461. }
  462. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  463. OBSService newService = obs_service_create(service_id, "temp_service",
  464. settings, nullptr);
  465. obs_service_release(newService);
  466. return newService;
  467. }
  468. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  469. {
  470. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  471. if (a) {
  472. bool validKey = !a->key().empty();
  473. if (validKey)
  474. ui->key->setText(QT_UTF8(a->key().c_str()));
  475. ui->streamKeyWidget->setVisible(false);
  476. ui->streamKeyLabel->setVisible(false);
  477. ui->connectAccount2->setVisible(false);
  478. ui->disconnectAccount->setVisible(true);
  479. ui->useStreamKeyAdv->setVisible(false);
  480. ui->connectedAccountLabel->setVisible(false);
  481. ui->connectedAccountText->setVisible(false);
  482. if (strcmp(a->service(), "Twitch") == 0) {
  483. ui->bandwidthTestEnable->setVisible(true);
  484. ui->twitchAddonLabel->setVisible(true);
  485. ui->twitchAddonDropdown->setVisible(true);
  486. }
  487. #if YOUTUBE_ENABLED
  488. if (IsYouTubeService(a->service())) {
  489. ui->key->clear();
  490. ui->connectedAccountLabel->setVisible(true);
  491. ui->connectedAccountText->setVisible(true);
  492. ui->connectedAccountText->setText(
  493. QTStr("Auth.LoadingChannel.Title"));
  494. std::string a_service = a->service();
  495. std::shared_ptr<YoutubeApiWrappers> ytAuth =
  496. std::dynamic_pointer_cast<YoutubeApiWrappers>(
  497. auth);
  498. auto act = [&]() {
  499. get_yt_ch_title(ui.get(), ytAuth.get());
  500. };
  501. QScopedPointer<QThread> thread(CreateQThread(act));
  502. thread->start();
  503. thread->wait();
  504. }
  505. #endif
  506. ui->bandwidthTestEnable->setChecked(false);
  507. }
  508. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  509. }
  510. void OBSBasicSettings::OnAuthConnected()
  511. {
  512. std::string service = QT_TO_UTF8(ui->service->currentText());
  513. Auth::Type type = Auth::AuthType(service);
  514. if (type == Auth::Type::OAuth_StreamKey ||
  515. type == Auth::Type::OAuth_LinkedAccount) {
  516. OnOAuthStreamKeyConnected();
  517. }
  518. if (!loading) {
  519. stream1Changed = true;
  520. EnableApplyButton(true);
  521. }
  522. }
  523. void OBSBasicSettings::on_connectAccount_clicked()
  524. {
  525. std::string service = QT_TO_UTF8(ui->service->currentText());
  526. OAuth::DeleteCookies(service);
  527. auth = OAuthStreamKey::Login(this, service);
  528. if (!!auth) {
  529. OnAuthConnected();
  530. ui->useStreamKeyAdv->setVisible(false);
  531. }
  532. }
  533. #define DISCONNECT_COMFIRM_TITLE \
  534. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  535. #define DISCONNECT_COMFIRM_TEXT \
  536. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  537. void OBSBasicSettings::on_disconnectAccount_clicked()
  538. {
  539. QMessageBox::StandardButton button;
  540. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  541. QTStr(DISCONNECT_COMFIRM_TEXT));
  542. if (button == QMessageBox::No) {
  543. return;
  544. }
  545. main->auth.reset();
  546. auth.reset();
  547. std::string service = QT_TO_UTF8(ui->service->currentText());
  548. #ifdef BROWSER_AVAILABLE
  549. OAuth::DeleteCookies(service);
  550. #endif
  551. ui->bandwidthTestEnable->setChecked(false);
  552. reset_service_ui_fields(ui.get(), service, loading);
  553. ui->bandwidthTestEnable->setVisible(false);
  554. ui->twitchAddonDropdown->setVisible(false);
  555. ui->twitchAddonLabel->setVisible(false);
  556. ui->key->setText("");
  557. ui->connectedAccountLabel->setVisible(false);
  558. ui->connectedAccountText->setVisible(false);
  559. }
  560. void OBSBasicSettings::on_useStreamKey_clicked()
  561. {
  562. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  563. }
  564. void OBSBasicSettings::on_useAuth_toggled()
  565. {
  566. if (!IsCustomService())
  567. return;
  568. bool use_auth = ui->useAuth->isChecked();
  569. ui->authUsernameLabel->setVisible(use_auth);
  570. ui->authUsername->setVisible(use_auth);
  571. ui->authPwLabel->setVisible(use_auth);
  572. ui->authPwWidget->setVisible(use_auth);
  573. }
  574. void OBSBasicSettings::UpdateVodTrackSetting()
  575. {
  576. bool enableForCustomServer = config_get_bool(
  577. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  578. bool enableVodTrack = ui->service->currentText() == "Twitch";
  579. bool wasEnabled = !!vodTrackCheckbox;
  580. if (enableForCustomServer && IsCustomService())
  581. enableVodTrack = true;
  582. if (enableVodTrack == wasEnabled)
  583. return;
  584. if (!enableVodTrack) {
  585. delete vodTrackCheckbox;
  586. delete vodTrackContainer;
  587. delete simpleVodTrack;
  588. return;
  589. }
  590. /* -------------------------------------- */
  591. /* simple output mode vod track widgets */
  592. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  593. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  594. "VodTrackEnabled");
  595. simpleVodTrack = new QCheckBox(this);
  596. simpleVodTrack->setText(
  597. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  598. simpleVodTrack->setVisible(simpleAdv);
  599. simpleVodTrack->setChecked(vodTrackEnabled);
  600. int pos;
  601. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  602. &pos, nullptr);
  603. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  604. HookWidget(simpleVodTrack, SIGNAL(clicked(bool)),
  605. SLOT(OutputsChanged()));
  606. connect(ui->simpleOutAdvanced, SIGNAL(toggled(bool)),
  607. simpleVodTrack.data(), SLOT(setVisible(bool)));
  608. /* -------------------------------------- */
  609. /* advanced output mode vod track widgets */
  610. vodTrackCheckbox = new QCheckBox(this);
  611. vodTrackCheckbox->setText(
  612. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  613. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  614. vodTrackContainer = new QWidget(this);
  615. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  616. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  617. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  618. vodTrackLayout->addWidget(vodTrack[i]);
  619. HookWidget(vodTrack[i], SIGNAL(clicked(bool)),
  620. SLOT(OutputsChanged()));
  621. }
  622. HookWidget(vodTrackCheckbox, SIGNAL(clicked(bool)),
  623. SLOT(OutputsChanged()));
  624. vodTrackLayout->addStretch();
  625. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  626. vodTrackContainer->setLayout(vodTrackLayout);
  627. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  628. vodTrackEnabled =
  629. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  630. vodTrackCheckbox->setChecked(vodTrackEnabled);
  631. vodTrackContainer->setEnabled(vodTrackEnabled);
  632. connect(vodTrackCheckbox, SIGNAL(clicked(bool)), vodTrackContainer,
  633. SLOT(setEnabled(bool)));
  634. int trackIndex =
  635. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  636. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  637. vodTrack[i]->setChecked((i + 1) == trackIndex);
  638. }
  639. }
  640. OBSService OBSBasicSettings::GetStream1Service()
  641. {
  642. return stream1Changed ? SpawnTempService()
  643. : OBSService(main->GetService());
  644. }
  645. void OBSBasicSettings::UpdateServiceRecommendations()
  646. {
  647. bool customServer = IsCustomService();
  648. ui->ignoreRecommended->setVisible(!customServer);
  649. ui->enforceSettingsLabel->setVisible(!customServer);
  650. OBSService service = GetStream1Service();
  651. int vbitrate, abitrate;
  652. BPtr<obs_service_resolution> res_list;
  653. size_t res_count;
  654. int fps;
  655. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  656. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  657. obs_service_get_max_fps(service, &fps);
  658. QString text;
  659. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  660. if (vbitrate)
  661. text += ENFORCE_TEXT("MaxVideoBitrate")
  662. .arg(QString::number(vbitrate));
  663. if (abitrate) {
  664. if (!text.isEmpty())
  665. text += "\n";
  666. text += ENFORCE_TEXT("MaxAudioBitrate")
  667. .arg(QString::number(abitrate));
  668. }
  669. if (res_count) {
  670. if (!text.isEmpty())
  671. text += "\n";
  672. obs_service_resolution best_res = {};
  673. int best_res_pixels = 0;
  674. for (size_t i = 0; i < res_count; i++) {
  675. obs_service_resolution res = res_list[i];
  676. int res_pixels = res.cx + res.cy;
  677. if (res_pixels > best_res_pixels) {
  678. best_res = res;
  679. best_res_pixels = res_pixels;
  680. }
  681. }
  682. QString res_str =
  683. QString("%1x%2").arg(QString::number(best_res.cx),
  684. QString::number(best_res.cy));
  685. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  686. }
  687. if (fps) {
  688. if (!text.isEmpty())
  689. text += "\n";
  690. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  691. }
  692. #undef ENFORCE_TEXT
  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. }