5#include <QStandardPaths>
7#include "ParameterRecord.h"
8#include "RabbitCommonDir.h"
10CParameterRecord::CParameterRecord(QObject *parent,
const QString &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)
24 , m_AudioSampleRate(-1)
25 , m_AudioChannelCount(1)
26 , m_EndAction(ENDACTION::OpenFile)
28#if HAVE_QT6_MULTIMEDIA
29 QMediaRecorder recorder;
30 m_VideoResolution = recorder.videoResolution();
31 m_VideoBitRate = recorder.videoBitRate();
32 m_AudioBitRate = recorder.audioBitRate();
33 m_AudioChannelCount = recorder.audioChannelCount();
36 m_szVideoPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
38 if(m_szVideoPath.isEmpty() || !d.exists(m_szVideoPath))
39 m_szVideoPath = RabbitCommon::CDir::Instance()->GetDirUserImage();
40 m_szVideoPath += QDir::separator() + QString(
"RabbitRemoteControl")
41 + QDir::separator() + QString(
"Record");
43 if(!d.exists(m_szVideoPath))
44 d.mkpath(m_szVideoPath);
46 m_szImagePath = QStandardPaths::writableLocation(
47 QStandardPaths::PicturesLocation);
48 if(m_szImagePath.isEmpty() || !d.exists(m_szImagePath))
49 m_szImagePath = RabbitCommon::CDir::Instance()->GetDirUserImage();
50 m_szImagePath += QDir::separator() + QString(
"RabbitRemoteControl")
51 + QDir::separator() + QString(
"ScreenShot");
52 if(!d.exists(m_szImagePath))
53 d.mkpath(m_szImagePath);
60 m_bEnableVideo = in.m_bEnableVideo;
61 m_bEnableAudio = in.m_bEnableAudio;
62 m_szVideoFile = in.m_szVideoFile;
63 m_szImageFile = in.m_szImageFile;
64 m_szVideoPath = in.m_szVideoPath;
65 m_szImagePath = in.m_szImagePath;
67#if HAVE_QT6_MULTIMEDIA
68 m_FileFormat = in.m_FileFormat;
69 m_VideoCodec = in.m_VideoCodec;
70 m_AudioCodec = in.m_AudioCodec;
71 m_Quality = in.m_Quality;
72 m_EncodingMode = in.m_EncodingMode;
75 m_VideoResolution = in.m_VideoResolution;
76 m_VideoBitRate = in.m_VideoBitRate;
77 m_VideoFrameRate = in.m_VideoFrameRate;
78 m_AudioBitRate = in.m_AudioBitRate;
79 m_AudioSampleRate = in.m_AudioSampleRate;
80 m_AudioChannelCount = in.m_AudioChannelCount;
82 m_EndAction = in.m_EndAction;
87bool CParameterRecord::GetEnableVideo()
const
89 return m_bEnableVideo;
92void CParameterRecord::SetEnableVideo(
bool newEnableVideo)
94 if (m_bEnableVideo == newEnableVideo)
96 m_bEnableVideo = newEnableVideo;
98 emit sigEnableVideoChanged();
101bool CParameterRecord::GetEnableAudio()
const
103 return m_bEnableAudio;
106void CParameterRecord::SetEnableAudio(
bool newEnableAudio)
108 if (m_bEnableAudio == newEnableAudio)
110 m_bEnableAudio = newEnableAudio;
112 emit sigEnableAudioChanged();
115CParameterRecord::ENDACTION CParameterRecord::GetEndAction()
const
120void CParameterRecord::SetEndAction(ENDACTION newEndAction)
122 if (m_EndAction == newEndAction)
124 m_EndAction = newEndAction;
126 emit sigEndActionChanged();
129QString CParameterRecord::GetImagePath()
const
131 return m_szImagePath;
134void CParameterRecord::SetImagePath(
const QString &newImagePath)
136 if (m_szImagePath == newImagePath)
138 m_szImagePath = newImagePath;
140 QDir d(m_szImagePath);
142 d.mkpath(m_szImagePath);
143 emit ImagePathChanged();
146int CParameterRecord::OnLoad(QSettings &set)
148 set.beginGroup(
"Record");
150 SetEnableVideo(set.value(
"EnableVideo", GetEnableVideo()).toBool());
151 SetEnableAudio(set.value(
"EnableAudio", GetEnableAudio()).toBool());
152 SetVideoPath(set.value(
"Path/Video", GetVideoPath()).toString());
153 SetImagePath(set.value(
"Path/Image", GetImagePath()).toString());
154#if HAVE_QT6_MULTIMEDIA
155 SetFileFormat((QMediaFormat::FileFormat)
156 set.value(
"FileFormat", (
int)GetFileFormat()).toInt());
157 SetVideoCodec((QMediaFormat::VideoCodec)
158 set.value(
"Video/Codec", (
int)GetVideoCodec()).toInt());
159 SetAudioCodec((QMediaFormat::AudioCodec)
160 set.value(
"Audio/Codec", (
int)GetAudioCodec()).toInt());
161 SetQuality((QMediaRecorder::Quality)
162 set.value(
"Quality", GetQuality()).toInt());
163 SetEncodingMode((QMediaRecorder::EncodingMode)
164 set.value(
"EncodingMode", GetEncodingMode()).toInt());
166 SetAudioSampleRate(set.value(
"Audio/SampleRate", GetAudioSampleRate()).toInt());
167 SetVideoFrameRate(set.value(
"Video/FrameRate", GetVideoFrameRate()).toInt());
168 SetEndAction((ENDACTION)set.value(
"EndAction", GetEndAction()).toInt());
173int CParameterRecord::OnSave(QSettings &set)
175 set.beginGroup(
"Record");
177 set.setValue(
"EnableVideo", GetEnableVideo());
178 set.setValue(
"EnableAudio", GetEnableAudio());
179 set.setValue(
"Path/Video", GetVideoPath());
180 set.setValue(
"Path/Image", GetImagePath());
181#if HAVE_QT6_MULTIMEDIA
182 set.setValue(
"FileFormat", (
int)GetFileFormat());
183 set.setValue(
"Video/Codec", (
int)GetVideoCodec());
184 set.setValue(
"Audio/Codec", (
int)GetAudioCodec());
185 set.setValue(
"Quality", (
int)GetQuality());
186 set.setValue(
"EncodingMode", GetEncodingMode());
188 set.setValue(
"Audio/SampleRate", GetAudioSampleRate());
189 set.setValue(
"Video/FrameRate", GetVideoFrameRate());
190 set.setValue(
"EndAction", (
int)GetEndAction());
198 m_szVideoFile = GetVideoPath() + QDir::separator()
199 + QDateTime::currentDateTime().toLocalTime()
200 .toString(
"yyyy_MM_dd_hh_mm_ss_zzz");
202 return m_szVideoFile;
205int CParameterRecord::SetVideoFile(
const QString &szFile)
207 if(m_szVideoFile == szFile)
210 m_szVideoFile = szFile;
214QString CParameterRecord::GetImageFile(
bool bAuto)
216 QString szPath = GetImagePath();
218 m_szImageFile = szPath
220 + QDateTime::currentDateTime().toLocalTime()
221 .toString(
"yyyy_MM_dd_hh_mm_ss_zzz") +
".png";
223 return m_szImageFile;
226void CParameterRecord::SetImageFile(
const QString &newImageFile)
228 if (m_szImageFile == newImageFile)
230 m_szImageFile = newImageFile;
232 emit sigImageFileChanged();
235const QString CParameterRecord::GetVideoPath()
const
237 return m_szVideoPath;
240int CParameterRecord::SetVideoPath(
const QString &szPath)
242 if(m_szVideoPath == szPath)
244 m_szVideoPath = szPath;
246 QDir d(m_szVideoPath);
248 d.mkpath(m_szVideoPath);
252#if HAVE_QT6_MULTIMEDIA
253const QMediaFormat::FileFormat CParameterRecord::GetFileFormat()
const
258int CParameterRecord::SetFileFormat(
const QMediaFormat::FileFormat &f)
260 if(m_FileFormat == f)
267const QMediaFormat::VideoCodec CParameterRecord::GetVideoCodec()
const
272int CParameterRecord::SetVideoCodec(QMediaFormat::VideoCodec v)
274 if(m_VideoCodec == v)
281const QMediaFormat::AudioCodec CParameterRecord::GetAudioCodec()
const
286int CParameterRecord::SetAudioCodec(QMediaFormat::AudioCodec a)
288 if(m_AudioCodec == a)
295QMediaRecorder::Quality CParameterRecord::GetQuality()
const
300void CParameterRecord::SetQuality(
const QMediaRecorder::Quality &newQuality)
302 if (m_Quality == newQuality)
304 m_Quality = newQuality;
306 emit sigQualityChanged();
309QMediaRecorder::EncodingMode CParameterRecord::GetEncodingMode()
const
311 return m_EncodingMode;
314void CParameterRecord::SetEncodingMode(
const QMediaRecorder::EncodingMode &newEncodingMode)
316 if (m_EncodingMode == newEncodingMode)
318 m_EncodingMode = newEncodingMode;
320 emit sigEncodingModeChanged();
324QSize CParameterRecord::GetVideoResolution()
326 return m_VideoResolution;
329void CParameterRecord::SetVideoResolution(QSize size)
331 m_VideoResolution = size;
334int CParameterRecord::GetVideoBitRate()
const
336 return m_VideoBitRate;
339void CParameterRecord::SetVideoBitRate(
int bitRate)
341 m_VideoBitRate = bitRate;
344qreal CParameterRecord::GetVideoFrameRate()
const
346 return m_VideoFrameRate;
349void CParameterRecord::SetVideoFrameRate(qreal newVideoFrameRate)
351 if(m_VideoFrameRate == newVideoFrameRate)
353 m_VideoFrameRate = newVideoFrameRate;
358int CParameterRecord::GetAudioBitRate()
360 return m_AudioBitRate;
363void CParameterRecord::SetAudioBitRate(
int bitRate)
365 m_AudioBitRate = bitRate;
368int CParameterRecord::GetAudioSampleRate()
const
370 return m_AudioSampleRate;
373void CParameterRecord::SetAudioSampleRate(
int newAudioSampleRate)
375 if(m_AudioSampleRate == newAudioSampleRate)
377 m_AudioSampleRate = newAudioSampleRate;
382int CParameterRecord::GetAudioChannelCount()
384 return m_AudioChannelCount;
387void CParameterRecord::SetAudioChannelCount(
int count)
389 m_AudioChannelCount = count;
394#if HAVE_QT6_MULTIMEDIA
395 para.SetVideoResolution(recorder.videoResolution());
396 para.SetVideoBitRate(recorder.videoBitRate());
397 para.SetVideoFrameRate(recorder.videoFrameRate());
398 para.SetAudioBitRate(recorder.audioBitRate());
399 para.SetAudioSampleRate(recorder.audioSampleRate());
400 para.SetAudioChannelCount(recorder.audioChannelCount());
402 format = recorder.mediaFormat();
403 para.SetAudioCodec(format.audioCodec());
404 para.SetVideoCodec(format.videoCodec());
405 para.SetFileFormat(format.fileFormat());
406 para.SetQuality(recorder.quality());
407 para.SetEncodingMode(recorder.encodingMode());
409 para.SetVideoFile(recorder.outputLocation().toString());
415#if HAVE_QT6_MULTIMEDIA
416 recorder.setVideoResolution(para.GetVideoResolution());
417 recorder.setVideoBitRate(para.GetVideoBitRate());
418 recorder.setVideoFrameRate(para.GetVideoFrameRate());
419 recorder.setAudioBitRate(para.GetAudioBitRate());
420 recorder.setAudioSampleRate(para.GetAudioSampleRate());
421 recorder.setAudioChannelCount(para.GetAudioChannelCount());
423 format.setAudioCodec(para.GetAudioCodec());
424 format.setVideoCodec(para.GetVideoCodec());
425 format.setFileFormat(para.GetFileFormat());
426 recorder.setMediaFormat(format);
427 recorder.setQuality(para.GetQuality());
428 recorder.setEncodingMode(para.GetEncodingMode());
432 recorder.setOutputLocation(QUrl::fromLocalFile(para.
GetVideoFile(
true)));
const QString GetVideoFile(bool bAuto=false)
int SetModified(bool bModified=true)
在设置参数时,如果有修改,则调用。