window-basic-settings-stream.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  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. #ifdef 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. WHIP,
  25. };
  26. enum class Section : int {
  27. Connect,
  28. StreamKey,
  29. };
  30. inline bool OBSBasicSettings::IsCustomService() const
  31. {
  32. return ui->service->currentData().toInt() == (int)ListOpt::Custom;
  33. }
  34. inline bool OBSBasicSettings::IsWHIP() const
  35. {
  36. return ui->service->currentData().toInt() == (int)ListOpt::WHIP;
  37. }
  38. void OBSBasicSettings::InitStreamPage()
  39. {
  40. ui->connectAccount2->setVisible(false);
  41. ui->disconnectAccount->setVisible(false);
  42. ui->bandwidthTestEnable->setVisible(false);
  43. ui->twitchAddonDropdown->setVisible(false);
  44. ui->twitchAddonLabel->setVisible(false);
  45. ui->connectedAccountLabel->setVisible(false);
  46. ui->connectedAccountText->setVisible(false);
  47. int vertSpacing = ui->topStreamLayout->verticalSpacing();
  48. QMargins m = ui->topStreamLayout->contentsMargins();
  49. m.setBottom(vertSpacing / 2);
  50. ui->topStreamLayout->setContentsMargins(m);
  51. m = ui->loginPageLayout->contentsMargins();
  52. m.setTop(vertSpacing / 2);
  53. ui->loginPageLayout->setContentsMargins(m);
  54. m = ui->streamkeyPageLayout->contentsMargins();
  55. m.setTop(vertSpacing / 2);
  56. ui->streamkeyPageLayout->setContentsMargins(m);
  57. LoadServices(false);
  58. ui->twitchAddonDropdown->addItem(
  59. QTStr("Basic.Settings.Stream.TTVAddon.None"));
  60. ui->twitchAddonDropdown->addItem(
  61. QTStr("Basic.Settings.Stream.TTVAddon.BTTV"));
  62. ui->twitchAddonDropdown->addItem(
  63. QTStr("Basic.Settings.Stream.TTVAddon.FFZ"));
  64. ui->twitchAddonDropdown->addItem(
  65. QTStr("Basic.Settings.Stream.TTVAddon.Both"));
  66. connect(ui->ignoreRecommended, &QCheckBox::clicked, this,
  67. &OBSBasicSettings::DisplayEnforceWarning);
  68. connect(ui->ignoreRecommended, &QCheckBox::toggled, this,
  69. &OBSBasicSettings::UpdateResFPSLimits);
  70. }
  71. void OBSBasicSettings::LoadStream1Settings()
  72. {
  73. bool ignoreRecommended =
  74. config_get_bool(main->Config(), "Stream1", "IgnoreRecommended");
  75. obs_service_t *service_obj = main->GetService();
  76. const char *type = obs_service_get_type(service_obj);
  77. bool is_rtmp_custom = (strcmp(type, "rtmp_custom") == 0);
  78. bool is_rtmp_common = (strcmp(type, "rtmp_common") == 0);
  79. bool is_whip = (strcmp(type, "whip_custom") == 0);
  80. loading = true;
  81. OBSDataAutoRelease settings = obs_service_get_settings(service_obj);
  82. const char *service = obs_data_get_string(settings, "service");
  83. const char *server = obs_data_get_string(settings, "server");
  84. const char *key = obs_data_get_string(settings, "key");
  85. protocol = QT_UTF8(obs_service_get_protocol(service_obj));
  86. const char *bearer_token =
  87. obs_data_get_string(settings, "bearer_token");
  88. if (is_rtmp_custom || is_whip)
  89. ui->customServer->setText(server);
  90. if (is_rtmp_custom) {
  91. ui->service->setCurrentIndex(0);
  92. lastServiceIdx = 0;
  93. lastCustomServer = ui->customServer->text();
  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. /* add tooltips for stream key, user, password fields */
  103. QString file = !App()->IsThemeDark()
  104. ? ":/res/images/help.svg"
  105. : ":/res/images/help_light.svg";
  106. QString lStr = "<html>%1 <img src='%2' style=' \
  107. vertical-align: bottom; \
  108. ' /></html>";
  109. ui->streamKeyLabel->setText(
  110. lStr.arg(ui->streamKeyLabel->text(), file));
  111. ui->streamKeyLabel->setToolTip(
  112. QTStr("Basic.AutoConfig.StreamPage.StreamKey.ToolTip"));
  113. ui->authUsernameLabel->setText(
  114. lStr.arg(ui->authUsernameLabel->text(), file));
  115. ui->authUsernameLabel->setToolTip(
  116. QTStr("Basic.Settings.Stream.Custom.Username.ToolTip"));
  117. ui->authPwLabel->setText(
  118. lStr.arg(ui->authPwLabel->text(), file));
  119. ui->authPwLabel->setToolTip(
  120. QTStr("Basic.Settings.Stream.Custom.Password.ToolTip"));
  121. } else {
  122. int idx = ui->service->findText(service);
  123. if (idx == -1) {
  124. if (service && *service)
  125. ui->service->insertItem(1, service);
  126. idx = 1;
  127. }
  128. ui->service->setCurrentIndex(idx);
  129. lastServiceIdx = idx;
  130. bool bw_test = obs_data_get_bool(settings, "bwtest");
  131. ui->bandwidthTestEnable->setChecked(bw_test);
  132. idx = config_get_int(main->Config(), "Twitch", "AddonChoice");
  133. ui->twitchAddonDropdown->setCurrentIndex(idx);
  134. }
  135. UpdateServerList();
  136. if (is_rtmp_common) {
  137. int idx = ui->server->findData(server);
  138. if (idx == -1) {
  139. if (server && *server)
  140. ui->server->insertItem(0, server, server);
  141. idx = 0;
  142. }
  143. ui->server->setCurrentIndex(idx);
  144. }
  145. if (is_whip)
  146. ui->key->setText(bearer_token);
  147. else
  148. ui->key->setText(key);
  149. ServiceChanged();
  150. UpdateKeyLink();
  151. UpdateMoreInfoLink();
  152. UpdateVodTrackSetting();
  153. UpdateServiceRecommendations();
  154. bool streamActive = obs_frontend_streaming_active();
  155. ui->streamPage->setEnabled(!streamActive);
  156. ui->ignoreRecommended->setChecked(ignoreRecommended);
  157. loading = false;
  158. QMetaObject::invokeMethod(this, "UpdateResFPSLimits",
  159. Qt::QueuedConnection);
  160. }
  161. void OBSBasicSettings::SaveStream1Settings()
  162. {
  163. bool customServer = IsCustomService();
  164. bool whip = IsWHIP();
  165. const char *service_id = "rtmp_common";
  166. if (customServer) {
  167. service_id = "rtmp_custom";
  168. } else if (whip) {
  169. service_id = "whip_custom";
  170. }
  171. obs_service_t *oldService = main->GetService();
  172. OBSDataAutoRelease hotkeyData = obs_hotkeys_save_service(oldService);
  173. OBSDataAutoRelease settings = obs_data_create();
  174. if (!customServer && !whip) {
  175. obs_data_set_string(settings, "service",
  176. QT_TO_UTF8(ui->service->currentText()));
  177. obs_data_set_string(settings, "protocol", QT_TO_UTF8(protocol));
  178. obs_data_set_string(
  179. settings, "server",
  180. QT_TO_UTF8(ui->server->currentData().toString()));
  181. } else {
  182. obs_data_set_string(
  183. settings, "server",
  184. QT_TO_UTF8(ui->customServer->text().trimmed()));
  185. obs_data_set_bool(settings, "use_auth",
  186. ui->useAuth->isChecked());
  187. if (ui->useAuth->isChecked()) {
  188. obs_data_set_string(
  189. settings, "username",
  190. QT_TO_UTF8(ui->authUsername->text()));
  191. obs_data_set_string(settings, "password",
  192. QT_TO_UTF8(ui->authPw->text()));
  193. }
  194. }
  195. if (!!auth && strcmp(auth->service(), "Twitch") == 0) {
  196. bool choiceExists = config_has_user_value(
  197. main->Config(), "Twitch", "AddonChoice");
  198. int currentChoice =
  199. config_get_int(main->Config(), "Twitch", "AddonChoice");
  200. int newChoice = ui->twitchAddonDropdown->currentIndex();
  201. config_set_int(main->Config(), "Twitch", "AddonChoice",
  202. newChoice);
  203. if (choiceExists && currentChoice != newChoice)
  204. forceAuthReload = true;
  205. obs_data_set_bool(settings, "bwtest",
  206. ui->bandwidthTestEnable->isChecked());
  207. } else {
  208. obs_data_set_bool(settings, "bwtest", false);
  209. }
  210. if (whip) {
  211. obs_data_set_string(settings, "service", "WHIP");
  212. obs_data_set_string(settings, "bearer_token",
  213. QT_TO_UTF8(ui->key->text()));
  214. } else {
  215. obs_data_set_string(settings, "key",
  216. QT_TO_UTF8(ui->key->text()));
  217. }
  218. OBSServiceAutoRelease newService = obs_service_create(
  219. service_id, "default_service", settings, hotkeyData);
  220. if (!newService)
  221. return;
  222. main->SetService(newService);
  223. main->SaveService();
  224. main->auth = auth;
  225. if (!!main->auth) {
  226. main->auth->LoadUI();
  227. main->SetBroadcastFlowEnabled(main->auth->broadcastFlow());
  228. } else {
  229. main->SetBroadcastFlowEnabled(false);
  230. }
  231. SaveCheckBox(ui->ignoreRecommended, "Stream1", "IgnoreRecommended");
  232. }
  233. void OBSBasicSettings::UpdateMoreInfoLink()
  234. {
  235. if (IsCustomService() || IsWHIP()) {
  236. ui->moreInfoButton->hide();
  237. return;
  238. }
  239. QString serviceName = ui->service->currentText();
  240. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  241. obs_property_t *services = obs_properties_get(props, "service");
  242. OBSDataAutoRelease settings = obs_data_create();
  243. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  244. obs_property_modified(services, settings);
  245. const char *more_info_link =
  246. obs_data_get_string(settings, "more_info_link");
  247. if (!more_info_link || (*more_info_link == '\0')) {
  248. ui->moreInfoButton->hide();
  249. } else {
  250. ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
  251. ui->moreInfoButton->show();
  252. }
  253. obs_properties_destroy(props);
  254. }
  255. void OBSBasicSettings::UpdateKeyLink()
  256. {
  257. QString serviceName = ui->service->currentText();
  258. QString customServer = ui->customServer->text().trimmed();
  259. QString streamKeyLink;
  260. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  261. obs_property_t *services = obs_properties_get(props, "service");
  262. OBSDataAutoRelease settings = obs_data_create();
  263. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  264. obs_property_modified(services, settings);
  265. streamKeyLink = obs_data_get_string(settings, "stream_key_link");
  266. if (customServer.contains("fbcdn.net") && IsCustomService()) {
  267. streamKeyLink =
  268. "https://www.facebook.com/live/producer?ref=OBS";
  269. }
  270. if (serviceName == "Dacast") {
  271. ui->streamKeyLabel->setText(
  272. QTStr("Basic.AutoConfig.StreamPage.EncoderKey"));
  273. } else if (IsWHIP()) {
  274. ui->streamKeyLabel->setText(
  275. QTStr("Basic.AutoConfig.StreamPage.BearerToken"));
  276. } else if (!IsCustomService()) {
  277. ui->streamKeyLabel->setText(
  278. QTStr("Basic.AutoConfig.StreamPage.StreamKey"));
  279. }
  280. if (QString(streamKeyLink).isNull() ||
  281. QString(streamKeyLink).isEmpty()) {
  282. ui->getStreamKeyButton->hide();
  283. } else {
  284. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  285. ui->getStreamKeyButton->show();
  286. }
  287. obs_properties_destroy(props);
  288. }
  289. void OBSBasicSettings::LoadServices(bool showAll)
  290. {
  291. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  292. OBSDataAutoRelease settings = obs_data_create();
  293. obs_data_set_bool(settings, "show_all", showAll);
  294. obs_property_t *prop = obs_properties_get(props, "show_all");
  295. obs_property_modified(prop, settings);
  296. ui->service->blockSignals(true);
  297. ui->service->clear();
  298. QStringList names;
  299. obs_property_t *services = obs_properties_get(props, "service");
  300. size_t services_count = obs_property_list_item_count(services);
  301. for (size_t i = 0; i < services_count; i++) {
  302. const char *name = obs_property_list_item_string(services, i);
  303. names.push_back(name);
  304. }
  305. if (showAll)
  306. names.sort(Qt::CaseInsensitive);
  307. for (QString &name : names)
  308. ui->service->addItem(name);
  309. if (obs_is_output_protocol_registered("WHIP")) {
  310. ui->service->addItem(QTStr("WHIP"),
  311. QVariant((int)ListOpt::WHIP));
  312. }
  313. if (!showAll) {
  314. ui->service->addItem(
  315. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  316. QVariant((int)ListOpt::ShowAll));
  317. }
  318. ui->service->insertItem(
  319. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  320. QVariant((int)ListOpt::Custom));
  321. if (!lastService.isEmpty()) {
  322. int idx = ui->service->findText(lastService);
  323. if (idx != -1)
  324. ui->service->setCurrentIndex(idx);
  325. }
  326. obs_properties_destroy(props);
  327. ui->service->blockSignals(false);
  328. }
  329. static inline bool is_auth_service(const std::string &service)
  330. {
  331. return Auth::AuthType(service) != Auth::Type::None;
  332. }
  333. static inline bool is_external_oauth(const std::string &service)
  334. {
  335. return Auth::External(service);
  336. }
  337. static void reset_service_ui_fields(Ui::OBSBasicSettings *ui,
  338. std::string &service, bool loading)
  339. {
  340. bool external_oauth = is_external_oauth(service);
  341. if (external_oauth) {
  342. ui->streamKeyWidget->setVisible(false);
  343. ui->streamKeyLabel->setVisible(false);
  344. ui->connectAccount2->setVisible(true);
  345. ui->useStreamKeyAdv->setVisible(true);
  346. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  347. } else if (cef) {
  348. QString key = ui->key->text();
  349. bool can_auth = is_auth_service(service);
  350. int page = can_auth && (!loading || key.isEmpty())
  351. ? (int)Section::Connect
  352. : (int)Section::StreamKey;
  353. ui->streamStackWidget->setCurrentIndex(page);
  354. ui->streamKeyWidget->setVisible(true);
  355. ui->streamKeyLabel->setVisible(true);
  356. ui->connectAccount2->setVisible(can_auth);
  357. ui->useStreamKeyAdv->setVisible(false);
  358. } else {
  359. ui->connectAccount2->setVisible(false);
  360. ui->useStreamKeyAdv->setVisible(false);
  361. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  362. }
  363. ui->connectedAccountLabel->setVisible(false);
  364. ui->connectedAccountText->setVisible(false);
  365. ui->disconnectAccount->setVisible(false);
  366. }
  367. #ifdef YOUTUBE_ENABLED
  368. static void get_yt_ch_title(Ui::OBSBasicSettings *ui)
  369. {
  370. const char *name = config_get_string(OBSBasic::Get()->Config(),
  371. "YouTube", "ChannelName");
  372. if (name) {
  373. ui->connectedAccountText->setText(name);
  374. } else {
  375. // if we still not changed the service page
  376. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  377. ui->connectedAccountText->setText(
  378. QTStr("Auth.LoadingChannel.Error"));
  379. }
  380. }
  381. }
  382. #endif
  383. void OBSBasicSettings::UseStreamKeyAdvClicked()
  384. {
  385. ui->streamKeyWidget->setVisible(true);
  386. }
  387. void OBSBasicSettings::on_service_currentIndexChanged(int idx)
  388. {
  389. if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll) {
  390. LoadServices(true);
  391. ui->service->showPopup();
  392. return;
  393. }
  394. ServiceChanged();
  395. UpdateMoreInfoLink();
  396. UpdateServerList();
  397. UpdateKeyLink();
  398. UpdateServiceRecommendations();
  399. UpdateVodTrackSetting();
  400. protocol = FindProtocol();
  401. UpdateAdvNetworkGroup();
  402. if (ServiceSupportsCodecCheck() && UpdateResFPSLimits()) {
  403. lastServiceIdx = idx;
  404. if (idx == 0)
  405. lastCustomServer = ui->customServer->text();
  406. }
  407. }
  408. void OBSBasicSettings::on_customServer_textChanged(const QString &)
  409. {
  410. UpdateKeyLink();
  411. protocol = FindProtocol();
  412. UpdateAdvNetworkGroup();
  413. if (ServiceSupportsCodecCheck())
  414. lastCustomServer = ui->customServer->text();
  415. }
  416. void OBSBasicSettings::ServiceChanged()
  417. {
  418. std::string service = QT_TO_UTF8(ui->service->currentText());
  419. bool custom = IsCustomService();
  420. bool whip = IsWHIP();
  421. ui->disconnectAccount->setVisible(false);
  422. ui->bandwidthTestEnable->setVisible(false);
  423. ui->twitchAddonDropdown->setVisible(false);
  424. ui->twitchAddonLabel->setVisible(false);
  425. if (lastService != service.c_str()) {
  426. reset_service_ui_fields(ui.get(), service, loading);
  427. }
  428. ui->useAuth->setVisible(custom);
  429. ui->authUsernameLabel->setVisible(custom);
  430. ui->authUsername->setVisible(custom);
  431. ui->authPwLabel->setVisible(custom);
  432. ui->authPwWidget->setVisible(custom);
  433. if (custom || whip) {
  434. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  435. ui->serverStackedWidget);
  436. ui->serverStackedWidget->setCurrentIndex(1);
  437. ui->serverStackedWidget->setVisible(true);
  438. ui->serverLabel->setVisible(true);
  439. on_useAuth_toggled();
  440. } else {
  441. ui->serverStackedWidget->setCurrentIndex(0);
  442. }
  443. auth.reset();
  444. if (!main->auth) {
  445. return;
  446. }
  447. auto system_auth_service = main->auth->service();
  448. bool service_check = service.find(system_auth_service) !=
  449. std::string::npos;
  450. #ifdef YOUTUBE_ENABLED
  451. service_check = service_check ? service_check
  452. : IsYouTubeService(system_auth_service) &&
  453. IsYouTubeService(service);
  454. #endif
  455. if (service_check) {
  456. auth = main->auth;
  457. OnAuthConnected();
  458. }
  459. }
  460. QString OBSBasicSettings::FindProtocol()
  461. {
  462. if (IsCustomService()) {
  463. if (ui->customServer->text().isEmpty())
  464. return QString("RTMP");
  465. QString server = ui->customServer->text();
  466. if (obs_is_output_protocol_registered("RTMPS") &&
  467. server.startsWith("rtmps://"))
  468. return QString("RTMPS");
  469. if (server.startsWith("ftl://"))
  470. return QString("FTL");
  471. if (server.startsWith("srt://"))
  472. return QString("SRT");
  473. if (server.startsWith("rist://"))
  474. return QString("RIST");
  475. } else {
  476. obs_properties_t *props =
  477. obs_get_service_properties("rtmp_common");
  478. obs_property_t *services = obs_properties_get(props, "service");
  479. OBSDataAutoRelease settings = obs_data_create();
  480. obs_data_set_string(settings, "service",
  481. QT_TO_UTF8(ui->service->currentText()));
  482. obs_property_modified(services, settings);
  483. obs_properties_destroy(props);
  484. const char *protocol =
  485. obs_data_get_string(settings, "protocol");
  486. if (protocol && *protocol)
  487. return QT_UTF8(protocol);
  488. }
  489. return QString("RTMP");
  490. }
  491. void OBSBasicSettings::UpdateServerList()
  492. {
  493. QString serviceName = ui->service->currentText();
  494. lastService = serviceName;
  495. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  496. obs_property_t *services = obs_properties_get(props, "service");
  497. OBSDataAutoRelease settings = obs_data_create();
  498. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  499. obs_property_modified(services, settings);
  500. obs_property_t *servers = obs_properties_get(props, "server");
  501. ui->server->clear();
  502. size_t servers_count = obs_property_list_item_count(servers);
  503. for (size_t i = 0; i < servers_count; i++) {
  504. const char *name = obs_property_list_item_name(servers, i);
  505. const char *server = obs_property_list_item_string(servers, i);
  506. ui->server->addItem(name, server);
  507. }
  508. obs_properties_destroy(props);
  509. }
  510. void OBSBasicSettings::on_show_clicked()
  511. {
  512. if (ui->key->echoMode() == QLineEdit::Password) {
  513. ui->key->setEchoMode(QLineEdit::Normal);
  514. ui->show->setText(QTStr("Hide"));
  515. } else {
  516. ui->key->setEchoMode(QLineEdit::Password);
  517. ui->show->setText(QTStr("Show"));
  518. }
  519. }
  520. void OBSBasicSettings::on_authPwShow_clicked()
  521. {
  522. if (ui->authPw->echoMode() == QLineEdit::Password) {
  523. ui->authPw->setEchoMode(QLineEdit::Normal);
  524. ui->authPwShow->setText(QTStr("Hide"));
  525. } else {
  526. ui->authPw->setEchoMode(QLineEdit::Password);
  527. ui->authPwShow->setText(QTStr("Show"));
  528. }
  529. }
  530. OBSService OBSBasicSettings::SpawnTempService()
  531. {
  532. bool custom = IsCustomService();
  533. bool whip = IsWHIP();
  534. const char *service_id = "rtmp_common";
  535. if (custom) {
  536. service_id = "rtmp_custom";
  537. } else if (whip) {
  538. service_id = "whip_custom";
  539. }
  540. OBSDataAutoRelease settings = obs_data_create();
  541. if (!custom && !whip) {
  542. obs_data_set_string(settings, "service",
  543. QT_TO_UTF8(ui->service->currentText()));
  544. obs_data_set_string(
  545. settings, "server",
  546. QT_TO_UTF8(ui->server->currentData().toString()));
  547. } else {
  548. obs_data_set_string(
  549. settings, "server",
  550. QT_TO_UTF8(ui->customServer->text().trimmed()));
  551. }
  552. if (whip)
  553. obs_data_set_string(settings, "bearer_token",
  554. QT_TO_UTF8(ui->key->text()));
  555. else
  556. obs_data_set_string(settings, "key",
  557. QT_TO_UTF8(ui->key->text()));
  558. OBSServiceAutoRelease newService = obs_service_create(
  559. service_id, "temp_service", settings, nullptr);
  560. return newService.Get();
  561. }
  562. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  563. {
  564. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  565. if (a) {
  566. bool validKey = !a->key().empty();
  567. if (validKey)
  568. ui->key->setText(QT_UTF8(a->key().c_str()));
  569. ui->streamKeyWidget->setVisible(false);
  570. ui->streamKeyLabel->setVisible(false);
  571. ui->connectAccount2->setVisible(false);
  572. ui->disconnectAccount->setVisible(true);
  573. ui->useStreamKeyAdv->setVisible(false);
  574. ui->connectedAccountLabel->setVisible(false);
  575. ui->connectedAccountText->setVisible(false);
  576. if (strcmp(a->service(), "Twitch") == 0) {
  577. ui->bandwidthTestEnable->setVisible(true);
  578. ui->twitchAddonLabel->setVisible(true);
  579. ui->twitchAddonDropdown->setVisible(true);
  580. } else {
  581. ui->bandwidthTestEnable->setChecked(false);
  582. }
  583. #ifdef YOUTUBE_ENABLED
  584. if (IsYouTubeService(a->service())) {
  585. ui->key->clear();
  586. ui->connectedAccountLabel->setVisible(true);
  587. ui->connectedAccountText->setVisible(true);
  588. ui->connectedAccountText->setText(
  589. QTStr("Auth.LoadingChannel.Title"));
  590. get_yt_ch_title(ui.get());
  591. }
  592. #endif
  593. }
  594. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  595. }
  596. void OBSBasicSettings::OnAuthConnected()
  597. {
  598. std::string service = QT_TO_UTF8(ui->service->currentText());
  599. Auth::Type type = Auth::AuthType(service);
  600. if (type == Auth::Type::OAuth_StreamKey ||
  601. type == Auth::Type::OAuth_LinkedAccount) {
  602. OnOAuthStreamKeyConnected();
  603. }
  604. if (!loading) {
  605. stream1Changed = true;
  606. EnableApplyButton(true);
  607. }
  608. }
  609. void OBSBasicSettings::on_connectAccount_clicked()
  610. {
  611. std::string service = QT_TO_UTF8(ui->service->currentText());
  612. OAuth::DeleteCookies(service);
  613. auth = OAuthStreamKey::Login(this, service);
  614. if (!!auth) {
  615. OnAuthConnected();
  616. #ifdef YOUTUBE_ENABLED
  617. if (IsYouTubeService(service)) {
  618. if (!main->GetYouTubeAppDock()) {
  619. main->NewYouTubeAppDock();
  620. }
  621. main->GetYouTubeAppDock()->AccountConnected();
  622. }
  623. #endif
  624. ui->useStreamKeyAdv->setVisible(false);
  625. }
  626. }
  627. #define DISCONNECT_COMFIRM_TITLE \
  628. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  629. #define DISCONNECT_COMFIRM_TEXT \
  630. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  631. void OBSBasicSettings::on_disconnectAccount_clicked()
  632. {
  633. QMessageBox::StandardButton button;
  634. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  635. QTStr(DISCONNECT_COMFIRM_TEXT));
  636. if (button == QMessageBox::No) {
  637. return;
  638. }
  639. main->auth.reset();
  640. auth.reset();
  641. main->SetBroadcastFlowEnabled(false);
  642. std::string service = QT_TO_UTF8(ui->service->currentText());
  643. #ifdef BROWSER_AVAILABLE
  644. OAuth::DeleteCookies(service);
  645. #endif
  646. ui->bandwidthTestEnable->setChecked(false);
  647. reset_service_ui_fields(ui.get(), service, loading);
  648. ui->bandwidthTestEnable->setVisible(false);
  649. ui->twitchAddonDropdown->setVisible(false);
  650. ui->twitchAddonLabel->setVisible(false);
  651. ui->key->setText("");
  652. ui->connectedAccountLabel->setVisible(false);
  653. ui->connectedAccountText->setVisible(false);
  654. #ifdef YOUTUBE_ENABLED
  655. if (IsYouTubeService(service)) {
  656. if (!main->GetYouTubeAppDock()) {
  657. main->NewYouTubeAppDock();
  658. }
  659. main->GetYouTubeAppDock()->AccountDisconnected();
  660. main->GetYouTubeAppDock()->Update();
  661. }
  662. #endif
  663. }
  664. void OBSBasicSettings::on_useStreamKey_clicked()
  665. {
  666. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  667. }
  668. void OBSBasicSettings::on_useAuth_toggled()
  669. {
  670. if (!IsCustomService())
  671. return;
  672. bool use_auth = ui->useAuth->isChecked();
  673. ui->authUsernameLabel->setVisible(use_auth);
  674. ui->authUsername->setVisible(use_auth);
  675. ui->authPwLabel->setVisible(use_auth);
  676. ui->authPwWidget->setVisible(use_auth);
  677. }
  678. void OBSBasicSettings::UpdateVodTrackSetting()
  679. {
  680. bool enableForCustomServer = config_get_bool(
  681. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  682. bool enableVodTrack = ui->service->currentText() == "Twitch";
  683. bool wasEnabled = !!vodTrackCheckbox;
  684. if (enableForCustomServer && IsCustomService())
  685. enableVodTrack = true;
  686. if (enableVodTrack == wasEnabled)
  687. return;
  688. if (!enableVodTrack) {
  689. delete vodTrackCheckbox;
  690. delete vodTrackContainer;
  691. delete simpleVodTrack;
  692. return;
  693. }
  694. /* -------------------------------------- */
  695. /* simple output mode vod track widgets */
  696. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  697. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  698. "VodTrackEnabled");
  699. simpleVodTrack = new QCheckBox(this);
  700. simpleVodTrack->setText(
  701. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  702. simpleVodTrack->setVisible(simpleAdv);
  703. simpleVodTrack->setChecked(vodTrackEnabled);
  704. int pos;
  705. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  706. &pos, nullptr);
  707. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  708. HookWidget(simpleVodTrack.data(), &QCheckBox::clicked,
  709. &OBSBasicSettings::OutputsChanged);
  710. connect(ui->simpleOutAdvanced, &QCheckBox::toggled,
  711. simpleVodTrack.data(), &QCheckBox::setVisible);
  712. /* -------------------------------------- */
  713. /* advanced output mode vod track widgets */
  714. vodTrackCheckbox = new QCheckBox(this);
  715. vodTrackCheckbox->setText(
  716. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  717. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  718. vodTrackContainer = new QWidget(this);
  719. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  720. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  721. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  722. vodTrackLayout->addWidget(vodTrack[i]);
  723. HookWidget(vodTrack[i].data(), &QRadioButton::clicked,
  724. &OBSBasicSettings::OutputsChanged);
  725. }
  726. HookWidget(vodTrackCheckbox.data(), &QCheckBox::clicked,
  727. &OBSBasicSettings::OutputsChanged);
  728. vodTrackLayout->addStretch();
  729. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  730. vodTrackContainer->setLayout(vodTrackLayout);
  731. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  732. vodTrackEnabled =
  733. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  734. vodTrackCheckbox->setChecked(vodTrackEnabled);
  735. vodTrackContainer->setEnabled(vodTrackEnabled);
  736. connect(vodTrackCheckbox, &QCheckBox::clicked, vodTrackContainer,
  737. &QWidget::setEnabled);
  738. int trackIndex =
  739. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  740. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  741. vodTrack[i]->setChecked((i + 1) == trackIndex);
  742. }
  743. }
  744. OBSService OBSBasicSettings::GetStream1Service()
  745. {
  746. return stream1Changed ? SpawnTempService()
  747. : OBSService(main->GetService());
  748. }
  749. void OBSBasicSettings::UpdateServiceRecommendations()
  750. {
  751. bool customServer = IsCustomService();
  752. ui->ignoreRecommended->setVisible(!customServer);
  753. ui->enforceSettingsLabel->setVisible(!customServer);
  754. OBSService service = GetStream1Service();
  755. int vbitrate, abitrate;
  756. BPtr<obs_service_resolution> res_list;
  757. size_t res_count;
  758. int fps;
  759. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  760. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  761. obs_service_get_max_fps(service, &fps);
  762. QString text;
  763. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  764. if (vbitrate)
  765. text += ENFORCE_TEXT("MaxVideoBitrate")
  766. .arg(QString::number(vbitrate));
  767. if (abitrate) {
  768. if (!text.isEmpty())
  769. text += "<br>";
  770. text += ENFORCE_TEXT("MaxAudioBitrate")
  771. .arg(QString::number(abitrate));
  772. }
  773. if (res_count) {
  774. if (!text.isEmpty())
  775. text += "<br>";
  776. obs_service_resolution best_res = {};
  777. int best_res_pixels = 0;
  778. for (size_t i = 0; i < res_count; i++) {
  779. obs_service_resolution res = res_list[i];
  780. int res_pixels = res.cx + res.cy;
  781. if (res_pixels > best_res_pixels) {
  782. best_res = res;
  783. best_res_pixels = res_pixels;
  784. }
  785. }
  786. QString res_str =
  787. QString("%1x%2").arg(QString::number(best_res.cx),
  788. QString::number(best_res.cy));
  789. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  790. }
  791. if (fps) {
  792. if (!text.isEmpty())
  793. text += "<br>";
  794. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  795. }
  796. #undef ENFORCE_TEXT
  797. #ifdef YOUTUBE_ENABLED
  798. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  799. if (!text.isEmpty())
  800. text += "<br><br>";
  801. text += "<a href=\"https://www.youtube.com/t/terms\">"
  802. "YouTube Terms of Service</a><br>"
  803. "<a href=\"http://www.google.com/policies/privacy\">"
  804. "Google Privacy Policy</a><br>"
  805. "<a href=\"https://security.google.com/settings/security/permissions\">"
  806. "Google Third-Party Permissions</a>";
  807. }
  808. #endif
  809. ui->enforceSettingsLabel->setText(text);
  810. }
  811. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  812. {
  813. if (IsCustomService())
  814. return;
  815. if (!checked) {
  816. SimpleRecordingEncoderChanged();
  817. return;
  818. }
  819. QMessageBox::StandardButton button;
  820. #define ENFORCE_WARNING(x) \
  821. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  822. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  823. ENFORCE_WARNING("Text"));
  824. #undef ENFORCE_WARNING
  825. if (button == QMessageBox::No) {
  826. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  827. Qt::QueuedConnection,
  828. Q_ARG(bool, false));
  829. return;
  830. }
  831. SimpleRecordingEncoderChanged();
  832. }
  833. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  834. size_t res_count, int max_fps)
  835. {
  836. if (!res_count && !max_fps)
  837. return true;
  838. if (res_count) {
  839. QString res = ui->outputResolution->currentText();
  840. bool found_res = false;
  841. int cx, cy;
  842. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  843. return false;
  844. for (size_t i = 0; i < res_count; i++) {
  845. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  846. found_res = true;
  847. break;
  848. }
  849. }
  850. if (!found_res)
  851. return false;
  852. }
  853. if (max_fps) {
  854. int fpsType = ui->fpsType->currentIndex();
  855. if (fpsType != 0)
  856. return false;
  857. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  858. float fps;
  859. sscanf(fps_str.c_str(), "%f", &fps);
  860. if (fps > (float)max_fps)
  861. return false;
  862. }
  863. return true;
  864. }
  865. extern void set_closest_res(int &cx, int &cy,
  866. struct obs_service_resolution *res_list,
  867. size_t count);
  868. /* Checks for and updates the resolution and FPS limits of a service, if any.
  869. *
  870. * If the service has a resolution and/or FPS limit, this will enforce those
  871. * limitations in the UI itself, preventing the user from selecting a
  872. * resolution or FPS that's not supported.
  873. *
  874. * This is an unpleasant thing to have to do to users, but there is no other
  875. * way to ensure that a service's restricted resolution/framerate values are
  876. * properly enforced, otherwise users will just be confused when things aren't
  877. * working correctly. The user can turn it off if they're partner (or if they
  878. * want to risk getting in trouble with their service) by selecting the "Ignore
  879. * recommended settings" option in the stream section of settings.
  880. *
  881. * This only affects services that have a resolution and/or framerate limit, of
  882. * which as of this writing, and hopefully for the foreseeable future, there is
  883. * only one.
  884. */
  885. bool OBSBasicSettings::UpdateResFPSLimits()
  886. {
  887. if (loading)
  888. return false;
  889. int idx = ui->service->currentIndex();
  890. if (idx == -1)
  891. return false;
  892. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  893. BPtr<obs_service_resolution> res_list;
  894. size_t res_count = 0;
  895. int max_fps = 0;
  896. if (!IsCustomService() && !ignoreRecommended) {
  897. OBSService service = GetStream1Service();
  898. obs_service_get_supported_resolutions(service, &res_list,
  899. &res_count);
  900. obs_service_get_max_fps(service, &max_fps);
  901. }
  902. /* ------------------------------------ */
  903. /* Check for enforced res/FPS */
  904. QString res = ui->outputResolution->currentText();
  905. QString fps_str;
  906. int cx = 0, cy = 0;
  907. double max_fpsd = (double)max_fps;
  908. int closest_fps_index = -1;
  909. double fpsd;
  910. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  911. if (res_count)
  912. set_closest_res(cx, cy, res_list, res_count);
  913. if (max_fps) {
  914. int fpsType = ui->fpsType->currentIndex();
  915. if (fpsType == 1) { //Integer
  916. fpsd = (double)ui->fpsInteger->value();
  917. } else if (fpsType == 2) { //Fractional
  918. fpsd = (double)ui->fpsNumerator->value() /
  919. (double)ui->fpsDenominator->value();
  920. } else { //Common
  921. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  922. &fpsd);
  923. }
  924. double closest_diff = 1000000000000.0;
  925. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  926. double com_fpsd;
  927. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  928. &com_fpsd);
  929. if (com_fpsd > max_fpsd) {
  930. continue;
  931. }
  932. double diff = fabs(com_fpsd - fpsd);
  933. if (diff < closest_diff) {
  934. closest_diff = diff;
  935. closest_fps_index = i;
  936. fps_str = ui->fpsCommon->itemText(i);
  937. }
  938. }
  939. }
  940. QString res_str =
  941. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  942. /* ------------------------------------ */
  943. /* Display message box if res/FPS bad */
  944. bool valid = ResFPSValid(res_list, res_count, max_fps);
  945. if (!valid) {
  946. /* if the user was already on facebook with an incompatible
  947. * resolution, assume it's an upgrade */
  948. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  949. ui->ignoreRecommended->setChecked(true);
  950. ui->ignoreRecommended->setProperty("changed", true);
  951. stream1Changed = true;
  952. EnableApplyButton(true);
  953. return UpdateResFPSLimits();
  954. }
  955. QMessageBox::StandardButton button;
  956. #define WARNING_VAL(x) \
  957. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  958. QString str;
  959. if (res_count)
  960. str += WARNING_VAL("Resolution").arg(res_str);
  961. if (max_fps) {
  962. if (!str.isEmpty())
  963. str += "\n";
  964. str += WARNING_VAL("FPS").arg(fps_str);
  965. }
  966. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  967. WARNING_VAL("Msg").arg(str));
  968. #undef WARNING_VAL
  969. if (button == QMessageBox::No) {
  970. if (idx != lastServiceIdx)
  971. QMetaObject::invokeMethod(
  972. ui->service, "setCurrentIndex",
  973. Qt::QueuedConnection,
  974. Q_ARG(int, lastServiceIdx));
  975. else
  976. QMetaObject::invokeMethod(ui->ignoreRecommended,
  977. "setChecked",
  978. Qt::QueuedConnection,
  979. Q_ARG(bool, true));
  980. return false;
  981. }
  982. }
  983. /* ------------------------------------ */
  984. /* Update widgets/values if switching */
  985. /* to/from enforced resolution/FPS */
  986. ui->outputResolution->blockSignals(true);
  987. if (res_count) {
  988. ui->outputResolution->clear();
  989. ui->outputResolution->setEditable(false);
  990. HookWidget(ui->outputResolution,
  991. &QComboBox::currentIndexChanged,
  992. &OBSBasicSettings::VideoChangedResolution);
  993. int new_res_index = -1;
  994. for (size_t i = 0; i < res_count; i++) {
  995. obs_service_resolution val = res_list[i];
  996. QString str =
  997. QString("%1x%2").arg(QString::number(val.cx),
  998. QString::number(val.cy));
  999. ui->outputResolution->addItem(str);
  1000. if (val.cx == cx && val.cy == cy)
  1001. new_res_index = (int)i;
  1002. }
  1003. ui->outputResolution->setCurrentIndex(new_res_index);
  1004. if (!valid) {
  1005. ui->outputResolution->setProperty("changed", true);
  1006. videoChanged = true;
  1007. EnableApplyButton(true);
  1008. }
  1009. } else {
  1010. QString baseRes = ui->baseResolution->currentText();
  1011. int baseCX, baseCY;
  1012. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  1013. if (!ui->outputResolution->isEditable()) {
  1014. RecreateOutputResolutionWidget();
  1015. ui->outputResolution->blockSignals(true);
  1016. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  1017. true);
  1018. ui->outputResolution->setCurrentText(res);
  1019. }
  1020. }
  1021. ui->outputResolution->blockSignals(false);
  1022. if (max_fps) {
  1023. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  1024. double com_fpsd;
  1025. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  1026. &com_fpsd);
  1027. if (com_fpsd > max_fpsd) {
  1028. SetComboItemEnabled(ui->fpsCommon, i, false);
  1029. continue;
  1030. }
  1031. }
  1032. ui->fpsType->setCurrentIndex(0);
  1033. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  1034. if (!valid) {
  1035. ui->fpsType->setProperty("changed", true);
  1036. ui->fpsCommon->setProperty("changed", true);
  1037. videoChanged = true;
  1038. EnableApplyButton(true);
  1039. }
  1040. } else {
  1041. for (int i = 0; i < ui->fpsCommon->count(); i++)
  1042. SetComboItemEnabled(ui->fpsCommon, i, true);
  1043. }
  1044. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  1045. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  1046. /* ------------------------------------ */
  1047. lastIgnoreRecommended = (int)ignoreRecommended;
  1048. return true;
  1049. }
  1050. static bool service_supports_codec(const char **codecs, const char *codec)
  1051. {
  1052. if (!codecs)
  1053. return true;
  1054. while (*codecs) {
  1055. if (strcmp(*codecs, codec) == 0)
  1056. return true;
  1057. codecs++;
  1058. }
  1059. return false;
  1060. }
  1061. extern bool EncoderAvailable(const char *encoder);
  1062. extern const char *get_simple_output_encoder(const char *name);
  1063. static inline bool service_supports_encoder(const char **codecs,
  1064. const char *encoder)
  1065. {
  1066. if (!EncoderAvailable(encoder))
  1067. return false;
  1068. const char *codec = obs_get_encoder_codec(encoder);
  1069. return service_supports_codec(codecs, codec);
  1070. }
  1071. static bool return_first_id(void *data, const char *id)
  1072. {
  1073. const char **output = (const char **)data;
  1074. *output = id;
  1075. return false;
  1076. }
  1077. bool OBSBasicSettings::ServiceAndVCodecCompatible()
  1078. {
  1079. bool simple = (ui->outputMode->currentIndex() == 0);
  1080. bool ret;
  1081. const char *codec;
  1082. if (simple) {
  1083. QString encoder =
  1084. ui->simpleOutStrEncoder->currentData().toString();
  1085. const char *id = get_simple_output_encoder(QT_TO_UTF8(encoder));
  1086. codec = obs_get_encoder_codec(id);
  1087. } else {
  1088. QString encoder = ui->advOutEncoder->currentData().toString();
  1089. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1090. }
  1091. OBSService service = SpawnTempService();
  1092. const char **codecs = obs_service_get_supported_video_codecs(service);
  1093. if (!codecs || IsCustomService()) {
  1094. const char *output;
  1095. char **output_codecs;
  1096. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1097. &output, return_first_id);
  1098. output_codecs = strlist_split(
  1099. obs_get_output_supported_video_codecs(output), ';',
  1100. false);
  1101. ret = service_supports_codec((const char **)output_codecs,
  1102. codec);
  1103. strlist_free(output_codecs);
  1104. } else {
  1105. ret = service_supports_codec(codecs, codec);
  1106. }
  1107. return ret;
  1108. }
  1109. bool OBSBasicSettings::ServiceAndACodecCompatible()
  1110. {
  1111. bool simple = (ui->outputMode->currentIndex() == 0);
  1112. bool ret;
  1113. QString codec;
  1114. if (simple) {
  1115. codec = ui->simpleOutStrAEncoder->currentData().toString();
  1116. } else {
  1117. QString encoder = ui->advOutAEncoder->currentData().toString();
  1118. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1119. }
  1120. OBSService service = SpawnTempService();
  1121. const char **codecs = obs_service_get_supported_audio_codecs(service);
  1122. if (!codecs || IsCustomService()) {
  1123. const char *output;
  1124. char **output_codecs;
  1125. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1126. &output, return_first_id);
  1127. output_codecs = strlist_split(
  1128. obs_get_output_supported_audio_codecs(output), ';',
  1129. false);
  1130. ret = service_supports_codec((const char **)output_codecs,
  1131. QT_TO_UTF8(codec));
  1132. strlist_free(output_codecs);
  1133. } else {
  1134. ret = service_supports_codec(codecs, QT_TO_UTF8(codec));
  1135. }
  1136. return ret;
  1137. }
  1138. /* we really need a way to find fallbacks in a less hardcoded way. maybe. */
  1139. static QString get_adv_fallback(const QString &enc)
  1140. {
  1141. if (enc == "jim_hevc_nvenc" || enc == "jim_av1_nvenc")
  1142. return "jim_nvenc";
  1143. if (enc == "h265_texture_amf" || enc == "av1_texture_amf")
  1144. return "h264_texture_amf";
  1145. if (enc == "com.apple.videotoolbox.videoencoder.ave.hevc")
  1146. return "com.apple.videotoolbox.videoencoder.ave.avc";
  1147. if (enc == "obs_qsv11_av1")
  1148. return "obs_qsv11";
  1149. return "obs_x264";
  1150. }
  1151. static QString get_adv_audio_fallback(const QString &enc)
  1152. {
  1153. const char *codec = obs_get_encoder_codec(QT_TO_UTF8(enc));
  1154. if (strcmp(codec, "aac") == 0)
  1155. return "ffmpeg_opus";
  1156. QString aac_default = "ffmpeg_aac";
  1157. if (EncoderAvailable("CoreAudio_AAC"))
  1158. aac_default = "CoreAudio_AAC";
  1159. else if (EncoderAvailable("libfdk_aac"))
  1160. aac_default = "libfdk_aac";
  1161. return aac_default;
  1162. }
  1163. static QString get_simple_fallback(const QString &enc)
  1164. {
  1165. if (enc == SIMPLE_ENCODER_NVENC_HEVC || enc == SIMPLE_ENCODER_NVENC_AV1)
  1166. return SIMPLE_ENCODER_NVENC;
  1167. if (enc == SIMPLE_ENCODER_AMD_HEVC || enc == SIMPLE_ENCODER_AMD_AV1)
  1168. return SIMPLE_ENCODER_AMD;
  1169. if (enc == SIMPLE_ENCODER_APPLE_HEVC)
  1170. return SIMPLE_ENCODER_APPLE_H264;
  1171. if (enc == SIMPLE_ENCODER_QSV_AV1)
  1172. return SIMPLE_ENCODER_QSV;
  1173. return SIMPLE_ENCODER_X264;
  1174. }
  1175. bool OBSBasicSettings::ServiceSupportsCodecCheck()
  1176. {
  1177. if (loading)
  1178. return false;
  1179. bool vcodec_compat = ServiceAndVCodecCompatible();
  1180. bool acodec_compat = ServiceAndACodecCompatible();
  1181. if (vcodec_compat && acodec_compat) {
  1182. if (lastServiceIdx != ui->service->currentIndex() ||
  1183. IsCustomService())
  1184. ResetEncoders(true);
  1185. return true;
  1186. }
  1187. QString service = ui->service->currentText();
  1188. QString cur_video_name;
  1189. QString fb_video_name;
  1190. QString cur_audio_name;
  1191. QString fb_audio_name;
  1192. bool simple = (ui->outputMode->currentIndex() == 0);
  1193. /* ------------------------------------------------- */
  1194. /* get current codec */
  1195. if (simple) {
  1196. QString cur_enc =
  1197. ui->simpleOutStrEncoder->currentData().toString();
  1198. QString fb_enc = get_simple_fallback(cur_enc);
  1199. int cur_idx = ui->simpleOutStrEncoder->findData(cur_enc);
  1200. int fb_idx = ui->simpleOutStrEncoder->findData(fb_enc);
  1201. cur_video_name = ui->simpleOutStrEncoder->itemText(cur_idx);
  1202. fb_video_name = ui->simpleOutStrEncoder->itemText(fb_idx);
  1203. cur_enc = ui->simpleOutStrAEncoder->currentData().toString();
  1204. fb_enc = (cur_enc == "opus") ? "aac" : "opus";
  1205. cur_audio_name = ui->simpleOutStrAEncoder->itemText(
  1206. ui->simpleOutStrAEncoder->findData(cur_enc));
  1207. fb_audio_name =
  1208. (cur_enc == "opus")
  1209. ? QTStr("Basic.Settings.Output.Simple.Codec.AAC")
  1210. : QTStr("Basic.Settings.Output.Simple.Codec.Opus");
  1211. } else {
  1212. QString cur_enc = ui->advOutEncoder->currentData().toString();
  1213. QString fb_enc = get_adv_fallback(cur_enc);
  1214. cur_video_name =
  1215. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1216. fb_video_name =
  1217. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1218. cur_enc = ui->advOutAEncoder->currentData().toString();
  1219. fb_enc = get_adv_audio_fallback(cur_enc);
  1220. cur_audio_name =
  1221. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1222. fb_audio_name =
  1223. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1224. }
  1225. #define WARNING_VAL(x) \
  1226. QTStr("Basic.Settings.Output.Warn.ServiceCodecCompatibility." x)
  1227. QString msg = WARNING_VAL("Msg").arg(
  1228. service, vcodec_compat ? cur_audio_name : cur_video_name,
  1229. vcodec_compat ? fb_audio_name : fb_video_name);
  1230. if (!vcodec_compat && !acodec_compat)
  1231. msg = WARNING_VAL("Msg2").arg(service, cur_video_name,
  1232. cur_audio_name, fb_video_name,
  1233. fb_audio_name);
  1234. auto button = OBSMessageBox::question(this, WARNING_VAL("Title"), msg);
  1235. #undef WARNING_VAL
  1236. if (button == QMessageBox::No) {
  1237. if (lastServiceIdx == 0 &&
  1238. lastServiceIdx == ui->service->currentIndex())
  1239. QMetaObject::invokeMethod(ui->customServer, "setText",
  1240. Qt::QueuedConnection,
  1241. Q_ARG(QString,
  1242. lastCustomServer));
  1243. else
  1244. QMetaObject::invokeMethod(ui->service,
  1245. "setCurrentIndex",
  1246. Qt::QueuedConnection,
  1247. Q_ARG(int, lastServiceIdx));
  1248. return false;
  1249. }
  1250. ResetEncoders(true);
  1251. return true;
  1252. }
  1253. #define TEXT_USE_STREAM_ENC \
  1254. QTStr("Basic.Settings.Output.Adv.Recording.UseStreamEncoder")
  1255. void OBSBasicSettings::ResetEncoders(bool streamOnly)
  1256. {
  1257. QString lastAdvVideoEnc = ui->advOutEncoder->currentData().toString();
  1258. QString lastVideoEnc =
  1259. ui->simpleOutStrEncoder->currentData().toString();
  1260. QString lastAdvAudioEnc = ui->advOutAEncoder->currentData().toString();
  1261. QString lastAudioEnc =
  1262. ui->simpleOutStrAEncoder->currentData().toString();
  1263. OBSService service = SpawnTempService();
  1264. const char **vcodecs = obs_service_get_supported_video_codecs(service);
  1265. const char **acodecs = obs_service_get_supported_audio_codecs(service);
  1266. const char *type;
  1267. BPtr<char *> output_vcodecs;
  1268. BPtr<char *> output_acodecs;
  1269. size_t idx = 0;
  1270. if (!vcodecs || IsCustomService()) {
  1271. const char *output;
  1272. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1273. &output, return_first_id);
  1274. output_vcodecs = strlist_split(
  1275. obs_get_output_supported_video_codecs(output), ';',
  1276. false);
  1277. vcodecs = (const char **)output_vcodecs.Get();
  1278. }
  1279. if (!acodecs || IsCustomService()) {
  1280. const char *output;
  1281. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1282. &output, return_first_id);
  1283. output_acodecs = strlist_split(
  1284. obs_get_output_supported_audio_codecs(output), ';',
  1285. false);
  1286. acodecs = (const char **)output_acodecs.Get();
  1287. }
  1288. QSignalBlocker s1(ui->simpleOutStrEncoder);
  1289. QSignalBlocker s2(ui->advOutEncoder);
  1290. QSignalBlocker s3(ui->simpleOutStrAEncoder);
  1291. QSignalBlocker s4(ui->advOutAEncoder);
  1292. /* ------------------------------------------------- */
  1293. /* clear encoder lists */
  1294. ui->simpleOutStrEncoder->clear();
  1295. ui->advOutEncoder->clear();
  1296. ui->simpleOutStrAEncoder->clear();
  1297. ui->advOutAEncoder->clear();
  1298. if (!streamOnly) {
  1299. ui->advOutRecEncoder->clear();
  1300. ui->advOutRecAEncoder->clear();
  1301. }
  1302. /* ------------------------------------------------- */
  1303. /* load advanced stream/recording encoders */
  1304. while (obs_enum_encoder_types(idx++, &type)) {
  1305. const char *name = obs_encoder_get_display_name(type);
  1306. const char *codec = obs_get_encoder_codec(type);
  1307. uint32_t caps = obs_get_encoder_caps(type);
  1308. QString qName = QT_UTF8(name);
  1309. QString qType = QT_UTF8(type);
  1310. if (obs_get_encoder_type(type) == OBS_ENCODER_VIDEO) {
  1311. if ((caps & ENCODER_HIDE_FLAGS) != 0)
  1312. continue;
  1313. if (service_supports_codec(vcodecs, codec))
  1314. ui->advOutEncoder->addItem(qName, qType);
  1315. if (!streamOnly)
  1316. ui->advOutRecEncoder->addItem(qName, qType);
  1317. }
  1318. if (obs_get_encoder_type(type) == OBS_ENCODER_AUDIO) {
  1319. if (service_supports_codec(acodecs, codec))
  1320. ui->advOutAEncoder->addItem(qName, qType);
  1321. if (!streamOnly)
  1322. ui->advOutRecAEncoder->addItem(qName, qType);
  1323. }
  1324. }
  1325. ui->advOutEncoder->model()->sort(0);
  1326. ui->advOutAEncoder->model()->sort(0);
  1327. if (!streamOnly) {
  1328. ui->advOutRecEncoder->model()->sort(0);
  1329. ui->advOutRecEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1330. "none");
  1331. ui->advOutRecAEncoder->model()->sort(0);
  1332. ui->advOutRecAEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1333. "none");
  1334. }
  1335. /* ------------------------------------------------- */
  1336. /* load simple stream encoders */
  1337. #define ENCODER_STR(str) QTStr("Basic.Settings.Output.Simple.Encoder." str)
  1338. ui->simpleOutStrEncoder->addItem(ENCODER_STR("Software"),
  1339. QString(SIMPLE_ENCODER_X264));
  1340. #ifdef _WIN32
  1341. if (service_supports_encoder(vcodecs, "obs_qsv11"))
  1342. ui->simpleOutStrEncoder->addItem(
  1343. ENCODER_STR("Hardware.QSV.H264"),
  1344. QString(SIMPLE_ENCODER_QSV));
  1345. if (service_supports_encoder(vcodecs, "obs_qsv11_av1"))
  1346. ui->simpleOutStrEncoder->addItem(
  1347. ENCODER_STR("Hardware.QSV.AV1"),
  1348. QString(SIMPLE_ENCODER_QSV_AV1));
  1349. #endif
  1350. if (service_supports_encoder(vcodecs, "ffmpeg_nvenc"))
  1351. ui->simpleOutStrEncoder->addItem(
  1352. ENCODER_STR("Hardware.NVENC.H264"),
  1353. QString(SIMPLE_ENCODER_NVENC));
  1354. if (service_supports_encoder(vcodecs, "jim_av1_nvenc"))
  1355. ui->simpleOutStrEncoder->addItem(
  1356. ENCODER_STR("Hardware.NVENC.AV1"),
  1357. QString(SIMPLE_ENCODER_NVENC_AV1));
  1358. #ifdef ENABLE_HEVC
  1359. if (service_supports_encoder(vcodecs, "h265_texture_amf"))
  1360. ui->simpleOutStrEncoder->addItem(
  1361. ENCODER_STR("Hardware.AMD.HEVC"),
  1362. QString(SIMPLE_ENCODER_AMD_HEVC));
  1363. if (service_supports_encoder(vcodecs, "ffmpeg_hevc_nvenc"))
  1364. ui->simpleOutStrEncoder->addItem(
  1365. ENCODER_STR("Hardware.NVENC.HEVC"),
  1366. QString(SIMPLE_ENCODER_NVENC_HEVC));
  1367. #endif
  1368. if (service_supports_encoder(vcodecs, "h264_texture_amf"))
  1369. ui->simpleOutStrEncoder->addItem(
  1370. ENCODER_STR("Hardware.AMD.H264"),
  1371. QString(SIMPLE_ENCODER_AMD));
  1372. if (service_supports_encoder(vcodecs, "av1_texture_amf"))
  1373. ui->simpleOutStrEncoder->addItem(
  1374. ENCODER_STR("Hardware.AMD.AV1"),
  1375. QString(SIMPLE_ENCODER_AMD_AV1));
  1376. /* Preprocessor guard required for the macOS version check */
  1377. #ifdef __APPLE__
  1378. if (service_supports_encoder(
  1379. vcodecs, "com.apple.videotoolbox.videoencoder.ave.avc")
  1380. #ifndef __aarch64__
  1381. && os_get_emulation_status() == true
  1382. #endif
  1383. ) {
  1384. if (__builtin_available(macOS 13.0, *)) {
  1385. ui->simpleOutStrEncoder->addItem(
  1386. ENCODER_STR("Hardware.Apple.H264"),
  1387. QString(SIMPLE_ENCODER_APPLE_H264));
  1388. }
  1389. }
  1390. #ifdef ENABLE_HEVC
  1391. if (service_supports_encoder(
  1392. vcodecs, "com.apple.videotoolbox.videoencoder.ave.hevc")
  1393. #ifndef __aarch64__
  1394. && os_get_emulation_status() == true
  1395. #endif
  1396. ) {
  1397. if (__builtin_available(macOS 13.0, *)) {
  1398. ui->simpleOutStrEncoder->addItem(
  1399. ENCODER_STR("Hardware.Apple.HEVC"),
  1400. QString(SIMPLE_ENCODER_APPLE_HEVC));
  1401. }
  1402. }
  1403. #endif
  1404. #endif
  1405. if (service_supports_encoder(acodecs, "CoreAudio_AAC") ||
  1406. service_supports_encoder(acodecs, "libfdk_aac") ||
  1407. service_supports_encoder(acodecs, "ffmpeg_aac"))
  1408. ui->simpleOutStrAEncoder->addItem(
  1409. QTStr("Basic.Settings.Output.Simple.Codec.AAC.Default"),
  1410. "aac");
  1411. if (service_supports_encoder(acodecs, "ffmpeg_opus"))
  1412. ui->simpleOutStrAEncoder->addItem(
  1413. QTStr("Basic.Settings.Output.Simple.Codec.Opus"),
  1414. "opus");
  1415. #undef ENCODER_STR
  1416. /* ------------------------------------------------- */
  1417. /* Find fallback encoders */
  1418. if (!lastAdvVideoEnc.isEmpty()) {
  1419. int idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1420. if (idx == -1) {
  1421. lastAdvVideoEnc = get_adv_fallback(lastAdvVideoEnc);
  1422. ui->advOutEncoder->setProperty("changed",
  1423. QVariant(true));
  1424. OutputsChanged();
  1425. }
  1426. idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1427. s2.unblock();
  1428. ui->advOutEncoder->setCurrentIndex(idx);
  1429. }
  1430. if (!lastAdvAudioEnc.isEmpty()) {
  1431. int idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1432. if (idx == -1) {
  1433. lastAdvAudioEnc =
  1434. get_adv_audio_fallback(lastAdvAudioEnc);
  1435. ui->advOutAEncoder->setProperty("changed",
  1436. QVariant(true));
  1437. OutputsChanged();
  1438. }
  1439. idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1440. s4.unblock();
  1441. ui->advOutAEncoder->setCurrentIndex(idx);
  1442. }
  1443. if (!lastVideoEnc.isEmpty()) {
  1444. int idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1445. if (idx == -1) {
  1446. lastVideoEnc = get_simple_fallback(lastVideoEnc);
  1447. ui->simpleOutStrEncoder->setProperty("changed",
  1448. QVariant(true));
  1449. OutputsChanged();
  1450. }
  1451. idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1452. s1.unblock();
  1453. ui->simpleOutStrEncoder->setCurrentIndex(idx);
  1454. }
  1455. if (!lastAudioEnc.isEmpty()) {
  1456. int idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1457. if (idx == -1) {
  1458. lastAudioEnc = (lastAudioEnc == "opus") ? "aac"
  1459. : "opus";
  1460. ui->simpleOutStrAEncoder->setProperty("changed",
  1461. QVariant(true));
  1462. OutputsChanged();
  1463. }
  1464. idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1465. s3.unblock();
  1466. ui->simpleOutStrAEncoder->setCurrentIndex(idx);
  1467. }
  1468. }