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->service, SIGNAL(currentIndexChanged(int)), this,
  78. SLOT(UpdateMoreInfoLink()));
  79. }
  80. void OBSBasicSettings::LoadStream1Settings()
  81. {
  82. bool ignoreRecommended =
  83. config_get_bool(main->Config(), "Stream1", "IgnoreRecommended");
  84. obs_service_t *service_obj = main->GetService();
  85. const char *type = obs_service_get_type(service_obj);
  86. loading = true;
  87. obs_data_t *settings = obs_service_get_settings(service_obj);
  88. const char *service = obs_data_get_string(settings, "service");
  89. const char *server = obs_data_get_string(settings, "server");
  90. const char *key = obs_data_get_string(settings, "key");
  91. if (strcmp(type, "rtmp_custom") == 0) {
  92. ui->service->setCurrentIndex(0);
  93. ui->customServer->setText(server);
  94. bool use_auth = obs_data_get_bool(settings, "use_auth");
  95. const char *username =
  96. obs_data_get_string(settings, "username");
  97. const char *password =
  98. obs_data_get_string(settings, "password");
  99. ui->authUsername->setText(QT_UTF8(username));
  100. ui->authPw->setText(QT_UTF8(password));
  101. ui->useAuth->setChecked(use_auth);
  102. } else {
  103. int idx = ui->service->findText(service);
  104. if (idx == -1) {
  105. if (service && *service)
  106. ui->service->insertItem(1, service);
  107. idx = 1;
  108. }
  109. ui->service->setCurrentIndex(idx);
  110. bool bw_test = obs_data_get_bool(settings, "bwtest");
  111. ui->bandwidthTestEnable->setChecked(bw_test);
  112. idx = config_get_int(main->Config(), "Twitch", "AddonChoice");
  113. ui->twitchAddonDropdown->setCurrentIndex(idx);
  114. }
  115. UpdateServerList();
  116. if (strcmp(type, "rtmp_common") == 0) {
  117. int idx = ui->server->findData(server);
  118. if (idx == -1) {
  119. if (server && *server)
  120. ui->server->insertItem(0, server, server);
  121. idx = 0;
  122. }
  123. ui->server->setCurrentIndex(idx);
  124. }
  125. ui->key->setText(key);
  126. lastService.clear();
  127. on_service_currentIndexChanged(0);
  128. obs_data_release(settings);
  129. UpdateKeyLink();
  130. UpdateMoreInfoLink();
  131. UpdateVodTrackSetting();
  132. UpdateServiceRecommendations();
  133. bool streamActive = obs_frontend_streaming_active();
  134. ui->streamPage->setEnabled(!streamActive);
  135. ui->ignoreRecommended->setChecked(ignoreRecommended);
  136. loading = false;
  137. QMetaObject::invokeMethod(this, "UpdateResFPSLimits",
  138. Qt::QueuedConnection);
  139. }
  140. void OBSBasicSettings::SaveStream1Settings()
  141. {
  142. bool customServer = IsCustomService();
  143. const char *service_id = customServer ? "rtmp_custom" : "rtmp_common";
  144. obs_service_t *oldService = main->GetService();
  145. OBSData hotkeyData = obs_hotkeys_save_service(oldService);
  146. obs_data_release(hotkeyData);
  147. OBSData settings = obs_data_create();
  148. obs_data_release(settings);
  149. if (!customServer) {
  150. obs_data_set_string(settings, "service",
  151. QT_TO_UTF8(ui->service->currentText()));
  152. obs_data_set_string(
  153. settings, "server",
  154. QT_TO_UTF8(ui->server->currentData().toString()));
  155. } else {
  156. obs_data_set_string(
  157. settings, "server",
  158. QT_TO_UTF8(ui->customServer->text().trimmed()));
  159. obs_data_set_bool(settings, "use_auth",
  160. ui->useAuth->isChecked());
  161. if (ui->useAuth->isChecked()) {
  162. obs_data_set_string(
  163. settings, "username",
  164. QT_TO_UTF8(ui->authUsername->text()));
  165. obs_data_set_string(settings, "password",
  166. QT_TO_UTF8(ui->authPw->text()));
  167. }
  168. }
  169. if (!!auth && strcmp(auth->service(), "Twitch") == 0) {
  170. bool choiceExists = config_has_user_value(
  171. main->Config(), "Twitch", "AddonChoice");
  172. int currentChoice =
  173. config_get_int(main->Config(), "Twitch", "AddonChoice");
  174. int newChoice = ui->twitchAddonDropdown->currentIndex();
  175. config_set_int(main->Config(), "Twitch", "AddonChoice",
  176. newChoice);
  177. if (choiceExists && currentChoice != newChoice)
  178. forceAuthReload = true;
  179. obs_data_set_bool(settings, "bwtest",
  180. ui->bandwidthTestEnable->isChecked());
  181. } else {
  182. obs_data_set_bool(settings, "bwtest", false);
  183. }
  184. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  185. OBSService newService = obs_service_create(
  186. service_id, "default_service", settings, hotkeyData);
  187. obs_service_release(newService);
  188. if (!newService)
  189. return;
  190. main->SetService(newService);
  191. main->SaveService();
  192. main->auth = auth;
  193. if (!!main->auth) {
  194. main->auth->LoadUI();
  195. main->SetBroadcastFlowEnabled(main->auth->broadcastFlow());
  196. } else {
  197. main->SetBroadcastFlowEnabled(false);
  198. }
  199. SaveCheckBox(ui->ignoreRecommended, "Stream1", "IgnoreRecommended");
  200. }
  201. void OBSBasicSettings::UpdateMoreInfoLink()
  202. {
  203. if (IsCustomService()) {
  204. ui->moreInfoButton->hide();
  205. return;
  206. }
  207. QString serviceName = ui->service->currentText();
  208. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  209. obs_property_t *services = obs_properties_get(props, "service");
  210. OBSData settings = obs_data_create();
  211. obs_data_release(settings);
  212. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  213. obs_property_modified(services, settings);
  214. const char *more_info_link =
  215. obs_data_get_string(settings, "more_info_link");
  216. if (!more_info_link || (*more_info_link == '\0')) {
  217. ui->moreInfoButton->hide();
  218. } else {
  219. ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
  220. ui->moreInfoButton->show();
  221. }
  222. obs_properties_destroy(props);
  223. }
  224. void OBSBasicSettings::UpdateKeyLink()
  225. {
  226. QString serviceName = ui->service->currentText();
  227. QString customServer = ui->customServer->text().trimmed();
  228. QString streamKeyLink;
  229. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  230. obs_property_t *services = obs_properties_get(props, "service");
  231. OBSData settings = obs_data_create();
  232. obs_data_release(settings);
  233. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  234. obs_property_modified(services, settings);
  235. streamKeyLink = obs_data_get_string(settings, "stream_key_link");
  236. if (customServer.contains("fbcdn.net") && IsCustomService()) {
  237. streamKeyLink =
  238. "https://www.facebook.com/live/producer?ref=OBS";
  239. }
  240. if (serviceName == "Dacast") {
  241. ui->streamKeyLabel->setText(
  242. QTStr("Basic.AutoConfig.StreamPage.EncoderKey"));
  243. } else {
  244. ui->streamKeyLabel->setText(
  245. QTStr("Basic.AutoConfig.StreamPage.StreamKey"));
  246. }
  247. if (QString(streamKeyLink).isNull() ||
  248. QString(streamKeyLink).isEmpty()) {
  249. ui->getStreamKeyButton->hide();
  250. } else {
  251. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  252. ui->getStreamKeyButton->show();
  253. }
  254. obs_properties_destroy(props);
  255. }
  256. void OBSBasicSettings::LoadServices(bool showAll)
  257. {
  258. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  259. OBSData settings = obs_data_create();
  260. obs_data_release(settings);
  261. obs_data_set_bool(settings, "show_all", showAll);
  262. obs_property_t *prop = obs_properties_get(props, "show_all");
  263. obs_property_modified(prop, settings);
  264. ui->service->blockSignals(true);
  265. ui->service->clear();
  266. QStringList names;
  267. obs_property_t *services = obs_properties_get(props, "service");
  268. size_t services_count = obs_property_list_item_count(services);
  269. for (size_t i = 0; i < services_count; i++) {
  270. const char *name = obs_property_list_item_string(services, i);
  271. names.push_back(name);
  272. }
  273. if (showAll)
  274. names.sort(Qt::CaseInsensitive);
  275. for (QString &name : names)
  276. ui->service->addItem(name);
  277. if (!showAll) {
  278. ui->service->addItem(
  279. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  280. QVariant((int)ListOpt::ShowAll));
  281. }
  282. ui->service->insertItem(
  283. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  284. QVariant((int)ListOpt::Custom));
  285. if (!lastService.isEmpty()) {
  286. int idx = ui->service->findText(lastService);
  287. if (idx != -1)
  288. ui->service->setCurrentIndex(idx);
  289. }
  290. obs_properties_destroy(props);
  291. ui->service->blockSignals(false);
  292. }
  293. static inline bool is_auth_service(const std::string &service)
  294. {
  295. return Auth::AuthType(service) != Auth::Type::None;
  296. }
  297. static inline bool is_external_oauth(const std::string &service)
  298. {
  299. return Auth::External(service);
  300. }
  301. static void reset_service_ui_fields(Ui::OBSBasicSettings *ui,
  302. std::string &service, bool loading)
  303. {
  304. bool external_oauth = is_external_oauth(service);
  305. if (external_oauth) {
  306. ui->streamKeyWidget->setVisible(false);
  307. ui->streamKeyLabel->setVisible(false);
  308. ui->connectAccount2->setVisible(true);
  309. ui->useStreamKeyAdv->setVisible(true);
  310. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  311. } else if (cef) {
  312. QString key = ui->key->text();
  313. bool can_auth = is_auth_service(service);
  314. int page = can_auth && (!loading || key.isEmpty())
  315. ? (int)Section::Connect
  316. : (int)Section::StreamKey;
  317. ui->streamStackWidget->setCurrentIndex(page);
  318. ui->streamKeyWidget->setVisible(true);
  319. ui->streamKeyLabel->setVisible(true);
  320. ui->connectAccount2->setVisible(can_auth);
  321. ui->useStreamKeyAdv->setVisible(false);
  322. } else {
  323. ui->connectAccount2->setVisible(false);
  324. ui->useStreamKeyAdv->setVisible(false);
  325. }
  326. ui->connectedAccountLabel->setVisible(false);
  327. ui->connectedAccountText->setVisible(false);
  328. ui->disconnectAccount->setVisible(false);
  329. }
  330. #if YOUTUBE_ENABLED
  331. static void get_yt_ch_title(Ui::OBSBasicSettings *ui)
  332. {
  333. const char *name = config_get_string(OBSBasic::Get()->Config(),
  334. "YouTube", "ChannelName");
  335. if (name) {
  336. ui->connectedAccountText->setText(name);
  337. } else {
  338. // if we still not changed the service page
  339. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  340. ui->connectedAccountText->setText(
  341. QTStr("Auth.LoadingChannel.Error"));
  342. }
  343. }
  344. }
  345. #endif
  346. void OBSBasicSettings::UseStreamKeyAdvClicked()
  347. {
  348. ui->streamKeyWidget->setVisible(true);
  349. }
  350. void OBSBasicSettings::on_service_currentIndexChanged(int)
  351. {
  352. bool showMore = ui->service->currentData().toInt() ==
  353. (int)ListOpt::ShowAll;
  354. if (showMore)
  355. return;
  356. std::string service = QT_TO_UTF8(ui->service->currentText());
  357. bool custom = IsCustomService();
  358. ui->disconnectAccount->setVisible(false);
  359. ui->bandwidthTestEnable->setVisible(false);
  360. ui->twitchAddonDropdown->setVisible(false);
  361. ui->twitchAddonLabel->setVisible(false);
  362. if (lastService != service.c_str()) {
  363. reset_service_ui_fields(ui.get(), service, loading);
  364. }
  365. ui->useAuth->setVisible(custom);
  366. ui->authUsernameLabel->setVisible(custom);
  367. ui->authUsername->setVisible(custom);
  368. ui->authPwLabel->setVisible(custom);
  369. ui->authPwWidget->setVisible(custom);
  370. if (custom) {
  371. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  372. ui->serverStackedWidget);
  373. ui->serverStackedWidget->setCurrentIndex(1);
  374. ui->serverStackedWidget->setVisible(true);
  375. ui->serverLabel->setVisible(true);
  376. on_useAuth_toggled();
  377. } else {
  378. ui->serverStackedWidget->setCurrentIndex(0);
  379. }
  380. auth.reset();
  381. if (!main->auth) {
  382. return;
  383. }
  384. auto system_auth_service = main->auth->service();
  385. bool service_check = service.find(system_auth_service) !=
  386. std::string::npos;
  387. #if YOUTUBE_ENABLED
  388. service_check = service_check ? service_check
  389. : IsYouTubeService(system_auth_service) &&
  390. IsYouTubeService(service);
  391. #endif
  392. if (service_check) {
  393. auth = main->auth;
  394. OnAuthConnected();
  395. }
  396. }
  397. void OBSBasicSettings::UpdateServerList()
  398. {
  399. QString serviceName = ui->service->currentText();
  400. bool showMore = ui->service->currentData().toInt() ==
  401. (int)ListOpt::ShowAll;
  402. if (showMore) {
  403. LoadServices(true);
  404. ui->service->showPopup();
  405. return;
  406. } else {
  407. lastService = serviceName;
  408. }
  409. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  410. obs_property_t *services = obs_properties_get(props, "service");
  411. OBSData settings = obs_data_create();
  412. obs_data_release(settings);
  413. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  414. obs_property_modified(services, settings);
  415. obs_property_t *servers = obs_properties_get(props, "server");
  416. ui->server->clear();
  417. size_t servers_count = obs_property_list_item_count(servers);
  418. for (size_t i = 0; i < servers_count; i++) {
  419. const char *name = obs_property_list_item_name(servers, i);
  420. const char *server = obs_property_list_item_string(servers, i);
  421. ui->server->addItem(name, server);
  422. }
  423. obs_properties_destroy(props);
  424. }
  425. void OBSBasicSettings::on_show_clicked()
  426. {
  427. if (ui->key->echoMode() == QLineEdit::Password) {
  428. ui->key->setEchoMode(QLineEdit::Normal);
  429. ui->show->setText(QTStr("Hide"));
  430. } else {
  431. ui->key->setEchoMode(QLineEdit::Password);
  432. ui->show->setText(QTStr("Show"));
  433. }
  434. }
  435. void OBSBasicSettings::on_authPwShow_clicked()
  436. {
  437. if (ui->authPw->echoMode() == QLineEdit::Password) {
  438. ui->authPw->setEchoMode(QLineEdit::Normal);
  439. ui->authPwShow->setText(QTStr("Hide"));
  440. } else {
  441. ui->authPw->setEchoMode(QLineEdit::Password);
  442. ui->authPwShow->setText(QTStr("Show"));
  443. }
  444. }
  445. OBSService OBSBasicSettings::SpawnTempService()
  446. {
  447. bool custom = IsCustomService();
  448. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  449. OBSData settings = obs_data_create();
  450. obs_data_release(settings);
  451. if (!custom) {
  452. obs_data_set_string(settings, "service",
  453. QT_TO_UTF8(ui->service->currentText()));
  454. obs_data_set_string(
  455. settings, "server",
  456. QT_TO_UTF8(ui->server->currentData().toString()));
  457. } else {
  458. obs_data_set_string(
  459. settings, "server",
  460. QT_TO_UTF8(ui->customServer->text().trimmed()));
  461. }
  462. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  463. OBSService newService = obs_service_create(service_id, "temp_service",
  464. settings, nullptr);
  465. obs_service_release(newService);
  466. return newService;
  467. }
  468. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  469. {
  470. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  471. if (a) {
  472. bool validKey = !a->key().empty();
  473. if (validKey)
  474. ui->key->setText(QT_UTF8(a->key().c_str()));
  475. ui->streamKeyWidget->setVisible(false);
  476. ui->streamKeyLabel->setVisible(false);
  477. ui->connectAccount2->setVisible(false);
  478. ui->disconnectAccount->setVisible(true);
  479. ui->useStreamKeyAdv->setVisible(false);
  480. ui->connectedAccountLabel->setVisible(false);
  481. ui->connectedAccountText->setVisible(false);
  482. if (strcmp(a->service(), "Twitch") == 0) {
  483. ui->bandwidthTestEnable->setVisible(true);
  484. ui->twitchAddonLabel->setVisible(true);
  485. ui->twitchAddonDropdown->setVisible(true);
  486. } else {
  487. ui->bandwidthTestEnable->setChecked(false);
  488. }
  489. #if YOUTUBE_ENABLED
  490. if (IsYouTubeService(a->service())) {
  491. ui->key->clear();
  492. ui->connectedAccountLabel->setVisible(true);
  493. ui->connectedAccountText->setVisible(true);
  494. ui->connectedAccountText->setText(
  495. QTStr("Auth.LoadingChannel.Title"));
  496. get_yt_ch_title(ui.get());
  497. }
  498. #endif
  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. }