window-basic-settings-stream.cpp 27 KB

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