window-basic-settings-stream.cpp 49 KB

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