diff --git a/QtScrcpy/inputcontrol/controlevent.cpp b/QtScrcpy/inputcontrol/controlevent.cpp index 4619680..1de03b4 100644 --- a/QtScrcpy/inputcontrol/controlevent.cpp +++ b/QtScrcpy/inputcontrol/controlevent.cpp @@ -48,11 +48,6 @@ void ControlEvent::setScrollEventData(QRect position, qint32 hScroll, qint32 vSc m_data.scrollEvent.vScroll = vScroll; } -void ControlEvent::setCommandEventData(ControlEventCommand action) -{ - m_data.commandEvent.action = action; -} - void ControlEvent::write32(QBuffer &buffer, quint32 value) { buffer.putChar(value >> 24); @@ -109,8 +104,9 @@ QByteArray ControlEvent::serializeData() write32(buffer, m_data.scrollEvent.hScroll); write32(buffer, m_data.scrollEvent.vScroll); break; - case CET_COMMAND: - buffer.putChar(m_data.commandEvent.action); + case CET_BACK_OR_SCREEN_ON: + case CET_EXPAND_NOTIFICATION_PANEL: + case CET_COLLAPSE_NOTIFICATION_PANEL: break; default: qDebug() << "Unknown event type:" << m_data.type; diff --git a/QtScrcpy/inputcontrol/controlevent.h b/QtScrcpy/inputcontrol/controlevent.h index 01b0a11..02688e1 100644 --- a/QtScrcpy/inputcontrol/controlevent.h +++ b/QtScrcpy/inputcontrol/controlevent.h @@ -15,19 +15,15 @@ class ControlEvent : public QScrcpyEvent { public: enum ControlEventType { - CET_KEYCODE, + CET_KEYCODE = 0, CET_TEXT, CET_MOUSE, CET_SCROLL, - CET_COMMAND, CET_TOUCH, - }; - - enum ControlEventCommand { - CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON = 0, - CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL, - CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL, - }; + CET_BACK_OR_SCREEN_ON, + CET_EXPAND_NOTIFICATION_PANEL, + CET_COLLAPSE_NOTIFICATION_PANEL, + }; ControlEvent(ControlEventType controlEventType); @@ -39,7 +35,6 @@ public: // position action动作对应的位置 void setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position); void setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll); - void setCommandEventData(ControlEvent::ControlEventCommand action); QByteArray serializeData(); @@ -74,10 +69,7 @@ private: QRect position; qint32 hScroll; qint32 vScroll; - } scrollEvent; - struct { - ControlEventCommand action; - } commandEvent; + } scrollEvent; }; ControlEventData(){} diff --git a/QtScrcpy/stream/stream.cpp b/QtScrcpy/stream/stream.cpp index 95e1845..21f93af 100644 --- a/QtScrcpy/stream/stream.cpp +++ b/QtScrcpy/stream/stream.cpp @@ -15,7 +15,7 @@ typedef qint32 (*ReadPacketFunc)(void*, quint8*, qint32); Stream::Stream() { - + m_quit.store(0); } Stream::~Stream() @@ -314,7 +314,14 @@ void Stream::run() packet.data = Q_NULLPTR; packet.size = 0; - while (!m_quit.load() && !av_read_frame(formatCtx, &packet)) { + while (!av_read_frame(formatCtx, &packet)) { + if (m_quit.load()) { + // if the stream is stopped, the socket had been shutdown, so the + // last packet is probably corrupted (but not detected as such by + // FFmpeg) and will not be decoded correctly + av_packet_unref(&packet); + goto runQuit; + } if (m_decoder && !m_decoder->push(&packet)) { av_packet_unref(&packet); goto runQuit; diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index 55a89d1..f3278ee 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -340,31 +340,28 @@ void VideoForm::postVolumeDown() void VideoForm::postTurnOn() { - ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); + ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_BACK_OR_SCREEN_ON); if (!controlEvent) { return; - } - controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON); + } m_inputConvert.sendControlEvent(controlEvent); } void VideoForm::expandNotificationPanel() { - ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); + ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_EXPAND_NOTIFICATION_PANEL); if (!controlEvent) { return; } - controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL); m_inputConvert.sendControlEvent(controlEvent); } void VideoForm::collapseNotificationPanel() { - ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); + ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COLLAPSE_NOTIFICATION_PANEL); if (!controlEvent) { return; - } - controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL); + } m_inputConvert.sendControlEvent(controlEvent); } diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java b/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java index 2d7c0a3..b368d31 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java +++ b/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java @@ -9,17 +9,16 @@ public final class ControlEvent { public static final int TYPE_TEXT = 1; public static final int TYPE_MOUSE = 2; public static final int TYPE_SCROLL = 3; - public static final int TYPE_COMMAND = 4; - public static final int TYPE_TOUCH = 5; + public static final int TYPE_TOUCH = 4; + public static final int TYPE_BACK_OR_SCREEN_ON = 5; + public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 6; + public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 7; - public static final int COMMAND_BACK_OR_SCREEN_ON = 0; - public static final int COMMAND_EXPAND_NOTIFICATION_PANEL = 1; - public static final int COMMAND_COLLAPSE_NOTIFICATION_PANEL = 2; private int type; private String text; private int metaState; // KeyEvent.META_* - private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* or COMMAND_* + private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* private int keycode; // KeyEvent.KEYCODE_* private int buttons; // MotionEvent.BUTTON_* private int id; @@ -73,10 +72,9 @@ public final class ControlEvent { return event; } - public static ControlEvent createCommandControlEvent(int action) { + public static ControlEvent createSimpleControlEvent(int type) { ControlEvent event = new ControlEvent(); - event.type = TYPE_COMMAND; - event.action = action; + event.type = type; return event; } diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java index f65c895..6b9e8ea 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java +++ b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java @@ -12,7 +12,6 @@ public class ControlEventReader { private static final int MOUSE_PAYLOAD_LENGTH = 13; private static final int TOUCH_PAYLOAD_LENGTH = 10; private static final int SCROLL_PAYLOAD_LENGTH = 16; - private static final int COMMAND_PAYLOAD_LENGTH = 1; public static final int TEXT_MAX_LENGTH = 300; private static final int RAW_BUFFER_SIZE = 1024; @@ -67,8 +66,10 @@ public class ControlEventReader { case ControlEvent.TYPE_SCROLL: controlEvent = parseScrollControlEvent(); break; - case ControlEvent.TYPE_COMMAND: - controlEvent = parseCommandControlEvent(); + case ControlEvent.TYPE_BACK_OR_SCREEN_ON: + case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL: + case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL: + controlEvent = ControlEvent.createSimpleControlEvent(type); break; default: Ln.w("Unknown event type: " + type); @@ -136,14 +137,6 @@ public class ControlEventReader { return ControlEvent.createScrollControlEvent(position, hScroll, vScroll); } - private ControlEvent parseCommandControlEvent() { - if (buffer.remaining() < COMMAND_PAYLOAD_LENGTH) { - return null; - } - int action = toUnsigned(buffer.get()); - return ControlEvent.createCommandControlEvent(action); - } - private static Position readPosition(ByteBuffer buffer) { int x = toUnsigned(buffer.getShort()); int y = toUnsigned(buffer.getShort()); diff --git a/server/src/main/java/com/genymobile/scrcpy/EventController.java b/server/src/main/java/com/genymobile/scrcpy/EventController.java index f66a3f6..34f555a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/EventController.java +++ b/server/src/main/java/com/genymobile/scrcpy/EventController.java @@ -124,8 +124,14 @@ public class EventController { case ControlEvent.TYPE_SCROLL: injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll()); break; - case ControlEvent.TYPE_COMMAND: - executeCommand(controlEvent.getAction()); + case ControlEvent.TYPE_BACK_OR_SCREEN_ON: + pressBackOrTurnScreenOn(); + break; + case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL: + device.expandNotificationPanel(); + break; + case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL: + device.collapsePanels(); break; default: // do nothing @@ -155,6 +161,7 @@ public class EventController { int successCount = 0; for (char c : text.toCharArray()) { if (!injectChar(c)) { + Ln.w("Could not inject char u+" + String.format("%04x", (int) c)); continue; } successCount++; @@ -298,20 +305,4 @@ public class EventController { int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER; return injectKeycode(keycode); } - - private boolean executeCommand(int action) { - switch (action) { - case ControlEvent.COMMAND_BACK_OR_SCREEN_ON: - return pressBackOrTurnScreenOn(); - case ControlEvent.COMMAND_EXPAND_NOTIFICATION_PANEL: - device.expandNotificationPanel(); - return true; - case ControlEvent.COMMAND_COLLAPSE_NOTIFICATION_PANEL: - device.collapsePanels(); - return true; - default: - Ln.w("Unsupported command: " + action); - } - return false; - } } diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java index 770bb27..543cabb 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java @@ -1,9 +1,9 @@ package com.genymobile.scrcpy.wrappers; -import android.os.IInterface; - import com.genymobile.scrcpy.Ln; +import android.os.IInterface; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method;