1 /*
2 Copyright (c) 2012-2020 Maarten Baert <maarten-baert@hotmail.com>
3 
4 This file is part of SimpleScreenRecorder.
5 
6 SimpleScreenRecorder is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 SimpleScreenRecorder is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with SimpleScreenRecorder.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #include "Global.h"
22 
23 #include "ProfileBox.h"
24 
25 class MainWindow;
26 
27 class PageOutput : public QWidget {
28 	Q_OBJECT
29 
30 public:
31 	enum enum_container {
32 		CONTAINER_MKV,
33 		CONTAINER_MP4,
34 		CONTAINER_WEBM,
35 		CONTAINER_OGG,
36 		CONTAINER_OTHER,
37 		CONTAINER_COUNT // must be last
38 	};
39 	enum enum_video_codec {
40 		VIDEO_CODEC_H264,
41 		VIDEO_CODEC_VP8,
42 		VIDEO_CODEC_THEORA,
43 		VIDEO_CODEC_OTHER,
44 		VIDEO_CODEC_COUNT // must be last
45 	};
46 	enum enum_audio_codec {
47 		AUDIO_CODEC_VORBIS,
48 		AUDIO_CODEC_MP3,
49 		AUDIO_CODEC_AAC,
50 		AUDIO_CODEC_UNCOMPRESSED,
51 		AUDIO_CODEC_OTHER,
52 		AUDIO_CODEC_COUNT // must be last
53 	};
54 	enum enum_h264_preset {
55 		H264_PRESET_ULTRAFAST,
56 		H264_PRESET_SUPERFAST,
57 		H264_PRESET_VERYFAST,
58 		H264_PRESET_FASTER,
59 		H264_PRESET_FAST,
60 		H264_PRESET_MEDIUM,
61 		H264_PRESET_SLOW,
62 		H264_PRESET_SLOWER,
63 		H264_PRESET_VERYSLOW,
64 		H264_PRESET_PLACEBO,
65 		H264_PRESET_COUNT // must be last
66 	};
67 
68 private:
69 	struct ContainerData {
70 		QString name, avname;
71 		QStringList suffixes;
72 		QString filter;
73 		std::set<enum_video_codec> supported_video_codecs;
74 		std::set<enum_audio_codec> supported_audio_codecs;
75 		inline bool operator<(const ContainerData& other) const { return (avname < other.avname); }
76 	};
77 	struct VideoCodecData {
78 		QString name, avname;
79 		inline bool operator<(const VideoCodecData& other) const { return (avname < other.avname); }
80 	};
81 	struct AudioCodecData {
82 		QString name, avname;
83 		inline bool operator<(const AudioCodecData& other) const { return (avname < other.avname); }
84 	};
85 
86 private:
87 	MainWindow *m_main_window;
88 
89 	enum_container m_old_container;
90 	unsigned int m_old_container_av;
91 
92 	std::vector<ContainerData> m_containers, m_containers_av;
93 	std::vector<VideoCodecData> m_video_codecs, m_video_codecs_av;
94 	std::vector<AudioCodecData> m_audio_codecs, m_audio_codecs_av;
95 
96 	ProfileBox *m_profile_box;
97 
98 	QComboBox *m_combobox_profiles;
99 	QPushButton *m_pushbutton_profile_save, *m_pushbutton_profile_new, *m_pushbutton_profile_delete;
100 
101 	QLineEdit *m_lineedit_file;
102 	QCheckBox *m_checkbox_separate_files, *m_checkbox_add_timestamp;
103 	QComboBox *m_combobox_container;
104 	QLabel *m_label_container_av;
105 	QComboBox *m_combobox_container_av;
106 	QLabel *m_label_container_warning;
107 
108 	QComboBox *m_combobox_video_codec;
109 	QLabel *m_label_video_codec_av;
110 	QComboBox *m_combobox_video_codec_av;
111 	QLabel *m_label_video_kbit_rate;
112 	QLineEdit *m_lineedit_video_kbit_rate;
113 	QLabel *m_label_h264_crf;
114 	QSlider *m_slider_h264_crf;
115 	QLabel *m_label_h264_crf_value;
116 	QLabel *m_label_h264_preset;
117 	QComboBox *m_combobox_h264_preset;
118 	QLabel *m_label_vp8_cpu_used;
119 	QComboBox *m_combobox_vp8_cpu_used;
120 	QLabel *m_label_video_options;
121 	QLineEdit *m_lineedit_video_options;
122 	QCheckBox *m_checkbox_video_allow_frame_skipping;
123 
124 	QGroupBox *m_groupbox_audio;
125 	QComboBox *m_combobox_audio_codec;
126 	QLabel *m_label_audio_codec_av;
127 	QComboBox *m_combobox_audio_codec_av;
128 	QLabel *m_label_audio_kbit_rate;
129 	QLineEdit *m_lineedit_audio_kbit_rate;
130 	QLabel *m_label_audio_options;
131 	QLineEdit *m_lineedit_audio_options;
132 
133 public:
134 	PageOutput(MainWindow* main_window);
135 
136 	void LoadSettings(QSettings* settings);
137 	void SaveSettings(QSettings* settings);
138 
139 private:
140 	static void LoadProfileSettingsCallback(QSettings* settings, void* userdata);
141 	static void SaveProfileSettingsCallback(QSettings* settings, void* userdata);
142 	void LoadProfileSettings(QSettings* settings);
143 	void SaveProfileSettings(QSettings* settings);
144 
145 public:
146 	void StartPage();
147 	bool Validate();
148 
149 	QString GetFileProtocol();
150 	QString GetContainerAVName();
151 	QString GetVideoCodecAVName();
152 	QString GetAudioCodecAVName();
153 
154 private:
155 	unsigned int FindContainerAV(const QString& name);
156 	unsigned int FindVideoCodecAV(const QString& name);
157 	unsigned int FindAudioCodecAV(const QString& name);
158 
159 private:
160 	void LoadProfiles();
161 	void LoadProfilesFromDir(const QString& path, bool can_delete);
162 	void UpdateProfileFields();
163 
164 public slots:
165 	void OnUpdateSuffixAndContainerFields();
166 	void OnUpdateContainerFields();
167 	void OnUpdateVideoCodecFields();
168 	void OnUpdateAudioCodecFields();
169 
170 private slots:
171 	void OnBrowse();
172 	void OnContinue();
173 
174 public:
GetProfile()175 	inline unsigned int GetProfile() { return m_profile_box->GetProfile(); }
GetFile()176 	inline QString GetFile() { return m_lineedit_file->text(); }
GetSeparateFiles()177 	inline bool GetSeparateFiles() { return m_checkbox_separate_files->isChecked(); }
GetAddTimestamp()178 	inline bool GetAddTimestamp() { return m_checkbox_add_timestamp->isChecked(); }
GetContainer()179 	inline enum_container GetContainer() { return (enum_container) clamp(m_combobox_container->currentIndex(), 0, CONTAINER_COUNT - 1); }
GetContainerAV()180 	inline unsigned int GetContainerAV() { return clamp(m_combobox_container_av->currentIndex(), 0, (int) m_containers_av.size() - 1); }
GetVideoCodec()181 	inline enum_video_codec GetVideoCodec() { return (enum_video_codec) clamp(m_combobox_video_codec->currentIndex(), 0, VIDEO_CODEC_COUNT - 1); }
GetVideoCodecAV()182 	inline unsigned int GetVideoCodecAV() { return clamp(m_combobox_video_codec_av->currentIndex(), 0, (int) m_video_codecs_av.size() - 1); }
GetVideoKBitRate()183 	inline unsigned int GetVideoKBitRate() { return m_lineedit_video_kbit_rate->text().toUInt(); }
GetH264CRF()184 	inline unsigned int GetH264CRF() { return m_slider_h264_crf->value(); }
GetH264Preset()185 	inline enum_h264_preset GetH264Preset() { return (enum_h264_preset) clamp(m_combobox_h264_preset->currentIndex(), 0, H264_PRESET_COUNT - 1); }
GetVP8CPUUsed()186 	inline unsigned int GetVP8CPUUsed() { return clamp(5 - m_combobox_vp8_cpu_used->currentIndex(), 0, 5); }
GetVideoOptions()187 	inline QString GetVideoOptions() { return m_lineedit_video_options->text(); }
GetVideoAllowFrameSkipping()188 	inline bool GetVideoAllowFrameSkipping() { return m_checkbox_video_allow_frame_skipping->isChecked(); }
GetAudioCodec()189 	inline enum_audio_codec GetAudioCodec() { return (enum_audio_codec) clamp(m_combobox_audio_codec->currentIndex(), 0, AUDIO_CODEC_COUNT - 1); }
GetAudioCodecAV()190 	inline unsigned int GetAudioCodecAV() { return clamp(m_combobox_audio_codec_av->currentIndex(), 0, (int) m_audio_codecs_av.size() - 1); }
GetAudioKBitRate()191 	inline unsigned int GetAudioKBitRate() { return m_lineedit_audio_kbit_rate->text().toUInt(); }
GetAudioOptions()192 	inline QString GetAudioOptions() { return m_lineedit_audio_options->text(); }
193 
SetProfile(unsigned int profile)194 	inline void SetProfile(unsigned int profile) { m_profile_box->SetProfile(profile); }
SetContainer(enum_container container)195 	inline void SetContainer(enum_container container) { m_combobox_container->setCurrentIndex(clamp((unsigned int) container, 0u, (unsigned int) CONTAINER_COUNT - 1)); }
SetContainerAV(unsigned int container)196 	inline void SetContainerAV(unsigned int container) { m_combobox_container_av->setCurrentIndex(clamp(container, 0u, (unsigned int) m_containers_av.size() - 1)); }
SetFile(const QString & file)197 	inline void SetFile(const QString& file) { m_lineedit_file->setText(file); }
SetSeparateFiles(bool separate_files)198 	inline void SetSeparateFiles(bool separate_files) { m_checkbox_separate_files->setChecked(separate_files); }
SetAddTimestamp(bool add_timestamp)199 	inline void SetAddTimestamp(bool add_timestamp) { m_checkbox_add_timestamp->setChecked(add_timestamp); }
SetVideoCodec(enum_video_codec video_codec)200 	inline void SetVideoCodec(enum_video_codec video_codec) { m_combobox_video_codec->setCurrentIndex(clamp((unsigned int) video_codec, 0u, (unsigned int) VIDEO_CODEC_COUNT - 1)); }
SetVideoCodecAV(unsigned int video_codec_av)201 	inline void SetVideoCodecAV(unsigned int video_codec_av) { m_combobox_video_codec_av->setCurrentIndex(clamp(video_codec_av, 0u, (unsigned int) m_video_codecs_av.size() - 1)); }
SetVideoKBitRate(unsigned int kbit_rate)202 	inline void SetVideoKBitRate(unsigned int kbit_rate) { m_lineedit_video_kbit_rate->setText(QString::number(kbit_rate)); }
SetH264CRF(unsigned int crf)203 	inline void SetH264CRF(unsigned int crf) { m_slider_h264_crf->setValue(crf); }
SetH264Preset(enum_h264_preset preset)204 	inline void SetH264Preset(enum_h264_preset preset) { m_combobox_h264_preset->setCurrentIndex(clamp((unsigned int) preset, 0u, (unsigned int) H264_PRESET_COUNT - 1)); }
SetVP8CPUUsed(unsigned int cpu_used)205 	inline void SetVP8CPUUsed(unsigned int cpu_used) { m_combobox_vp8_cpu_used->setCurrentIndex(clamp(5 - (int) cpu_used, 0, 5)); }
SetVideoOptions(const QString & options)206 	inline void SetVideoOptions(const QString& options) { m_lineedit_video_options->setText(options); }
SetVideoAllowFrameSkipping(bool allow_frame_skipping)207 	inline void SetVideoAllowFrameSkipping(bool allow_frame_skipping) { return m_checkbox_video_allow_frame_skipping->setChecked(allow_frame_skipping); }
SetAudioCodec(enum_audio_codec audio_codec)208 	inline void SetAudioCodec(enum_audio_codec audio_codec) { m_combobox_audio_codec->setCurrentIndex(clamp((unsigned int) audio_codec, 0u, (unsigned int) AUDIO_CODEC_COUNT - 1)); }
SetAudioCodecAV(unsigned int audio_codec_av)209 	inline void SetAudioCodecAV(unsigned int audio_codec_av) { m_combobox_audio_codec_av->setCurrentIndex(clamp(audio_codec_av, 0u, (unsigned int) m_audio_codecs_av.size() - 1)); }
SetAudioKBitRate(unsigned int kbit_rate)210 	inline void SetAudioKBitRate(unsigned int kbit_rate) { m_lineedit_audio_kbit_rate->setText(QString::number(kbit_rate)); }
SetAudioOptions(const QString & options)211 	inline void SetAudioOptions(const QString& options) { m_lineedit_audio_options->setText(options); }
212 
213 };
214