From 1defdc66aba1f4d03d2e34c86f8377ec26ec0da3 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sun, 18 Nov 2018 17:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E8=BE=A8=E7=8E=87=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=9A=E6=94=B9=E4=B8=BA=E5=8F=AA=E6=94=AF=E6=8C=81=E6=A0=87?= =?UTF-8?q?=E5=87=86480p=20720p=201080p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtScrcpy/videoform.cpp | 7 +++- .../java/com/genymobile/scrcpy/Device.java | 42 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index 25a0732..e1b2d6a 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -72,16 +72,19 @@ VideoForm::VideoForm(QWidget *parent) : // must be Qt::QueuedConnection, ui update must be main thread QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ - m_frames.lock(); + m_frames.lock(); const AVFrame *frame = m_frames.consumeRenderedFrame(); + qDebug() << "widthxheight:" << frame->width << "x" << frame->height; 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, ""); + // support 480p 720p 1080p //m_server->start("P7C0218510000537", 27183, 0, 8000000, ""); + //m_server->start("P7C0218510000537", 27183, 1080, 8000000, ""); + m_server->start("P7C0218510000537", 27183, 720, 8000000, ""); } VideoForm::~VideoForm() diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index d2862ac..96f86e6 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -69,6 +69,7 @@ public final class Device { @SuppressWarnings("checkstyle:MagicNumber") private static Size computeVideoSize(int w, int h, int maxSize) { // Compute the video size and the padding of the content inside this video. + /* // Principle: // - scale down the great side of the screen to maxSize (if necessary); // - scale down the other side so that the aspect ratio is preserved; @@ -91,7 +92,46 @@ public final class Device { w = portrait ? minor : major; h = portrait ? major : minor; } - return new Size(w, h); + */ + + // Principle:480p/720p/1080p and not larger than device size. + w &= ~7; // in case it's not a multiple of 8 + h &= ~7; + boolean vertival = h > w; + boolean validSize = false; + int newWidth = w; + int newHeight = h; + // 480p/720p/1080p + switch (maxSize) { + case 480: // 480p:640x480 + newWidth = 640; + newHeight = 480; + validSize = true; + break; + case 720: // 720p:1280x720 + newWidth = 1280; + newHeight = 720; + validSize = true; + break; + case 1080: // 1080p:1920x1080 + newWidth = 1920; + newHeight = 1080; + validSize = true; + break; + } + // vertival convert + if (validSize && vertival) { + int temp = newWidth; + newWidth = newHeight; + newHeight = temp; + } + // not larger than device size. + if (newWidth > w || newHeight > h) { + newWidth = w; + newHeight = h; + } + + return new Size(newWidth, newHeight); } public Point getPhysicalPoint(Position position) {