window-basic-settings.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. int lastSimpleRecQualityIdx = 0;
  103. int lastChannelSetupIdx = 0;
  104. OBSFFFormatDesc formats;
  105. OBSPropertiesView *streamProperties = nullptr;
  106. OBSPropertiesView *streamEncoderProps = nullptr;
  107. OBSPropertiesView *recordEncoderProps = nullptr;
  108. QPointer<QLabel> advOutRecWarning;
  109. QPointer<QLabel> simpleOutRecWarning;
  110. QString curPreset;
  111. QString curQSVPreset;
  112. QString curNVENCPreset;
  113. QString curAMDPreset;
  114. QString curAdvStreamEncoder;
  115. QString curAdvRecordEncoder;
  116. using AudioSource_t =
  117. std::tuple<OBSWeakSource, QPointer<QCheckBox>,
  118. QPointer<QSpinBox>, QPointer<QCheckBox>,
  119. QPointer<QSpinBox>>;
  120. std::vector<AudioSource_t> audioSources;
  121. std::vector<OBSSignal> audioSourceSignals;
  122. OBSSignal sourceCreated;
  123. OBSSignal channelChanged;
  124. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  125. OBSSignal hotkeyRegistered;
  126. OBSSignal hotkeyUnregistered;
  127. uint32_t outputCX = 0;
  128. uint32_t outputCY = 0;
  129. QPointer<QCheckBox> vodTrackCheckbox;
  130. QPointer<QWidget> vodTrackContainer;
  131. QPointer<QRadioButton> vodTrack[MAX_AUDIO_MIXES];
  132. void SaveCombo(QComboBox *widget, const char *section,
  133. const char *value);
  134. void SaveComboData(QComboBox *widget, const char *section,
  135. const char *value);
  136. void SaveCheckBox(QAbstractButton *widget, const char *section,
  137. const char *value, bool invert = false);
  138. void SaveEdit(QLineEdit *widget, const char *section,
  139. const char *value);
  140. void SaveSpinBox(QSpinBox *widget, const char *section,
  141. const char *value);
  142. void SaveFormat(QComboBox *combo);
  143. void SaveEncoder(QComboBox *combo, const char *section,
  144. const char *value);
  145. inline bool Changed() const
  146. {
  147. return generalChanged || outputsChanged || stream1Changed ||
  148. audioChanged || videoChanged || advancedChanged ||
  149. hotkeysChanged;
  150. }
  151. inline void EnableApplyButton(bool en)
  152. {
  153. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  154. }
  155. inline void ClearChanged()
  156. {
  157. generalChanged = false;
  158. stream1Changed = false;
  159. outputsChanged = false;
  160. audioChanged = false;
  161. videoChanged = false;
  162. hotkeysChanged = false;
  163. advancedChanged = false;
  164. EnableApplyButton(false);
  165. }
  166. #ifdef _WIN32
  167. bool aeroWasDisabled = false;
  168. QCheckBox *toggleAero = nullptr;
  169. void ToggleDisableAero(bool checked);
  170. #endif
  171. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  172. bool QueryChanges();
  173. void LoadEncoderTypes();
  174. void LoadColorRanges();
  175. void LoadFormats();
  176. void ReloadCodecs(const ff_format_desc *formatDesc);
  177. void LoadGeneralSettings();
  178. void LoadStream1Settings();
  179. void LoadOutputSettings();
  180. void LoadAudioSettings();
  181. void LoadVideoSettings();
  182. void
  183. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  184. void LoadAdvancedSettings();
  185. void LoadSettings(bool changedOnly);
  186. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  187. const char *path,
  188. bool changed = false);
  189. /* general */
  190. void LoadLanguageList();
  191. void LoadThemeList();
  192. /* stream */
  193. void InitStreamPage();
  194. inline bool IsCustomService() const;
  195. void LoadServices(bool showAll);
  196. void OnOAuthStreamKeyConnected();
  197. void OnAuthConnected();
  198. QString lastService;
  199. int prevLangIndex;
  200. bool prevBrowserAccel;
  201. private slots:
  202. void UpdateServerList();
  203. void UpdateKeyLink();
  204. void UpdateVodTrackSetting();
  205. void UpdateMoreInfoLink();
  206. void on_show_clicked();
  207. void on_authPwShow_clicked();
  208. void on_connectAccount_clicked();
  209. void on_disconnectAccount_clicked();
  210. void on_useStreamKey_clicked();
  211. void on_useAuth_toggled();
  212. private:
  213. /* output */
  214. void LoadSimpleOutputSettings();
  215. void LoadAdvOutputStreamingSettings();
  216. void LoadAdvOutputStreamingEncoderProperties();
  217. void LoadAdvOutputRecordingSettings();
  218. void LoadAdvOutputRecordingEncoderProperties();
  219. void LoadAdvOutputFFmpegSettings();
  220. void LoadAdvOutputAudioSettings();
  221. void SetAdvOutputFFmpegEnablement(ff_codec_type encoderType,
  222. bool enabled,
  223. bool enableEncode = false);
  224. /* audio */
  225. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  226. void LoadAudioDevices();
  227. void LoadAudioSources();
  228. /* video */
  229. void LoadRendererList();
  230. void ResetDownscales(uint32_t cx, uint32_t cy);
  231. void LoadDownscaleFilters();
  232. void LoadResolutionLists();
  233. void LoadFPSData();
  234. void SaveGeneralSettings();
  235. void SaveStream1Settings();
  236. void SaveOutputSettings();
  237. void SaveAudioSettings();
  238. void SaveVideoSettings();
  239. void SaveHotkeySettings();
  240. void SaveAdvancedSettings();
  241. void SaveSettings();
  242. void UpdateSimpleOutStreamDelayEstimate();
  243. void UpdateAdvOutStreamDelayEstimate();
  244. void FillSimpleRecordingValues();
  245. void FillSimpleStreamingValues();
  246. void FillAudioMonitoringDevices();
  247. void RecalcOutputResPixels(const char *resText);
  248. bool AskIfCanCloseSettings();
  249. QIcon generalIcon;
  250. QIcon streamIcon;
  251. QIcon outputIcon;
  252. QIcon audioIcon;
  253. QIcon videoIcon;
  254. QIcon hotkeysIcon;
  255. QIcon advancedIcon;
  256. QIcon GetGeneralIcon() const;
  257. QIcon GetStreamIcon() const;
  258. QIcon GetOutputIcon() const;
  259. QIcon GetAudioIcon() const;
  260. QIcon GetVideoIcon() const;
  261. QIcon GetHotkeysIcon() const;
  262. QIcon GetAdvancedIcon() const;
  263. int CurrentFLVTrack();
  264. private slots:
  265. void on_theme_activated(int idx);
  266. void on_listWidget_itemSelectionChanged();
  267. void on_buttonBox_clicked(QAbstractButton *button);
  268. void on_service_currentIndexChanged(int idx);
  269. void on_simpleOutputBrowse_clicked();
  270. void on_advOutRecPathBrowse_clicked();
  271. void on_advOutFFPathBrowse_clicked();
  272. void on_advOutEncoder_currentIndexChanged(int idx);
  273. void on_advOutRecEncoder_currentIndexChanged(int idx);
  274. void on_advOutFFIgnoreCompat_stateChanged(int state);
  275. void on_advOutFFFormat_currentIndexChanged(int idx);
  276. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  277. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  278. void on_advOutFFType_currentIndexChanged(int idx);
  279. void on_colorFormat_currentIndexChanged(const QString &text);
  280. void on_filenameFormatting_textEdited(const QString &text);
  281. void on_outputResolution_editTextChanged(const QString &text);
  282. void on_baseResolution_editTextChanged(const QString &text);
  283. void on_disableOSXVSync_clicked();
  284. void GeneralChanged();
  285. void AudioChanged();
  286. void AudioChangedRestart();
  287. void ReloadAudioSources();
  288. void SurroundWarning(int idx);
  289. void SpeakerLayoutChanged(int idx);
  290. void OutputsChanged();
  291. void Stream1Changed();
  292. void VideoChanged();
  293. void VideoChangedResolution();
  294. void VideoChangedRestart();
  295. void HotkeysChanged();
  296. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  297. void AdvancedChanged();
  298. void AdvancedChangedRestart();
  299. void UpdateStreamDelayEstimate();
  300. void UpdateAutomaticReplayBufferCheckboxes();
  301. void AdvOutRecCheckWarnings();
  302. void SimpleRecordingQualityChanged();
  303. void SimpleRecordingEncoderChanged();
  304. void SimpleRecordingQualityLosslessWarning(int idx);
  305. void SimpleReplayBufferChanged();
  306. void AdvReplayBufferChanged();
  307. void SimpleStreamingEncoderChanged();
  308. OBSService SpawnTempService();
  309. void SetGeneralIcon(const QIcon &icon);
  310. void SetStreamIcon(const QIcon &icon);
  311. void SetOutputIcon(const QIcon &icon);
  312. void SetAudioIcon(const QIcon &icon);
  313. void SetVideoIcon(const QIcon &icon);
  314. void SetHotkeysIcon(const QIcon &icon);
  315. void SetAdvancedIcon(const QIcon &icon);
  316. protected:
  317. virtual void closeEvent(QCloseEvent *event) override;
  318. void reject() override;
  319. public:
  320. OBSBasicSettings(QWidget *parent);
  321. ~OBSBasicSettings();
  322. };