add:不显示,只后台录制

This commit is contained in:
Barry 2019-06-20 17:49:53 +08:00
parent 5ea35a2ef2
commit 3435950102
5 changed files with 102 additions and 75 deletions

View file

@ -14,25 +14,37 @@ Device::Device(DeviceParams params, QObject *parent)
: QObject(parent)
, m_params(params)
{
m_vb = new VideoBuffer();
m_vb->init();
m_decoder = new Decoder(m_vb, this);
if (!params.display && m_params.recordFileName.trimmed().isEmpty()) {
qCritical("not display must be recorded");
deleteLater();
return;
}
if (params.display) {
m_vb = new VideoBuffer();
m_vb->init();
m_decoder = new Decoder(m_vb, this);
m_fileHandler = new FileHandler(this);
m_controller = new Controller(this);
m_videoForm = new VideoForm();
if (m_controller) {
m_videoForm->setController(m_controller);
}
if (m_fileHandler) {
m_videoForm->setFileHandler(m_fileHandler);
}
m_videoForm->show();
}
m_stream = new Stream(this);
m_stream->setDecoder(m_decoder);
if (m_decoder) {
m_stream->setDecoder(m_decoder);
}
m_server = new Server(this);
m_controller = new Controller(this);
m_fileHandler = new FileHandler(this);
if (!m_params.recordFileName.trimmed().isEmpty()) {
m_recorder = new Recorder(m_params.recordFileName);
m_stream->setRecoder(m_recorder);
}
m_videoForm = new VideoForm();
m_videoForm->setController(m_controller);
m_videoForm->show();
initSignals();
startServer();
}
@ -71,7 +83,7 @@ Controller *Device::getController()
void Device::initSignals()
{
if (m_videoForm) {
if (m_controller && m_videoForm) {
connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor);
}
if (m_fileHandler) {
@ -117,9 +129,12 @@ void Device::initSignals()
m_stream->startDecode();
// init controller
m_controller->setControlSocket(m_server->getControlSocket());
if (m_controller) {
m_controller->setControlSocket(m_server->getControlSocket());
}
if (m_params.closeScreen && m_controller) {
// 显示界面时才自动息屏m_params.display
if (m_params.closeScreen && m_params.display && m_controller) {
m_controller->setScreenPowerMode(ControlMsg::SPM_OFF);
}
}
@ -137,7 +152,7 @@ void Device::initSignals()
});
}
if (m_decoder) {
if (m_decoder && m_vb) {
// must be Qt::QueuedConnection, ui update must be main thread
connect(m_decoder, &Decoder::onNewFrame, this, [this](){
m_vb->lock();

View file

@ -18,19 +18,20 @@ class Device : public QObject
Q_OBJECT
public:
struct DeviceParams {
QString recordFileName = "";
QString serial = "";
quint16 localPort = 27183;
quint16 maxSize = 0;
quint32 bitRate = 8000000;
bool closeScreen = false;
bool useReverse = true;
QString recordFileName = ""; // 视频录制文件名
QString serial = ""; // 设备序列号
quint16 localPort = 27183; // reverse时本地监听端口
quint16 maxSize = 720; // 视频分辨率
quint32 bitRate = 8000000; // 视频比特率
bool closeScreen = false; // 启动时自动息屏
bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward
bool display = true; // 是否显示画面(或者仅仅后台录制)
};
explicit Device(DeviceParams params, QObject *parent = nullptr);
virtual ~Device();
VideoForm *getVideoForm();
Controller* getController();
Controller *getController();
private:
void initSignals();

View file

@ -23,14 +23,14 @@ class Server : public QObject
};
public:
struct ServerParams {
QString serial = "";
quint16 localPort = 27183;
quint16 maxSize = 750;
quint32 bitRate = 8000000;
QString crop = "-";
bool sendFrameMeta = false;
bool control = true;
bool useReverse = true;
QString serial = ""; // 设备序列号
quint16 localPort = 27183; // reverse时本地监听端口
quint16 maxSize = 720; // 视频分辨率
quint32 bitRate = 8000000; // 视频比特率
QString crop = "-"; // 视频裁剪
bool sendFrameMeta = false; // 是否发送mp4帧数据
bool control = true; // 安卓端是否接收键鼠控制
bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward
};
explicit Server(QObject *parent = nullptr);

View file

@ -103,6 +103,8 @@ void Dialog::on_updateDevice_clicked()
void Dialog::on_startServerBtn_clicked()
{
if (!m_device) {
outLog("start server...", false);
QString absFilePath;
QString fileDir(ui->recordPathEdt->text().trimmed());
if (!fileDir.isEmpty()) {
@ -124,12 +126,11 @@ void Dialog::on_startServerBtn_clicked()
params.recordFileName = absFilePath;
params.closeScreen = ui->closeScreenCheck->isChecked();
params.useReverse = ui->useReverseCheck->isChecked();
params.display = !ui->notDisplayCheck->isChecked();
m_device = new Device(params, this);
if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) {
m_device->getVideoForm()->staysOnTop();
}
outLog("start server...", false);
}
}
}
@ -241,7 +242,8 @@ void Dialog::on_selectRecordPathBtn_clicked()
void Dialog::on_recordPathEdt_textChanged(const QString &arg1)
{
ui->recordPathEdt->setToolTip(arg1);
ui->recordPathEdt->setToolTip(arg1.trimmed());
ui->notDisplayCheck->setCheckable(!arg1.trimmed().isEmpty());
}
void Dialog::on_adbCommandBtn_clicked()

View file

@ -119,24 +119,17 @@
<string>Start Config</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="4">
<widget class="QLabel" name="label_4">
<property name="text">
<string>video size:</string>
<item row="1" column="3" colspan="5">
<widget class="QLineEdit" name="recordPathEdt">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>bit rate:</string>
</property>
</widget>
</item>
<item row="0" column="7">
<item row="0" column="9">
<widget class="QComboBox" name="formatBox"/>
</item>
<item row="0" column="3">
<item row="0" column="3" colspan="2">
<widget class="QComboBox" name="bitRateBox">
<property name="toolTip">
<string/>
@ -146,17 +139,21 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<item row="0" column="8">
<widget class="QLabel" name="label_6">
<property name="text">
<string>record save path:</string>
</property>
<property name="buddy">
<cstring>recordPathEdt</cstring>
<string>record format</string>
</property>
</widget>
</item>
<item row="1" column="6" colspan="2">
<item row="0" column="7">
<widget class="QComboBox" name="videoSizeBox">
<property name="toolTip">
<string/>
</property>
</widget>
</item>
<item row="1" column="8" colspan="2">
<widget class="QPushButton" name="selectRecordPathBtn">
<property name="text">
<string>select path</string>
@ -166,7 +163,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="3" colspan="3">
<widget class="QCheckBox" name="alwaysTopCheck">
<property name="text">
<string>always top</string>
@ -176,28 +173,27 @@
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="label_6">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="notDisplayCheck">
<property name="text">
<string>record format</string>
<string>not display</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="3" colspan="3">
<widget class="QLineEdit" name="recordPathEdt">
<property name="readOnly">
<bool>true</bool>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>record save path:</string>
</property>
<property name="buddy">
<cstring>recordPathEdt</cstring>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="videoSizeBox">
<property name="toolTip">
<string/>
</property>
</widget>
</item>
<item row="2" column="5">
<item row="2" column="8" colspan="2">
<widget class="QCheckBox" name="useReverseCheck">
<property name="text">
<string>use reverse</string>
@ -207,13 +203,27 @@
</property>
</widget>
</item>
<item row="2" column="3" colspan="2">
<item row="2" column="6" colspan="2">
<widget class="QCheckBox" name="closeScreenCheck">
<property name="text">
<string>close screen</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>bit rate:</string>
</property>
</widget>
</item>
<item row="0" column="5" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>video size:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -351,7 +361,6 @@
<tabstop>formatBox</tabstop>
<tabstop>recordPathEdt</tabstop>
<tabstop>selectRecordPathBtn</tabstop>
<tabstop>alwaysTopCheck</tabstop>
<tabstop>serialBox</tabstop>
<tabstop>startServerBtn</tabstop>
<tabstop>stopServerBtn</tabstop>