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^776(Vh#od1_m|;1_qAe RjQnziw1VQzb2whG0RZhgPTT+h delta 270 zcmdll-y%OjL~{ZI>$VsM2CmHvY~M^77`SgSu-k+(Fz_%l$ZWP?VBk5*U?#eVfq~t8 zqOG{44nvQoGXn$TCq~Oh=NK5c#To7892gi_G#LYqPG?|XY+&5gGKqnKy^NXrsvH9Y zFB|h=t_2JXye<=a)fo*YZdG@TU|-X_gMoqT4*N5$M+^+?``EvG#xXE(&*89fRAyjc z{>%|)bee&I;ReS)W*G(smW7-SMyU)8?7uh@FR(B$u>G4X%c$-c!F^)C8v_GdCy!HH z2m=G_XP!FqD+~-g?L4p79A#i&KFss}Xcq$m$9Xfile 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;SV7CcnVBomHAhX$mfq}D(!Ax`!0|V=t ziMHaFe;Il-of#MyOBgL5onv6&P-3)~b6{X#)@KYjI-P-mQHpU_%OnN{*4xb7SLGNO zI9D?t=32nOzorFi7?|$!yg%B- zz`%BaPujADfq`un-|EXE3=CYX{0fiPF)*;G^Jiu~W?*3To7~E%!sxJh6=M*qELWOc jr4>UOLjglE2Ll5G0~-Sa14nU2ez`(gLGk7{Y!_JoT1iRp delta 243 zcmew)zE^yLh~@+a)@?Bi4D1UT*uI%EFmSXmu-k+(FmSA9klAd(z`*IrU?#eVfq}Jt zqOG{)1%@6?X9fnw5=P5M=NK5+zcSj(IWRCV>oW!%ozB3(D8;y|WfB7e>pEuct8xqs zoOR5HxfU=maITrytIlXOajTjX$2ayhy*n5f*pIP4(|W|f!1{#!yJs8&14qQfukxHi zoQW4$7#LXnCd)FaJF0P?*zd-`!19^LDK3P8fu)zH&io1k1E(y{>orFi7?|$!yg%B- xz`(YcPujADfq^ZTZ}nvn1_sU>{0fiPF)*;GPwr(@VHDoHi7|+EvmyII769AkK==Rv diff --git a/QtScrcpy/res/i18n/QtScrcpy_zh.ts b/QtScrcpy/res/i18n/QtScrcpy_zh.ts index 40d4e3a..bb0223f 100644 --- a/QtScrcpy/res/i18n/QtScrcpy_zh.ts +++ b/QtScrcpy/res/i18n/QtScrcpy_zh.ts @@ -16,22 +16,22 @@ 文件传输失败 - + 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 文件不存在