window-basic-settings-stream.cpp 27 KB

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