window-basic-settings-stream.cpp 39 KB

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