window-basic-settings.hpp 10 KB

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