From 74f7c27c992de479b9231cdbd6a6c5b5ac55c045 Mon Sep 17 00:00:00 2001 From: rankun Date: Sun, 19 Apr 2020 19:59:08 +0800 Subject: [PATCH] feat: show fps --- QtScrcpy/device/decoder/fpscounter.cpp | 1 + QtScrcpy/device/decoder/fpscounter.h | 3 ++ QtScrcpy/device/decoder/videobuffer.cpp | 5 ++ QtScrcpy/device/decoder/videobuffer.h | 2 + QtScrcpy/device/device.cpp | 1 + QtScrcpy/device/ui/videoform.cpp | 28 ++++++++++ QtScrcpy/device/ui/videoform.h | 4 ++ QtScrcpy/devicemanage/devicemanage.cpp | 15 ++++++ QtScrcpy/devicemanage/devicemanage.h | 1 + QtScrcpy/dialog.cpp | 1 + QtScrcpy/dialog.ui | 49 ++++++++++-------- QtScrcpy/res/i18n/QtScrcpy_en.qm | Bin 3972 -> 4031 bytes QtScrcpy/res/i18n/QtScrcpy_en.ts | 65 +++++++++++++----------- QtScrcpy/res/i18n/QtScrcpy_zh.qm | Bin 3005 -> 3058 bytes QtScrcpy/res/i18n/QtScrcpy_zh.ts | 65 +++++++++++++----------- 15 files changed, 159 insertions(+), 81 deletions(-) diff --git a/QtScrcpy/device/decoder/fpscounter.cpp b/QtScrcpy/device/decoder/fpscounter.cpp index 0bb099f..e59bb40 100644 --- a/QtScrcpy/device/decoder/fpscounter.cpp +++ b/QtScrcpy/device/decoder/fpscounter.cpp @@ -40,6 +40,7 @@ void FpsCounter::timerEvent(QTimerEvent *event) m_curRendered = m_rendered; m_curSkipped = m_skipped; resetCounter(); + emit updateFPS(m_curRendered); //qInfo("FPS:%d Discard:%d", m_curRendered, m_skipped); } } diff --git a/QtScrcpy/device/decoder/fpscounter.h b/QtScrcpy/device/decoder/fpscounter.h index badb958..50a8d7a 100644 --- a/QtScrcpy/device/decoder/fpscounter.h +++ b/QtScrcpy/device/decoder/fpscounter.h @@ -15,6 +15,9 @@ public: void addRenderedFrame(); void addSkippedFrame(); +signals: + void updateFPS(quint32 fps); + protected: virtual void timerEvent(QTimerEvent *event); diff --git a/QtScrcpy/device/decoder/videobuffer.cpp b/QtScrcpy/device/decoder/videobuffer.cpp index 6ddecbd..f41e922 100644 --- a/QtScrcpy/device/decoder/videobuffer.cpp +++ b/QtScrcpy/device/decoder/videobuffer.cpp @@ -115,6 +115,11 @@ void VideoBuffer::interrupt() } } +FpsCounter *VideoBuffer::getFPSCounter() +{ + return &m_fpsCounter; +} + void VideoBuffer::swap() { AVFrame *tmp = m_decodingFrame; diff --git a/QtScrcpy/device/decoder/videobuffer.h b/QtScrcpy/device/decoder/videobuffer.h index fad772a..908cbc6 100644 --- a/QtScrcpy/device/decoder/videobuffer.h +++ b/QtScrcpy/device/decoder/videobuffer.h @@ -37,6 +37,8 @@ public: // wake up and avoid any blocking call void interrupt(); + FpsCounter *getFPSCounter(); + private: void swap(); diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index fe87af9..6f4609b 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -277,6 +277,7 @@ void Device::initSignals() m_vb->unLock(); }, Qt::QueuedConnection); + connect(m_vb->getFPSCounter(), &::FpsCounter::updateFPS, m_videoForm, &VideoForm::updateFPS); } } diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index c6b9428..5f41be0 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -68,6 +69,16 @@ void VideoForm::initUI() ui->keepRadioWidget->setWidget(m_videoWidget); ui->keepRadioWidget->setWidthHeightRadio(m_widthHeightRatio); + m_fpsLabel = new QLabel(m_videoWidget); + QFont ft; + ft.setPointSize(15); + ft.setWeight(QFont::Light); + ft.setBold(true); + m_fpsLabel->setFont(ft); + m_fpsLabel->move(5, 15); + m_fpsLabel->setMinimumWidth(100); + m_fpsLabel->setStyleSheet(R"(QLabel {color: #00FF00;})"); + setMouseTracking(true); m_videoWidget->setMouseTracking(true); ui->keepRadioWidget->setMouseTracking(true); @@ -115,6 +126,14 @@ void VideoForm::removeBlackRect() resize(ui->keepRadioWidget->goodSize()); } +void VideoForm::showFPS(bool show) +{ + if (!m_fpsLabel) { + return; + } + m_fpsLabel->setVisible(show); +} + void VideoForm::updateRender(const AVFrame *frame) { if (m_videoWidget->isHidden()) { @@ -429,6 +448,15 @@ void VideoForm::onSwitchFullScreen() } } +void VideoForm::updateFPS(quint32 fps) +{ + qDebug() << "FPS:" << fps; + if (!m_fpsLabel) { + return; + } + m_fpsLabel->setText(QString("FPS:%1").arg(fps)); +} + void VideoForm::staysOnTop(bool top) { bool needShow = false; diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index e000f5a..bda37a4 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -14,6 +14,7 @@ class ToolForm; class Device; class FileHandler; class QYUVOpenGLWidget; +class QLabel; class VideoForm : public QWidget { Q_OBJECT @@ -29,9 +30,11 @@ public: const QSize &frameSize(); void resizeSquare(); void removeBlackRect(); + void showFPS(bool show); public slots: void onSwitchFullScreen(); + void updateFPS(quint32 fps); private: void updateStyleSheet(bool vertical); @@ -68,6 +71,7 @@ private: QPointer m_toolForm; QPointer m_loadingWidget; QPointer m_videoWidget; + QPointer m_fpsLabel; //inside member QSize m_frameSize; diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index 9d6e113..6bcfcaa 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -76,6 +76,21 @@ bool DeviceManage::staysOnTop(const QString &serial) return true; } +void DeviceManage::showFPS(const QString &serial, bool show) +{ + if (!serial.isEmpty() && m_devices.contains(serial)) { + auto it = m_devices.find(serial); + if (!it->data()) { + return; + } + if (!it->data()->getVideoForm()) { + return; + } + it->data()->getVideoForm()->showFPS(show); + } + return; +} + bool DeviceManage::disconnectDevice(const QString &serial) { bool ret = false; diff --git a/QtScrcpy/devicemanage/devicemanage.h b/QtScrcpy/devicemanage/devicemanage.h index 1d0250a..968a6e0 100644 --- a/QtScrcpy/devicemanage/devicemanage.h +++ b/QtScrcpy/devicemanage/devicemanage.h @@ -16,6 +16,7 @@ public: bool connectDevice(Device::DeviceParams params); void updateScript(QString script); bool staysOnTop(const QString &serial); + void showFPS(const QString &serial, bool show); bool disconnectDevice(const QString &serial); void disconnectAllDevice(); diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 722da32..38fa4d8 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -188,6 +188,7 @@ void Dialog::on_startServerBtn_clicked() if (ui->alwaysTopCheck->isChecked()) { m_deviceManage.staysOnTop(params.serial); } + m_deviceManage.showFPS(params.serial, ui->fpsCheck->isChecked()); } void Dialog::on_stopServerBtn_clicked() diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index 9060e15..05c7eef 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -208,10 +208,23 @@ 0 - - + + + + + 0 + 0 + + - record screen + screen-off + + + + + + + frameless @@ -231,8 +244,8 @@ - - + + 0 @@ -240,7 +253,10 @@ - screen-off + background record + + + false @@ -260,26 +276,17 @@ - - - - - 0 - 0 - - + + - background record - - - false + record screen - - + + - frameless + show fps diff --git a/QtScrcpy/res/i18n/QtScrcpy_en.qm b/QtScrcpy/res/i18n/QtScrcpy_en.qm index 2db842e26fbe3585be6bd2be25877451178a96bf..62f5dce1ad3e9dfea8e1591940c906de5a7ae323 100644 GIT binary patch delta 314 zcmZpX-!DHwL~{lM>$VsM2CioeY~M^77AiUW(y$wgTYL65d#Bz)0p$~z`&u)nRtN(sNQh0ETg(-H}{GCZVU`;ojgu)Aq)(xpLy!cuK*pp zi|6&4qd-#*^SnRW#lXPH#3yap0@S^ZZ}nvnpgY#{D?DBYRG-P8ne`Z`|KH?RMr9^G yw#};;nb?&D7>XG(81fm)859`O7z!AQIe-pfU;|=~;*9)qg|vd=&2u$VsM2CmHvY~M^77`SgSu-k+(Fz_%l$ZWO%(nlH0L>DnIu$xb` z6}Qx3=+Sg$U|{^jX!+x;yO8v>pLf?qmP%83#0J4u_4SG6MtiXO1|d(+ms@ zH#q(=%K%MY$mw8|3RL%tGw}io0|VQ?$+C<=iZ{Ebn#J>4C H#|<_BD0)X0 diff --git a/QtScrcpy/res/i18n/QtScrcpy_en.ts b/QtScrcpy/res/i18n/QtScrcpy_en.ts index 8321b51..4b9df55 100644 --- a/QtScrcpy/res/i18n/QtScrcpy_en.ts +++ b/QtScrcpy/res/i18n/QtScrcpy_en.ts @@ -16,22 +16,22 @@ file transfer failed - + install apk install apk - + file transfer file transfer - + wait current %1 to complete wait current %1 to complete - + %1 complete, save in %2 %1 complete, save in %2 @@ -41,7 +41,7 @@ %1 complete\n save in %2 - + %1 failed %1 failed @@ -49,17 +49,17 @@ Dialog - + Wireless Wireless - + wireless connect wireless connect - + wireless disconnect wireless disconnect @@ -75,7 +75,7 @@ - + select path select path @@ -85,42 +85,47 @@ record format: - + record screen record screen - + frameless frameless - + + show fps + show fps + + + stop all server stop all server - + adb command: adb command: - + terminate terminate - + execute execute - + clear clear - + reverse connection reverse connection @@ -129,12 +134,12 @@ auto enable - + background record background record - + screen-off screen-off @@ -149,7 +154,7 @@ max size: - + always on top always on top @@ -159,27 +164,27 @@ refresh script - + get device IP get device IP - + USB line USB line - + stop server stop server - + start server start server - + device serial: device serial: @@ -193,17 +198,17 @@ bit rate: - + start adbd start adbd - + refresh devices refresh devices - + original original @@ -221,7 +226,7 @@ You can download it at the following address: This software is completely open source and free.\nStrictly used for illegal purposes, or at your own risk.\nYou can download it at the following address: - + This software is completely open source and free. Strictly used for illegal purposes, or at your own risk. You can download it at the following address: This software is completely open source and free. Strictly used for illegal purposes, or at your own risk. You can download it at the following address: @@ -317,7 +322,7 @@ You can download it at the following address: file transfer failed - + file does not exist file does not exist diff --git a/QtScrcpy/res/i18n/QtScrcpy_zh.qm b/QtScrcpy/res/i18n/QtScrcpy_zh.qm index e5ce84d69fdb21116b120015309c7c6b888d702f..2a6e5c8bb6f8a3d0edf945302a25bbc51d5c51a6 100644 GIT binary patch delta 281 zcmdlh{z-g-h~^9i)@?Bi4D9C^*uI%EFmP;SV7Cbc(l;1nHd`<-aF#Kci7sMbU|loO zR^0M0Lyx920|R3TqvfM>Kt)Q7_Hqsk49xnB0Y|3;#ibZ`wM+skzRk>iRSu|mHS=Mv z1wi`d#9npA^od*5q&St?*YxfH+V`3Lnbso)1~x(V@1Ai$qgp3^mFKkQOuWDX)L%VW zmQmd^nES+jHwFfl&pb|XAwas9r_THe&@?Ze*K3Y4FfiTcd4IGEXv76RY0DNMJ&SMk zWf2AjE>?bp$LoOV)%i2C9s^DDo7~E%!sxJh6=M*qELWOcr4>UOLjglE2LlkW0Wn8$ QMt-?MT0!yVH*6PK09r{&@Bjb+ delta 243 zcmew)zE^yLh~@+a)@?Bi4D1UT*uI%EFmSXmu-k+J>D3G}n=Kd^I6WE6L>DnIu+~qs z6}P;=(4*文件传输失败 - + install apk 安装apk - + file transfer 文件传输 - + wait current %1 to complete 等待当前%1完成 - + %1 complete, save in %2 %1完成,保存在%2 @@ -41,7 +41,7 @@ %1完成\n 保存在 %2 - + %1 failed %1 失败 @@ -49,17 +49,17 @@ Dialog - + Wireless 无线 - + wireless connect 无线连接 - + wireless disconnect 无线断开 @@ -75,7 +75,7 @@ - + select path 选择路径 @@ -85,42 +85,47 @@ 录制格式: - + record screen 录制屏幕 - + frameless 无边框 - + + show fps + 显示fps + + + stop all server 停止所有服务 - + adb command: adb命令: - + terminate 终止 - + execute 执行 - + clear 清理 - + reverse connection 反向连接 @@ -129,12 +134,12 @@ 自动启用脚本 - + background record 后台录制 - + screen-off 自动息屏 @@ -149,7 +154,7 @@ 最大尺寸: - + always on top 窗口置顶 @@ -159,27 +164,27 @@ 刷新脚本 - + get device IP 获取设备IP - + USB line USB线 - + stop server 停止服务 - + start server 启动服务 - + device serial: 设备序列号: @@ -193,17 +198,17 @@ 比特率: - + start adbd 启动adbd - + refresh devices 刷新设备列表 - + original 原始 @@ -221,7 +226,7 @@ You can download it at the following address: 本软件完全开源免费.\n严禁用于非法用途,否则后果自负.\n你可以在下面地址下载: - + This software is completely open source and free. Strictly used for illegal purposes, or at your own risk. You can download it at the following address: 本软件完全开源免费,严禁用于非法用途,否则后果自负,你可以在下面地址下载: @@ -317,7 +322,7 @@ You can download it at the following address: 文件传输失败 - + file does not exist 文件不存在