1
0

window-basic-settings-stream.cpp 28 KB

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