window-basic-settings-stream.cpp 31 KB

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