window-basic-settings-stream.cpp 31 KB

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