window-basic-settings-stream.cpp 31 KB

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