|
|
@@ -31,13 +31,13 @@ AvRecorder::AvRecorder(QWidget* parent)
|
|
|
m_captureComboBox = new QComboBox;
|
|
|
m_updateListBtn = new QPushButton("刷新窗口列表");
|
|
|
QGroupBox* captureGroup = new QGroupBox("捕获源");
|
|
|
- QVBoxLayout* captureLayout = new QVBoxLayout;
|
|
|
QHBoxLayout* captureRow = new QHBoxLayout;
|
|
|
captureRow->addWidget(m_captureComboBox);
|
|
|
captureRow->addWidget(m_updateListBtn);
|
|
|
- captureLayout->addLayout(captureRow);
|
|
|
- captureGroup->setLayout(captureLayout);
|
|
|
- captureGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
+ captureGroup->setLayout(captureRow);
|
|
|
+
|
|
|
+ // m_captureComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
+ m_captureComboBox->setMinimumWidth(20);
|
|
|
|
|
|
// 4. 音频区分组
|
|
|
QGroupBox* audioGroup = new QGroupBox("音频");
|
|
|
@@ -45,7 +45,7 @@ AvRecorder::AvRecorder(QWidget* parent)
|
|
|
audioLayout->addWidget(m_microphoneWidget);
|
|
|
audioLayout->addWidget(m_speakerWidget);
|
|
|
audioGroup->setLayout(audioLayout);
|
|
|
- audioGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
+ //audioGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
|
|
|
// 5. 操作区
|
|
|
m_isDrawCursorBox = new QCheckBox("绘制鼠标指针");
|
|
|
@@ -69,7 +69,7 @@ AvRecorder::AvRecorder(QWidget* parent)
|
|
|
actionLayout->addWidget(m_recordBtn);
|
|
|
actionLayout->addWidget(m_liveBtn);
|
|
|
actionGroup->setLayout(actionLayout);
|
|
|
- actionGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
+ //actionGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
|
|
|
|
// 6. 设置区
|
|
|
QHBoxLayout* utilLayout = new QHBoxLayout;
|
|
|
@@ -96,7 +96,7 @@ AvRecorder::AvRecorder(QWidget* parent)
|
|
|
initStatusBarUi();
|
|
|
|
|
|
// 让视频区尽量大
|
|
|
- m_glWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
+ // m_glWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
|
// 11. 总体布局
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|
|
@@ -316,29 +316,45 @@ void AvRecorder::stopCapture()
|
|
|
m_videoRecorder.Close();
|
|
|
m_audioRecorder.Close();
|
|
|
}
|
|
|
-
|
|
|
+void AvRecorder::renderFrame()
|
|
|
+{
|
|
|
+ auto frame = m_videoRecorder.GetRenderFrame();
|
|
|
+ m_glWidget->Render(frame);
|
|
|
+}
|
|
|
void AvRecorder::startPreview()
|
|
|
{
|
|
|
m_glWidget->Open(m_settingsParam.videoParam.width, m_settingsParam.videoParam.height);
|
|
|
|
|
|
// 视频需要做到和帧率一样的渲染速度,QTimer 达不到要求
|
|
|
// 需要自己封装一个计时器
|
|
|
- m_videoRenderTimer.Start(m_settingsParam.videoParam.fps, [this] {
|
|
|
- if (windowState() == Qt::WindowMinimized) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 视频
|
|
|
- auto frame = m_videoRecorder.GetRenderFrame();
|
|
|
- m_glWidget->Render(frame);
|
|
|
- });
|
|
|
-
|
|
|
+ // m_videoRenderTimer.Start(m_settingsParam.videoParam.fps, [this] {
|
|
|
+ // if (windowState() == Qt::WindowMinimized) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // QMetaObject::invokeMethod(this, "renderFrame", Qt::QueuedConnection);
|
|
|
+ // // // 视频
|
|
|
+ // // auto frame = m_videoRecorder.GetRenderFrame();
|
|
|
+ // // m_glWidget->Render(frame);
|
|
|
+ // });
|
|
|
+
|
|
|
+ if (!m_videoRenderTimer) {
|
|
|
+ m_videoRenderTimer = new QTimer(this);
|
|
|
+ connect(m_videoRenderTimer, &QTimer::timeout, this, [this] {
|
|
|
+ if (windowState() == Qt::WindowMinimized)
|
|
|
+ return;
|
|
|
+ renderFrame();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ m_videoRenderTimer->start(1000 / m_settingsParam.videoParam.fps);
|
|
|
// 刷新率设置为 25
|
|
|
m_otherTimer.start(40);
|
|
|
}
|
|
|
|
|
|
void AvRecorder::stopPreview()
|
|
|
{
|
|
|
- m_videoRenderTimer.Stop();
|
|
|
+ if (m_videoRenderTimer) {
|
|
|
+ m_videoRenderTimer->stop();
|
|
|
+ }
|
|
|
m_otherTimer.stop();
|
|
|
}
|
|
|
|