Skip to content

Commit

Permalink
Modify the input method of bitrate. Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXfkSIE committed Jun 28, 2021
1 parent e23c566 commit 049ba21
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 95 deletions.
12 changes: 1 addition & 11 deletions QtScrcpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,17 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ***********************************************************
# Qt Package finding
# ***********************************************************

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Network LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Network LinguistTools REQUIRED)

# ***********************************************************
# Cross-platform settings
# ***********************************************************

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

if(MSVC)
# FFmpeg cannot be compiled natively by MSVC version < 12.0 (2013)
if(MSVC_VERSION LESS 1800)
message(FATAL_ERROR "[QtScrcpy] FATAL ERROR: MSVC version is older than 12.0 (2013).")
endif()

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")

endif()


Expand Down
4 changes: 2 additions & 2 deletions QtScrcpy/device/device.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef DEVICE_H
#ifndef DEVICE_H
#define DEVICE_H

#include <QElapsedTimer>
Expand Down Expand Up @@ -30,7 +30,7 @@ class Device : public QObject
QString serial = ""; // 设备序列号
quint16 localPort = 27183; // reverse时本地监听端口
quint16 maxSize = 720; // 视频分辨率
quint32 bitRate = 8000000; // 视频比特率
quint32 bitRate = 2000000; // 视频比特率
quint32 maxFps = 60; // 视频最大帧率
bool closeScreen = false; // 启动时自动息屏
bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
Expand Down
38 changes: 24 additions & 14 deletions QtScrcpy/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)

Dialog::~Dialog()
{
qDebug() << "~Dialog()";
updateBootConfig(false);
m_deviceManage.disconnectAllDevice();
delete ui;
Expand All @@ -108,14 +109,9 @@ void Dialog::initUI()
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint);

ui->bitRateBox->addItem("2000000");
ui->bitRateBox->addItem("6000000");
ui->bitRateBox->addItem("8000000");
ui->bitRateBox->addItem("10000000");
ui->bitRateBox->addItem("20000000");
ui->bitRateBox->addItem("50000000");
ui->bitRateBox->addItem("100000000");
ui->bitRateBox->addItem("200000000");
setWindowTitle(Config::getInstance().getTitle());

ui->bitRateEdit->setValidator(new QIntValidator(1, 99999, this));

ui->maxSizeBox->addItem("640");
ui->maxSizeBox->addItem("720");
Expand Down Expand Up @@ -156,7 +152,18 @@ void Dialog::updateBootConfig(bool toView)
if (toView) {
UserBootConfig config = Config::getInstance().getUserBootConfig();

ui->bitRateBox->setCurrentIndex(config.bitRateIndex);
if(config.bitRate != 0 && config.bitRate % 1000000 == 0)
{
ui->bitRateEdit->setText(QString::number(config.bitRate / 1000000));
ui->bitRateBox->setCurrentText("Mbps");
}
else if(config.bitRate == 0)
ui->bitRateBox->setCurrentText("Mbps");
else
{
ui->bitRateEdit->setText(QString::number(config.bitRate / 1000));
ui->bitRateBox->setCurrentText("Kbps");
}
ui->maxSizeBox->setCurrentIndex(config.maxSizeIndex);
ui->formatBox->setCurrentIndex(config.recordFormatIndex);
ui->recordPathEdt->setText(config.recordPath);
Expand All @@ -173,7 +180,7 @@ void Dialog::updateBootConfig(bool toView)
} else {
UserBootConfig config;

config.bitRateIndex = ui->bitRateBox->currentIndex();
config.bitRate = getBitRate();
config.maxSizeIndex = ui->maxSizeBox->currentIndex();
config.recordFormatIndex = ui->formatBox->currentIndex();
config.recordPath = ui->recordPathEdt->text();
Expand All @@ -187,7 +194,6 @@ void Dialog::updateBootConfig(bool toView)
config.framelessWindow = ui->framelessCheck->isChecked();
config.keepAlive = ui->stayAwakeCheck->isChecked();
config.simpleMode = ui->useSingleModeCheck->isChecked();

Config::getInstance().setUserBootConfig(config);
}
}
Expand Down Expand Up @@ -235,7 +241,6 @@ void Dialog::slotActivated(QSystemTrayIcon::ActivationReason reason)
switch (reason) {
case QSystemTrayIcon::Trigger:
this->show();
m_hideIcon->hide();
break;
default:
break;
Expand Down Expand Up @@ -278,13 +283,12 @@ void Dialog::on_startServerBtn_clicked()
}
}

quint32 bitRate = ui->bitRateBox->currentText().trimmed().toUInt();
// this is ok that "native" toUshort is 0
quint16 videoSize = ui->maxSizeBox->currentText().trimmed().toUShort();
Device::DeviceParams params;
params.serial = ui->serialBox->currentText().trimmed();
params.maxSize = videoSize;
params.bitRate = bitRate;
params.bitRate = getBitRate();
// on devices with Android >= 10, the capture frame rate can be limited
params.maxFps = static_cast<quint32>(Config::getInstance().getMaxFps());
params.recordFileName = absFilePath;
Expand Down Expand Up @@ -621,3 +625,9 @@ void Dialog::on_serialBox_currentIndexChanged(const QString &arg1)
{
ui->userNameEdt->setText(Config::getInstance().getNickName(arg1));
}

quint32 Dialog::getBitRate()
{
return ui->bitRateEdit->text().trimmed().toUInt() *
(ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000);
}
22 changes: 1 addition & 21 deletions QtScrcpy/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,26 @@ class Dialog : public QDialog

private slots:
void on_updateDevice_clicked();

void on_startServerBtn_clicked();

void on_stopServerBtn_clicked();

void on_wirelessConnectBtn_clicked();

void on_startAdbdBtn_clicked();

void on_getIPBtn_clicked();

void on_wirelessDisConnectBtn_clicked();

void on_selectRecordPathBtn_clicked();

void on_recordPathEdt_textChanged(const QString &arg1);

void on_adbCommandBtn_clicked();

void on_stopAdbBtn_clicked();

void on_clearOut_clicked();

void on_stopAllServerBtn_clicked();

void on_refreshGameScriptBtn_clicked();

void on_applyScriptBtn_clicked();

void on_recordScreenCheck_clicked(bool checked);

void on_usbConnectBtn_clicked();

void on_wifiConnectBtn_clicked();

void on_connectedPhoneList_itemDoubleClicked(QListWidgetItem *item);

void on_updateNameBtn_clicked();

void on_useSingleModeCheck_clicked();

void on_serialBox_currentIndexChanged(const QString &arg1);

private:
Expand All @@ -85,6 +64,7 @@ private slots:
void slotShow();
void slotActivated(QSystemTrayIcon::ActivationReason reason);
int findDeviceFromeSerialBox(bool wifi);
quint32 getBitRate();

protected:
void closeEvent(QCloseEvent *event);
Expand Down
128 changes: 102 additions & 26 deletions QtScrcpy/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>769</height>
<height>858</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -133,23 +133,112 @@
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>bit rate:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="bitRateEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="bitRateBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string/>
</property>
<property name="currentText">
<string/>
</property>
<string notr="true">Mbps</string>
</property>
<item>
<property name="text">
<string>Mbps</string>
</property>
</item>
<item>
<property name="text">
<string>Kbps</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>max size:</string>
</property>
Expand All @@ -162,16 +251,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>record format:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="formatBox"/>
</item>
</layout>
</widget>
</item>
Expand All @@ -191,27 +270,24 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_8">
<widget class="QLabel" name="label_6">
<property name="text">
<string>lock orientation:</string>
<string>record format:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="lockOrientationBox"/>
<widget class="QComboBox" name="formatBox"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<widget class="QLabel" name="label_8">
<property name="text">
<string>lock orientation:</string>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QComboBox" name="lockOrientationBox"/>
</item>
</layout>
</widget>
Expand Down
Loading

0 comments on commit 049ba21

Please sign in to comment.