window-basic-settings.hpp 12 KB

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