window-basic-settings.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Philippe Groarke <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <util/util.hpp>
  17. #include <QDialog>
  18. #include <QPointer>
  19. #include <memory>
  20. #include <string>
  21. #include <libff/ff-util.h>
  22. #include <obs.hpp>
  23. #include "auth-base.hpp"
  24. class OBSBasic;
  25. class QAbstractButton;
  26. class QRadioButton;
  27. class QComboBox;
  28. class QCheckBox;
  29. class QLabel;
  30. class OBSPropertiesView;
  31. class OBSHotkeyWidget;
  32. #include "ui_OBSBasicSettings.h"
  33. #define VOLUME_METER_DECAY_FAST 23.53
  34. #define VOLUME_METER_DECAY_MEDIUM 11.76
  35. #define VOLUME_METER_DECAY_SLOW 8.57
  36. class SilentUpdateCheckBox : public QCheckBox {
  37. Q_OBJECT
  38. public slots:
  39. void setCheckedSilently(bool checked)
  40. {
  41. bool blocked = blockSignals(true);
  42. setChecked(checked);
  43. blockSignals(blocked);
  44. }
  45. };
  46. class SilentUpdateSpinBox : public QSpinBox {
  47. Q_OBJECT
  48. public slots:
  49. void setValueSilently(int val)
  50. {
  51. bool blocked = blockSignals(true);
  52. setValue(val);
  53. blockSignals(blocked);
  54. }
  55. };
  56. class OBSFFDeleter {
  57. public:
  58. void operator()(const ff_format_desc *format)
  59. {
  60. ff_format_desc_free(format);
  61. }
  62. void operator()(const ff_codec_desc *codec)
  63. {
  64. ff_codec_desc_free(codec);
  65. }
  66. };
  67. using OBSFFCodecDesc = std::unique_ptr<const ff_codec_desc, OBSFFDeleter>;
  68. using OBSFFFormatDesc = std::unique_ptr<const ff_format_desc, OBSFFDeleter>;
  69. class OBSBasicSettings : public QDialog {
  70. Q_OBJECT
  71. Q_PROPERTY(QIcon generalIcon READ GetGeneralIcon WRITE SetGeneralIcon
  72. DESIGNABLE true)
  73. Q_PROPERTY(QIcon streamIcon READ GetStreamIcon WRITE SetStreamIcon
  74. DESIGNABLE true)
  75. Q_PROPERTY(QIcon outputIcon READ GetOutputIcon WRITE SetOutputIcon
  76. DESIGNABLE true)
  77. Q_PROPERTY(QIcon audioIcon READ GetAudioIcon WRITE SetAudioIcon
  78. DESIGNABLE true)
  79. Q_PROPERTY(QIcon videoIcon READ GetVideoIcon WRITE SetVideoIcon
  80. DESIGNABLE true)
  81. Q_PROPERTY(QIcon hotkeysIcon READ GetHotkeysIcon WRITE SetHotkeysIcon
  82. DESIGNABLE true)
  83. Q_PROPERTY(QIcon advancedIcon READ GetAdvancedIcon WRITE SetAdvancedIcon
  84. DESIGNABLE true)
  85. private:
  86. OBSBasic *main;
  87. std::unique_ptr<Ui::OBSBasicSettings> ui;
  88. std::shared_ptr<Auth> auth;
  89. bool generalChanged = false;
  90. bool stream1Changed = false;
  91. bool outputsChanged = false;
  92. bool audioChanged = false;
  93. bool videoChanged = false;
  94. bool hotkeysChanged = false;
  95. bool advancedChanged = false;
  96. int pageIndex = 0;
  97. bool loading = true;
  98. bool forceAuthReload = false;
  99. std::string savedTheme;
  100. int sampleRateIndex = 0;
  101. int channelIndex = 0;
  102. bool llBufferingEnabled = false;
  103. int lastSimpleRecQualityIdx = 0;
  104. int lastServiceIdx = -1;
  105. int lastIgnoreRecommended = -1;
  106. int lastChannelSetupIdx = 0;
  107. OBSFFFormatDesc formats;
  108. OBSPropertiesView *streamProperties = nullptr;
  109. OBSPropertiesView *streamEncoderProps = nullptr;
  110. OBSPropertiesView *recordEncoderProps = nullptr;
  111. QPointer<QLabel> advOutRecWarning;
  112. QPointer<QLabel> simpleOutRecWarning;
  113. QString curPreset;
  114. QString curQSVPreset;
  115. QString curNVENCPreset;
  116. QString curAMDPreset;
  117. QString curAdvStreamEncoder;
  118. QString curAdvRecordEncoder;
  119. using AudioSource_t =
  120. std::tuple<OBSWeakSource, QPointer<QCheckBox>,
  121. QPointer<QSpinBox>, QPointer<QCheckBox>,
  122. QPointer<QSpinBox>>;
  123. std::vector<AudioSource_t> audioSources;
  124. std::vector<OBSSignal> audioSourceSignals;
  125. OBSSignal sourceCreated;
  126. OBSSignal channelChanged;
  127. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  128. OBSSignal hotkeyRegistered;
  129. OBSSignal hotkeyUnregistered;
  130. uint32_t outputCX = 0;
  131. uint32_t outputCY = 0;
  132. QPointer<QCheckBox> simpleVodTrack;
  133. QPointer<QCheckBox> vodTrackCheckbox;
  134. QPointer<QWidget> vodTrackContainer;
  135. QPointer<QRadioButton> vodTrack[MAX_AUDIO_MIXES];
  136. QIcon hotkeyConflictIcon;
  137. void SaveCombo(QComboBox *widget, const char *section,
  138. const char *value);
  139. void SaveComboData(QComboBox *widget, const char *section,
  140. const char *value);
  141. void SaveCheckBox(QAbstractButton *widget, const char *section,
  142. const char *value, bool invert = false);
  143. void SaveEdit(QLineEdit *widget, const char *section,
  144. const char *value);
  145. void SaveSpinBox(QSpinBox *widget, const char *section,
  146. const char *value);
  147. void SaveFormat(QComboBox *combo);
  148. void SaveEncoder(QComboBox *combo, const char *section,
  149. const char *value);
  150. bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
  151. int max_fps);
  152. void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
  153. int max_fps, int &new_cx, int &new_cy, int &new_fps);
  154. inline bool Changed() const
  155. {
  156. return generalChanged || outputsChanged || stream1Changed ||
  157. audioChanged || videoChanged || advancedChanged ||
  158. hotkeysChanged;
  159. }
  160. inline void EnableApplyButton(bool en)
  161. {
  162. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  163. }
  164. inline void ClearChanged()
  165. {
  166. generalChanged = false;
  167. stream1Changed = false;
  168. outputsChanged = false;
  169. audioChanged = false;
  170. videoChanged = false;
  171. hotkeysChanged = false;
  172. advancedChanged = false;
  173. EnableApplyButton(false);
  174. }
  175. #ifdef _WIN32
  176. bool aeroWasDisabled = false;
  177. QCheckBox *toggleAero = nullptr;
  178. void ToggleDisableAero(bool checked);
  179. #endif
  180. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  181. bool QueryChanges();
  182. void LoadEncoderTypes();
  183. void LoadColorRanges();
  184. void LoadColorSpaces();
  185. void LoadColorFormats();
  186. void LoadFormats();
  187. void ReloadCodecs(const ff_format_desc *formatDesc);
  188. void UpdateColorFormatSpaceWarning();
  189. void LoadGeneralSettings();
  190. void LoadStream1Settings();
  191. void LoadOutputSettings();
  192. void LoadAudioSettings();
  193. void LoadVideoSettings();
  194. void
  195. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  196. void LoadAdvancedSettings();
  197. void LoadSettings(bool changedOnly);
  198. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  199. const char *path,
  200. bool changed = false);
  201. /* general */
  202. void LoadLanguageList();
  203. void LoadThemeList();
  204. /* stream */
  205. void InitStreamPage();
  206. inline bool IsCustomService() const;
  207. void LoadServices(bool showAll);
  208. void OnOAuthStreamKeyConnected();
  209. void OnAuthConnected();
  210. QString lastService;
  211. int prevLangIndex;
  212. bool prevBrowserAccel;
  213. private slots:
  214. void UpdateServerList();
  215. void UpdateKeyLink();
  216. void UpdateVodTrackSetting();
  217. void UpdateServiceRecommendations();
  218. void RecreateOutputResolutionWidget();
  219. void UpdateResFPSLimits();
  220. void UpdateMoreInfoLink();
  221. void DisplayEnforceWarning(bool checked);
  222. void on_show_clicked();
  223. void on_authPwShow_clicked();
  224. void on_connectAccount_clicked();
  225. void on_disconnectAccount_clicked();
  226. void on_useStreamKey_clicked();
  227. void on_useAuth_toggled();
  228. void on_hotkeyFilterReset_clicked();
  229. void on_hotkeyFilterSearch_textChanged(const QString text);
  230. void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);
  231. private:
  232. /* output */
  233. void LoadSimpleOutputSettings();
  234. void LoadAdvOutputStreamingSettings();
  235. void LoadAdvOutputStreamingEncoderProperties();
  236. void LoadAdvOutputRecordingSettings();
  237. void LoadAdvOutputRecordingEncoderProperties();
  238. void LoadAdvOutputFFmpegSettings();
  239. void LoadAdvOutputAudioSettings();
  240. void SetAdvOutputFFmpegEnablement(ff_codec_type encoderType,
  241. bool enabled,
  242. bool enableEncode = false);
  243. /* audio */
  244. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  245. void LoadAudioDevices();
  246. void LoadAudioSources();
  247. /* video */
  248. void LoadRendererList();
  249. void ResetDownscales(uint32_t cx, uint32_t cy,
  250. bool ignoreAllSignals = false);
  251. void LoadDownscaleFilters();
  252. void LoadResolutionLists();
  253. void LoadFPSData();
  254. void SaveGeneralSettings();
  255. void SaveStream1Settings();
  256. void SaveOutputSettings();
  257. void SaveAudioSettings();
  258. void SaveVideoSettings();
  259. void SaveHotkeySettings();
  260. void SaveAdvancedSettings();
  261. void SaveSettings();
  262. void SearchHotkeys(const QString &text,
  263. obs_key_combination_t filterCombo);
  264. void UpdateSimpleOutStreamDelayEstimate();
  265. void UpdateAdvOutStreamDelayEstimate();
  266. void FillSimpleRecordingValues();
  267. void FillSimpleStreamingValues();
  268. void FillAudioMonitoringDevices();
  269. void RecalcOutputResPixels(const char *resText);
  270. bool AskIfCanCloseSettings();
  271. QIcon generalIcon;
  272. QIcon streamIcon;
  273. QIcon outputIcon;
  274. QIcon audioIcon;
  275. QIcon videoIcon;
  276. QIcon hotkeysIcon;
  277. QIcon advancedIcon;
  278. QIcon GetGeneralIcon() const;
  279. QIcon GetStreamIcon() const;
  280. QIcon GetOutputIcon() const;
  281. QIcon GetAudioIcon() const;
  282. QIcon GetVideoIcon() const;
  283. QIcon GetHotkeysIcon() const;
  284. QIcon GetAdvancedIcon() const;
  285. int CurrentFLVTrack();
  286. OBSService GetStream1Service();
  287. private slots:
  288. void on_theme_activated(int idx);
  289. void on_listWidget_itemSelectionChanged();
  290. void on_buttonBox_clicked(QAbstractButton *button);
  291. void on_service_currentIndexChanged(int idx);
  292. void on_simpleOutputBrowse_clicked();
  293. void on_advOutRecPathBrowse_clicked();
  294. void on_advOutFFPathBrowse_clicked();
  295. void on_advOutEncoder_currentIndexChanged(int idx);
  296. void on_advOutRecEncoder_currentIndexChanged(int idx);
  297. void on_advOutFFIgnoreCompat_stateChanged(int state);
  298. void on_advOutFFFormat_currentIndexChanged(int idx);
  299. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  300. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  301. void on_advOutFFType_currentIndexChanged(int idx);
  302. void on_colorFormat_currentIndexChanged(const QString &text);
  303. void on_colorSpace_currentIndexChanged(const QString &text);
  304. void on_filenameFormatting_textEdited(const QString &text);
  305. void on_outputResolution_editTextChanged(const QString &text);
  306. void on_baseResolution_editTextChanged(const QString &text);
  307. void on_disableOSXVSync_clicked();
  308. void GeneralChanged();
  309. void HideOBSWindowWarning(int state);
  310. void AudioChanged();
  311. void AudioChangedRestart();
  312. void ReloadAudioSources();
  313. void SurroundWarning(int idx);
  314. void SpeakerLayoutChanged(int idx);
  315. void LowLatencyBufferingChanged(bool checked);
  316. void UpdateAudioWarnings();
  317. void OutputsChanged();
  318. void Stream1Changed();
  319. void VideoChanged();
  320. void VideoChangedResolution();
  321. void VideoChangedRestart();
  322. void HotkeysChanged();
  323. bool ScanDuplicateHotkeys(QFormLayout *layout);
  324. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  325. void AdvancedChanged();
  326. void AdvancedChangedRestart();
  327. void UpdateStreamDelayEstimate();
  328. void UpdateAutomaticReplayBufferCheckboxes();
  329. void AdvOutSplitFileChanged();
  330. void AdvOutRecCheckWarnings();
  331. void SimpleRecordingQualityChanged();
  332. void SimpleRecordingEncoderChanged();
  333. void SimpleRecordingQualityLosslessWarning(int idx);
  334. void SimpleReplayBufferChanged();
  335. void AdvReplayBufferChanged();
  336. void SimpleStreamingEncoderChanged();
  337. OBSService SpawnTempService();
  338. void SetGeneralIcon(const QIcon &icon);
  339. void SetStreamIcon(const QIcon &icon);
  340. void SetOutputIcon(const QIcon &icon);
  341. void SetAudioIcon(const QIcon &icon);
  342. void SetVideoIcon(const QIcon &icon);
  343. void SetHotkeysIcon(const QIcon &icon);
  344. void SetAdvancedIcon(const QIcon &icon);
  345. void UseStreamKeyAdvClicked();
  346. protected:
  347. virtual void closeEvent(QCloseEvent *event) override;
  348. void reject() override;
  349. public:
  350. OBSBasicSettings(QWidget *parent);
  351. ~OBSBasicSettings();
  352. inline const QIcon &GetHotkeyConflictIcon() const
  353. {
  354. return hotkeyConflictIcon;
  355. }
  356. };