window-basic-settings-stream.cpp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  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. ui->useStreamKeyAdv->setVisible(false);
  617. }
  618. }
  619. #define DISCONNECT_COMFIRM_TITLE \
  620. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  621. #define DISCONNECT_COMFIRM_TEXT \
  622. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  623. void OBSBasicSettings::on_disconnectAccount_clicked()
  624. {
  625. QMessageBox::StandardButton button;
  626. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  627. QTStr(DISCONNECT_COMFIRM_TEXT));
  628. if (button == QMessageBox::No) {
  629. return;
  630. }
  631. main->auth.reset();
  632. auth.reset();
  633. main->SetBroadcastFlowEnabled(false);
  634. std::string service = QT_TO_UTF8(ui->service->currentText());
  635. #ifdef BROWSER_AVAILABLE
  636. OAuth::DeleteCookies(service);
  637. #endif
  638. ui->bandwidthTestEnable->setChecked(false);
  639. reset_service_ui_fields(ui.get(), service, loading);
  640. ui->bandwidthTestEnable->setVisible(false);
  641. ui->twitchAddonDropdown->setVisible(false);
  642. ui->twitchAddonLabel->setVisible(false);
  643. ui->key->setText("");
  644. ui->connectedAccountLabel->setVisible(false);
  645. ui->connectedAccountText->setVisible(false);
  646. }
  647. void OBSBasicSettings::on_useStreamKey_clicked()
  648. {
  649. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  650. }
  651. void OBSBasicSettings::on_useAuth_toggled()
  652. {
  653. if (!IsCustomService())
  654. return;
  655. bool use_auth = ui->useAuth->isChecked();
  656. ui->authUsernameLabel->setVisible(use_auth);
  657. ui->authUsername->setVisible(use_auth);
  658. ui->authPwLabel->setVisible(use_auth);
  659. ui->authPwWidget->setVisible(use_auth);
  660. }
  661. void OBSBasicSettings::UpdateVodTrackSetting()
  662. {
  663. bool enableForCustomServer = config_get_bool(
  664. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  665. bool enableVodTrack = ui->service->currentText() == "Twitch";
  666. bool wasEnabled = !!vodTrackCheckbox;
  667. if (enableForCustomServer && IsCustomService())
  668. enableVodTrack = true;
  669. if (enableVodTrack == wasEnabled)
  670. return;
  671. if (!enableVodTrack) {
  672. delete vodTrackCheckbox;
  673. delete vodTrackContainer;
  674. delete simpleVodTrack;
  675. return;
  676. }
  677. /* -------------------------------------- */
  678. /* simple output mode vod track widgets */
  679. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  680. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  681. "VodTrackEnabled");
  682. simpleVodTrack = new QCheckBox(this);
  683. simpleVodTrack->setText(
  684. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  685. simpleVodTrack->setVisible(simpleAdv);
  686. simpleVodTrack->setChecked(vodTrackEnabled);
  687. int pos;
  688. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  689. &pos, nullptr);
  690. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  691. HookWidget(simpleVodTrack.data(), &QCheckBox::clicked,
  692. &OBSBasicSettings::OutputsChanged);
  693. connect(ui->simpleOutAdvanced, &QCheckBox::toggled,
  694. simpleVodTrack.data(), &QCheckBox::setVisible);
  695. /* -------------------------------------- */
  696. /* advanced output mode vod track widgets */
  697. vodTrackCheckbox = new QCheckBox(this);
  698. vodTrackCheckbox->setText(
  699. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  700. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  701. vodTrackContainer = new QWidget(this);
  702. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  703. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  704. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  705. vodTrackLayout->addWidget(vodTrack[i]);
  706. HookWidget(vodTrack[i].data(), &QRadioButton::clicked,
  707. &OBSBasicSettings::OutputsChanged);
  708. }
  709. HookWidget(vodTrackCheckbox.data(), &QCheckBox::clicked,
  710. &OBSBasicSettings::OutputsChanged);
  711. vodTrackLayout->addStretch();
  712. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  713. vodTrackContainer->setLayout(vodTrackLayout);
  714. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  715. vodTrackEnabled =
  716. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  717. vodTrackCheckbox->setChecked(vodTrackEnabled);
  718. vodTrackContainer->setEnabled(vodTrackEnabled);
  719. connect(vodTrackCheckbox, &QCheckBox::clicked, vodTrackContainer,
  720. &QWidget::setEnabled);
  721. int trackIndex =
  722. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  723. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  724. vodTrack[i]->setChecked((i + 1) == trackIndex);
  725. }
  726. }
  727. OBSService OBSBasicSettings::GetStream1Service()
  728. {
  729. return stream1Changed ? SpawnTempService()
  730. : OBSService(main->GetService());
  731. }
  732. void OBSBasicSettings::UpdateServiceRecommendations()
  733. {
  734. bool customServer = IsCustomService();
  735. ui->ignoreRecommended->setVisible(!customServer);
  736. ui->enforceSettingsLabel->setVisible(!customServer);
  737. OBSService service = GetStream1Service();
  738. int vbitrate, abitrate;
  739. BPtr<obs_service_resolution> res_list;
  740. size_t res_count;
  741. int fps;
  742. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  743. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  744. obs_service_get_max_fps(service, &fps);
  745. QString text;
  746. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  747. if (vbitrate)
  748. text += ENFORCE_TEXT("MaxVideoBitrate")
  749. .arg(QString::number(vbitrate));
  750. if (abitrate) {
  751. if (!text.isEmpty())
  752. text += "<br>";
  753. text += ENFORCE_TEXT("MaxAudioBitrate")
  754. .arg(QString::number(abitrate));
  755. }
  756. if (res_count) {
  757. if (!text.isEmpty())
  758. text += "<br>";
  759. obs_service_resolution best_res = {};
  760. int best_res_pixels = 0;
  761. for (size_t i = 0; i < res_count; i++) {
  762. obs_service_resolution res = res_list[i];
  763. int res_pixels = res.cx + res.cy;
  764. if (res_pixels > best_res_pixels) {
  765. best_res = res;
  766. best_res_pixels = res_pixels;
  767. }
  768. }
  769. QString res_str =
  770. QString("%1x%2").arg(QString::number(best_res.cx),
  771. QString::number(best_res.cy));
  772. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  773. }
  774. if (fps) {
  775. if (!text.isEmpty())
  776. text += "<br>";
  777. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  778. }
  779. #undef ENFORCE_TEXT
  780. #ifdef YOUTUBE_ENABLED
  781. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  782. if (!text.isEmpty())
  783. text += "<br><br>";
  784. text += "<a href=\"https://www.youtube.com/t/terms\">"
  785. "YouTube Terms of Service</a><br>"
  786. "<a href=\"http://www.google.com/policies/privacy\">"
  787. "Google Privacy Policy</a><br>"
  788. "<a href=\"https://security.google.com/settings/security/permissions\">"
  789. "Google Third-Party Permissions</a>";
  790. }
  791. #endif
  792. ui->enforceSettingsLabel->setText(text);
  793. }
  794. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  795. {
  796. if (IsCustomService())
  797. return;
  798. if (!checked) {
  799. SimpleRecordingEncoderChanged();
  800. return;
  801. }
  802. QMessageBox::StandardButton button;
  803. #define ENFORCE_WARNING(x) \
  804. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  805. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  806. ENFORCE_WARNING("Text"));
  807. #undef ENFORCE_WARNING
  808. if (button == QMessageBox::No) {
  809. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  810. Qt::QueuedConnection,
  811. Q_ARG(bool, false));
  812. return;
  813. }
  814. SimpleRecordingEncoderChanged();
  815. }
  816. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  817. size_t res_count, int max_fps)
  818. {
  819. if (!res_count && !max_fps)
  820. return true;
  821. if (res_count) {
  822. QString res = ui->outputResolution->currentText();
  823. bool found_res = false;
  824. int cx, cy;
  825. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  826. return false;
  827. for (size_t i = 0; i < res_count; i++) {
  828. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  829. found_res = true;
  830. break;
  831. }
  832. }
  833. if (!found_res)
  834. return false;
  835. }
  836. if (max_fps) {
  837. int fpsType = ui->fpsType->currentIndex();
  838. if (fpsType != 0)
  839. return false;
  840. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  841. float fps;
  842. sscanf(fps_str.c_str(), "%f", &fps);
  843. if (fps > (float)max_fps)
  844. return false;
  845. }
  846. return true;
  847. }
  848. extern void set_closest_res(int &cx, int &cy,
  849. struct obs_service_resolution *res_list,
  850. size_t count);
  851. /* Checks for and updates the resolution and FPS limits of a service, if any.
  852. *
  853. * If the service has a resolution and/or FPS limit, this will enforce those
  854. * limitations in the UI itself, preventing the user from selecting a
  855. * resolution or FPS that's not supported.
  856. *
  857. * This is an unpleasant thing to have to do to users, but there is no other
  858. * way to ensure that a service's restricted resolution/framerate values are
  859. * properly enforced, otherwise users will just be confused when things aren't
  860. * working correctly. The user can turn it off if they're partner (or if they
  861. * want to risk getting in trouble with their service) by selecting the "Ignore
  862. * recommended settings" option in the stream section of settings.
  863. *
  864. * This only affects services that have a resolution and/or framerate limit, of
  865. * which as of this writing, and hopefully for the foreseeable future, there is
  866. * only one.
  867. */
  868. bool OBSBasicSettings::UpdateResFPSLimits()
  869. {
  870. if (loading)
  871. return false;
  872. int idx = ui->service->currentIndex();
  873. if (idx == -1)
  874. return false;
  875. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  876. BPtr<obs_service_resolution> res_list;
  877. size_t res_count = 0;
  878. int max_fps = 0;
  879. if (!IsCustomService() && !ignoreRecommended) {
  880. OBSService service = GetStream1Service();
  881. obs_service_get_supported_resolutions(service, &res_list,
  882. &res_count);
  883. obs_service_get_max_fps(service, &max_fps);
  884. }
  885. /* ------------------------------------ */
  886. /* Check for enforced res/FPS */
  887. QString res = ui->outputResolution->currentText();
  888. QString fps_str;
  889. int cx = 0, cy = 0;
  890. double max_fpsd = (double)max_fps;
  891. int closest_fps_index = -1;
  892. double fpsd;
  893. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  894. if (res_count)
  895. set_closest_res(cx, cy, res_list, res_count);
  896. if (max_fps) {
  897. int fpsType = ui->fpsType->currentIndex();
  898. if (fpsType == 1) { //Integer
  899. fpsd = (double)ui->fpsInteger->value();
  900. } else if (fpsType == 2) { //Fractional
  901. fpsd = (double)ui->fpsNumerator->value() /
  902. (double)ui->fpsDenominator->value();
  903. } else { //Common
  904. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  905. &fpsd);
  906. }
  907. double closest_diff = 1000000000000.0;
  908. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  909. double com_fpsd;
  910. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  911. &com_fpsd);
  912. if (com_fpsd > max_fpsd) {
  913. continue;
  914. }
  915. double diff = fabs(com_fpsd - fpsd);
  916. if (diff < closest_diff) {
  917. closest_diff = diff;
  918. closest_fps_index = i;
  919. fps_str = ui->fpsCommon->itemText(i);
  920. }
  921. }
  922. }
  923. QString res_str =
  924. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  925. /* ------------------------------------ */
  926. /* Display message box if res/FPS bad */
  927. bool valid = ResFPSValid(res_list, res_count, max_fps);
  928. if (!valid) {
  929. /* if the user was already on facebook with an incompatible
  930. * resolution, assume it's an upgrade */
  931. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  932. ui->ignoreRecommended->setChecked(true);
  933. ui->ignoreRecommended->setProperty("changed", true);
  934. stream1Changed = true;
  935. EnableApplyButton(true);
  936. return UpdateResFPSLimits();
  937. }
  938. QMessageBox::StandardButton button;
  939. #define WARNING_VAL(x) \
  940. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  941. QString str;
  942. if (res_count)
  943. str += WARNING_VAL("Resolution").arg(res_str);
  944. if (max_fps) {
  945. if (!str.isEmpty())
  946. str += "\n";
  947. str += WARNING_VAL("FPS").arg(fps_str);
  948. }
  949. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  950. WARNING_VAL("Msg").arg(str));
  951. #undef WARNING_VAL
  952. if (button == QMessageBox::No) {
  953. if (idx != lastServiceIdx)
  954. QMetaObject::invokeMethod(
  955. ui->service, "setCurrentIndex",
  956. Qt::QueuedConnection,
  957. Q_ARG(int, lastServiceIdx));
  958. else
  959. QMetaObject::invokeMethod(ui->ignoreRecommended,
  960. "setChecked",
  961. Qt::QueuedConnection,
  962. Q_ARG(bool, true));
  963. return false;
  964. }
  965. }
  966. /* ------------------------------------ */
  967. /* Update widgets/values if switching */
  968. /* to/from enforced resolution/FPS */
  969. ui->outputResolution->blockSignals(true);
  970. if (res_count) {
  971. ui->outputResolution->clear();
  972. ui->outputResolution->setEditable(false);
  973. HookWidget(ui->outputResolution,
  974. &QComboBox::currentIndexChanged,
  975. &OBSBasicSettings::VideoChangedResolution);
  976. int new_res_index = -1;
  977. for (size_t i = 0; i < res_count; i++) {
  978. obs_service_resolution val = res_list[i];
  979. QString str =
  980. QString("%1x%2").arg(QString::number(val.cx),
  981. QString::number(val.cy));
  982. ui->outputResolution->addItem(str);
  983. if (val.cx == cx && val.cy == cy)
  984. new_res_index = (int)i;
  985. }
  986. ui->outputResolution->setCurrentIndex(new_res_index);
  987. if (!valid) {
  988. ui->outputResolution->setProperty("changed", true);
  989. videoChanged = true;
  990. EnableApplyButton(true);
  991. }
  992. } else {
  993. QString baseRes = ui->baseResolution->currentText();
  994. int baseCX, baseCY;
  995. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  996. if (!ui->outputResolution->isEditable()) {
  997. RecreateOutputResolutionWidget();
  998. ui->outputResolution->blockSignals(true);
  999. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  1000. true);
  1001. ui->outputResolution->setCurrentText(res);
  1002. }
  1003. }
  1004. ui->outputResolution->blockSignals(false);
  1005. if (max_fps) {
  1006. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  1007. double com_fpsd;
  1008. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  1009. &com_fpsd);
  1010. if (com_fpsd > max_fpsd) {
  1011. SetComboItemEnabled(ui->fpsCommon, i, false);
  1012. continue;
  1013. }
  1014. }
  1015. ui->fpsType->setCurrentIndex(0);
  1016. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  1017. if (!valid) {
  1018. ui->fpsType->setProperty("changed", true);
  1019. ui->fpsCommon->setProperty("changed", true);
  1020. videoChanged = true;
  1021. EnableApplyButton(true);
  1022. }
  1023. } else {
  1024. for (int i = 0; i < ui->fpsCommon->count(); i++)
  1025. SetComboItemEnabled(ui->fpsCommon, i, true);
  1026. }
  1027. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  1028. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  1029. /* ------------------------------------ */
  1030. lastIgnoreRecommended = (int)ignoreRecommended;
  1031. return true;
  1032. }
  1033. static bool service_supports_codec(const char **codecs, const char *codec)
  1034. {
  1035. if (!codecs)
  1036. return true;
  1037. while (*codecs) {
  1038. if (strcmp(*codecs, codec) == 0)
  1039. return true;
  1040. codecs++;
  1041. }
  1042. return false;
  1043. }
  1044. extern bool EncoderAvailable(const char *encoder);
  1045. extern const char *get_simple_output_encoder(const char *name);
  1046. static inline bool service_supports_encoder(const char **codecs,
  1047. const char *encoder)
  1048. {
  1049. if (!EncoderAvailable(encoder))
  1050. return false;
  1051. const char *codec = obs_get_encoder_codec(encoder);
  1052. return service_supports_codec(codecs, codec);
  1053. }
  1054. static bool return_first_id(void *data, const char *id)
  1055. {
  1056. const char **output = (const char **)data;
  1057. *output = id;
  1058. return false;
  1059. }
  1060. bool OBSBasicSettings::ServiceAndVCodecCompatible()
  1061. {
  1062. bool simple = (ui->outputMode->currentIndex() == 0);
  1063. bool ret;
  1064. const char *codec;
  1065. if (simple) {
  1066. QString encoder =
  1067. ui->simpleOutStrEncoder->currentData().toString();
  1068. const char *id = get_simple_output_encoder(QT_TO_UTF8(encoder));
  1069. codec = obs_get_encoder_codec(id);
  1070. } else {
  1071. QString encoder = ui->advOutEncoder->currentData().toString();
  1072. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1073. }
  1074. OBSService service = SpawnTempService();
  1075. const char **codecs = obs_service_get_supported_video_codecs(service);
  1076. if (!codecs || IsCustomService()) {
  1077. const char *output;
  1078. char **output_codecs;
  1079. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1080. &output, return_first_id);
  1081. output_codecs = strlist_split(
  1082. obs_get_output_supported_video_codecs(output), ';',
  1083. false);
  1084. ret = service_supports_codec((const char **)output_codecs,
  1085. codec);
  1086. strlist_free(output_codecs);
  1087. } else {
  1088. ret = service_supports_codec(codecs, codec);
  1089. }
  1090. return ret;
  1091. }
  1092. bool OBSBasicSettings::ServiceAndACodecCompatible()
  1093. {
  1094. bool simple = (ui->outputMode->currentIndex() == 0);
  1095. bool ret;
  1096. QString codec;
  1097. if (simple) {
  1098. codec = ui->simpleOutStrAEncoder->currentData().toString();
  1099. } else {
  1100. QString encoder = ui->advOutAEncoder->currentData().toString();
  1101. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1102. }
  1103. OBSService service = SpawnTempService();
  1104. const char **codecs = obs_service_get_supported_audio_codecs(service);
  1105. if (!codecs || IsCustomService()) {
  1106. const char *output;
  1107. char **output_codecs;
  1108. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1109. &output, return_first_id);
  1110. output_codecs = strlist_split(
  1111. obs_get_output_supported_audio_codecs(output), ';',
  1112. false);
  1113. ret = service_supports_codec((const char **)output_codecs,
  1114. QT_TO_UTF8(codec));
  1115. strlist_free(output_codecs);
  1116. } else {
  1117. ret = service_supports_codec(codecs, QT_TO_UTF8(codec));
  1118. }
  1119. return ret;
  1120. }
  1121. /* we really need a way to find fallbacks in a less hardcoded way. maybe. */
  1122. static QString get_adv_fallback(const QString &enc)
  1123. {
  1124. if (enc == "jim_hevc_nvenc" || enc == "jim_av1_nvenc")
  1125. return "jim_nvenc";
  1126. if (enc == "h265_texture_amf" || enc == "av1_texture_amf")
  1127. return "h264_texture_amf";
  1128. if (enc == "com.apple.videotoolbox.videoencoder.ave.hevc")
  1129. return "com.apple.videotoolbox.videoencoder.ave.avc";
  1130. if (enc == "obs_qsv11_av1")
  1131. return "obs_qsv11";
  1132. return "obs_x264";
  1133. }
  1134. static QString get_adv_audio_fallback(const QString &enc)
  1135. {
  1136. const char *codec = obs_get_encoder_codec(QT_TO_UTF8(enc));
  1137. if (strcmp(codec, "aac") == 0)
  1138. return "ffmpeg_opus";
  1139. QString aac_default = "ffmpeg_aac";
  1140. if (EncoderAvailable("CoreAudio_AAC"))
  1141. aac_default = "CoreAudio_AAC";
  1142. else if (EncoderAvailable("libfdk_aac"))
  1143. aac_default = "libfdk_aac";
  1144. return aac_default;
  1145. }
  1146. static QString get_simple_fallback(const QString &enc)
  1147. {
  1148. if (enc == SIMPLE_ENCODER_NVENC_HEVC || enc == SIMPLE_ENCODER_NVENC_AV1)
  1149. return SIMPLE_ENCODER_NVENC;
  1150. if (enc == SIMPLE_ENCODER_AMD_HEVC || enc == SIMPLE_ENCODER_AMD_AV1)
  1151. return SIMPLE_ENCODER_AMD;
  1152. if (enc == SIMPLE_ENCODER_APPLE_HEVC)
  1153. return SIMPLE_ENCODER_APPLE_H264;
  1154. if (enc == SIMPLE_ENCODER_QSV_AV1)
  1155. return SIMPLE_ENCODER_QSV;
  1156. return SIMPLE_ENCODER_X264;
  1157. }
  1158. bool OBSBasicSettings::ServiceSupportsCodecCheck()
  1159. {
  1160. if (loading)
  1161. return false;
  1162. bool vcodec_compat = ServiceAndVCodecCompatible();
  1163. bool acodec_compat = ServiceAndACodecCompatible();
  1164. if (vcodec_compat && acodec_compat) {
  1165. if (lastServiceIdx != ui->service->currentIndex() ||
  1166. IsCustomService())
  1167. ResetEncoders(true);
  1168. return true;
  1169. }
  1170. QString service = ui->service->currentText();
  1171. QString cur_video_name;
  1172. QString fb_video_name;
  1173. QString cur_audio_name;
  1174. QString fb_audio_name;
  1175. bool simple = (ui->outputMode->currentIndex() == 0);
  1176. /* ------------------------------------------------- */
  1177. /* get current codec */
  1178. if (simple) {
  1179. QString cur_enc =
  1180. ui->simpleOutStrEncoder->currentData().toString();
  1181. QString fb_enc = get_simple_fallback(cur_enc);
  1182. int cur_idx = ui->simpleOutStrEncoder->findData(cur_enc);
  1183. int fb_idx = ui->simpleOutStrEncoder->findData(fb_enc);
  1184. cur_video_name = ui->simpleOutStrEncoder->itemText(cur_idx);
  1185. fb_video_name = ui->simpleOutStrEncoder->itemText(fb_idx);
  1186. cur_enc = ui->simpleOutStrAEncoder->currentData().toString();
  1187. fb_enc = (cur_enc == "opus") ? "aac" : "opus";
  1188. cur_audio_name = ui->simpleOutStrAEncoder->itemText(
  1189. ui->simpleOutStrAEncoder->findData(cur_enc));
  1190. fb_audio_name =
  1191. (cur_enc == "opus")
  1192. ? QTStr("Basic.Settings.Output.Simple.Codec.AAC")
  1193. : QTStr("Basic.Settings.Output.Simple.Codec.Opus");
  1194. } else {
  1195. QString cur_enc = ui->advOutEncoder->currentData().toString();
  1196. QString fb_enc = get_adv_fallback(cur_enc);
  1197. cur_video_name =
  1198. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1199. fb_video_name =
  1200. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1201. cur_enc = ui->advOutAEncoder->currentData().toString();
  1202. fb_enc = get_adv_audio_fallback(cur_enc);
  1203. cur_audio_name =
  1204. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1205. fb_audio_name =
  1206. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1207. }
  1208. #define WARNING_VAL(x) \
  1209. QTStr("Basic.Settings.Output.Warn.ServiceCodecCompatibility." x)
  1210. QString msg = WARNING_VAL("Msg").arg(
  1211. service, vcodec_compat ? cur_audio_name : cur_video_name,
  1212. vcodec_compat ? fb_audio_name : fb_video_name);
  1213. if (!vcodec_compat && !acodec_compat)
  1214. msg = WARNING_VAL("Msg2").arg(service, cur_video_name,
  1215. cur_audio_name, fb_video_name,
  1216. fb_audio_name);
  1217. auto button = OBSMessageBox::question(this, WARNING_VAL("Title"), msg);
  1218. #undef WARNING_VAL
  1219. if (button == QMessageBox::No) {
  1220. if (lastServiceIdx == 0 &&
  1221. lastServiceIdx == ui->service->currentIndex())
  1222. QMetaObject::invokeMethod(ui->customServer, "setText",
  1223. Qt::QueuedConnection,
  1224. Q_ARG(QString,
  1225. lastCustomServer));
  1226. else
  1227. QMetaObject::invokeMethod(ui->service,
  1228. "setCurrentIndex",
  1229. Qt::QueuedConnection,
  1230. Q_ARG(int, lastServiceIdx));
  1231. return false;
  1232. }
  1233. ResetEncoders(true);
  1234. return true;
  1235. }
  1236. #define TEXT_USE_STREAM_ENC \
  1237. QTStr("Basic.Settings.Output.Adv.Recording.UseStreamEncoder")
  1238. void OBSBasicSettings::ResetEncoders(bool streamOnly)
  1239. {
  1240. QString lastAdvVideoEnc = ui->advOutEncoder->currentData().toString();
  1241. QString lastVideoEnc =
  1242. ui->simpleOutStrEncoder->currentData().toString();
  1243. QString lastAdvAudioEnc = ui->advOutAEncoder->currentData().toString();
  1244. QString lastAudioEnc =
  1245. ui->simpleOutStrAEncoder->currentData().toString();
  1246. OBSService service = SpawnTempService();
  1247. const char **vcodecs = obs_service_get_supported_video_codecs(service);
  1248. const char **acodecs = obs_service_get_supported_audio_codecs(service);
  1249. const char *type;
  1250. BPtr<char *> output_vcodecs;
  1251. BPtr<char *> output_acodecs;
  1252. size_t idx = 0;
  1253. if (!vcodecs || IsCustomService()) {
  1254. const char *output;
  1255. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1256. &output, return_first_id);
  1257. output_vcodecs = strlist_split(
  1258. obs_get_output_supported_video_codecs(output), ';',
  1259. false);
  1260. vcodecs = (const char **)output_vcodecs.Get();
  1261. }
  1262. if (!acodecs || IsCustomService()) {
  1263. const char *output;
  1264. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1265. &output, return_first_id);
  1266. output_acodecs = strlist_split(
  1267. obs_get_output_supported_audio_codecs(output), ';',
  1268. false);
  1269. acodecs = (const char **)output_acodecs.Get();
  1270. }
  1271. QSignalBlocker s1(ui->simpleOutStrEncoder);
  1272. QSignalBlocker s2(ui->advOutEncoder);
  1273. QSignalBlocker s3(ui->simpleOutStrAEncoder);
  1274. QSignalBlocker s4(ui->advOutAEncoder);
  1275. /* ------------------------------------------------- */
  1276. /* clear encoder lists */
  1277. ui->simpleOutStrEncoder->clear();
  1278. ui->advOutEncoder->clear();
  1279. ui->simpleOutStrAEncoder->clear();
  1280. ui->advOutAEncoder->clear();
  1281. if (!streamOnly) {
  1282. ui->advOutRecEncoder->clear();
  1283. ui->advOutRecAEncoder->clear();
  1284. }
  1285. /* ------------------------------------------------- */
  1286. /* load advanced stream/recording encoders */
  1287. while (obs_enum_encoder_types(idx++, &type)) {
  1288. const char *name = obs_encoder_get_display_name(type);
  1289. const char *codec = obs_get_encoder_codec(type);
  1290. uint32_t caps = obs_get_encoder_caps(type);
  1291. QString qName = QT_UTF8(name);
  1292. QString qType = QT_UTF8(type);
  1293. if (obs_get_encoder_type(type) == OBS_ENCODER_VIDEO) {
  1294. if ((caps & ENCODER_HIDE_FLAGS) != 0)
  1295. continue;
  1296. if (service_supports_codec(vcodecs, codec))
  1297. ui->advOutEncoder->addItem(qName, qType);
  1298. if (!streamOnly)
  1299. ui->advOutRecEncoder->addItem(qName, qType);
  1300. }
  1301. if (obs_get_encoder_type(type) == OBS_ENCODER_AUDIO) {
  1302. if (service_supports_codec(acodecs, codec))
  1303. ui->advOutAEncoder->addItem(qName, qType);
  1304. if (!streamOnly)
  1305. ui->advOutRecAEncoder->addItem(qName, qType);
  1306. }
  1307. }
  1308. ui->advOutEncoder->model()->sort(0);
  1309. ui->advOutAEncoder->model()->sort(0);
  1310. if (!streamOnly) {
  1311. ui->advOutRecEncoder->model()->sort(0);
  1312. ui->advOutRecEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1313. "none");
  1314. ui->advOutRecAEncoder->model()->sort(0);
  1315. ui->advOutRecAEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1316. "none");
  1317. }
  1318. /* ------------------------------------------------- */
  1319. /* load simple stream encoders */
  1320. #define ENCODER_STR(str) QTStr("Basic.Settings.Output.Simple.Encoder." str)
  1321. ui->simpleOutStrEncoder->addItem(ENCODER_STR("Software"),
  1322. QString(SIMPLE_ENCODER_X264));
  1323. #ifdef _WIN32
  1324. if (service_supports_encoder(vcodecs, "obs_qsv11"))
  1325. ui->simpleOutStrEncoder->addItem(
  1326. ENCODER_STR("Hardware.QSV.H264"),
  1327. QString(SIMPLE_ENCODER_QSV));
  1328. if (service_supports_encoder(vcodecs, "obs_qsv11_av1"))
  1329. ui->simpleOutStrEncoder->addItem(
  1330. ENCODER_STR("Hardware.QSV.AV1"),
  1331. QString(SIMPLE_ENCODER_QSV_AV1));
  1332. #endif
  1333. if (service_supports_encoder(vcodecs, "ffmpeg_nvenc"))
  1334. ui->simpleOutStrEncoder->addItem(
  1335. ENCODER_STR("Hardware.NVENC.H264"),
  1336. QString(SIMPLE_ENCODER_NVENC));
  1337. if (service_supports_encoder(vcodecs, "jim_av1_nvenc"))
  1338. ui->simpleOutStrEncoder->addItem(
  1339. ENCODER_STR("Hardware.NVENC.AV1"),
  1340. QString(SIMPLE_ENCODER_NVENC_AV1));
  1341. #ifdef ENABLE_HEVC
  1342. if (service_supports_encoder(vcodecs, "h265_texture_amf"))
  1343. ui->simpleOutStrEncoder->addItem(
  1344. ENCODER_STR("Hardware.AMD.HEVC"),
  1345. QString(SIMPLE_ENCODER_AMD_HEVC));
  1346. if (service_supports_encoder(vcodecs, "ffmpeg_hevc_nvenc"))
  1347. ui->simpleOutStrEncoder->addItem(
  1348. ENCODER_STR("Hardware.NVENC.HEVC"),
  1349. QString(SIMPLE_ENCODER_NVENC_HEVC));
  1350. #endif
  1351. if (service_supports_encoder(vcodecs, "h264_texture_amf"))
  1352. ui->simpleOutStrEncoder->addItem(
  1353. ENCODER_STR("Hardware.AMD.H264"),
  1354. QString(SIMPLE_ENCODER_AMD));
  1355. if (service_supports_encoder(vcodecs, "av1_texture_amf"))
  1356. ui->simpleOutStrEncoder->addItem(
  1357. ENCODER_STR("Hardware.AMD.AV1"),
  1358. QString(SIMPLE_ENCODER_AMD_AV1));
  1359. /* Preprocessor guard required for the macOS version check */
  1360. #ifdef __APPLE__
  1361. if (service_supports_encoder(
  1362. vcodecs, "com.apple.videotoolbox.videoencoder.ave.avc")
  1363. #ifndef __aarch64__
  1364. && os_get_emulation_status() == true
  1365. #endif
  1366. ) {
  1367. if (__builtin_available(macOS 13.0, *)) {
  1368. ui->simpleOutStrEncoder->addItem(
  1369. ENCODER_STR("Hardware.Apple.H264"),
  1370. QString(SIMPLE_ENCODER_APPLE_H264));
  1371. }
  1372. }
  1373. #ifdef ENABLE_HEVC
  1374. if (service_supports_encoder(
  1375. vcodecs, "com.apple.videotoolbox.videoencoder.ave.hevc")
  1376. #ifndef __aarch64__
  1377. && os_get_emulation_status() == true
  1378. #endif
  1379. ) {
  1380. if (__builtin_available(macOS 13.0, *)) {
  1381. ui->simpleOutStrEncoder->addItem(
  1382. ENCODER_STR("Hardware.Apple.HEVC"),
  1383. QString(SIMPLE_ENCODER_APPLE_HEVC));
  1384. }
  1385. }
  1386. #endif
  1387. #endif
  1388. if (service_supports_encoder(acodecs, "CoreAudio_AAC") ||
  1389. service_supports_encoder(acodecs, "libfdk_aac") ||
  1390. service_supports_encoder(acodecs, "ffmpeg_aac"))
  1391. ui->simpleOutStrAEncoder->addItem(
  1392. QTStr("Basic.Settings.Output.Simple.Codec.AAC.Default"),
  1393. "aac");
  1394. if (service_supports_encoder(acodecs, "ffmpeg_opus"))
  1395. ui->simpleOutStrAEncoder->addItem(
  1396. QTStr("Basic.Settings.Output.Simple.Codec.Opus"),
  1397. "opus");
  1398. #undef ENCODER_STR
  1399. /* ------------------------------------------------- */
  1400. /* Find fallback encoders */
  1401. if (!lastAdvVideoEnc.isEmpty()) {
  1402. int idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1403. if (idx == -1) {
  1404. lastAdvVideoEnc = get_adv_fallback(lastAdvVideoEnc);
  1405. ui->advOutEncoder->setProperty("changed",
  1406. QVariant(true));
  1407. OutputsChanged();
  1408. }
  1409. idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1410. s2.unblock();
  1411. ui->advOutEncoder->setCurrentIndex(idx);
  1412. }
  1413. if (!lastAdvAudioEnc.isEmpty()) {
  1414. int idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1415. if (idx == -1) {
  1416. lastAdvAudioEnc =
  1417. get_adv_audio_fallback(lastAdvAudioEnc);
  1418. ui->advOutAEncoder->setProperty("changed",
  1419. QVariant(true));
  1420. OutputsChanged();
  1421. }
  1422. idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1423. s4.unblock();
  1424. ui->advOutAEncoder->setCurrentIndex(idx);
  1425. }
  1426. if (!lastVideoEnc.isEmpty()) {
  1427. int idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1428. if (idx == -1) {
  1429. lastVideoEnc = get_simple_fallback(lastVideoEnc);
  1430. ui->simpleOutStrEncoder->setProperty("changed",
  1431. QVariant(true));
  1432. OutputsChanged();
  1433. }
  1434. idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1435. s1.unblock();
  1436. ui->simpleOutStrEncoder->setCurrentIndex(idx);
  1437. }
  1438. if (!lastAudioEnc.isEmpty()) {
  1439. int idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1440. if (idx == -1) {
  1441. lastAudioEnc = (lastAudioEnc == "opus") ? "aac"
  1442. : "opus";
  1443. ui->simpleOutStrAEncoder->setProperty("changed",
  1444. QVariant(true));
  1445. OutputsChanged();
  1446. }
  1447. idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1448. s3.unblock();
  1449. ui->simpleOutStrAEncoder->setCurrentIndex(idx);
  1450. }
  1451. }