window-basic-main-profiles.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /******************************************************************************
  2. Copyright (C) 2015 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <obs.hpp>
  15. #include <util/platform.h>
  16. #include <util/util.hpp>
  17. #include <QMessageBox>
  18. #include <QVariant>
  19. #include <QFileDialog>
  20. #include "window-basic-main.hpp"
  21. #include "window-namedialog.hpp"
  22. #include "qt-wrappers.hpp"
  23. extern void DestroyPanelCookieManager();
  24. extern void DuplicateCurrentCookieProfile(ConfigFile &config);
  25. extern void CheckExistingCookieId();
  26. extern void DeleteCookies();
  27. void EnumProfiles(std::function<bool (const char *, const char *)> &&cb)
  28. {
  29. char path[512];
  30. os_glob_t *glob;
  31. int ret = GetConfigPath(path, sizeof(path),
  32. "obs-studio/basic/profiles/*");
  33. if (ret <= 0) {
  34. blog(LOG_WARNING, "Failed to get profiles config path");
  35. return;
  36. }
  37. if (os_glob(path, 0, &glob) != 0) {
  38. blog(LOG_WARNING, "Failed to glob profiles");
  39. return;
  40. }
  41. for (size_t i = 0; i < glob->gl_pathc; i++) {
  42. const char *filePath = glob->gl_pathv[i].path;
  43. const char *dirName = strrchr(filePath, '/') + 1;
  44. if (!glob->gl_pathv[i].directory)
  45. continue;
  46. if (strcmp(dirName, ".") == 0 ||
  47. strcmp(dirName, "..") == 0)
  48. continue;
  49. std::string file = filePath;
  50. file += "/basic.ini";
  51. ConfigFile config;
  52. int ret = config.Open(file.c_str(), CONFIG_OPEN_EXISTING);
  53. if (ret != CONFIG_SUCCESS)
  54. continue;
  55. const char *name = config_get_string(config, "General", "Name");
  56. if (!name)
  57. name = strrchr(filePath, '/') + 1;
  58. if (!cb(name, filePath))
  59. break;
  60. }
  61. os_globfree(glob);
  62. }
  63. static bool ProfileExists(const char *findName)
  64. {
  65. bool found = false;
  66. auto func = [&](const char *name, const char*)
  67. {
  68. if (strcmp(name, findName) == 0) {
  69. found = true;
  70. return false;
  71. }
  72. return true;
  73. };
  74. EnumProfiles(func);
  75. return found;
  76. }
  77. static bool GetProfileName(QWidget *parent, std::string &name,
  78. std::string &file, const char *title, const char *text,
  79. const char *oldName = nullptr)
  80. {
  81. char path[512];
  82. int ret;
  83. for (;;) {
  84. bool success = NameDialog::AskForName(parent, title, text,
  85. name, QT_UTF8(oldName));
  86. if (!success) {
  87. return false;
  88. }
  89. if (name.empty()) {
  90. OBSMessageBox::warning(parent,
  91. QTStr("NoNameEntered.Title"),
  92. QTStr("NoNameEntered.Text"));
  93. continue;
  94. }
  95. if (ProfileExists(name.c_str())) {
  96. OBSMessageBox::warning(parent,
  97. QTStr("NameExists.Title"),
  98. QTStr("NameExists.Text"));
  99. continue;
  100. }
  101. break;
  102. }
  103. if (!GetFileSafeName(name.c_str(), file)) {
  104. blog(LOG_WARNING, "Failed to create safe file name for '%s'",
  105. name.c_str());
  106. return false;
  107. }
  108. ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/profiles/");
  109. if (ret <= 0) {
  110. blog(LOG_WARNING, "Failed to get profiles config path");
  111. return false;
  112. }
  113. file.insert(0, path);
  114. if (!GetClosestUnusedFileName(file, nullptr)) {
  115. blog(LOG_WARNING, "Failed to get closest file name for %s",
  116. file.c_str());
  117. return false;
  118. }
  119. file.erase(0, ret);
  120. return true;
  121. }
  122. static bool CopyProfile(const char *fromPartial, const char *to)
  123. {
  124. os_glob_t *glob;
  125. char path[514];
  126. char dir[512];
  127. int ret;
  128. ret = GetConfigPath(dir, sizeof(dir), "obs-studio/basic/profiles/");
  129. if (ret <= 0) {
  130. blog(LOG_WARNING, "Failed to get profiles config path");
  131. return false;
  132. }
  133. snprintf(path, sizeof(path), "%s%s/*", dir, fromPartial);
  134. if (os_glob(path, 0, &glob) != 0) {
  135. blog(LOG_WARNING, "Failed to glob profile '%s'", fromPartial);
  136. return false;
  137. }
  138. for (size_t i = 0; i < glob->gl_pathc; i++) {
  139. const char *filePath = glob->gl_pathv[i].path;
  140. if (glob->gl_pathv[i].directory)
  141. continue;
  142. ret = snprintf(path, sizeof(path), "%s/%s",
  143. to, strrchr(filePath, '/') + 1);
  144. if (ret > 0) {
  145. if (os_copyfile(filePath, path) != 0) {
  146. blog(LOG_WARNING, "CopyProfile: Failed to "
  147. "copy file %s to %s",
  148. filePath, path);
  149. }
  150. }
  151. }
  152. os_globfree(glob);
  153. return true;
  154. }
  155. bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
  156. const char *init_text, bool rename)
  157. {
  158. std::string newName;
  159. std::string newDir;
  160. std::string newPath;
  161. ConfigFile config;
  162. if (!GetProfileName(this, newName, newDir, title, text, init_text))
  163. return false;
  164. std::string curDir = config_get_string(App()->GlobalConfig(),
  165. "Basic", "ProfileDir");
  166. char baseDir[512];
  167. int ret = GetConfigPath(baseDir, sizeof(baseDir),
  168. "obs-studio/basic/profiles/");
  169. if (ret <= 0) {
  170. blog(LOG_WARNING, "Failed to get profiles config path");
  171. return false;
  172. }
  173. newPath = baseDir;
  174. newPath += newDir;
  175. if (os_mkdir(newPath.c_str()) < 0) {
  176. blog(LOG_WARNING, "Failed to create profile directory '%s'",
  177. newDir.c_str());
  178. return false;
  179. }
  180. if (!create_new)
  181. CopyProfile(curDir.c_str(), newPath.c_str());
  182. newPath += "/basic.ini";
  183. if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
  184. blog(LOG_ERROR, "Failed to open new config file '%s'",
  185. newDir.c_str());
  186. return false;
  187. }
  188. config_set_string(App()->GlobalConfig(), "Basic", "Profile",
  189. newName.c_str());
  190. config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
  191. newDir.c_str());
  192. Auth::Save();
  193. if (create_new) {
  194. auth.reset();
  195. DestroyPanelCookieManager();
  196. } else if (!rename) {
  197. DuplicateCurrentCookieProfile(config);
  198. }
  199. config_set_string(config, "General", "Name", newName.c_str());
  200. basicConfig.SaveSafe("tmp");
  201. config.SaveSafe("tmp");
  202. config.Swap(basicConfig);
  203. InitBasicConfigDefaults();
  204. InitBasicConfigDefaults2();
  205. RefreshProfiles();
  206. if (create_new)
  207. ResetProfileData();
  208. blog(LOG_INFO, "Created profile '%s' (%s, %s)", newName.c_str(),
  209. create_new ? "clean" : "duplicate", newDir.c_str());
  210. blog(LOG_INFO, "------------------------------------------------");
  211. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  212. UpdateTitleBar();
  213. if (api) {
  214. api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
  215. api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
  216. }
  217. return true;
  218. }
  219. void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir)
  220. {
  221. char profilePath[512];
  222. char basePath[512];
  223. int ret = GetConfigPath(basePath, 512, "obs-studio/basic/profiles");
  224. if (ret <= 0) {
  225. blog(LOG_WARNING, "Failed to get profiles config path");
  226. return;
  227. }
  228. ret = snprintf(profilePath, 512, "%s/%s/*", basePath, profileDir);
  229. if (ret <= 0) {
  230. blog(LOG_WARNING, "Failed to get path for profile dir '%s'",
  231. profileDir);
  232. return;
  233. }
  234. os_glob_t *glob;
  235. if (os_glob(profilePath, 0, &glob) != 0) {
  236. blog(LOG_WARNING, "Failed to glob profile dir '%s'",
  237. profileDir);
  238. return;
  239. }
  240. for (size_t i = 0; i < glob->gl_pathc; i++) {
  241. const char *filePath = glob->gl_pathv[i].path;
  242. if (glob->gl_pathv[i].directory)
  243. continue;
  244. os_unlink(filePath);
  245. }
  246. os_globfree(glob);
  247. ret = snprintf(profilePath, 512, "%s/%s", basePath, profileDir);
  248. if (ret <= 0) {
  249. blog(LOG_WARNING, "Failed to get path for profile dir '%s'",
  250. profileDir);
  251. return;
  252. }
  253. os_rmdir(profilePath);
  254. blog(LOG_INFO, "------------------------------------------------");
  255. blog(LOG_INFO, "Removed profile '%s' (%s)",
  256. profileName, profileDir);
  257. blog(LOG_INFO, "------------------------------------------------");
  258. }
  259. void OBSBasic::RefreshProfiles()
  260. {
  261. QList<QAction*> menuActions = ui->profileMenu->actions();
  262. int count = 0;
  263. for (int i = 0; i < menuActions.count(); i++) {
  264. QVariant v = menuActions[i]->property("file_name");
  265. if (v.typeName() != nullptr)
  266. delete menuActions[i];
  267. }
  268. const char *curName = config_get_string(App()->GlobalConfig(),
  269. "Basic", "Profile");
  270. auto addProfile = [&](const char *name, const char *path)
  271. {
  272. std::string file = strrchr(path, '/') + 1;
  273. QAction *action = new QAction(QT_UTF8(name), this);
  274. action->setProperty("file_name", QT_UTF8(path));
  275. connect(action, &QAction::triggered,
  276. this, &OBSBasic::ChangeProfile);
  277. action->setCheckable(true);
  278. action->setChecked(strcmp(name, curName) == 0);
  279. ui->profileMenu->addAction(action);
  280. count++;
  281. return true;
  282. };
  283. EnumProfiles(addProfile);
  284. ui->actionRemoveProfile->setEnabled(count > 1);
  285. }
  286. void OBSBasic::ResetProfileData()
  287. {
  288. ResetVideo();
  289. service = nullptr;
  290. InitService();
  291. ResetOutputs();
  292. ClearHotkeys();
  293. CreateHotkeys();
  294. /* load audio monitoring */
  295. #if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
  296. const char *device_name = config_get_string(basicConfig, "Audio",
  297. "MonitoringDeviceName");
  298. const char *device_id = config_get_string(basicConfig, "Audio",
  299. "MonitoringDeviceId");
  300. obs_set_audio_monitoring_device(device_name, device_id);
  301. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
  302. device_name, device_id);
  303. #endif
  304. }
  305. void OBSBasic::on_actionNewProfile_triggered()
  306. {
  307. AddProfile(true, Str("AddProfile.Title"), Str("AddProfile.Text"));
  308. }
  309. void OBSBasic::on_actionDupProfile_triggered()
  310. {
  311. AddProfile(false, Str("AddProfile.Title"), Str("AddProfile.Text"));
  312. }
  313. void OBSBasic::on_actionRenameProfile_triggered()
  314. {
  315. std::string curDir = config_get_string(App()->GlobalConfig(),
  316. "Basic", "ProfileDir");
  317. std::string curName = config_get_string(App()->GlobalConfig(),
  318. "Basic", "Profile");
  319. /* Duplicate and delete in case there are any issues in the process */
  320. bool success = AddProfile(false, Str("RenameProfile.Title"),
  321. Str("AddProfile.Text"), curName.c_str(), true);
  322. if (success) {
  323. DeleteProfile(curName.c_str(), curDir.c_str());
  324. RefreshProfiles();
  325. }
  326. if (api) {
  327. api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
  328. api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
  329. }
  330. }
  331. void OBSBasic::on_actionRemoveProfile_triggered()
  332. {
  333. std::string newName;
  334. std::string newPath;
  335. ConfigFile config;
  336. std::string oldDir = config_get_string(App()->GlobalConfig(),
  337. "Basic", "ProfileDir");
  338. std::string oldName = config_get_string(App()->GlobalConfig(),
  339. "Basic", "Profile");
  340. auto cb = [&](const char *name, const char *filePath)
  341. {
  342. if (strcmp(oldName.c_str(), name) != 0) {
  343. newName = name;
  344. newPath = filePath;
  345. return false;
  346. }
  347. return true;
  348. };
  349. EnumProfiles(cb);
  350. /* this should never be true due to menu item being grayed out */
  351. if (newPath.empty())
  352. return;
  353. QString text = QTStr("ConfirmRemove.Text");
  354. text.replace("$1", QT_UTF8(oldName.c_str()));
  355. QMessageBox::StandardButton button = OBSMessageBox::question(this,
  356. QTStr("ConfirmRemove.Title"), text);
  357. if (button == QMessageBox::No)
  358. return;
  359. size_t newPath_len = newPath.size();
  360. newPath += "/basic.ini";
  361. if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
  362. blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
  363. newPath.c_str());
  364. return;
  365. }
  366. newPath.resize(newPath_len);
  367. const char *newDir = strrchr(newPath.c_str(), '/') + 1;
  368. config_set_string(App()->GlobalConfig(), "Basic", "Profile",
  369. newName.c_str());
  370. config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
  371. newDir);
  372. Auth::Save();
  373. auth.reset();
  374. DeleteCookies();
  375. DestroyPanelCookieManager();
  376. config.Swap(basicConfig);
  377. InitBasicConfigDefaults();
  378. InitBasicConfigDefaults2();
  379. ResetProfileData();
  380. DeleteProfile(oldName.c_str(), oldDir.c_str());
  381. RefreshProfiles();
  382. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  383. blog(LOG_INFO, "Switched to profile '%s' (%s)",
  384. newName.c_str(), newDir);
  385. blog(LOG_INFO, "------------------------------------------------");
  386. UpdateTitleBar();
  387. Auth::Load();
  388. if (api) {
  389. api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
  390. api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
  391. }
  392. }
  393. void OBSBasic::on_actionImportProfile_triggered()
  394. {
  395. char path[512];
  396. QString home = QDir::homePath();
  397. int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
  398. if (ret <= 0) {
  399. blog(LOG_WARNING, "Failed to get profile config path");
  400. return;
  401. }
  402. QString dir = QFileDialog::getExistingDirectory(
  403. this,
  404. QTStr("Basic.MainMenu.Profile.Import"),
  405. home,
  406. QFileDialog::ShowDirsOnly |
  407. QFileDialog::DontResolveSymlinks);
  408. if (!dir.isEmpty() && !dir.isNull()) {
  409. QString inputPath = QString::fromUtf8(path);
  410. QFileInfo finfo(dir);
  411. QString directory = finfo.fileName();
  412. QString profileDir = inputPath + directory;
  413. QDir folder(profileDir);
  414. if (!folder.exists()) {
  415. folder.mkpath(profileDir);
  416. QFile::copy(dir + "/basic.ini",
  417. profileDir + "/basic.ini");
  418. QFile::copy(dir + "/service.json",
  419. profileDir + "/service.json");
  420. QFile::copy(dir + "/streamEncoder.json",
  421. profileDir + "/streamEncoder.json");
  422. QFile::copy(dir + "/recordEncoder.json",
  423. profileDir + "/recordEncoder.json");
  424. RefreshProfiles();
  425. } else {
  426. OBSMessageBox::warning(this,
  427. QTStr("Basic.MainMenu.Profile.Import"),
  428. QTStr("Basic.MainMenu.Profile.Exists"));
  429. }
  430. }
  431. }
  432. void OBSBasic::on_actionExportProfile_triggered()
  433. {
  434. char path[512];
  435. QString home = QDir::homePath();
  436. QString currentProfile =
  437. QString::fromUtf8(config_get_string(App()->GlobalConfig(),
  438. "Basic", "ProfileDir"));
  439. int ret = GetConfigPath(path, 512, "obs-studio/basic/profiles/");
  440. if (ret <= 0) {
  441. blog(LOG_WARNING, "Failed to get profile config path");
  442. return;
  443. }
  444. QString dir = QFileDialog::getExistingDirectory(
  445. this,
  446. QTStr("Basic.MainMenu.Profile.Export"),
  447. home,
  448. QFileDialog::ShowDirsOnly |
  449. QFileDialog::DontResolveSymlinks);
  450. if (!dir.isEmpty() && !dir.isNull()) {
  451. QString outputDir = dir + "/" + currentProfile;
  452. QString inputPath = QString::fromUtf8(path);
  453. QDir folder(outputDir);
  454. if (!folder.exists()) {
  455. folder.mkpath(outputDir);
  456. } else {
  457. if (QFile::exists(outputDir + "/basic.ini"))
  458. QFile::remove(outputDir + "/basic.ini");
  459. if (QFile::exists(outputDir + "/service.json"))
  460. QFile::remove(outputDir + "/service.json");
  461. if (QFile::exists(outputDir + "/streamEncoder.json"))
  462. QFile::remove(outputDir + "/streamEncoder.json");
  463. if (QFile::exists(outputDir + "/recordEncoder.json"))
  464. QFile::remove(outputDir + "/recordEncoder.json");
  465. }
  466. QFile::copy(inputPath + currentProfile + "/basic.ini",
  467. outputDir + "/basic.ini");
  468. QFile::copy(inputPath + currentProfile + "/service.json",
  469. outputDir + "/service.json");
  470. QFile::copy(inputPath + currentProfile + "/streamEncoder.json",
  471. outputDir + "/streamEncoder.json");
  472. QFile::copy(inputPath + currentProfile + "/recordEncoder.json",
  473. outputDir + "/recordEncoder.json");
  474. }
  475. }
  476. void OBSBasic::ChangeProfile()
  477. {
  478. QAction *action = reinterpret_cast<QAction*>(sender());
  479. ConfigFile config;
  480. std::string path;
  481. if (!action)
  482. return;
  483. path = QT_TO_UTF8(action->property("file_name").value<QString>());
  484. if (path.empty())
  485. return;
  486. const char *oldName = config_get_string(App()->GlobalConfig(),
  487. "Basic", "Profile");
  488. if (action->text().compare(QT_UTF8(oldName)) == 0) {
  489. action->setChecked(true);
  490. return;
  491. }
  492. size_t path_len = path.size();
  493. path += "/basic.ini";
  494. if (config.Open(path.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
  495. blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
  496. path.c_str());
  497. return;
  498. }
  499. path.resize(path_len);
  500. const char *newName = config_get_string(config, "General", "Name");
  501. const char *newDir = strrchr(path.c_str(), '/') + 1;
  502. config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName);
  503. config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
  504. newDir);
  505. Auth::Save();
  506. auth.reset();
  507. DestroyPanelCookieManager();
  508. config.Swap(basicConfig);
  509. InitBasicConfigDefaults();
  510. InitBasicConfigDefaults2();
  511. ResetProfileData();
  512. RefreshProfiles();
  513. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  514. UpdateTitleBar();
  515. Auth::Load();
  516. CheckForSimpleModeX264Fallback();
  517. blog(LOG_INFO, "Switched to profile '%s' (%s)",
  518. newName, newDir);
  519. blog(LOG_INFO, "------------------------------------------------");
  520. if (api)
  521. api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
  522. }
  523. void OBSBasic::CheckForSimpleModeX264Fallback()
  524. {
  525. const char *curStreamEncoder = config_get_string(basicConfig,
  526. "SimpleOutput", "StreamEncoder");
  527. const char *curRecEncoder = config_get_string(basicConfig,
  528. "SimpleOutput", "RecEncoder");
  529. bool qsv_supported = false;
  530. bool amd_supported = false;
  531. bool nve_supported = false;
  532. bool changed = false;
  533. size_t idx = 0;
  534. const char *id;
  535. while (obs_enum_encoder_types(idx++, &id)) {
  536. if (strcmp(id, "amd_amf_h264") == 0)
  537. amd_supported = true;
  538. else if (strcmp(id, "obs_qsv11") == 0)
  539. qsv_supported = true;
  540. else if (strcmp(id, "ffmpeg_nvenc") == 0)
  541. nve_supported = true;
  542. }
  543. auto CheckEncoder = [&] (const char *&name)
  544. {
  545. if (strcmp(name, SIMPLE_ENCODER_QSV) == 0) {
  546. if (!qsv_supported) {
  547. changed = true;
  548. name = SIMPLE_ENCODER_X264;
  549. return false;
  550. }
  551. } else if (strcmp(name, SIMPLE_ENCODER_NVENC) == 0) {
  552. if (!nve_supported) {
  553. changed = true;
  554. name = SIMPLE_ENCODER_X264;
  555. return false;
  556. }
  557. } else if (strcmp(name, SIMPLE_ENCODER_AMD) == 0) {
  558. if (!amd_supported) {
  559. changed = true;
  560. name = SIMPLE_ENCODER_X264;
  561. return false;
  562. }
  563. }
  564. return true;
  565. };
  566. if (!CheckEncoder(curStreamEncoder))
  567. config_set_string(basicConfig,
  568. "SimpleOutput", "StreamEncoder",
  569. curStreamEncoder);
  570. if (!CheckEncoder(curRecEncoder))
  571. config_set_string(basicConfig,
  572. "SimpleOutput", "RecEncoder",
  573. curRecEncoder);
  574. if (changed)
  575. config_save_safe(basicConfig, "tmp", nullptr);
  576. }