window-basic-settings-stream.cpp 49 KB

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