@@ -9,13 +9,13 @@ static Q_LOGGING_CATEGORY(log, "WebBrowser.Record")
99
1010CMultimediaRecord::CMultimediaRecord(CParameterWebBrowser *pPara, QObject *parent)
1111 : QObject{parent}
12- , m_pParaRecord(nullptr )
1312 , m_pMediaDevices(nullptr )
1413 , m_VideoFrameStartTime(0 )
1514{
1615 bool check = false ;
16+ qDebug (log) << Q_FUNC_INFO;
1717 if (pPara) {
18- m_pParaRecord = & pPara->m_Record ;
18+ m_ParaRecord = pPara->m_Record ;
1919 m_pMediaDevices = &pPara->m_MediaDevices ;
2020 }
2121#if HAVE_QT6_RECORD
@@ -28,35 +28,46 @@ CMultimediaRecord::CMultimediaRecord(CParameterWebBrowser *pPara, QObject *paren
2828#endif // #if HAVE_QT6_RECORD
2929}
3030
31+ CMultimediaRecord::~CMultimediaRecord ()
32+ {
33+ qDebug (log) << Q_FUNC_INFO;
34+ }
35+
3136void CMultimediaRecord::slotStart ()
3237{
33- // 配置音频输入(捕获系统音频或麦克风)
38+ #ifdef HAVE_QT6_RECORD
39+ // 配置音频输入(捕获系统音频输入或麦克风)
3440 if (m_pMediaDevices) {
3541 const auto inputs = QMediaDevices::audioInputs ();
3642 foreach (auto input, inputs) {
3743 if (input.id () == m_pMediaDevices->m_Para .m_AudioInput ) {
3844 m_AudioInput.setDevice (input);
45+ m_CaptureSession.setAudioInput (&m_AudioInput);
3946 break ;
4047 }
4148 }
4249 }
43- m_CaptureSession.setAudioInput (&m_AudioInput);
4450 m_CaptureSession.setVideoFrameInput (&m_VideoFrameInput);
4551 // 配置录制器, 设置录制参数:输出文件、编码、质量等
46- if (m_pParaRecord)
47- *m_pParaRecord >> m_Recorder;
52+ m_ParaRecord >> m_Recorder;
4853 m_CaptureSession.setRecorder (&m_Recorder);
4954 m_VideoFrameStartTime = 0 ;
5055 m_Recorder.record ();
56+ #endif
5157}
5258
5359void CMultimediaRecord::slotStop ()
5460{
61+ #ifdef HAVE_QT6_RECORD
5562 m_Recorder.stop ();
63+ #endif
64+ m_pMediaDevices = nullptr ;
5665}
5766
5867void CMultimediaRecord::slotUpdateVideoFrame (const QImage image)
5968{
69+ // qDebug(log) << Q_FUNC_INFO;
70+ #ifdef HAVE_QT6_RECORD
6071 // 将 QImage 转换为 QVideoFrame
6172 QImage img = image;
6273 // qDebug(log) << "Image format:" << img.format();
@@ -74,12 +85,13 @@ void CMultimediaRecord::slotUpdateVideoFrame(const QImage image)
7485 if (m_VideoFrameStartTime == 0 ) m_VideoFrameStartTime = QDateTime::currentMSecsSinceEpoch () * 1000 ;
7586 qint64 currentTime = QDateTime::currentMSecsSinceEpoch () * 1000 - m_VideoFrameStartTime;
7687 frame.setStartTime (currentTime);
77- qreal rate = m_pParaRecord-> GetVideoFrameRate ();
88+ qreal rate = m_ParaRecord. GetVideoFrameRate ();
7889 if (rate <= 0 )
7990 rate = 24 ;
8091 frame.setEndTime (currentTime + qreal (1000000 ) / rate);
81- frame.setStreamFrameRate (m_pParaRecord-> GetVideoFrameRate ());// */
92+ frame.setStreamFrameRate (m_ParaRecord. GetVideoFrameRate ());// */
8293 m_VideoFrameInput.sendVideoFrame (frame);
94+ #endif
8395}
8496
8597#if HAVE_QT6_RECORD
@@ -89,7 +101,7 @@ void CMultimediaRecord::slotRecordStateChanged(QMediaRecorder::RecorderState sta
89101 switch (state) {
90102 case QMediaRecorder::RecorderState::StoppedState: {
91103 QString szFile = m_Recorder.actualLocation ().toLocalFile ();
92- switch (m_pParaRecord-> GetEndAction ())
104+ switch (m_ParaRecord. GetEndAction ())
93105 {
94106 case CParameterRecord::ENDACTION::OpenFile: {
95107 bool bRet = QDesktopServices::openUrl (QUrl::fromLocalFile (szFile));
@@ -125,30 +137,45 @@ void CMultimediaRecord::slotRecordError(QMediaRecorder::Error error, const QStri
125137}
126138#endif // HAVE_QT6_RECORD
127139
128- CMultimediaRecordThread::CMultimediaRecordThread (CParameterWebBrowser* pPara, QObject *parent)
140+ CMultimediaRecordThread::CMultimediaRecordThread (
141+ CParameterWebBrowser* pPara, QObject *parent)
129142 : QThread(parent)
130143 , m_pPara(pPara)
131144 , m_pRecord(nullptr )
132- {}
145+ {
146+ qDebug (log) << Q_FUNC_INFO;
147+ connect (this , &QThread::finished, this , &QObject::deleteLater);
148+ }
149+
150+ CMultimediaRecordThread::~CMultimediaRecordThread ()
151+ {
152+ qDebug (log) << Q_FUNC_INFO;
153+ }
133154
134155void CMultimediaRecordThread::run ()
135156{
136157 m_pRecord = new CMultimediaRecord (m_pPara);
137158 if (!m_pRecord) return ;
138159 connect (m_pRecord, &CMultimediaRecord::sigFinished,
139- this , &CMultimediaRecordThread ::quit);
160+ this , &QThread ::quit);
140161 m_pRecord->slotStart ();
141162 exec ();
142- m_pRecord->slotStop ();
143- exec ();
144163 delete m_pRecord;
164+ m_pRecord = nullptr ;
145165}
146166
147167void CMultimediaRecordThread::slotUpdateVideoFrame (const QImage image)
148168{
149169 if (!m_pRecord) return ;
170+ m_pRecord->slotUpdateVideoFrame (image);
171+ }
172+
173+ void CMultimediaRecordThread::slotQuit ()
174+ {
175+ if (!m_pRecord) return ;
176+ m_pRecord->slotStop ();
177+ /*
150178 QMetaObject::invokeMethod(m_pRecord,
151- " slotUpdateVideoFrame" ,
152- Qt::AutoConnection,
153- Q_ARG (QImage, image));
179+ "slotStop",
180+ Qt::AutoConnection);*/
154181}
0 commit comments