parent
7e9352112d
commit
efecb01edf
@ -1,24 +1,28 @@
|
|||||||
#include "dialog.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
|
||||||
|
#include "dialog.h"
|
||||||
|
#include "decoder.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
//QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
|
//QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
|
||||||
//QApplication::setAttribute(Qt::AA_UseOpenGLES);
|
//QApplication::setAttribute(Qt::AA_UseOpenGLES);
|
||||||
//QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
|
//QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
|
||||||
|
|
||||||
|
Decoder::init();
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
qputenv("QTSCRCPY_ADB_PATH", "G:\\mygitcode\\QtScrcpy\\src\\adb.exe");
|
qputenv("QTSCRCPY_ADB_PATH", "G:\\mygitcode\\QtScrcpy\\src\\adb.exe");
|
||||||
qputenv("QTSCRCPY_SERVER_PATH", "G:\\mygitcode\\QtScrcpy\\src\\scrcpy-server.jar");
|
qputenv("QTSCRCPY_SERVER_PATH", "G:\\mygitcode\\QtScrcpy\\src\\scrcpy-server.jar");
|
||||||
|
|
||||||
Dialog w;
|
Dialog* w = new Dialog;
|
||||||
//w.move(50, 930);
|
w->show();
|
||||||
w.show();
|
|
||||||
|
int ret = a.exec();
|
||||||
|
|
||||||
return a.exec();
|
Decoder::deInit();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,87 @@
|
|||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
|
#include "videoform.h"
|
||||||
|
#include "ui_videoform.h"
|
||||||
|
|
||||||
|
VideoForm::VideoForm(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::videoForm)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
m_server = new Server();
|
||||||
|
m_frames.init();
|
||||||
|
m_decoder.setFrames(&m_frames);
|
||||||
|
|
||||||
|
connect(m_server, &Server::serverStartResult, this, [this](bool success){
|
||||||
|
if (success) {
|
||||||
|
m_server->connectTo();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_server, &Server::connectToResult, this, [this](bool success, const QString &deviceName, const QSize &size){
|
||||||
|
if (success) {
|
||||||
|
setWindowTitle(deviceName);
|
||||||
|
|
||||||
|
updateShowSize(size);
|
||||||
|
// 双屏有问题,位置有问题
|
||||||
|
QDesktopWidget* desktop = QApplication::desktop();
|
||||||
|
if (desktop) {
|
||||||
|
QSize screenSize = desktop->size();
|
||||||
|
if (!screenSize.isEmpty()) {
|
||||||
|
move((screenSize.width() - width())/2, (screenSize.height() - height())/2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_decoder.setDeviceSocket(m_server->getDeviceSocketByThread(&m_decoder));
|
||||||
|
m_decoder.startDecode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_server, &Server::onServerStop, this, [this](){
|
||||||
|
close();
|
||||||
|
qDebug() << "server process stop";
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(&m_decoder, &Decoder::onDecodeStop, this, [this](){
|
||||||
|
close();
|
||||||
|
qDebug() << "decoder thread stop";
|
||||||
|
});
|
||||||
|
|
||||||
|
// must be Qt::QueuedConnection, ui update must be main thread
|
||||||
|
QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){
|
||||||
|
m_frames.lock();
|
||||||
|
const AVFrame *frame = m_frames.consumeRenderedFrame();
|
||||||
|
updateShowSize(QSize(frame->width, frame->height));
|
||||||
|
ui->videoWidget->setFrameSize(QSize(frame->width, frame->height));
|
||||||
|
ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]);
|
||||||
|
m_frames.unLock();
|
||||||
|
},Qt::QueuedConnection);
|
||||||
|
|
||||||
|
m_server->start("P7C0218510000537", 27183, 1080, 8000000, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoForm::~VideoForm()
|
||||||
|
{
|
||||||
|
m_decoder.stopDecode();
|
||||||
|
m_server->stop();
|
||||||
|
delete m_server;
|
||||||
|
m_frames.deInit();
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
|
{
|
||||||
|
QSize showSize = newSize;
|
||||||
|
QDesktopWidget* desktop = QApplication::desktop();
|
||||||
|
if (desktop) {
|
||||||
|
QSize screenSize = desktop->size();
|
||||||
|
showSize.setWidth(qMin(newSize.width(), screenSize.width()));
|
||||||
|
showSize.setHeight(qMin(newSize.height(), screenSize.height() - 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showSize != size()) {
|
||||||
|
resize(showSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef VIDEOFORM_H
|
||||||
|
#define VIDEOFORM_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "server.h"
|
||||||
|
#include "decoder.h"
|
||||||
|
#include "frames.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class videoForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
class VideoForm : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit VideoForm(QWidget *parent = 0);
|
||||||
|
~VideoForm();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateShowSize(const QSize &newSize);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::videoForm *ui;
|
||||||
|
Server* m_server = Q_NULLPTR;
|
||||||
|
Decoder m_decoder;
|
||||||
|
Frames m_frames;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VIDEOFORM_H
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>videoForm</class>
|
||||||
|
<widget class="QWidget" name="videoForm">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>454</width>
|
||||||
|
<height>908</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QYUVOpenGLWidget" name="videoWidget" native="true"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QYUVOpenGLWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qyuvopenglwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
Reference in new issue