OBSBasic.cpp 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include "OBSBasic.hpp"
  17. #include "ui-config.h"
  18. #include "ColorSelect.hpp"
  19. #include "OBSBasicControls.hpp"
  20. #include "OBSBasicStats.hpp"
  21. #include "plugin-manager/PluginManager.hpp"
  22. #include "VolControl.hpp"
  23. #include <obs-module.h>
  24. #ifdef YOUTUBE_ENABLED
  25. #include <docks/YouTubeAppDock.hpp>
  26. #endif
  27. #include <dialogs/NameDialog.hpp>
  28. #include <dialogs/OBSAbout.hpp>
  29. #include <dialogs/OBSBasicAdvAudio.hpp>
  30. #include <dialogs/OBSBasicFilters.hpp>
  31. #include <dialogs/OBSBasicInteraction.hpp>
  32. #include <dialogs/OBSBasicProperties.hpp>
  33. #include <dialogs/OBSBasicTransform.hpp>
  34. #include <models/SceneCollection.hpp>
  35. #include <settings/OBSBasicSettings.hpp>
  36. #include <utility/QuickTransition.hpp>
  37. #include <utility/SceneRenameDelegate.hpp>
  38. #if defined(_WIN32) || defined(WHATSNEW_ENABLED)
  39. #include <utility/WhatsNewInfoThread.hpp>
  40. #endif
  41. #include <widgets/OBSProjector.hpp>
  42. #include <OBSStudioAPI.hpp>
  43. #ifdef BROWSER_AVAILABLE
  44. #include <browser-panel.hpp>
  45. #endif
  46. #ifdef ENABLE_WAYLAND
  47. #include <obs-nix-platform.h>
  48. #endif
  49. #include <qt-wrappers.hpp>
  50. #include <QActionGroup>
  51. #include <QThread>
  52. #include <QWidgetAction>
  53. #ifdef _WIN32
  54. #include <sstream>
  55. #endif
  56. #include <string>
  57. #include <unordered_set>
  58. #ifdef _WIN32
  59. #define WIN32_LEAN_AND_MEAN
  60. #include "Windows.h"
  61. #endif
  62. #include "moc_OBSBasic.cpp"
  63. using namespace std;
  64. extern bool portable_mode;
  65. extern bool disable_3p_plugins;
  66. extern bool opt_studio_mode;
  67. extern bool opt_always_on_top;
  68. extern bool opt_minimize_tray;
  69. extern std::string opt_starting_profile;
  70. extern std::string opt_starting_collection;
  71. extern bool safe_mode;
  72. extern bool opt_start_recording;
  73. extern bool opt_start_replaybuffer;
  74. extern bool opt_start_virtualcam;
  75. extern volatile long insideEventLoop;
  76. extern bool restart;
  77. extern bool EncoderAvailable(const char *encoder);
  78. extern void RegisterTwitchAuth();
  79. extern void RegisterRestreamAuth();
  80. #ifdef YOUTUBE_ENABLED
  81. extern void RegisterYoutubeAuth();
  82. #endif
  83. struct QCef;
  84. extern QCef *cef;
  85. extern bool cef_js_avail;
  86. extern void DestroyPanelCookieManager();
  87. extern void CheckExistingCookieId();
  88. static void AddExtraModulePaths()
  89. {
  90. string plugins_path, plugins_data_path;
  91. char *s;
  92. s = getenv("OBS_PLUGINS_PATH");
  93. if (s)
  94. plugins_path = s;
  95. s = getenv("OBS_PLUGINS_DATA_PATH");
  96. if (s)
  97. plugins_data_path = s;
  98. if (!plugins_path.empty() && !plugins_data_path.empty()) {
  99. #if defined(__APPLE__)
  100. plugins_path += "/%module%.plugin/Contents/MacOS";
  101. plugins_data_path += "/%module%.plugin/Contents/Resources";
  102. obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
  103. #else
  104. string data_path_with_module_suffix;
  105. data_path_with_module_suffix += plugins_data_path;
  106. data_path_with_module_suffix += "/%module%";
  107. obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
  108. #endif
  109. }
  110. if (portable_mode)
  111. return;
  112. char base_module_dir[512];
  113. #if defined(_WIN32)
  114. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  115. #elif defined(__APPLE__)
  116. int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
  117. #else
  118. int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  119. #endif
  120. if (ret <= 0)
  121. return;
  122. string path = base_module_dir;
  123. #if defined(__APPLE__)
  124. /* User Application Support Search Path */
  125. obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
  126. #ifndef __aarch64__
  127. /* Legacy System Library Search Path */
  128. char system_legacy_module_dir[PATH_MAX];
  129. GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
  130. std::string path_system_legacy = system_legacy_module_dir;
  131. obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
  132. /* Legacy User Application Support Search Path */
  133. char user_legacy_module_dir[PATH_MAX];
  134. GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
  135. std::string path_user_legacy = user_legacy_module_dir;
  136. obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
  137. #endif
  138. #else
  139. #if ARCH_BITS == 64
  140. obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
  141. #else
  142. obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
  143. #endif
  144. #endif
  145. }
  146. /* First-party modules considered to be potentially unsafe to load in Safe Mode
  147. * due to them allowing external code (e.g. scripts) to modify OBS's state. */
  148. static const unordered_set<string> unsafe_modules = {
  149. "frontend-tools", // Scripting
  150. "obs-websocket", // Allows outside modifications
  151. };
  152. static void SetSafeModuleNames()
  153. {
  154. #ifndef SAFE_MODULES
  155. return;
  156. #else
  157. string module;
  158. stringstream modules_(SAFE_MODULES);
  159. while (getline(modules_, module, '|')) {
  160. /* When only disallowing third-party plugins, still add
  161. * "unsafe" bundled modules to the safe list. */
  162. if (disable_3p_plugins || !unsafe_modules.count(module))
  163. obs_add_safe_module(module.c_str());
  164. }
  165. #endif
  166. }
  167. static void SetCoreModuleNames()
  168. {
  169. #ifndef SAFE_MODULES
  170. throw "SAFE_MODULES not defined";
  171. #else
  172. std::string safeModules = SAFE_MODULES;
  173. if (safeModules.empty()) {
  174. throw "SAFE_MODULES is empty";
  175. }
  176. string module;
  177. stringstream modules_(SAFE_MODULES);
  178. while (getline(modules_, module, '|')) {
  179. obs_add_core_module(module.c_str());
  180. }
  181. #endif
  182. }
  183. extern void setupDockAction(QDockWidget *dock);
  184. OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic)
  185. {
  186. collections = {};
  187. setAttribute(Qt::WA_NativeWindow);
  188. #ifdef TWITCH_ENABLED
  189. RegisterTwitchAuth();
  190. #endif
  191. #ifdef RESTREAM_ENABLED
  192. RegisterRestreamAuth();
  193. #endif
  194. #ifdef YOUTUBE_ENABLED
  195. RegisterYoutubeAuth();
  196. #endif
  197. setAcceptDrops(true);
  198. setContextMenuPolicy(Qt::CustomContextMenu);
  199. QEvent::registerEventType(QEvent::User + QEvent::Close);
  200. api = InitializeAPIInterface(this);
  201. ui->setupUi(this);
  202. ui->previewDisabledWidget->setVisible(false);
  203. /* Set up streaming connections */
  204. connect(
  205. this, &OBSBasic::StreamingStarting, this, [this] { this->streamingStarting = true; },
  206. Qt::DirectConnection);
  207. connect(
  208. this, &OBSBasic::StreamingStarted, this, [this] { this->streamingStarting = false; },
  209. Qt::DirectConnection);
  210. connect(
  211. this, &OBSBasic::StreamingStopped, this, [this] { this->streamingStarting = false; },
  212. Qt::DirectConnection);
  213. /* Set up recording connections */
  214. connect(
  215. this, &OBSBasic::RecordingStarted, this,
  216. [this]() {
  217. this->recordingStarted = true;
  218. this->recordingPaused = false;
  219. },
  220. Qt::DirectConnection);
  221. connect(
  222. this, &OBSBasic::RecordingPaused, this, [this]() { this->recordingPaused = true; },
  223. Qt::DirectConnection);
  224. connect(
  225. this, &OBSBasic::RecordingUnpaused, this, [this]() { this->recordingPaused = false; },
  226. Qt::DirectConnection);
  227. connect(
  228. this, &OBSBasic::RecordingStopped, this,
  229. [this]() {
  230. this->recordingStarted = false;
  231. this->recordingPaused = false;
  232. },
  233. Qt::DirectConnection);
  234. /* Add controls dock */
  235. OBSBasicControls *controls = new OBSBasicControls(this);
  236. controlsDock = new OBSDock(this);
  237. controlsDock->setObjectName(QString::fromUtf8("controlsDock"));
  238. controlsDock->setWindowTitle(QTStr("Basic.Main.Controls"));
  239. /* Parenting is done there so controls will be deleted alongside controlsDock */
  240. controlsDock->setWidget(controls);
  241. addDockWidget(Qt::BottomDockWidgetArea, controlsDock);
  242. connect(controls, &OBSBasicControls::StreamButtonClicked, this, &OBSBasic::StreamActionTriggered);
  243. connect(controls, &OBSBasicControls::StartStreamMenuActionClicked, this, &OBSBasic::StartStreaming);
  244. connect(controls, &OBSBasicControls::StopStreamMenuActionClicked, this, &OBSBasic::StopStreaming);
  245. connect(controls, &OBSBasicControls::ForceStopStreamMenuActionClicked, this, &OBSBasic::ForceStopStreaming);
  246. connect(controls, &OBSBasicControls::BroadcastButtonClicked, this, &OBSBasic::BroadcastButtonClicked);
  247. connect(controls, &OBSBasicControls::RecordButtonClicked, this, &OBSBasic::RecordActionTriggered);
  248. connect(controls, &OBSBasicControls::PauseRecordButtonClicked, this, &OBSBasic::RecordPauseToggled);
  249. connect(controls, &OBSBasicControls::ReplayBufferButtonClicked, this, &OBSBasic::ReplayBufferActionTriggered);
  250. connect(controls, &OBSBasicControls::SaveReplayBufferButtonClicked, this, &OBSBasic::ReplayBufferSave);
  251. connect(controls, &OBSBasicControls::VirtualCamButtonClicked, this, &OBSBasic::VirtualCamActionTriggered);
  252. connect(controls, &OBSBasicControls::VirtualCamConfigButtonClicked, this, &OBSBasic::OpenVirtualCamConfig);
  253. connect(controls, &OBSBasicControls::StudioModeButtonClicked, this, &OBSBasic::TogglePreviewProgramMode);
  254. connect(controls, &OBSBasicControls::SettingsButtonClicked, this, &OBSBasic::on_action_Settings_triggered);
  255. /* Set up transitions combobox connections */
  256. connect(this, &OBSBasic::TransitionAdded, this, [this](const QString &name, const QString &uuid) {
  257. QSignalBlocker sb(ui->transitions);
  258. ui->transitions->addItem(name, uuid);
  259. });
  260. connect(this, &OBSBasic::TransitionRenamed, this, [this](const QString &uuid, const QString &newName) {
  261. QSignalBlocker sb(ui->transitions);
  262. ui->transitions->setItemText(ui->transitions->findData(uuid), newName);
  263. });
  264. connect(this, &OBSBasic::TransitionRemoved, this, [this](const QString &uuid) {
  265. QSignalBlocker sb(ui->transitions);
  266. ui->transitions->removeItem(ui->transitions->findData(uuid));
  267. });
  268. connect(this, &OBSBasic::TransitionsCleared, this, [this]() {
  269. QSignalBlocker sb(ui->transitions);
  270. ui->transitions->clear();
  271. });
  272. connect(this, &OBSBasic::CurrentTransitionChanged, this, [this](const QString &uuid) {
  273. QSignalBlocker sb(ui->transitions);
  274. ui->transitions->setCurrentIndex(ui->transitions->findData(uuid));
  275. });
  276. connect(ui->transitions, &QComboBox::currentIndexChanged, this,
  277. [this]() { SetCurrentTransition(ui->transitions->currentData().toString()); });
  278. connect(this, &OBSBasic::TransitionDurationChanged, this, [this](int duration) {
  279. QSignalBlocker sb(ui->transitionDuration);
  280. ui->transitionDuration->setValue(duration);
  281. });
  282. connect(ui->transitionDuration, &QSpinBox::valueChanged, this,
  283. [this](int value) { SetTransitionDuration(value); });
  284. startingDockLayout = saveState();
  285. statsDock = new OBSDock();
  286. statsDock->setObjectName(QStringLiteral("statsDock"));
  287. statsDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable |
  288. QDockWidget::DockWidgetFloatable);
  289. statsDock->setWindowTitle(QTStr("Basic.Stats"));
  290. addDockWidget(Qt::BottomDockWidgetArea, statsDock);
  291. statsDock->setVisible(false);
  292. statsDock->setFloating(true);
  293. statsDock->resize(700, 200);
  294. copyActionsDynamicProperties();
  295. qRegisterMetaType<int64_t>("int64_t");
  296. qRegisterMetaType<uint32_t>("uint32_t");
  297. qRegisterMetaType<OBSScene>("OBSScene");
  298. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  299. qRegisterMetaType<OBSSource>("OBSSource");
  300. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  301. qRegisterMetaType<SavedProjectorInfo *>("SavedProjectorInfo *");
  302. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  303. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  304. bool sceneGrid = config_get_bool(App()->GetUserConfig(), "BasicWindow", "gridMode");
  305. ui->scenes->SetGridMode(sceneGrid);
  306. if (sceneGrid)
  307. ui->actionSceneGridMode->setChecked(true);
  308. else
  309. ui->actionSceneListMode->setChecked(true);
  310. ui->scenes->setItemDelegate(new SceneRenameDelegate(ui->scenes));
  311. auto displayResize = [this]() {
  312. struct obs_video_info ovi;
  313. if (obs_get_video_info(&ovi))
  314. ResizePreview(ovi.base_width, ovi.base_height);
  315. UpdateContextBarVisibility();
  316. UpdatePreviewControls();
  317. dpi = devicePixelRatioF();
  318. };
  319. dpi = devicePixelRatioF();
  320. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  321. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  322. /* TODO: Move these into window-basic-preview */
  323. /* Preview Scaling label */
  324. connect(ui->preview, &OBSBasicPreview::scalingChanged, ui->previewScalePercent,
  325. &OBSPreviewScalingLabel::PreviewScaleChanged);
  326. /* Preview Scaling dropdown */
  327. connect(ui->preview, &OBSBasicPreview::scalingChanged, ui->previewScalingMode,
  328. &OBSPreviewScalingComboBox::PreviewScaleChanged);
  329. connect(ui->preview, &OBSBasicPreview::fixedScalingChanged, ui->previewScalingMode,
  330. &OBSPreviewScalingComboBox::PreviewFixedScalingChanged);
  331. connect(ui->previewScalingMode, &OBSPreviewScalingComboBox::currentIndexChanged, this,
  332. &OBSBasic::PreviewScalingModeChanged);
  333. /* Preview Controls */
  334. connect(ui->previewXScrollBar, &QScrollBar::sliderMoved, ui->preview, &OBSBasicPreview::xScrollBarChanged);
  335. connect(ui->previewYScrollBar, &QScrollBar::valueChanged, ui->preview, &OBSBasicPreview::yScrollBarChanged);
  336. connect(ui->previewZoomInButton, &QPushButton::clicked, ui->preview, &OBSBasicPreview::increaseScalingLevel);
  337. connect(ui->previewZoomOutButton, &QPushButton::clicked, ui->preview, &OBSBasicPreview::decreaseScalingLevel);
  338. /* Preview Actions */
  339. connect(ui->actionScaleWindow, &QAction::triggered, this, &OBSBasic::setPreviewScalingWindow);
  340. connect(ui->actionScaleCanvas, &QAction::triggered, this, &OBSBasic::setPreviewScalingCanvas);
  341. connect(ui->actionScaleOutput, &QAction::triggered, this, &OBSBasic::setPreviewScalingOutput);
  342. connect(ui->actionPreviewZoomIn, &QAction::triggered, ui->preview, &OBSBasicPreview::increaseScalingLevel);
  343. connect(ui->actionPreviewZoomOut, &QAction::triggered, ui->preview, &OBSBasicPreview::decreaseScalingLevel);
  344. connect(ui->actionPreviewResetZoom, &QAction::triggered, ui->preview, &OBSBasicPreview::resetScalingLevel);
  345. connect(this, &OBSBasic::CanvasResized, ui->previewScalingMode, &OBSPreviewScalingComboBox::CanvasResized);
  346. connect(this, &OBSBasic::OutputResized, ui->previewScalingMode, &OBSPreviewScalingComboBox::OutputResized);
  347. delete shortcutFilter;
  348. shortcutFilter = CreateShortcutFilter();
  349. installEventFilter(shortcutFilter);
  350. stringstream name;
  351. name << "OBS " << App()->GetVersionString();
  352. blog(LOG_INFO, "%s", name.str().c_str());
  353. blog(LOG_INFO, "---------------------------------");
  354. UpdateTitleBar();
  355. connect(ui->scenes->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, &OBSBasic::SceneNameEdited);
  356. cpuUsageInfo = os_cpu_usage_info_start();
  357. cpuUsageTimer = new QTimer(this);
  358. connect(cpuUsageTimer.data(), &QTimer::timeout, ui->statusbar, &OBSBasicStatusBar::UpdateCPUUsage);
  359. cpuUsageTimer->start(3000);
  360. diskFullTimer = new QTimer(this);
  361. connect(diskFullTimer, &QTimer::timeout, this, &OBSBasic::CheckDiskSpaceRemaining);
  362. renameScene = new QAction(QTStr("Rename"), ui->scenesDock);
  363. renameScene->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  364. connect(renameScene, &QAction::triggered, this, &OBSBasic::EditSceneName);
  365. ui->scenesDock->addAction(renameScene);
  366. renameSource = new QAction(QTStr("Rename"), ui->sourcesDock);
  367. renameSource->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  368. connect(renameSource, &QAction::triggered, this, &OBSBasic::EditSceneItemName);
  369. ui->sourcesDock->addAction(renameSource);
  370. #ifdef __APPLE__
  371. renameScene->setShortcut({Qt::Key_Return});
  372. renameSource->setShortcut({Qt::Key_Return});
  373. ui->actionRemoveSource->setShortcuts({Qt::Key_Backspace});
  374. ui->actionRemoveScene->setShortcuts({Qt::Key_Backspace});
  375. ui->actionCheckForUpdates->setMenuRole(QAction::AboutQtRole);
  376. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  377. ui->actionShowMacPermissions->setMenuRole(QAction::ApplicationSpecificRole);
  378. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  379. #else
  380. renameScene->setShortcut({Qt::Key_F2});
  381. renameSource->setShortcut({Qt::Key_F2});
  382. #endif
  383. #ifdef __linux__
  384. ui->actionE_xit->setShortcut(Qt::CTRL | Qt::Key_Q);
  385. #endif
  386. #ifndef ENABLE_IDIAN_PLAYGROUND
  387. ui->idianPlayground->setVisible(false);
  388. #endif
  389. auto addNudge = [this](const QKeySequence &seq, MoveDir direction, int distance) {
  390. QAction *nudge = new QAction(ui->preview);
  391. nudge->setShortcut(seq);
  392. nudge->setShortcutContext(Qt::WidgetShortcut);
  393. ui->preview->addAction(nudge);
  394. connect(nudge, &QAction::triggered, [this, distance, direction]() { Nudge(distance, direction); });
  395. };
  396. addNudge(Qt::Key_Up, MoveDir::Up, 1);
  397. addNudge(Qt::Key_Down, MoveDir::Down, 1);
  398. addNudge(Qt::Key_Left, MoveDir::Left, 1);
  399. addNudge(Qt::Key_Right, MoveDir::Right, 1);
  400. addNudge(Qt::SHIFT | Qt::Key_Up, MoveDir::Up, 10);
  401. addNudge(Qt::SHIFT | Qt::Key_Down, MoveDir::Down, 10);
  402. addNudge(Qt::SHIFT | Qt::Key_Left, MoveDir::Left, 10);
  403. addNudge(Qt::SHIFT | Qt::Key_Right, MoveDir::Right, 10);
  404. /* Setup dock toggle action
  405. * And hide all docks before restoring parent geometry */
  406. #define SETUP_DOCK(dock) \
  407. setupDockAction(dock); \
  408. ui->menuDocks->addAction(dock->toggleViewAction()); \
  409. dock->setVisible(false);
  410. SETUP_DOCK(ui->scenesDock);
  411. SETUP_DOCK(ui->sourcesDock);
  412. SETUP_DOCK(ui->mixerDock);
  413. SETUP_DOCK(ui->transitionsDock);
  414. SETUP_DOCK(controlsDock);
  415. SETUP_DOCK(statsDock);
  416. #undef SETUP_DOCK
  417. // Register shortcuts for Undo/Redo
  418. ui->actionMainUndo->setShortcut(Qt::CTRL | Qt::Key_Z);
  419. QList<QKeySequence> shrt;
  420. shrt << QKeySequence((Qt::CTRL | Qt::SHIFT) | Qt::Key_Z) << QKeySequence(Qt::CTRL | Qt::Key_Y);
  421. ui->actionMainRedo->setShortcuts(shrt);
  422. ui->actionMainUndo->setShortcutContext(Qt::ApplicationShortcut);
  423. ui->actionMainRedo->setShortcutContext(Qt::ApplicationShortcut);
  424. QPoint curPos;
  425. //restore parent window geometry
  426. const char *geometry = config_get_string(App()->GetUserConfig(), "BasicWindow", "geometry");
  427. if (geometry != NULL) {
  428. QByteArray byteArray = QByteArray::fromBase64(QByteArray(geometry));
  429. restoreGeometry(byteArray);
  430. QRect windowGeometry = normalGeometry();
  431. if (!WindowPositionValid(windowGeometry)) {
  432. QRect rect = QGuiApplication::primaryScreen()->geometry();
  433. setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), rect));
  434. }
  435. curPos = pos();
  436. } else {
  437. QRect desktopRect = QGuiApplication::primaryScreen()->geometry();
  438. QSize adjSize = desktopRect.size() / 2 - size() / 2;
  439. curPos = QPoint(adjSize.width(), adjSize.height());
  440. }
  441. QPoint curSize(width(), height());
  442. QPoint statsDockSize(statsDock->width(), statsDock->height());
  443. QPoint statsDockPos = curSize / 2 - statsDockSize / 2;
  444. QPoint newPos = curPos + statsDockPos;
  445. statsDock->move(newPos);
  446. ui->actionReleaseNotes->setVisible(true);
  447. ui->previewDisabledWidget->setContextMenuPolicy(Qt::CustomContextMenu);
  448. connect(ui->enablePreviewButton, &QPushButton::clicked, this, &OBSBasic::TogglePreview);
  449. connect(ui->scenes, &SceneTree::scenesReordered, []() { OBSProjector::UpdateMultiviewProjectors(); });
  450. connect(App(), &OBSApp::StyleChanged, this, [this]() { OnEvent(OBS_FRONTEND_EVENT_THEME_CHANGED); });
  451. QActionGroup *actionGroup = new QActionGroup(this);
  452. actionGroup->addAction(ui->actionSceneListMode);
  453. actionGroup->addAction(ui->actionSceneGridMode);
  454. UpdatePreviewSafeAreas();
  455. UpdatePreviewSpacingHelpers();
  456. UpdatePreviewOverflowSettings();
  457. }
  458. static const double scaled_vals[] = {1.0, 1.25, (1.0 / 0.75), 1.5, (1.0 / 0.6), 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 0.0};
  459. #ifdef __APPLE__ // macOS
  460. #define DEFAULT_CONTAINER "hybrid_mov"
  461. #else // Windows/Linux
  462. #define DEFAULT_CONTAINER "hybrid_mp4"
  463. #endif
  464. bool OBSBasic::InitBasicConfigDefaults()
  465. {
  466. QList<QScreen *> screens = QGuiApplication::screens();
  467. if (!screens.size()) {
  468. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  469. "technically shouldn't be possible.");
  470. return false;
  471. }
  472. QScreen *primaryScreen = QGuiApplication::primaryScreen();
  473. uint32_t cx = primaryScreen->size().width();
  474. uint32_t cy = primaryScreen->size().height();
  475. cx *= devicePixelRatioF();
  476. cy *= devicePixelRatioF();
  477. bool oldResolutionDefaults = config_get_bool(App()->GetUserConfig(), "General", "Pre19Defaults");
  478. /* use 1920x1080 for new default base res if main monitor is above
  479. * 1920x1080, but don't apply for people from older builds -- only to
  480. * new users */
  481. if (!oldResolutionDefaults && (cx * cy) > (1920 * 1080)) {
  482. cx = 1920;
  483. cy = 1080;
  484. }
  485. bool changed = false;
  486. /* ----------------------------------------------------- */
  487. /* move over old FFmpeg track settings */
  488. if (config_has_user_value(activeConfiguration, "AdvOut", "FFAudioTrack") &&
  489. !config_has_user_value(activeConfiguration, "AdvOut", "Pre22.1Settings")) {
  490. int track = (int)config_get_int(activeConfiguration, "AdvOut", "FFAudioTrack");
  491. config_set_int(activeConfiguration, "AdvOut", "FFAudioMixes", 1LL << (track - 1));
  492. config_set_bool(activeConfiguration, "AdvOut", "Pre22.1Settings", true);
  493. changed = true;
  494. }
  495. /* ----------------------------------------------------- */
  496. /* move over mixer values in advanced if older config */
  497. if (config_has_user_value(activeConfiguration, "AdvOut", "RecTrackIndex") &&
  498. !config_has_user_value(activeConfiguration, "AdvOut", "RecTracks")) {
  499. uint64_t track = config_get_uint(activeConfiguration, "AdvOut", "RecTrackIndex");
  500. track = 1ULL << (track - 1);
  501. config_set_uint(activeConfiguration, "AdvOut", "RecTracks", track);
  502. config_remove_value(activeConfiguration, "AdvOut", "RecTrackIndex");
  503. changed = true;
  504. }
  505. /* ----------------------------------------------------- */
  506. /* set twitch chat extensions to "both" if prev version */
  507. /* is under 24.1 */
  508. if (config_get_bool(App()->GetUserConfig(), "General", "Pre24.1Defaults") &&
  509. !config_has_user_value(activeConfiguration, "Twitch", "AddonChoice")) {
  510. config_set_int(activeConfiguration, "Twitch", "AddonChoice", 3);
  511. changed = true;
  512. }
  513. /* ----------------------------------------------------- */
  514. /* move bitrate enforcement setting to new value */
  515. if (config_has_user_value(activeConfiguration, "SimpleOutput", "EnforceBitrate") &&
  516. !config_has_user_value(activeConfiguration, "Stream1", "IgnoreRecommended") &&
  517. !config_has_user_value(activeConfiguration, "Stream1", "MovedOldEnforce")) {
  518. bool enforce = config_get_bool(activeConfiguration, "SimpleOutput", "EnforceBitrate");
  519. config_set_bool(activeConfiguration, "Stream1", "IgnoreRecommended", !enforce);
  520. config_set_bool(activeConfiguration, "Stream1", "MovedOldEnforce", true);
  521. changed = true;
  522. }
  523. /* ----------------------------------------------------- */
  524. /* enforce minimum retry delay of 1 second prior to 27.1 */
  525. if (config_has_user_value(activeConfiguration, "Output", "RetryDelay")) {
  526. int retryDelay = config_get_uint(activeConfiguration, "Output", "RetryDelay");
  527. if (retryDelay < 1) {
  528. config_set_uint(activeConfiguration, "Output", "RetryDelay", 1);
  529. changed = true;
  530. }
  531. }
  532. /* ----------------------------------------------------- */
  533. /* Migrate old container selection (if any) to new key. */
  534. auto MigrateFormat = [&](const char *section) {
  535. bool has_old_key = config_has_user_value(activeConfiguration, section, "RecFormat");
  536. bool has_new_key = config_has_user_value(activeConfiguration, section, "RecFormat2");
  537. if (!has_new_key && !has_old_key)
  538. return;
  539. string old_format =
  540. config_get_string(activeConfiguration, section, has_new_key ? "RecFormat2" : "RecFormat");
  541. string new_format = old_format;
  542. if (old_format == "ts")
  543. new_format = "mpegts";
  544. else if (old_format == "m3u8")
  545. new_format = "hls";
  546. else if (old_format == "fmp4")
  547. new_format = "fragmented_mp4";
  548. else if (old_format == "fmov")
  549. new_format = "fragmented_mov";
  550. if (new_format != old_format || !has_new_key) {
  551. config_set_string(activeConfiguration, section, "RecFormat2", new_format.c_str());
  552. changed = true;
  553. }
  554. };
  555. MigrateFormat("AdvOut");
  556. MigrateFormat("SimpleOutput");
  557. /* ----------------------------------------------------- */
  558. /* Migrate output scale setting to GPU scaling options. */
  559. if (config_get_bool(activeConfiguration, "AdvOut", "Rescale") &&
  560. !config_has_user_value(activeConfiguration, "AdvOut", "RescaleFilter")) {
  561. config_set_int(activeConfiguration, "AdvOut", "RescaleFilter", OBS_SCALE_BILINEAR);
  562. }
  563. if (config_get_bool(activeConfiguration, "AdvOut", "RecRescale") &&
  564. !config_has_user_value(activeConfiguration, "AdvOut", "RecRescaleFilter")) {
  565. config_set_int(activeConfiguration, "AdvOut", "RecRescaleFilter", OBS_SCALE_BILINEAR);
  566. }
  567. /* ----------------------------------------------------- */
  568. if (changed) {
  569. activeConfiguration.SaveSafe("tmp");
  570. }
  571. /* ----------------------------------------------------- */
  572. config_set_default_string(activeConfiguration, "Output", "Mode", "Simple");
  573. config_set_default_bool(activeConfiguration, "Stream1", "IgnoreRecommended", false);
  574. config_set_default_bool(activeConfiguration, "Stream1", "EnableMultitrackVideo", false);
  575. config_set_default_bool(activeConfiguration, "Stream1", "MultitrackVideoMaximumAggregateBitrateAuto", true);
  576. config_set_default_bool(activeConfiguration, "Stream1", "MultitrackVideoMaximumVideoTracksAuto", true);
  577. config_set_default_string(activeConfiguration, "SimpleOutput", "FilePath", GetDefaultVideoSavePath().c_str());
  578. config_set_default_string(activeConfiguration, "SimpleOutput", "RecFormat2", DEFAULT_CONTAINER);
  579. config_set_default_uint(activeConfiguration, "SimpleOutput", "VBitrate", 2500);
  580. config_set_default_uint(activeConfiguration, "SimpleOutput", "ABitrate", 160);
  581. config_set_default_bool(activeConfiguration, "SimpleOutput", "UseAdvanced", false);
  582. config_set_default_string(activeConfiguration, "SimpleOutput", "Preset", "veryfast");
  583. config_set_default_string(activeConfiguration, "SimpleOutput", "NVENCPreset2", "p5");
  584. config_set_default_string(activeConfiguration, "SimpleOutput", "RecQuality", "Stream");
  585. config_set_default_bool(activeConfiguration, "SimpleOutput", "RecRB", false);
  586. config_set_default_int(activeConfiguration, "SimpleOutput", "RecRBTime", 20);
  587. config_set_default_int(activeConfiguration, "SimpleOutput", "RecRBSize", 512);
  588. config_set_default_string(activeConfiguration, "SimpleOutput", "RecRBPrefix", "Replay");
  589. config_set_default_string(activeConfiguration, "SimpleOutput", "StreamAudioEncoder", "aac");
  590. config_set_default_string(activeConfiguration, "SimpleOutput", "RecAudioEncoder", "aac");
  591. config_set_default_uint(activeConfiguration, "SimpleOutput", "RecTracks", (1 << 0));
  592. config_set_default_bool(activeConfiguration, "AdvOut", "ApplyServiceSettings", true);
  593. config_set_default_bool(activeConfiguration, "AdvOut", "UseRescale", false);
  594. config_set_default_uint(activeConfiguration, "AdvOut", "TrackIndex", 1);
  595. config_set_default_uint(activeConfiguration, "AdvOut", "VodTrackIndex", 2);
  596. config_set_default_string(activeConfiguration, "AdvOut", "Encoder", "obs_x264");
  597. config_set_default_string(activeConfiguration, "AdvOut", "RecType", "Standard");
  598. config_set_default_string(activeConfiguration, "AdvOut", "RecFilePath", GetDefaultVideoSavePath().c_str());
  599. config_set_default_string(activeConfiguration, "AdvOut", "RecFormat2", DEFAULT_CONTAINER);
  600. config_set_default_bool(activeConfiguration, "AdvOut", "RecUseRescale", false);
  601. config_set_default_uint(activeConfiguration, "AdvOut", "RecTracks", (1 << 0));
  602. config_set_default_string(activeConfiguration, "AdvOut", "RecEncoder", "none");
  603. config_set_default_uint(activeConfiguration, "AdvOut", "FLVTrack", 1);
  604. config_set_default_uint(activeConfiguration, "AdvOut", "StreamMultiTrackAudioMixes", 1);
  605. config_set_default_bool(activeConfiguration, "AdvOut", "FFOutputToFile", true);
  606. config_set_default_string(activeConfiguration, "AdvOut", "FFFilePath", GetDefaultVideoSavePath().c_str());
  607. config_set_default_string(activeConfiguration, "AdvOut", "FFExtension", "mp4");
  608. config_set_default_uint(activeConfiguration, "AdvOut", "FFVBitrate", 2500);
  609. config_set_default_uint(activeConfiguration, "AdvOut", "FFVGOPSize", 250);
  610. config_set_default_bool(activeConfiguration, "AdvOut", "FFUseRescale", false);
  611. config_set_default_bool(activeConfiguration, "AdvOut", "FFIgnoreCompat", false);
  612. config_set_default_uint(activeConfiguration, "AdvOut", "FFABitrate", 160);
  613. config_set_default_uint(activeConfiguration, "AdvOut", "FFAudioMixes", 1);
  614. config_set_default_uint(activeConfiguration, "AdvOut", "Track1Bitrate", 160);
  615. config_set_default_uint(activeConfiguration, "AdvOut", "Track2Bitrate", 160);
  616. config_set_default_uint(activeConfiguration, "AdvOut", "Track3Bitrate", 160);
  617. config_set_default_uint(activeConfiguration, "AdvOut", "Track4Bitrate", 160);
  618. config_set_default_uint(activeConfiguration, "AdvOut", "Track5Bitrate", 160);
  619. config_set_default_uint(activeConfiguration, "AdvOut", "Track6Bitrate", 160);
  620. config_set_default_uint(activeConfiguration, "AdvOut", "RecSplitFileTime", 15);
  621. config_set_default_uint(activeConfiguration, "AdvOut", "RecSplitFileSize", 2048);
  622. config_set_default_bool(activeConfiguration, "AdvOut", "RecRB", false);
  623. config_set_default_uint(activeConfiguration, "AdvOut", "RecRBTime", 20);
  624. config_set_default_int(activeConfiguration, "AdvOut", "RecRBSize", 512);
  625. config_set_default_uint(activeConfiguration, "Video", "BaseCX", cx);
  626. config_set_default_uint(activeConfiguration, "Video", "BaseCY", cy);
  627. /* don't allow BaseCX/BaseCY to be susceptible to defaults changing */
  628. if (!config_has_user_value(activeConfiguration, "Video", "BaseCX") ||
  629. !config_has_user_value(activeConfiguration, "Video", "BaseCY")) {
  630. config_set_uint(activeConfiguration, "Video", "BaseCX", cx);
  631. config_set_uint(activeConfiguration, "Video", "BaseCY", cy);
  632. config_save_safe(activeConfiguration, "tmp", nullptr);
  633. }
  634. config_set_default_string(activeConfiguration, "Output", "FilenameFormatting", "%CCYY-%MM-%DD %hh-%mm-%ss");
  635. config_set_default_bool(activeConfiguration, "Output", "DelayEnable", false);
  636. config_set_default_uint(activeConfiguration, "Output", "DelaySec", 20);
  637. config_set_default_bool(activeConfiguration, "Output", "DelayPreserve", true);
  638. config_set_default_bool(activeConfiguration, "Output", "Reconnect", true);
  639. config_set_default_uint(activeConfiguration, "Output", "RetryDelay", 2);
  640. config_set_default_uint(activeConfiguration, "Output", "MaxRetries", 25);
  641. config_set_default_string(activeConfiguration, "Output", "BindIP", "default");
  642. config_set_default_string(activeConfiguration, "Output", "IPFamily", "IPv4+IPv6");
  643. config_set_default_bool(activeConfiguration, "Output", "NewSocketLoopEnable", false);
  644. config_set_default_bool(activeConfiguration, "Output", "LowLatencyEnable", false);
  645. int i = 0;
  646. uint32_t scale_cx = cx;
  647. uint32_t scale_cy = cy;
  648. /* use a default scaled resolution that has a pixel count no higher
  649. * than 1280x720 */
  650. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  651. double scale = scaled_vals[i++];
  652. scale_cx = uint32_t(double(cx) / scale);
  653. scale_cy = uint32_t(double(cy) / scale);
  654. }
  655. config_set_default_uint(activeConfiguration, "Video", "OutputCX", scale_cx);
  656. config_set_default_uint(activeConfiguration, "Video", "OutputCY", scale_cy);
  657. /* don't allow OutputCX/OutputCY to be susceptible to defaults
  658. * changing */
  659. if (!config_has_user_value(activeConfiguration, "Video", "OutputCX") ||
  660. !config_has_user_value(activeConfiguration, "Video", "OutputCY")) {
  661. config_set_uint(activeConfiguration, "Video", "OutputCX", scale_cx);
  662. config_set_uint(activeConfiguration, "Video", "OutputCY", scale_cy);
  663. config_save_safe(activeConfiguration, "tmp", nullptr);
  664. }
  665. config_set_default_uint(activeConfiguration, "Video", "FPSType", 0);
  666. config_set_default_string(activeConfiguration, "Video", "FPSCommon", "30");
  667. config_set_default_uint(activeConfiguration, "Video", "FPSInt", 30);
  668. config_set_default_uint(activeConfiguration, "Video", "FPSNum", 30);
  669. config_set_default_uint(activeConfiguration, "Video", "FPSDen", 1);
  670. config_set_default_string(activeConfiguration, "Video", "ScaleType", "bicubic");
  671. config_set_default_string(activeConfiguration, "Video", "ColorFormat", "NV12");
  672. config_set_default_string(activeConfiguration, "Video", "ColorSpace", "709");
  673. config_set_default_string(activeConfiguration, "Video", "ColorRange", "Partial");
  674. config_set_default_uint(activeConfiguration, "Video", "SdrWhiteLevel", 300);
  675. config_set_default_uint(activeConfiguration, "Video", "HdrNominalPeakLevel", 1000);
  676. config_set_default_string(activeConfiguration, "Audio", "MonitoringDeviceId", "default");
  677. config_set_default_string(activeConfiguration, "Audio", "MonitoringDeviceName",
  678. Str("Basic.Settings.Advanced.Audio.MonitoringDevice"
  679. ".Default"));
  680. config_set_default_uint(activeConfiguration, "Audio", "SampleRate", 48000);
  681. config_set_default_string(activeConfiguration, "Audio", "ChannelSetup", "Stereo");
  682. config_set_default_double(activeConfiguration, "Audio", "MeterDecayRate", VOLUME_METER_DECAY_FAST);
  683. config_set_default_uint(activeConfiguration, "Audio", "PeakMeterType", 0);
  684. CheckExistingCookieId();
  685. return true;
  686. }
  687. void OBSBasic::InitBasicConfigDefaults2()
  688. {
  689. bool oldEncDefaults = config_get_bool(App()->GetUserConfig(), "General", "Pre23Defaults");
  690. bool useNV = EncoderAvailable("ffmpeg_nvenc") && !oldEncDefaults;
  691. config_set_default_string(activeConfiguration, "SimpleOutput", "StreamEncoder",
  692. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  693. config_set_default_string(activeConfiguration, "SimpleOutput", "RecEncoder",
  694. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  695. const char *aac_default = "ffmpeg_aac";
  696. if (EncoderAvailable("CoreAudio_AAC"))
  697. aac_default = "CoreAudio_AAC";
  698. else if (EncoderAvailable("libfdk_aac"))
  699. aac_default = "libfdk_aac";
  700. config_set_default_string(activeConfiguration, "AdvOut", "AudioEncoder", aac_default);
  701. config_set_default_string(activeConfiguration, "AdvOut", "RecAudioEncoder", aac_default);
  702. }
  703. bool OBSBasic::InitBasicConfig()
  704. {
  705. ProfileScope("OBSBasic::InitBasicConfig");
  706. RefreshProfiles(true);
  707. const std::string currentProfileName{config_get_string(App()->GetUserConfig(), "Basic", "Profile")};
  708. const std::optional<OBSProfile> currentProfile = GetProfileByName(currentProfileName);
  709. const std::optional<OBSProfile> foundProfile = GetProfileByName(opt_starting_profile);
  710. try {
  711. if (foundProfile) {
  712. ActivateProfile(foundProfile.value());
  713. } else if (currentProfile) {
  714. ActivateProfile(currentProfile.value());
  715. } else {
  716. const OBSProfile &newProfile = CreateProfile(currentProfileName);
  717. ActivateProfile(newProfile);
  718. }
  719. } catch (const std::logic_error &) {
  720. OBSErrorBox(NULL, "Failed to open basic.ini: %d", -1);
  721. return false;
  722. }
  723. return true;
  724. }
  725. void OBSBasic::InitOBSCallbacks()
  726. {
  727. ProfileScope("OBSBasic::InitOBSCallbacks");
  728. signalHandlers.reserve(signalHandlers.size() + 10);
  729. signalHandlers.emplace_back(obs_get_signal_handler(), "source_create", OBSBasic::SourceCreated, this);
  730. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove", OBSBasic::SourceRemoved, this);
  731. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate", OBSBasic::SourceActivated, this);
  732. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate", OBSBasic::SourceDeactivated, this);
  733. signalHandlers.emplace_back(obs_get_signal_handler(), "source_audio_activate", OBSBasic::SourceAudioActivated,
  734. this);
  735. signalHandlers.emplace_back(obs_get_signal_handler(), "source_audio_deactivate",
  736. OBSBasic::SourceAudioDeactivated, this);
  737. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename", OBSBasic::SourceRenamed, this);
  738. signalHandlers.emplace_back(
  739. obs_get_signal_handler(), "source_filter_add",
  740. [](void *data, calldata_t *) {
  741. QMetaObject::invokeMethod(static_cast<OBSBasic *>(data), "UpdateEditMenu",
  742. Qt::QueuedConnection);
  743. },
  744. this);
  745. signalHandlers.emplace_back(
  746. obs_get_signal_handler(), "source_filter_remove",
  747. [](void *data, calldata_t *) {
  748. QMetaObject::invokeMethod(static_cast<OBSBasic *>(data), "UpdateEditMenu",
  749. Qt::QueuedConnection);
  750. },
  751. this);
  752. signalHandlers.emplace_back(obs_get_signal_handler(), "canvas_remove", OBSBasic::CanvasRemoved, this);
  753. }
  754. #define STARTUP_SEPARATOR "==== Startup complete ==============================================="
  755. #define SHUTDOWN_SEPARATOR "==== Shutting down =================================================="
  756. #define UNSUPPORTED_ERROR \
  757. "Failed to initialize video:\n\nRequired graphics API functionality " \
  758. "not found. Your GPU may not be supported."
  759. #define UNKNOWN_ERROR \
  760. "Failed to initialize video. Your GPU may not be supported, " \
  761. "or your graphics drivers may need to be updated."
  762. static inline void LogEncoders()
  763. {
  764. constexpr uint32_t hide_flags = OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL;
  765. auto list_encoders = [](obs_encoder_type type) {
  766. size_t idx = 0;
  767. const char *encoder_type;
  768. while (obs_enum_encoder_types(idx++, &encoder_type)) {
  769. if (obs_get_encoder_caps(encoder_type) & hide_flags ||
  770. obs_get_encoder_type(encoder_type) != type) {
  771. continue;
  772. }
  773. blog(LOG_INFO, "\t- %s (%s)", encoder_type, obs_encoder_get_display_name(encoder_type));
  774. }
  775. };
  776. blog(LOG_INFO, "---------------------------------");
  777. blog(LOG_INFO, "Available Encoders:");
  778. blog(LOG_INFO, " Video Encoders:");
  779. list_encoders(OBS_ENCODER_VIDEO);
  780. blog(LOG_INFO, " Audio Encoders:");
  781. list_encoders(OBS_ENCODER_AUDIO);
  782. }
  783. void OBSBasic::OBSInit()
  784. {
  785. ProfileScope("OBSBasic::OBSInit");
  786. if (!InitBasicConfig())
  787. throw "Failed to load basic.ini";
  788. if (!ResetAudio())
  789. throw "Failed to initialize audio";
  790. int ret = 0;
  791. ret = ResetVideo();
  792. switch (ret) {
  793. case OBS_VIDEO_MODULE_NOT_FOUND:
  794. throw "Failed to initialize video: Graphics module not found";
  795. case OBS_VIDEO_NOT_SUPPORTED:
  796. throw UNSUPPORTED_ERROR;
  797. case OBS_VIDEO_INVALID_PARAM:
  798. throw "Failed to initialize video: Invalid parameters";
  799. default:
  800. if (ret != OBS_VIDEO_SUCCESS)
  801. throw UNKNOWN_ERROR;
  802. }
  803. /* load audio monitoring */
  804. if (obs_audio_monitoring_available()) {
  805. const char *device_name = config_get_string(activeConfiguration, "Audio", "MonitoringDeviceName");
  806. const char *device_id = config_get_string(activeConfiguration, "Audio", "MonitoringDeviceId");
  807. obs_set_audio_monitoring_device(device_name, device_id);
  808. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s", device_name, device_id);
  809. }
  810. InitOBSCallbacks();
  811. InitHotkeys();
  812. ui->preview->Init();
  813. /* hack to prevent elgato from loading its own QtNetwork that it tries
  814. * to ship with */
  815. #if defined(_WIN32) && !defined(_DEBUG)
  816. LoadLibraryW(L"Qt6Network");
  817. #endif
  818. struct obs_module_failure_info mfi;
  819. // Safe Mode disables third-party plugins so we don't need to add each path outside the OBS bundle/installation.
  820. if (safe_mode || disable_3p_plugins) {
  821. SetSafeModuleNames();
  822. } else {
  823. AddExtraModulePaths();
  824. }
  825. // Core modules are not allowed to be disabled by the user via plugin manager.
  826. SetCoreModuleNames();
  827. /* Modules can access frontend information (i.e. profile and scene collection data) during their initialization, and some modules (e.g. obs-websockets) are known to use the filesystem location of the current profile in their own code.
  828. Thus the profile and scene collection discovery needs to happen before any access to that information (but after intializing global settings) to ensure legacy code gets valid path information.
  829. */
  830. RefreshSceneCollections(true);
  831. App()->loadAppModules(mfi);
  832. BPtr<char *> failed_modules = mfi.failed_modules;
  833. #ifdef BROWSER_AVAILABLE
  834. cef = obs_browser_init_panel();
  835. cef_js_avail = cef && obs_browser_qcef_version() >= 3;
  836. #endif
  837. vcamEnabled = (obs_get_output_flags(VIRTUAL_CAM_ID) & OBS_OUTPUT_VIDEO) != 0;
  838. if (vcamEnabled) {
  839. emit VirtualCamEnabled();
  840. }
  841. UpdateProfileEncoders();
  842. LogEncoders();
  843. blog(LOG_INFO, STARTUP_SEPARATOR);
  844. if (!InitService())
  845. throw "Failed to initialize service";
  846. ResetOutputs();
  847. CreateHotkeys();
  848. InitPrimitives();
  849. sceneDuplicationMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SceneDuplicationMode");
  850. swapScenesMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SwapScenesMode");
  851. editPropertiesMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "EditPropertiesMode");
  852. if (!opt_studio_mode) {
  853. SetPreviewProgramMode(config_get_bool(App()->GetUserConfig(), "BasicWindow", "PreviewProgramMode"));
  854. } else {
  855. SetPreviewProgramMode(true);
  856. opt_studio_mode = false;
  857. }
  858. #define SET_VISIBILITY(name, control) \
  859. do { \
  860. if (config_has_user_value(App()->GetUserConfig(), "BasicWindow", name)) { \
  861. bool visible = config_get_bool(App()->GetUserConfig(), "BasicWindow", name); \
  862. ui->control->setChecked(visible); \
  863. } \
  864. } while (false)
  865. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  866. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  867. #undef SET_VISIBILITY
  868. bool sourceIconsVisible = config_get_bool(App()->GetUserConfig(), "BasicWindow", "ShowSourceIcons");
  869. ui->toggleSourceIcons->setChecked(sourceIconsVisible);
  870. bool contextVisible = config_get_bool(App()->GetUserConfig(), "BasicWindow", "ShowContextToolbars");
  871. ui->toggleContextBar->setChecked(contextVisible);
  872. ui->contextContainer->setVisible(contextVisible);
  873. if (contextVisible)
  874. UpdateContextBar(true);
  875. UpdateEditMenu();
  876. {
  877. ProfileScope("OBSBasic::Load");
  878. const std::string sceneCollectionName{
  879. config_get_string(App()->GetUserConfig(), "Basic", "SceneCollection")};
  880. std::optional<OBS::SceneCollection> configuredCollection =
  881. GetSceneCollectionByName(sceneCollectionName);
  882. std::optional<OBS::SceneCollection> foundCollection = GetSceneCollectionByName(opt_starting_collection);
  883. if (foundCollection) {
  884. ActivateSceneCollection(foundCollection.value());
  885. } else if (configuredCollection) {
  886. ActivateSceneCollection(configuredCollection.value());
  887. } else {
  888. disableSaving--;
  889. SetupNewSceneCollection(sceneCollectionName);
  890. disableSaving++;
  891. }
  892. if (foundCollection || configuredCollection) {
  893. disableSaving--;
  894. OnEvent(OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED);
  895. OnEvent(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED);
  896. OnEvent(OBS_FRONTEND_EVENT_SCENE_CHANGED);
  897. OnEvent(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  898. disableSaving++;
  899. }
  900. }
  901. loaded = true;
  902. previewEnabled = config_get_bool(App()->GetUserConfig(), "BasicWindow", "PreviewEnabled");
  903. if (!previewEnabled && !IsPreviewProgramMode())
  904. QMetaObject::invokeMethod(this, "EnablePreviewDisplay", Qt::QueuedConnection,
  905. Q_ARG(bool, previewEnabled));
  906. else if (!previewEnabled && IsPreviewProgramMode())
  907. QMetaObject::invokeMethod(this, "EnablePreviewDisplay", Qt::QueuedConnection, Q_ARG(bool, true));
  908. disableSaving--;
  909. auto addDisplay = [this](OBSQTDisplay *window) {
  910. obs_display_add_draw_callback(window->GetDisplay(), OBSBasic::RenderMain, this);
  911. struct obs_video_info ovi;
  912. if (obs_get_video_info(&ovi))
  913. ResizePreview(ovi.base_width, ovi.base_height);
  914. };
  915. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  916. /* Show the main window, unless the tray icon isn't available
  917. * or neither the setting nor flag for starting minimized is set. */
  918. bool sysTrayEnabled = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayEnabled");
  919. bool sysTrayWhenStarted = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayWhenStarted");
  920. bool hideWindowOnStart = QSystemTrayIcon::isSystemTrayAvailable() && sysTrayEnabled &&
  921. (opt_minimize_tray || sysTrayWhenStarted);
  922. #ifdef _WIN32
  923. SetWin32DropStyle(this);
  924. if (!hideWindowOnStart)
  925. show();
  926. #endif
  927. bool alwaysOnTop = config_get_bool(App()->GetUserConfig(), "BasicWindow", "AlwaysOnTop");
  928. #ifdef ENABLE_WAYLAND
  929. bool isWayland = obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND;
  930. #else
  931. bool isWayland = false;
  932. #endif
  933. if (!isWayland && (alwaysOnTop || opt_always_on_top)) {
  934. SetAlwaysOnTop(this, true);
  935. ui->actionAlwaysOnTop->setChecked(true);
  936. } else if (isWayland) {
  937. if (opt_always_on_top)
  938. blog(LOG_INFO, "Always On Top not available on Wayland, ignoring.");
  939. ui->actionAlwaysOnTop->setEnabled(false);
  940. ui->actionAlwaysOnTop->setVisible(false);
  941. }
  942. #ifndef _WIN32
  943. if (!hideWindowOnStart)
  944. show();
  945. #endif
  946. /* setup stats dock */
  947. OBSBasicStats *statsDlg = new OBSBasicStats(statsDock, false);
  948. statsDock->setWidget(statsDlg);
  949. /* ----------------------------- */
  950. /* add custom browser docks */
  951. #if defined(BROWSER_AVAILABLE) && defined(YOUTUBE_ENABLED)
  952. YouTubeAppDock::CleanupYouTubeUrls();
  953. #endif
  954. #ifdef BROWSER_AVAILABLE
  955. if (cef) {
  956. QAction *action = new QAction(QTStr("Basic.MainMenu.Docks."
  957. "CustomBrowserDocks"),
  958. this);
  959. ui->menuDocks->insertAction(ui->scenesDock->toggleViewAction(), action);
  960. connect(action, &QAction::triggered, this, &OBSBasic::ManageExtraBrowserDocks);
  961. ui->menuDocks->insertSeparator(ui->scenesDock->toggleViewAction());
  962. LoadExtraBrowserDocks();
  963. }
  964. #endif
  965. #ifdef YOUTUBE_ENABLED
  966. /* setup YouTube app dock */
  967. if (YouTubeAppDock::IsYTServiceSelected())
  968. NewYouTubeAppDock();
  969. #endif
  970. const char *dockStateStr = config_get_string(App()->GetUserConfig(), "BasicWindow", "DockState");
  971. if (!dockStateStr) {
  972. on_resetDocks_triggered(true);
  973. } else {
  974. QByteArray dockState = QByteArray::fromBase64(QByteArray(dockStateStr));
  975. if (!restoreState(dockState))
  976. on_resetDocks_triggered(true);
  977. }
  978. bool pre23Defaults = config_get_bool(App()->GetUserConfig(), "General", "Pre23Defaults");
  979. if (pre23Defaults) {
  980. bool resetDockLock23 = config_get_bool(App()->GetUserConfig(), "General", "ResetDockLock23");
  981. if (!resetDockLock23) {
  982. config_set_bool(App()->GetUserConfig(), "General", "ResetDockLock23", true);
  983. config_remove_value(App()->GetUserConfig(), "BasicWindow", "DocksLocked");
  984. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  985. }
  986. }
  987. bool docksLocked = config_get_bool(App()->GetUserConfig(), "BasicWindow", "DocksLocked");
  988. on_lockDocks_toggled(docksLocked);
  989. ui->lockDocks->blockSignals(true);
  990. ui->lockDocks->setChecked(docksLocked);
  991. ui->lockDocks->blockSignals(false);
  992. bool sideDocks = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SideDocks");
  993. on_sideDocks_toggled(sideDocks);
  994. ui->sideDocks->blockSignals(true);
  995. ui->sideDocks->setChecked(sideDocks);
  996. ui->sideDocks->blockSignals(false);
  997. SystemTray(true);
  998. TaskbarOverlayInit();
  999. #ifdef __APPLE__
  1000. disableColorSpaceConversion(this);
  1001. #endif
  1002. bool has_last_version = config_has_user_value(App()->GetAppConfig(), "General", "LastVersion");
  1003. bool first_run = config_get_bool(App()->GetUserConfig(), "General", "FirstRun");
  1004. if (!first_run) {
  1005. config_set_bool(App()->GetUserConfig(), "General", "FirstRun", true);
  1006. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  1007. }
  1008. if (!first_run && !has_last_version && !Active())
  1009. QMetaObject::invokeMethod(this, "on_autoConfigure_triggered", Qt::QueuedConnection);
  1010. #if (defined(_WIN32) || defined(__APPLE__)) && (OBS_RELEASE_CANDIDATE > 0 || OBS_BETA > 0)
  1011. /* Automatically set branch to "beta" the first time a pre-release build is run. */
  1012. if (!config_get_bool(App()->GetAppConfig(), "General", "AutoBetaOptIn")) {
  1013. config_set_string(App()->GetAppConfig(), "General", "UpdateBranch", "beta");
  1014. config_set_bool(App()->GetAppConfig(), "General", "AutoBetaOptIn", true);
  1015. config_save_safe(App()->GetAppConfig(), "tmp", nullptr);
  1016. }
  1017. #endif
  1018. TimedCheckForUpdates();
  1019. ToggleMixerLayout(config_get_bool(App()->GetUserConfig(), "BasicWindow", "VerticalVolControl"));
  1020. if (config_get_bool(activeConfiguration, "General", "OpenStatsOnStartup"))
  1021. on_stats_triggered();
  1022. OBSBasicStats::InitializeValues();
  1023. /* ----------------------- */
  1024. /* Add multiview menu */
  1025. ui->viewMenu->addSeparator();
  1026. connect(ui->viewMenu->menuAction(), &QAction::hovered, this, &OBSBasic::updateMultiviewProjectorMenu);
  1027. OBSBasic::updateMultiviewProjectorMenu();
  1028. ui->sources->UpdateIcons();
  1029. #if !defined(_WIN32)
  1030. delete ui->actionRepair;
  1031. ui->actionRepair = nullptr;
  1032. #if !defined(__APPLE__)
  1033. delete ui->actionShowCrashLogs;
  1034. delete ui->actionUploadLastCrashLog;
  1035. delete ui->menuCrashLogs;
  1036. delete ui->actionCheckForUpdates;
  1037. ui->actionShowCrashLogs = nullptr;
  1038. ui->actionUploadLastCrashLog = nullptr;
  1039. ui->menuCrashLogs = nullptr;
  1040. ui->actionCheckForUpdates = nullptr;
  1041. #endif
  1042. #endif
  1043. #ifdef __APPLE__
  1044. /* Remove OBS' Fullscreen Interface menu in favor of the one macOS adds by default */
  1045. delete ui->actionFullscreenInterface;
  1046. ui->actionFullscreenInterface = nullptr;
  1047. #else
  1048. /* Don't show menu to raise macOS-only permissions dialog */
  1049. delete ui->actionShowMacPermissions;
  1050. ui->actionShowMacPermissions = nullptr;
  1051. #endif
  1052. #if defined(_WIN32) || defined(__APPLE__)
  1053. if (App()->IsUpdaterDisabled()) {
  1054. ui->actionCheckForUpdates->setEnabled(false);
  1055. #if defined(_WIN32)
  1056. ui->actionRepair->setEnabled(false);
  1057. #endif
  1058. }
  1059. #endif
  1060. #ifndef WHATSNEW_ENABLED
  1061. delete ui->actionShowWhatsNew;
  1062. ui->actionShowWhatsNew = nullptr;
  1063. #endif
  1064. if (safe_mode) {
  1065. ui->actionRestartSafe->setText(QTStr("Basic.MainMenu.Help.RestartNormal"));
  1066. }
  1067. UpdatePreviewProgramIndicators();
  1068. OnFirstLoad();
  1069. if (!hideWindowOnStart)
  1070. activateWindow();
  1071. /* ------------------------------------------- */
  1072. /* display warning message for failed modules */
  1073. if (mfi.count) {
  1074. QString failed_plugins;
  1075. char **plugin = mfi.failed_modules;
  1076. while (*plugin) {
  1077. failed_plugins += *plugin;
  1078. failed_plugins += "\n";
  1079. plugin++;
  1080. }
  1081. QString failed_msg = QTStr("PluginsFailedToLoad.Text").arg(failed_plugins);
  1082. OBSMessageBox::warning(this, QTStr("PluginsFailedToLoad.Title"), failed_msg);
  1083. }
  1084. }
  1085. void OBSBasic::OnFirstLoad()
  1086. {
  1087. OnEvent(OBS_FRONTEND_EVENT_FINISHED_LOADING);
  1088. #ifdef WHATSNEW_ENABLED
  1089. /* Attempt to load init screen if available */
  1090. if (cef) {
  1091. WhatsNewInfoThread *wnit = new WhatsNewInfoThread();
  1092. connect(wnit, &WhatsNewInfoThread::Result, this, &OBSBasic::ReceivedIntroJson, Qt::QueuedConnection);
  1093. introCheckThread.reset(wnit);
  1094. introCheckThread->start();
  1095. }
  1096. #endif
  1097. Auth::Load();
  1098. bool showLogViewerOnStartup = config_get_bool(App()->GetUserConfig(), "LogViewer", "ShowLogStartup");
  1099. if (showLogViewerOnStartup)
  1100. on_actionViewCurrentLog_triggered();
  1101. }
  1102. OBSBasic::~OBSBasic()
  1103. {
  1104. if (!handledShutdown) {
  1105. applicationShutdown();
  1106. }
  1107. }
  1108. void OBSBasic::applicationShutdown() noexcept
  1109. {
  1110. /* clear out UI event queue */
  1111. QApplication::sendPostedEvents(nullptr);
  1112. QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
  1113. if (updateCheckThread && updateCheckThread->isRunning())
  1114. updateCheckThread->wait();
  1115. if (patronJsonThread && patronJsonThread->isRunning())
  1116. patronJsonThread->wait();
  1117. delete screenshotData;
  1118. delete previewProjector;
  1119. delete studioProgramProjector;
  1120. delete previewProjectorSource;
  1121. delete previewProjectorMain;
  1122. delete sourceProjector;
  1123. delete sceneProjectorMenu;
  1124. delete scaleFilteringMenu;
  1125. delete blendingModeMenu;
  1126. delete colorMenu;
  1127. delete colorWidgetAction;
  1128. delete colorSelect;
  1129. delete deinterlaceMenu;
  1130. delete perSceneTransitionMenu;
  1131. delete shortcutFilter;
  1132. delete trayMenu;
  1133. delete programOptions;
  1134. delete program;
  1135. /* XXX: any obs data must be released before calling obs_shutdown.
  1136. * currently, we can't automate this with C++ RAII because of the
  1137. * delicate nature of obs_shutdown needing to be freed before the UI
  1138. * can be freed, and we have no control over the destruction order of
  1139. * the Qt UI stuff, so we have to manually clear any references to
  1140. * libobs. */
  1141. delete cpuUsageTimer;
  1142. os_cpu_usage_info_destroy(cpuUsageInfo);
  1143. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1144. ClearHotkeys();
  1145. service = nullptr;
  1146. outputHandler.reset();
  1147. delete interaction;
  1148. delete properties;
  1149. delete filters;
  1150. delete transformWindow;
  1151. delete advAudioWindow;
  1152. delete about;
  1153. delete remux;
  1154. obs_display_remove_draw_callback(ui->preview->GetDisplay(), OBSBasic::RenderMain, this);
  1155. obs_enter_graphics();
  1156. gs_vertexbuffer_destroy(box);
  1157. gs_vertexbuffer_destroy(boxLeft);
  1158. gs_vertexbuffer_destroy(boxTop);
  1159. gs_vertexbuffer_destroy(boxRight);
  1160. gs_vertexbuffer_destroy(boxBottom);
  1161. gs_vertexbuffer_destroy(circle);
  1162. gs_vertexbuffer_destroy(actionSafeMargin);
  1163. gs_vertexbuffer_destroy(graphicsSafeMargin);
  1164. gs_vertexbuffer_destroy(fourByThreeSafeMargin);
  1165. gs_vertexbuffer_destroy(leftLine);
  1166. gs_vertexbuffer_destroy(topLine);
  1167. gs_vertexbuffer_destroy(rightLine);
  1168. obs_leave_graphics();
  1169. /* When shutting down, sometimes source references can get in to the
  1170. * event queue, and if we don't forcibly process those events they
  1171. * won't get processed until after obs_shutdown has been called. I
  1172. * really wish there were a more elegant way to deal with this via C++,
  1173. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1174. * normal C++ behavior for your data to be freed in the order that you
  1175. * expect or want it to. */
  1176. QApplication::sendPostedEvents(nullptr);
  1177. config_set_int(App()->GetAppConfig(), "General", "LastVersion", LIBOBS_API_VER);
  1178. config_save_safe(App()->GetAppConfig(), "tmp", nullptr);
  1179. config_set_bool(App()->GetUserConfig(), "BasicWindow", "PreviewEnabled", previewEnabled);
  1180. config_set_bool(App()->GetUserConfig(), "BasicWindow", "AlwaysOnTop", ui->actionAlwaysOnTop->isChecked());
  1181. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SceneDuplicationMode", sceneDuplicationMode);
  1182. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SwapScenesMode", swapScenesMode);
  1183. config_set_bool(App()->GetUserConfig(), "BasicWindow", "EditPropertiesMode", editPropertiesMode);
  1184. config_set_bool(App()->GetUserConfig(), "BasicWindow", "PreviewProgramMode", IsPreviewProgramMode());
  1185. config_set_bool(App()->GetUserConfig(), "BasicWindow", "DocksLocked", ui->lockDocks->isChecked());
  1186. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SideDocks", ui->sideDocks->isChecked());
  1187. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  1188. #ifdef BROWSER_AVAILABLE
  1189. DestroyPanelCookieManager();
  1190. delete cef;
  1191. cef = nullptr;
  1192. #endif
  1193. handledShutdown = true;
  1194. }
  1195. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  1196. {
  1197. return obs_reset_video(ovi);
  1198. }
  1199. static inline enum obs_scale_type GetScaleType(ConfigFile &activeConfiguration)
  1200. {
  1201. const char *scaleTypeStr = config_get_string(activeConfiguration, "Video", "ScaleType");
  1202. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  1203. return OBS_SCALE_BILINEAR;
  1204. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  1205. return OBS_SCALE_LANCZOS;
  1206. else if (astrcmpi(scaleTypeStr, "area") == 0)
  1207. return OBS_SCALE_AREA;
  1208. else
  1209. return OBS_SCALE_BICUBIC;
  1210. }
  1211. static inline enum video_format GetVideoFormatFromName(const char *name)
  1212. {
  1213. if (astrcmpi(name, "I420") == 0)
  1214. return VIDEO_FORMAT_I420;
  1215. else if (astrcmpi(name, "NV12") == 0)
  1216. return VIDEO_FORMAT_NV12;
  1217. else if (astrcmpi(name, "I444") == 0)
  1218. return VIDEO_FORMAT_I444;
  1219. else if (astrcmpi(name, "I010") == 0)
  1220. return VIDEO_FORMAT_I010;
  1221. else if (astrcmpi(name, "P010") == 0)
  1222. return VIDEO_FORMAT_P010;
  1223. else if (astrcmpi(name, "P216") == 0)
  1224. return VIDEO_FORMAT_P216;
  1225. else if (astrcmpi(name, "P416") == 0)
  1226. return VIDEO_FORMAT_P416;
  1227. #if 0 //currently unsupported
  1228. else if (astrcmpi(name, "YVYU") == 0)
  1229. return VIDEO_FORMAT_YVYU;
  1230. else if (astrcmpi(name, "YUY2") == 0)
  1231. return VIDEO_FORMAT_YUY2;
  1232. else if (astrcmpi(name, "UYVY") == 0)
  1233. return VIDEO_FORMAT_UYVY;
  1234. #endif
  1235. else
  1236. return VIDEO_FORMAT_BGRA;
  1237. }
  1238. static inline enum video_colorspace GetVideoColorSpaceFromName(const char *name)
  1239. {
  1240. enum video_colorspace colorspace = VIDEO_CS_SRGB;
  1241. if (strcmp(name, "601") == 0)
  1242. colorspace = VIDEO_CS_601;
  1243. else if (strcmp(name, "709") == 0)
  1244. colorspace = VIDEO_CS_709;
  1245. else if (strcmp(name, "2100PQ") == 0)
  1246. colorspace = VIDEO_CS_2100_PQ;
  1247. else if (strcmp(name, "2100HLG") == 0)
  1248. colorspace = VIDEO_CS_2100_HLG;
  1249. return colorspace;
  1250. }
  1251. int OBSBasic::ResetVideo()
  1252. {
  1253. if (outputHandler && outputHandler->Active())
  1254. return OBS_VIDEO_CURRENTLY_ACTIVE;
  1255. ProfileScope("OBSBasic::ResetVideo");
  1256. struct obs_video_info ovi;
  1257. int ret;
  1258. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  1259. const char *colorFormat = config_get_string(activeConfiguration, "Video", "ColorFormat");
  1260. const char *colorSpace = config_get_string(activeConfiguration, "Video", "ColorSpace");
  1261. const char *colorRange = config_get_string(activeConfiguration, "Video", "ColorRange");
  1262. ovi.graphics_module = App()->GetRenderModule();
  1263. ovi.base_width = (uint32_t)config_get_uint(activeConfiguration, "Video", "BaseCX");
  1264. ovi.base_height = (uint32_t)config_get_uint(activeConfiguration, "Video", "BaseCY");
  1265. ovi.output_width = (uint32_t)config_get_uint(activeConfiguration, "Video", "OutputCX");
  1266. ovi.output_height = (uint32_t)config_get_uint(activeConfiguration, "Video", "OutputCY");
  1267. ovi.output_format = GetVideoFormatFromName(colorFormat);
  1268. ovi.colorspace = GetVideoColorSpaceFromName(colorSpace);
  1269. ovi.range = astrcmpi(colorRange, "Full") == 0 ? VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  1270. ovi.adapter = config_get_uint(App()->GetUserConfig(), "Video", "AdapterIdx");
  1271. ovi.gpu_conversion = true;
  1272. ovi.scale_type = GetScaleType(activeConfiguration);
  1273. if (ovi.base_width < 32 || ovi.base_height < 32) {
  1274. ovi.base_width = 1920;
  1275. ovi.base_height = 1080;
  1276. config_set_uint(activeConfiguration, "Video", "BaseCX", 1920);
  1277. config_set_uint(activeConfiguration, "Video", "BaseCY", 1080);
  1278. }
  1279. if (ovi.output_width < 32 || ovi.output_height < 32) {
  1280. ovi.output_width = ovi.base_width;
  1281. ovi.output_height = ovi.base_height;
  1282. config_set_uint(activeConfiguration, "Video", "OutputCX", ovi.base_width);
  1283. config_set_uint(activeConfiguration, "Video", "OutputCY", ovi.base_height);
  1284. }
  1285. ret = AttemptToResetVideo(&ovi);
  1286. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  1287. blog(LOG_WARNING, "Tried to reset when already active");
  1288. return ret;
  1289. }
  1290. if (ret == OBS_VIDEO_SUCCESS) {
  1291. ResizePreview(ovi.base_width, ovi.base_height);
  1292. if (program)
  1293. ResizeProgram(ovi.base_width, ovi.base_height);
  1294. const float sdr_white_level = (float)config_get_uint(activeConfiguration, "Video", "SdrWhiteLevel");
  1295. const float hdr_nominal_peak_level =
  1296. (float)config_get_uint(activeConfiguration, "Video", "HdrNominalPeakLevel");
  1297. obs_set_video_levels(sdr_white_level, hdr_nominal_peak_level);
  1298. OBSBasicStats::InitializeValues();
  1299. OBSProjector::UpdateMultiviewProjectors();
  1300. if (!collections.empty()) {
  1301. const OBS::SceneCollection currentSceneCollection = OBSBasic::GetCurrentSceneCollection();
  1302. bool usingAbsoluteCoordinates = currentSceneCollection.getCoordinateMode() ==
  1303. OBS::SceneCoordinateMode::Absolute;
  1304. OBS::Rect migrationResolution = currentSceneCollection.getMigrationResolution();
  1305. OBS::Rect videoResolution = OBS::Rect(ovi.base_width, ovi.base_height);
  1306. bool canMigrate = usingAbsoluteCoordinates ||
  1307. (!migrationResolution.isZero() && migrationResolution != videoResolution);
  1308. ui->actionRemigrateSceneCollection->setEnabled(canMigrate);
  1309. } else {
  1310. ui->actionRemigrateSceneCollection->setEnabled(false);
  1311. }
  1312. emit CanvasResized(ovi.base_width, ovi.base_height);
  1313. emit OutputResized(ovi.output_width, ovi.output_height);
  1314. }
  1315. return ret;
  1316. }
  1317. bool OBSBasic::ResetAudio()
  1318. {
  1319. ProfileScope("OBSBasic::ResetAudio");
  1320. struct obs_audio_info2 ai = {};
  1321. ai.samples_per_sec = config_get_uint(activeConfiguration, "Audio", "SampleRate");
  1322. const char *channelSetupStr = config_get_string(activeConfiguration, "Audio", "ChannelSetup");
  1323. if (strcmp(channelSetupStr, "Mono") == 0)
  1324. ai.speakers = SPEAKERS_MONO;
  1325. else if (strcmp(channelSetupStr, "2.1") == 0)
  1326. ai.speakers = SPEAKERS_2POINT1;
  1327. else if (strcmp(channelSetupStr, "4.0") == 0)
  1328. ai.speakers = SPEAKERS_4POINT0;
  1329. else if (strcmp(channelSetupStr, "4.1") == 0)
  1330. ai.speakers = SPEAKERS_4POINT1;
  1331. else if (strcmp(channelSetupStr, "5.1") == 0)
  1332. ai.speakers = SPEAKERS_5POINT1;
  1333. else if (strcmp(channelSetupStr, "7.1") == 0)
  1334. ai.speakers = SPEAKERS_7POINT1;
  1335. else
  1336. ai.speakers = SPEAKERS_STEREO;
  1337. bool lowLatencyAudioBuffering = config_get_bool(App()->GetUserConfig(), "Audio", "LowLatencyAudioBuffering");
  1338. if (lowLatencyAudioBuffering) {
  1339. ai.max_buffering_ms = 20;
  1340. ai.fixed_buffering = true;
  1341. }
  1342. return obs_reset_audio2(&ai);
  1343. }
  1344. void OBSBasic::closeEvent(QCloseEvent *event)
  1345. {
  1346. /* Wait for multitrack video stream to start/finish processing in the background */
  1347. if (setupStreamingGuard.valid() &&
  1348. setupStreamingGuard.wait_for(std::chrono::seconds{0}) != std::future_status::ready) {
  1349. QTimer::singleShot(1000, this, &OBSBasic::close);
  1350. event->ignore();
  1351. return;
  1352. }
  1353. /* Do not close window if inside of a temporary event loop because we
  1354. * could be inside of an Auth::LoadUI call. Keep trying once per
  1355. * second until we've exit any known sub-loops. */
  1356. if (os_atomic_load_long(&insideEventLoop) != 0) {
  1357. QTimer::singleShot(1000, this, &OBSBasic::close);
  1358. event->ignore();
  1359. return;
  1360. }
  1361. #ifdef YOUTUBE_ENABLED
  1362. /* Also don't close the window if the youtube stream check is active */
  1363. if (youtubeStreamCheckThread) {
  1364. QTimer::singleShot(1000, this, &OBSBasic::close);
  1365. event->ignore();
  1366. return;
  1367. }
  1368. #endif
  1369. if (isVisible())
  1370. config_set_string(App()->GetUserConfig(), "BasicWindow", "geometry",
  1371. saveGeometry().toBase64().constData());
  1372. bool confirmOnExit = config_get_bool(App()->GetUserConfig(), "General", "ConfirmOnExit");
  1373. if (confirmOnExit && outputHandler && outputHandler->Active() && !clearingFailed) {
  1374. SetShowing(true);
  1375. QMessageBox::StandardButton button =
  1376. OBSMessageBox::question(this, QTStr("ConfirmExit.Title"), QTStr("ConfirmExit.Text"));
  1377. if (button == QMessageBox::No) {
  1378. event->ignore();
  1379. restart = false;
  1380. return;
  1381. }
  1382. }
  1383. if (remux && !remux->close()) {
  1384. event->ignore();
  1385. restart = false;
  1386. return;
  1387. }
  1388. QWidget::closeEvent(event);
  1389. if (!event->isAccepted())
  1390. return;
  1391. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  1392. closing = true;
  1393. /* While closing, a resize event to OBSQTDisplay could be triggered.
  1394. * The graphics thread on macOS dispatches a lambda function to be
  1395. * executed asynchronously in the main thread. However, the display is
  1396. * sometimes deleted before the lambda function is actually executed.
  1397. * To avoid such a case, destroy displays earlier than others such as
  1398. * deleting browser docks. */
  1399. ui->preview->DestroyDisplay();
  1400. if (program)
  1401. program->DestroyDisplay();
  1402. if (outputHandler->VirtualCamActive())
  1403. outputHandler->StopVirtualCam();
  1404. if (introCheckThread)
  1405. introCheckThread->wait();
  1406. if (whatsNewInitThread)
  1407. whatsNewInitThread->wait();
  1408. if (updateCheckThread)
  1409. updateCheckThread->wait();
  1410. if (logUploadThread)
  1411. logUploadThread->wait();
  1412. if (devicePropertiesThread && devicePropertiesThread->isRunning()) {
  1413. devicePropertiesThread->wait();
  1414. devicePropertiesThread.reset();
  1415. }
  1416. QApplication::sendPostedEvents(nullptr);
  1417. signalHandlers.clear();
  1418. Auth::Save();
  1419. SaveProjectNow();
  1420. auth.reset();
  1421. delete extraBrowsers;
  1422. config_set_string(App()->GetUserConfig(), "BasicWindow", "DockState", saveState().toBase64().constData());
  1423. #ifdef BROWSER_AVAILABLE
  1424. if (cef)
  1425. SaveExtraBrowserDocks();
  1426. ClearExtraBrowserDocks();
  1427. #endif
  1428. OnEvent(OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN);
  1429. disableSaving++;
  1430. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  1431. * sources, etc) so that all references are released before shutdown */
  1432. ClearSceneData();
  1433. OnEvent(OBS_FRONTEND_EVENT_EXIT);
  1434. // Destroys the frontend API so plugins can't continue calling it
  1435. obs_frontend_set_callbacks_internal(nullptr);
  1436. api = nullptr;
  1437. QMetaObject::invokeMethod(App(), "quit", Qt::QueuedConnection);
  1438. }
  1439. bool OBSBasic::nativeEvent(const QByteArray &, void *message, qintptr *)
  1440. {
  1441. #ifdef _WIN32
  1442. const MSG &msg = *static_cast<MSG *>(message);
  1443. switch (msg.message) {
  1444. case WM_MOVE:
  1445. for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
  1446. display->OnMove();
  1447. }
  1448. break;
  1449. case WM_DISPLAYCHANGE:
  1450. for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
  1451. display->OnDisplayChange();
  1452. }
  1453. }
  1454. #else
  1455. UNUSED_PARAMETER(message);
  1456. #endif
  1457. return false;
  1458. }
  1459. void OBSBasic::changeEvent(QEvent *event)
  1460. {
  1461. if (event->type() == QEvent::WindowStateChange) {
  1462. QWindowStateChangeEvent *stateEvent = (QWindowStateChangeEvent *)event;
  1463. if (isMinimized()) {
  1464. if (trayIcon && trayIcon->isVisible() && sysTrayMinimizeToTray()) {
  1465. ToggleShowHide();
  1466. return;
  1467. }
  1468. if (previewEnabled)
  1469. EnablePreviewDisplay(false);
  1470. } else if (stateEvent->oldState() & Qt::WindowMinimized && isVisible()) {
  1471. if (previewEnabled)
  1472. EnablePreviewDisplay(true);
  1473. }
  1474. }
  1475. }
  1476. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  1477. {
  1478. const char *val = config_get_string(activeConfiguration, "Video", "FPSCommon");
  1479. if (strcmp(val, "10") == 0) {
  1480. num = 10;
  1481. den = 1;
  1482. } else if (strcmp(val, "20") == 0) {
  1483. num = 20;
  1484. den = 1;
  1485. } else if (strcmp(val, "24 NTSC") == 0) {
  1486. num = 24000;
  1487. den = 1001;
  1488. } else if (strcmp(val, "25 PAL") == 0) {
  1489. num = 25;
  1490. den = 1;
  1491. } else if (strcmp(val, "29.97") == 0) {
  1492. num = 30000;
  1493. den = 1001;
  1494. } else if (strcmp(val, "48") == 0) {
  1495. num = 48;
  1496. den = 1;
  1497. } else if (strcmp(val, "50 PAL") == 0) {
  1498. num = 50;
  1499. den = 1;
  1500. } else if (strcmp(val, "59.94") == 0) {
  1501. num = 60000;
  1502. den = 1001;
  1503. } else if (strcmp(val, "60") == 0) {
  1504. num = 60;
  1505. den = 1;
  1506. } else {
  1507. num = 30;
  1508. den = 1;
  1509. }
  1510. }
  1511. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  1512. {
  1513. num = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSInt");
  1514. den = 1;
  1515. }
  1516. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  1517. {
  1518. num = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSNum");
  1519. den = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSDen");
  1520. }
  1521. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  1522. {
  1523. num = 1000000000;
  1524. den = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSNS");
  1525. }
  1526. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  1527. {
  1528. uint32_t type = config_get_uint(activeConfiguration, "Video", "FPSType");
  1529. if (type == 1) //"Integer"
  1530. GetFPSInteger(num, den);
  1531. else if (type == 2) //"Fraction"
  1532. GetFPSFraction(num, den);
  1533. /*
  1534. * else if (false) //"Nanoseconds", currently not implemented
  1535. * GetFPSNanoseconds(num, den);
  1536. */
  1537. else
  1538. GetFPSCommon(num, den);
  1539. }
  1540. config_t *OBSBasic::Config() const
  1541. {
  1542. return activeConfiguration;
  1543. }
  1544. void OBSBasic::UpdateEditMenu()
  1545. {
  1546. QModelIndexList items = GetAllSelectedSourceItems();
  1547. int totalCount = items.count();
  1548. size_t filter_count = 0;
  1549. if (totalCount == 1) {
  1550. OBSSceneItem sceneItem = ui->sources->Get(GetTopSelectedSourceItem());
  1551. OBSSource source = obs_sceneitem_get_source(sceneItem);
  1552. filter_count = obs_source_filter_count(source);
  1553. }
  1554. bool allowPastingDuplicate = !!clipboard.size();
  1555. for (size_t i = clipboard.size(); i > 0; i--) {
  1556. const size_t idx = i - 1;
  1557. OBSWeakSource &weak = clipboard[idx].weak_source;
  1558. if (obs_weak_source_expired(weak)) {
  1559. clipboard.erase(clipboard.begin() + idx);
  1560. continue;
  1561. }
  1562. OBSSourceAutoRelease strong = obs_weak_source_get_source(weak.Get());
  1563. if (allowPastingDuplicate && obs_source_get_output_flags(strong) & OBS_SOURCE_DO_NOT_DUPLICATE)
  1564. allowPastingDuplicate = false;
  1565. }
  1566. int videoCount = 0;
  1567. bool canTransformMultiple = false;
  1568. for (int i = 0; i < totalCount; i++) {
  1569. OBSSceneItem item = ui->sources->Get(items.value(i).row());
  1570. OBSSource source = obs_sceneitem_get_source(item);
  1571. const uint32_t flags = obs_source_get_output_flags(source);
  1572. const bool hasVideo = (flags & OBS_SOURCE_VIDEO) != 0;
  1573. if (hasVideo && !obs_sceneitem_locked(item))
  1574. canTransformMultiple = true;
  1575. if (hasVideo)
  1576. videoCount++;
  1577. }
  1578. const bool canTransformSingle = videoCount == 1 && totalCount == 1;
  1579. OBSSceneItem curItem = GetCurrentSceneItem();
  1580. bool locked = curItem && obs_sceneitem_locked(curItem);
  1581. ui->actionCopySource->setEnabled(totalCount > 0);
  1582. ui->actionEditTransform->setEnabled(canTransformSingle && !locked);
  1583. ui->actionCopyTransform->setEnabled(canTransformSingle);
  1584. ui->actionPasteTransform->setEnabled(canTransformMultiple && hasCopiedTransform && videoCount > 0);
  1585. ui->actionCopyFilters->setEnabled(filter_count > 0);
  1586. ui->actionPasteFilters->setEnabled(!obs_weak_source_expired(copyFiltersSource) && totalCount > 0);
  1587. ui->actionPasteRef->setEnabled(!!clipboard.size());
  1588. ui->actionPasteDup->setEnabled(allowPastingDuplicate);
  1589. ui->actionMoveUp->setEnabled(totalCount > 0);
  1590. ui->actionMoveDown->setEnabled(totalCount > 0);
  1591. ui->actionMoveToTop->setEnabled(totalCount > 0);
  1592. ui->actionMoveToBottom->setEnabled(totalCount > 0);
  1593. ui->actionResetTransform->setEnabled(canTransformMultiple);
  1594. ui->actionRotate90CW->setEnabled(canTransformMultiple);
  1595. ui->actionRotate90CCW->setEnabled(canTransformMultiple);
  1596. ui->actionRotate180->setEnabled(canTransformMultiple);
  1597. ui->actionFlipHorizontal->setEnabled(canTransformMultiple);
  1598. ui->actionFlipVertical->setEnabled(canTransformMultiple);
  1599. ui->actionFitToScreen->setEnabled(canTransformMultiple);
  1600. ui->actionStretchToScreen->setEnabled(canTransformMultiple);
  1601. ui->actionCenterToScreen->setEnabled(canTransformMultiple);
  1602. ui->actionVerticalCenter->setEnabled(canTransformMultiple);
  1603. ui->actionHorizontalCenter->setEnabled(canTransformMultiple);
  1604. }
  1605. void OBSBasic::UpdateTitleBar()
  1606. {
  1607. stringstream name;
  1608. const char *profile = config_get_string(App()->GetUserConfig(), "Basic", "Profile");
  1609. const char *sceneCollection = config_get_string(App()->GetUserConfig(), "Basic", "SceneCollection");
  1610. name << "OBS ";
  1611. if (previewProgramMode)
  1612. name << "Studio ";
  1613. name << App()->GetVersionString(false);
  1614. if (safe_mode)
  1615. name << " (" << Str("TitleBar.SafeMode") << ")";
  1616. if (App()->IsPortableMode())
  1617. name << " - " << Str("TitleBar.PortableMode");
  1618. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  1619. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  1620. setWindowTitle(QT_UTF8(name.str().c_str()));
  1621. }
  1622. OBSBasic *OBSBasic::Get()
  1623. {
  1624. return reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
  1625. }
  1626. void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)
  1627. {
  1628. if (!error.isEmpty())
  1629. return;
  1630. patronJson = QT_TO_UTF8(text);
  1631. }
  1632. void OBSBasic::SetDisplayAffinity(QWindow *window)
  1633. {
  1634. if (!SetDisplayAffinitySupported())
  1635. return;
  1636. bool hideFromCapture = config_get_bool(App()->GetUserConfig(), "BasicWindow", "HideOBSWindowsFromCapture");
  1637. // Don't hide projectors, those are designed to be visible / captured
  1638. if (window->property("isOBSProjectorWindow") == true)
  1639. return;
  1640. #ifdef _WIN32
  1641. HWND hwnd = (HWND)window->winId();
  1642. DWORD curAffinity;
  1643. if (GetWindowDisplayAffinity(hwnd, &curAffinity)) {
  1644. if (hideFromCapture && curAffinity != WDA_EXCLUDEFROMCAPTURE)
  1645. SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE);
  1646. else if (!hideFromCapture && curAffinity != WDA_NONE)
  1647. SetWindowDisplayAffinity(hwnd, WDA_NONE);
  1648. }
  1649. #else
  1650. // TODO: Implement for other platforms if possible. Don't forget to
  1651. // implement SetDisplayAffinitySupported too!
  1652. UNUSED_PARAMETER(hideFromCapture);
  1653. #endif
  1654. }
  1655. void OBSBasic::OnEvent(enum obs_frontend_event event)
  1656. {
  1657. if (api)
  1658. api->on_event(event);
  1659. }
  1660. OBSPromptResult OBSBasic::PromptForName(const OBSPromptRequest &request, const OBSPromptCallback &callback)
  1661. {
  1662. OBSPromptResult result;
  1663. for (;;) {
  1664. result.success = false;
  1665. if (request.withOption && !request.optionPrompt.empty()) {
  1666. result.optionValue = request.optionValue;
  1667. result.success = NameDialog::AskForNameWithOption(
  1668. this, request.title.c_str(), request.prompt.c_str(), result.promptValue,
  1669. request.optionPrompt.c_str(), result.optionValue,
  1670. (request.promptValue.empty() ? nullptr : request.promptValue.c_str()));
  1671. } else {
  1672. result.success = NameDialog::AskForName(
  1673. this, request.title.c_str(), request.prompt.c_str(), result.promptValue,
  1674. (request.promptValue.empty() ? nullptr : request.promptValue.c_str()));
  1675. }
  1676. if (!result.success) {
  1677. break;
  1678. }
  1679. if (result.promptValue.empty()) {
  1680. OBSMessageBox::warning(this, QTStr("NoNameEntered.Title"), QTStr("NoNameEntered.Text"));
  1681. continue;
  1682. }
  1683. if (!callback(result)) {
  1684. OBSMessageBox::warning(this, QTStr("NameExists.Title"), QTStr("NameExists.Text"));
  1685. continue;
  1686. }
  1687. break;
  1688. }
  1689. return result;
  1690. }
  1691. void OBSBasic::on_actionOpenPluginManager_triggered()
  1692. {
  1693. App()->pluginManagerOpenDialog();
  1694. }