update:合并command命令

This commit is contained in:
Barry 2019-06-18 16:37:12 +08:00
commit 1f073c2929
8 changed files with 45 additions and 71 deletions

View file

@ -48,11 +48,6 @@ void ControlEvent::setScrollEventData(QRect position, qint32 hScroll, qint32 vSc
m_data.scrollEvent.vScroll = vScroll; m_data.scrollEvent.vScroll = vScroll;
} }
void ControlEvent::setCommandEventData(ControlEventCommand action)
{
m_data.commandEvent.action = action;
}
void ControlEvent::write32(QBuffer &buffer, quint32 value) void ControlEvent::write32(QBuffer &buffer, quint32 value)
{ {
buffer.putChar(value >> 24); buffer.putChar(value >> 24);
@ -109,8 +104,9 @@ QByteArray ControlEvent::serializeData()
write32(buffer, m_data.scrollEvent.hScroll); write32(buffer, m_data.scrollEvent.hScroll);
write32(buffer, m_data.scrollEvent.vScroll); write32(buffer, m_data.scrollEvent.vScroll);
break; break;
case CET_COMMAND: case CET_BACK_OR_SCREEN_ON:
buffer.putChar(m_data.commandEvent.action); case CET_EXPAND_NOTIFICATION_PANEL:
case CET_COLLAPSE_NOTIFICATION_PANEL:
break; break;
default: default:
qDebug() << "Unknown event type:" << m_data.type; qDebug() << "Unknown event type:" << m_data.type;

View file

@ -15,19 +15,15 @@ class ControlEvent : public QScrcpyEvent
{ {
public: public:
enum ControlEventType { enum ControlEventType {
CET_KEYCODE, CET_KEYCODE = 0,
CET_TEXT, CET_TEXT,
CET_MOUSE, CET_MOUSE,
CET_SCROLL, CET_SCROLL,
CET_COMMAND,
CET_TOUCH, CET_TOUCH,
}; CET_BACK_OR_SCREEN_ON,
CET_EXPAND_NOTIFICATION_PANEL,
enum ControlEventCommand { CET_COLLAPSE_NOTIFICATION_PANEL,
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON = 0, };
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL,
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL,
};
ControlEvent(ControlEventType controlEventType); ControlEvent(ControlEventType controlEventType);
@ -39,7 +35,6 @@ public:
// position action动作对应的位置 // position action动作对应的位置
void setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position); void setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position);
void setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll); void setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll);
void setCommandEventData(ControlEvent::ControlEventCommand action);
QByteArray serializeData(); QByteArray serializeData();
@ -74,10 +69,7 @@ private:
QRect position; QRect position;
qint32 hScroll; qint32 hScroll;
qint32 vScroll; qint32 vScroll;
} scrollEvent; } scrollEvent;
struct {
ControlEventCommand action;
} commandEvent;
}; };
ControlEventData(){} ControlEventData(){}

View file

@ -15,7 +15,7 @@ typedef qint32 (*ReadPacketFunc)(void*, quint8*, qint32);
Stream::Stream() Stream::Stream()
{ {
m_quit.store(0);
} }
Stream::~Stream() Stream::~Stream()
@ -314,7 +314,14 @@ void Stream::run()
packet.data = Q_NULLPTR; packet.data = Q_NULLPTR;
packet.size = 0; 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)) { if (m_decoder && !m_decoder->push(&packet)) {
av_packet_unref(&packet); av_packet_unref(&packet);
goto runQuit; goto runQuit;

View file

@ -340,31 +340,28 @@ void VideoForm::postVolumeDown()
void VideoForm::postTurnOn() void VideoForm::postTurnOn()
{ {
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_BACK_OR_SCREEN_ON);
if (!controlEvent) { if (!controlEvent) {
return; return;
} }
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON);
m_inputConvert.sendControlEvent(controlEvent); m_inputConvert.sendControlEvent(controlEvent);
} }
void VideoForm::expandNotificationPanel() void VideoForm::expandNotificationPanel()
{ {
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_EXPAND_NOTIFICATION_PANEL);
if (!controlEvent) { if (!controlEvent) {
return; return;
} }
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL);
m_inputConvert.sendControlEvent(controlEvent); m_inputConvert.sendControlEvent(controlEvent);
} }
void VideoForm::collapseNotificationPanel() void VideoForm::collapseNotificationPanel()
{ {
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND); ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COLLAPSE_NOTIFICATION_PANEL);
if (!controlEvent) { if (!controlEvent) {
return; return;
} }
controlEvent->setCommandEventData(ControlEvent::CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL);
m_inputConvert.sendControlEvent(controlEvent); m_inputConvert.sendControlEvent(controlEvent);
} }

View file

@ -9,17 +9,16 @@ public final class ControlEvent {
public static final int TYPE_TEXT = 1; public static final int TYPE_TEXT = 1;
public static final int TYPE_MOUSE = 2; public static final int TYPE_MOUSE = 2;
public static final int TYPE_SCROLL = 3; public static final int TYPE_SCROLL = 3;
public static final int TYPE_COMMAND = 4; public static final int TYPE_TOUCH = 4;
public static final int TYPE_TOUCH = 5; 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 int type;
private String text; private String text;
private int metaState; // KeyEvent.META_* 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 keycode; // KeyEvent.KEYCODE_*
private int buttons; // MotionEvent.BUTTON_* private int buttons; // MotionEvent.BUTTON_*
private int id; private int id;
@ -73,10 +72,9 @@ public final class ControlEvent {
return event; return event;
} }
public static ControlEvent createCommandControlEvent(int action) { public static ControlEvent createSimpleControlEvent(int type) {
ControlEvent event = new ControlEvent(); ControlEvent event = new ControlEvent();
event.type = TYPE_COMMAND; event.type = type;
event.action = action;
return event; return event;
} }

View file

@ -12,7 +12,6 @@ public class ControlEventReader {
private static final int MOUSE_PAYLOAD_LENGTH = 13; private static final int MOUSE_PAYLOAD_LENGTH = 13;
private static final int TOUCH_PAYLOAD_LENGTH = 10; private static final int TOUCH_PAYLOAD_LENGTH = 10;
private static final int SCROLL_PAYLOAD_LENGTH = 16; private static final int SCROLL_PAYLOAD_LENGTH = 16;
private static final int COMMAND_PAYLOAD_LENGTH = 1;
public static final int TEXT_MAX_LENGTH = 300; public static final int TEXT_MAX_LENGTH = 300;
private static final int RAW_BUFFER_SIZE = 1024; private static final int RAW_BUFFER_SIZE = 1024;
@ -67,8 +66,10 @@ public class ControlEventReader {
case ControlEvent.TYPE_SCROLL: case ControlEvent.TYPE_SCROLL:
controlEvent = parseScrollControlEvent(); controlEvent = parseScrollControlEvent();
break; break;
case ControlEvent.TYPE_COMMAND: case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
controlEvent = parseCommandControlEvent(); case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
controlEvent = ControlEvent.createSimpleControlEvent(type);
break; break;
default: default:
Ln.w("Unknown event type: " + type); Ln.w("Unknown event type: " + type);
@ -136,14 +137,6 @@ public class ControlEventReader {
return ControlEvent.createScrollControlEvent(position, hScroll, vScroll); 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) { private static Position readPosition(ByteBuffer buffer) {
int x = toUnsigned(buffer.getShort()); int x = toUnsigned(buffer.getShort());
int y = toUnsigned(buffer.getShort()); int y = toUnsigned(buffer.getShort());

View file

@ -124,8 +124,14 @@ public class EventController {
case ControlEvent.TYPE_SCROLL: case ControlEvent.TYPE_SCROLL:
injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll()); injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll());
break; break;
case ControlEvent.TYPE_COMMAND: case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
executeCommand(controlEvent.getAction()); pressBackOrTurnScreenOn();
break;
case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
device.expandNotificationPanel();
break;
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
device.collapsePanels();
break; break;
default: default:
// do nothing // do nothing
@ -155,6 +161,7 @@ public class EventController {
int successCount = 0; int successCount = 0;
for (char c : text.toCharArray()) { for (char c : text.toCharArray()) {
if (!injectChar(c)) { if (!injectChar(c)) {
Ln.w("Could not inject char u+" + String.format("%04x", (int) c));
continue; continue;
} }
successCount++; successCount++;
@ -298,20 +305,4 @@ public class EventController {
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER; int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
return injectKeycode(keycode); 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;
}
} }

View file

@ -1,9 +1,9 @@
package com.genymobile.scrcpy.wrappers; package com.genymobile.scrcpy.wrappers;
import android.os.IInterface;
import com.genymobile.scrcpy.Ln; import com.genymobile.scrcpy.Ln;
import android.os.IInterface;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;