window-basic-settings-stream.cpp 29 KB

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