Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterRecord.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QDir>
4#include <QDateTime>
5#include <QStandardPaths>
6
7#include "ParameterRecord.h"
8#include "RabbitCommonDir.h"
9
10CParameterRecord::CParameterRecord(QObject *parent, const QString &szPrefix)
11 : CParameter(parent, szPrefix)
12 , m_bEnableVideo(true)
13 , m_bEnableAudio(true)
14#if HAVE_QT6_MULTIMEDIA
15 , m_FileFormat(QMediaFormat::FileFormat::MPEG4)
16 , m_VideoCodec(QMediaFormat::VideoCodec::H264)
17 , m_AudioCodec(QMediaFormat::AudioCodec::AAC)
18 , m_Quality(QMediaRecorder::NormalQuality)
19 , m_EncodingMode(QMediaRecorder::ConstantQualityEncoding)
20#endif
21 , m_VideoFrameRate(0)
22 , m_AudioSampleRate(-1)
23 , m_EndAction(ENDACTION::No)
24{
25 m_szPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
26 QDir d;
27 if(m_szPath.isEmpty() || !d.exists(m_szPath))
28 m_szPath = RabbitCommon::CDir::Instance()->GetDirUserImage();
29 m_szPath += QDir::separator() + tr("RabbitRemoteControl")
30 + QDir::separator() + tr("Record");
31
32 if(!d.exists(m_szPath))
33 d.mkpath(m_szPath);
34
35 m_szImagePath = QStandardPaths::writableLocation(
36 QStandardPaths::PicturesLocation);
37 if(m_szImagePath.isEmpty() || !d.exists(m_szImagePath))
38 m_szImagePath = RabbitCommon::CDir::Instance()->GetDirUserImage();
39 m_szImagePath += QDir::separator() + tr("RabbitRemoteControl")
40 + QDir::separator() + tr("ScreenShot");
41 if(!d.exists(m_szImagePath))
42 d.mkpath(m_szImagePath);
43}
44
45CParameterRecord& CParameterRecord::operator =(const CParameterRecord& in)
46{
47 if(this == &in)
48 return *this;
49 m_bEnableVideo = in.m_bEnableVideo;
50 m_bEnableAudio = in.m_bEnableAudio;
51 m_szFile = in.m_szFile;
52 m_szImageFile = in.m_szImageFile;
53 m_szPath = in.m_szPath;
54 m_szImagePath = in.m_szImagePath;
55
56#if HAVE_QT6_MULTIMEDIA
57 m_FileFormat = in.m_FileFormat;
58 m_VideoCodec = in.m_VideoCodec;
59 m_AudioCodec = in.m_AudioCodec;
60 m_Quality = in.m_Quality;
61 m_EncodingMode = in.m_EncodingMode;
62#endif
63
64 m_VideoFrameRate = in.m_VideoFrameRate;
65 m_AudioSampleRate = in.m_AudioSampleRate;
66
67 m_EndAction = in.m_EndAction;
68
69 return *this;
70}
71
72bool CParameterRecord::GetEnableVideo() const
73{
74 return m_bEnableVideo;
75}
76
77void CParameterRecord::SetEnableVideo(bool newEnableVideo)
78{
79 if (m_bEnableVideo == newEnableVideo)
80 return;
81 m_bEnableVideo = newEnableVideo;
82 SetModified(true);
83 emit sigEnableVideoChanged();
84}
85
86bool CParameterRecord::GetEnableAudio() const
87{
88 return m_bEnableAudio;
89}
90
91void CParameterRecord::SetEnableAudio(bool newEnableAudio)
92{
93 if (m_bEnableAudio == newEnableAudio)
94 return;
95 m_bEnableAudio = newEnableAudio;
96 SetModified(true);
97 emit sigEnableAudioChanged();
98}
99
100CParameterRecord::ENDACTION CParameterRecord::GetEndAction() const
101{
102 return m_EndAction;
103}
104
105void CParameterRecord::SetEndAction(ENDACTION newEndAction)
106{
107 if (m_EndAction == newEndAction)
108 return;
109 m_EndAction = newEndAction;
110 SetModified(true);
111 emit sigEndActionChanged();
112}
113
114QString CParameterRecord::GetImagePath() const
115{
116 return m_szImagePath;
117}
118
119void CParameterRecord::SetImagePath(const QString &newImagePath)
120{
121 if (m_szImagePath == newImagePath)
122 return;
123 m_szImagePath = newImagePath;
124 SetModified(true);
125 emit ImagePathChanged();
126}
127
128int CParameterRecord::OnLoad(QSettings &set)
129{
130 set.beginGroup("Record");
131
132 SetEnableVideo(set.value("EnableVideo", GetEnableVideo()).toBool());
133 SetEnableAudio(set.value("EnableAudio", GetEnableAudio()).toBool());
134 SetPath(set.value("Path", GetPath()).toString());
135 SetImagePath(set.value("ImagePath", GetImagePath()).toString());
136#if HAVE_QT6_MULTIMEDIA
137 SetFileFormat((QMediaFormat::FileFormat)
138 set.value("FileFormat", (int)GetFileFormat()).toInt());
139 SetVideoCodec((QMediaFormat::VideoCodec)
140 set.value("Video/Codec", (int)GetVideoCodec()).toInt());
141 SetAudioCodec((QMediaFormat::AudioCodec)
142 set.value("Audio/Codec", (int)GetAudioCodec()).toInt());
143 SetQuality((QMediaRecorder::Quality)
144 set.value("Quality", GetQuality()).toInt());
145 SetEncodingMode((QMediaRecorder::EncodingMode)
146 set.value("EncodingMode", GetEncodingMode()).toInt());
147#endif
148 SetAudioSampleRate(set.value("Audio/SampleRate", GetAudioSampleRate()).toInt());
149 SetVideoFrameRate(set.value("Video/FrameRate", GetVideoFrameRate()).toInt());
150 SetEndAction((ENDACTION)set.value("EndAction", GetEndAction()).toInt());
151 set.endGroup();
152 return 0;
153}
154
155int CParameterRecord::OnSave(QSettings &set)
156{
157 set.beginGroup("Record");
158
159 set.setValue("EnableVideo", GetEnableVideo());
160 set.setValue("EnableAudio", GetEnableAudio());
161 set.setValue("Path", GetPath());
162 set.setValue("ImagePath", GetImagePath());
163#if HAVE_QT6_MULTIMEDIA
164 set.setValue("FileFormat", (int)GetFileFormat());
165 set.setValue("Video/Codec", (int)GetVideoCodec());
166 set.setValue("Audio/Codec", (int)GetAudioCodec());
167 set.setValue("Quality", (int)GetQuality());
168 set.setValue("EncodingMode", GetEncodingMode());
169#endif
170 set.setValue("Audio/SampleRate", GetAudioSampleRate());
171 set.setValue("Video/FrameRate", GetVideoFrameRate());
172 set.setValue("EndAction", (int)GetEndAction());
173 set.endGroup();
174 return 0;
175}
176
177const QString CParameterRecord::GetFile(bool bAuto)
178{
179 if(bAuto)
180 m_szFile = GetPath() + QDir::separator()
181 + QDateTime::currentDateTime().toLocalTime()
182 .toString("yyyy_MM_dd_hh_mm_ss_zzz");
183
184 return m_szFile;
185}
186
187int CParameterRecord::SetFile(const QString &szFile)
188{
189 if(m_szFile == szFile)
190 return 0;
191 SetModified(true);
192 m_szFile = szFile;
193 return 0;
194}
195
196QString CParameterRecord::GetImageFile(bool bAuto)
197{
198 QString szPath = GetImagePath();
199 if(bAuto) {
200 m_szImageFile = szPath
201 + QDir::separator()
202 + QDateTime::currentDateTime().toLocalTime()
203 .toString("yyyy_MM_dd_hh_mm_ss_zzz") + ".png";
204 }
205 return m_szImageFile;
206}
207
208void CParameterRecord::SetImageFile(const QString &newImageFile)
209{
210 if (m_szImageFile == newImageFile)
211 return;
212 m_szImageFile = newImageFile;
213 SetModified(true);
214 emit sigImageFileChanged();
215}
216
217const QString CParameterRecord::GetPath() const
218{
219 return m_szPath;
220}
221
222int CParameterRecord::SetPath(const QString &szPath)
223{
224 if(m_szPath == szPath)
225 return 0;
226 m_szPath = szPath;
227 SetModified(true);
228 return 0;
229}
230
231#if HAVE_QT6_MULTIMEDIA
232const QMediaFormat::FileFormat CParameterRecord::GetFileFormat() const
233{
234 return m_FileFormat;
235}
236
237int CParameterRecord::SetFileFormat(const QMediaFormat::FileFormat &f)
238{
239 if(m_FileFormat == f)
240 return 0;
241 m_FileFormat = f;
242 SetModified(true);
243 return 0;
244}
245
246const QMediaFormat::VideoCodec CParameterRecord::GetVideoCodec() const
247{
248 return m_VideoCodec;
249}
250
251int CParameterRecord::SetVideoCodec(QMediaFormat::VideoCodec v)
252{
253 if(m_VideoCodec == v)
254 return 0;
255 m_VideoCodec = v;
256 SetModified(true);
257 return 0;
258}
259
260const QMediaFormat::AudioCodec CParameterRecord::GetAudioCodec() const
261{
262 return m_AudioCodec;
263}
264
265int CParameterRecord::SetAudioCodec(QMediaFormat::AudioCodec a)
266{
267 if(m_AudioCodec == a)
268 return 0;
269 m_AudioCodec = a;
270 SetModified(true);
271 return 0;
272}
273
274QMediaRecorder::Quality CParameterRecord::GetQuality() const
275{
276 return m_Quality;
277}
278
279void CParameterRecord::SetQuality(const QMediaRecorder::Quality &newQuality)
280{
281 if (m_Quality == newQuality)
282 return;
283 m_Quality = newQuality;
284 SetModified(true);
285 emit sigQualityChanged();
286}
287
288QMediaRecorder::EncodingMode CParameterRecord::GetEncodingMode() const
289{
290 return m_EncodingMode;
291}
292
293void CParameterRecord::SetEncodingMode(const QMediaRecorder::EncodingMode &newEncodingMode)
294{
295 if (m_EncodingMode == newEncodingMode)
296 return;
297 m_EncodingMode = newEncodingMode;
298 SetModified(true);
299 emit sigEncodingModeChanged();
300}
301#endif
302
303qreal CParameterRecord::GetVideoFrameRate() const
304{
305 return m_VideoFrameRate;
306}
307
308void CParameterRecord::SetVideoFrameRate(qreal newVideoFrameRate)
309{
310 if(m_VideoFrameRate == newVideoFrameRate)
311 return;
312 m_VideoFrameRate = newVideoFrameRate;
313 SetModified(true);
314 return;
315}
316
317int CParameterRecord::GetAudioSampleRate() const
318{
319 return m_AudioSampleRate;
320}
321
322void CParameterRecord::SetAudioSampleRate(int newAudioSampleRate)
323{
324 if(m_AudioSampleRate == newAudioSampleRate)
325 return;
326 m_AudioSampleRate = newAudioSampleRate;
327 SetModified(true);
328 return;
329}
330
331CParameterRecord& operator << (CParameterRecord& para, QMediaRecorder& recorder)
332{
333#if HAVE_QT6_MULTIMEDIA
334 para.SetVideoFrameRate(recorder.videoFrameRate());
335 para.SetAudioSampleRate(recorder.audioSampleRate());
336 QMediaFormat format;
337 format = recorder.mediaFormat();
338 para.SetAudioCodec(format.audioCodec());
339 para.SetVideoCodec(format.videoCodec());
340 para.SetFileFormat(format.fileFormat());
341 para.SetQuality(recorder.quality());
342 para.SetEncodingMode(recorder.encodingMode());
343#endif
344 para.SetFile(recorder.outputLocation().toString());
345 return para;
346}
347
348CParameterRecord& operator >> (CParameterRecord& para, QMediaRecorder& recorder)
349{
350#if HAVE_QT6_MULTIMEDIA
351 recorder.setVideoFrameRate(para.GetVideoFrameRate());
352 recorder.setAudioSampleRate(para.GetAudioSampleRate());
353 QMediaFormat format;
354 format.setAudioCodec(para.GetAudioCodec());
355 format.setVideoCodec(para.GetVideoCodec());
356 format.setFileFormat(para.GetFileFormat());
357 recorder.setMediaFormat(format);
358 recorder.setEncodingMode(para.GetEncodingMode());
359 recorder.setQuality(para.GetQuality());
360#endif
361
362 if(!para.GetFile(true).isEmpty())
363 recorder.setOutputLocation(QUrl::fromLocalFile(para.GetFile(true)));
364 return para;
365}
const QString GetFile(bool bAuto=false)
Parameter interface.
Definition Parameter.h:169
int SetModified(bool bModified=true)
When setting parameters, if there is a modification, it is called.