Compare commits

..

15 Commits

Author SHA1 Message Date
Romain Vimont
783eb95795 fix timestamp 2019-09-30 21:30:36 +02:00
Romain Vimont
7e21f28f2c wip 2019-09-30 21:30:36 +02:00
Romain Vimont
ccfd4db370 localId 2019-09-30 21:30:36 +02:00
Romain Vimont
6d26ed888e WIP ignore duplicate mouse events 2019-09-30 21:30:36 +02:00
Romain Vimont
73afdaf251 WIP process touch events on client 2019-09-30 21:30:36 +02:00
Romain Vimont
bb1bf99c6e WIP handle touch events on server 2019-09-30 21:30:36 +02:00
Romain Vimont
7aeec1c331 WIP Add "inject touch" event 2019-09-30 21:30:36 +02:00
Romain Vimont
3bb2222a34 Rename "pointer" to "mouse pointer"
This will help to distinguish them from "touch pointers".
2019-09-30 21:27:06 +02:00
Romain Vimont
bdf2644664 Add buffer_write64be()
Add a function to write 64 bits in big-endian from a uint64_t.
2019-09-30 21:27:06 +02:00
Romain Vimont
1f8ba1ca79 Include config.h everywhere
Ref: <https://github.com/Genymobile/scrcpy/issues/829>

Suggested-by: Louis Kruger <louisk@gmail.com>
2019-09-29 22:39:53 +02:00
Louis Kruger
129dabcfa4 Include config.h to fix HIDPI support
Ref: <https://github.com/Genymobile/scrcpy/issues/829>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2019-09-29 22:39:47 +02:00
Romain Vimont
f510f1de1c Remove "make" from build dependencies
The project is built with meson+ninja.
2019-09-28 14:46:44 +02:00
Romain Vimont
7d1932b907 Fix gradle warnings in tests 2019-09-28 12:23:54 +02:00
Yu-Chen Lin
795d103032 input_manager.c: Correct log
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
2019-09-28 10:37:25 +08:00
Ta-da
513d1ac96d Fix option "record-format" related short opt 2019-09-27 10:04:41 +08:00
49 changed files with 178 additions and 79 deletions

View File

@@ -43,7 +43,7 @@ Install the required packages from your package manager.
sudo apt install ffmpeg libsdl2-2.0-0
# client build dependencies
sudo apt install make gcc git pkg-config meson ninja-build \
sudo apt install gcc git pkg-config meson ninja-build \
libavcodec-dev libavformat-dev libavutil-dev \
libsdl2-dev

View File

@@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "config.h"
static inline void
buffer_write16be(uint8_t *buf, uint16_t value) {
buf[0] = value >> 8;

View File

@@ -5,6 +5,8 @@
#include <stdbool.h>
#include <unistd.h>
#include "config.h"
// To define a circular buffer type of 20 ints:
// struct cbuf_int CBUF(int, 20);
//

View File

@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "common.h"
#include "log.h"
#include "str_util.h"

View File

@@ -33,6 +33,8 @@
#endif
#include "config.h"
# define NO_EXIT_CODE -1
enum process_result {

View File

@@ -3,6 +3,8 @@
#include <stdint.h>
#include "config.h"
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)

View File

@@ -1,8 +1,9 @@
#include "control_msg.h"
#include <string.h>
#include <SDL_assert.h>
#include <SDL2/SDL_assert.h>
#include "config.h"
#include "buffer_util.h"
#include "log.h"
#include "str_util.h"

View File

@@ -5,6 +5,7 @@
#include <stddef.h>
#include <stdint.h>
#include "config.h"
#include "android/input.h"
#include "android/keycodes.h"
#include "common.h"

View File

@@ -5,6 +5,7 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
#include "cbuf.h"
#include "control_msg.h"
#include "net.h"

View File

@@ -8,8 +8,8 @@
#include <SDL2/SDL_thread.h>
#include <unistd.h>
#include "compat.h"
#include "config.h"
#include "compat.h"
#include "buffer_util.h"
#include "events.h"
#include "lock_util.h"

View File

@@ -4,6 +4,8 @@
#include <stdbool.h>
#include <libavformat/avformat.h>
#include "config.h"
struct video_buffer;
struct decoder {

View File

@@ -1,4 +1,6 @@
#include "device.h"
#include "config.h"
#include "log.h"
bool

View File

@@ -3,6 +3,7 @@
#include <stdbool.h>
#include "config.h"
#include "common.h"
#include "net.h"

View File

@@ -3,6 +3,7 @@
#include <string.h>
#include <SDL2/SDL_assert.h>
#include "config.h"
#include "buffer_util.h"
#include "log.h"

View File

@@ -5,6 +5,8 @@
#include <stdint.h>
#include <unistd.h>
#include "config.h"
#define DEVICE_MSG_TEXT_MAX_LENGTH 4093
#define DEVICE_MSG_SERIALIZED_MAX_SIZE (3 + DEVICE_MSG_TEXT_MAX_LENGTH)

View File

@@ -1,5 +1,7 @@
#include "event_converter.h"
#include "config.h"
#define MAP(FROM, TO) case FROM: *to = TO; return true
#define FAIL default: return false
@@ -228,7 +230,7 @@ convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
to->inject_touch_event.position.screen_size = screen_size;
// SDL touch event coordinates are normalized in the range [0; 1]
to->inject_touch_event.position.point.x = from->x * screen_size.width;
to->inject_touch_event.position.point.y = from->x * screen_size.height;
to->inject_touch_event.position.point.y = from->y * screen_size.height;
to->inject_touch_event.pressure = from->pressure;
return true;
}

View File

@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <SDL2/SDL_events.h>
#include "config.h"
#include "control_msg.h"
struct complete_mouse_motion_event {

View File

@@ -5,6 +5,7 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
#include "cbuf.h"
#include "command.h"

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL_assert.h>
#include <SDL2/SDL_timer.h>
#include "config.h"
#include "lock_util.h"
#include "log.h"

View File

@@ -7,6 +7,8 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
struct fps_counter {
SDL_Thread *thread;
SDL_mutex *mutex;

View File

@@ -1,6 +1,8 @@
#include "input_manager.h"
#include <SDL2/SDL_assert.h>
#include "config.h"
#include "event_converter.h"
#include "lock_util.h"
#include "log.h"
@@ -102,7 +104,7 @@ press_back_or_turn_screen_on(struct controller *controller) {
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
if (!controller_push_msg(controller, &msg)) {
LOGW("Could not request 'turn screen on'");
LOGW("Could not request 'press back or turn screen on'");
}
}

View File

@@ -3,6 +3,7 @@
#include <stdbool.h>
#include "config.h"
#include "common.h"
#include "controller.h"
#include "fps_counter.h"

View File

@@ -4,6 +4,7 @@
#include <stdint.h>
#include <SDL2/SDL_mutex.h>
#include "config.h"
#include "log.h"
static inline void

View File

@@ -8,8 +8,8 @@
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
#include <SDL2/SDL.h>
#include "compat.h"
#include "config.h"
#include "compat.h"
#include "log.h"
#include "recorder.h"
@@ -328,7 +328,7 @@ parse_args(struct args *args, int argc, char *argv[]) {
{"push-target", required_argument, NULL,
OPT_PUSH_TARGET},
{"record", required_argument, NULL, 'r'},
{"record-format", required_argument, NULL, 'f'},
{"record-format", required_argument, NULL, 'F'},
{"render-expired-frames", no_argument, NULL,
OPT_RENDER_EXPIRED_FRAMES},
{"serial", required_argument, NULL, 's'},

View File

@@ -2,6 +2,7 @@
#include <stdio.h>
#include "config.h"
#include "log.h"
#ifdef __WINDOWS__

View File

@@ -17,6 +17,8 @@
typedef int socket_t;
#endif
#include "config.h"
bool
net_init(void);

View File

@@ -6,6 +6,8 @@
#include <stddef.h>
#include <SDL2/SDL_assert.h>
#include "config.h"
// To define a queue type of "struct foo":
// struct queue_foo QUEUE(struct foo);
#define QUEUE(TYPE) { \

View File

@@ -5,6 +5,7 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
#include "net.h"
// receive events from the device

View File

@@ -3,8 +3,8 @@
#include <libavutil/time.h>
#include <SDL2/SDL_assert.h>
#include "compat.h"
#include "config.h"
#include "compat.h"
#include "lock_util.h"
#include "log.h"

View File

@@ -6,6 +6,7 @@
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
#include "common.h"
#include "queue.h"

View File

@@ -7,6 +7,7 @@
#include <sys/time.h>
#include <SDL2/SDL.h>
#include "config.h"
#include "command.h"
#include "common.h"
#include "compat.h"

View File

@@ -5,6 +5,8 @@
#include <stdint.h>
#include <recorder.h>
#include "config.h"
struct scrcpy_options {
const char *serial;
const char *crop;

View File

@@ -3,6 +3,7 @@
#include <string.h>
#include <SDL2/SDL.h>
#include "config.h"
#include "common.h"
#include "compat.h"
#include "icon.xpm"

View File

@@ -5,6 +5,7 @@
#include <SDL2/SDL.h>
#include <libavformat/avformat.h>
#include "config.h"
#include "common.h"
struct video_buffer;

View File

@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "config.h"
#include "command.h"
#include "net.h"

View File

@@ -10,6 +10,8 @@
#include <SDL2/SDL_stdinc.h>
#include "config.h"
size_t
xstrncpy(char *dest, const char *src, size_t n) {
size_t i;

View File

@@ -3,6 +3,8 @@
#include <stddef.h>
#include "config.h"
// like strncpy, except:
// - it copies at most n-1 chars
// - the dest string is nul-terminated

View File

@@ -8,8 +8,8 @@
#include <SDL2/SDL_thread.h>
#include <unistd.h>
#include "compat.h"
#include "config.h"
#include "compat.h"
#include "buffer_util.h"
#include "decoder.h"
#include "events.h"

View File

@@ -7,6 +7,7 @@
#include <SDL2/SDL_atomic.h>
#include <SDL2/SDL_thread.h>
#include "config.h"
#include "net.h"
struct video_buffer;

View File

@@ -7,6 +7,8 @@
#include "command.h"
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>

View File

@@ -2,6 +2,8 @@
#include <unistd.h>
#include "config.h"
bool
net_init(void) {
// do nothing

View File

@@ -1,5 +1,6 @@
#include "net.h"
#include "config.h"
#include "log.h"
bool

View File

@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "log.h"
struct index {

View File

@@ -3,6 +3,8 @@
#include <SDL2/SDL.h>
#include "config.h"
SDL_Surface *
read_xpm(char *xpm[]);

View File

@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <SDL2/SDL_mutex.h>
#include "config.h"
#include "fps_counter.h"
// forward declarations

View File

@@ -57,6 +57,9 @@ public class Controller {
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
coords.orientation = 0;
coords.size = 1;
touchPointerProperties[i] = props;
touchPointerCoords[i] = coords;
}
}
@@ -109,6 +112,9 @@ public class Controller {
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
injectMouse(msg.getAction(), msg.getButtons(), msg.getPosition());
break;
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
injectTouch(msg.getAction(), msg.getFingerId(), msg.getPosition(), msg.getPressure());
break;
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
break;
@@ -183,29 +189,45 @@ public class Controller {
return injectEvent(event);
}
private boolean injectTouch(int action, int fingerId, Position position, float pressure) {
private boolean injectTouch(int action, long fingerId, Position position, float pressure) {
long now = SystemClock.uptimeMillis();
if (action == MotionEvent.ACTION_DOWN) {
lastTouchDown = now;
}
Point point = device.getPhysicalPoint(position);
if (point == null) {
// ignore event
return false;
}
if (action == MotionEvent.ACTION_UP) {
if (!fingersState.unset(fingerId)) {
Ln.w("Unexpected ACTION_UP on unknown finger");
return false;
}
} else {
// ACTION_DOWN or ACTION_MOVE
if (!fingersState.set(fingerId, point, pressure)) {
Ln.w("Too many fingers for touch event");
return false;
}
int fingerIndex = fingersState.getFingerIndex(fingerId);
if (fingerIndex == -1) {
Ln.w("Too many fingers for touch event");
return false;
}
Finger finger = fingersState.get(fingerIndex);
finger.setPoint(point);
finger.setPressure(pressure);
finger.setUp(action == MotionEvent.ACTION_UP);
// FAIL: action_up will always remove the finger, and the event will not be written!
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
fingersState.cleanUp();
Ln.d("pointerCount = " + pointerCount);
for (int i = 0; i < pointerCount; ++i) {
Ln.d("props = " + touchPointerProperties[i].id);
Ln.d("coords = " + touchPointerCoords[i].x + "," + touchPointerCoords[i].y);
}
if (pointerCount > 1) {
if (action == MotionEvent.ACTION_UP) {
action = MotionEvent.ACTION_POINTER_UP | (fingerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
} else if (action == MotionEvent.ACTION_DOWN) {
action = MotionEvent.ACTION_POINTER_DOWN | (fingerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
}
} else if (action == MotionEvent.ACTION_DOWN) {
lastTouchDown = now;
}
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
return injectEvent(event);

View File

@@ -3,17 +3,24 @@ package com.genymobile.scrcpy;
public class Finger {
private final long id;
private final int localId;
private Point point;
private float pressure;
private boolean up;
public Finger(long id) {
public Finger(long id, int localId) {
this.id = id;
this.localId = localId;
}
public long getId() {
return id;
}
public int getLocalId() {
return localId;
}
public Point getPoint() {
return point;
}
@@ -29,4 +36,12 @@ public class Finger {
public void setPressure(float pressure) {
this.pressure = pressure;
}
public boolean isUp() {
return up;
}
public void setUp(boolean up) {
this.up = up;
}
}

View File

@@ -2,73 +2,70 @@ package com.genymobile.scrcpy;
import android.view.MotionEvent;
import java.util.ArrayList;
import java.util.List;
public class FingersState {
/**
* Array of enabled fingers (can contain "null" holes).
* <p>
* Once a Finger (identified by its id received from the client) is enabled, it is never moved.
* <p>
* Its index is its local identifier injected into MotionEvents.
*/
private final Finger[] fingers;
private final List<Finger> fingers = new ArrayList<>();
private int maxFingers;
public FingersState(int maxFingers) {
fingers = new Finger[maxFingers];
this.maxFingers = maxFingers;
}
private int indexOf(long id) {
for (int i = 0; i < fingers.length; ++i) {
Finger finger = fingers[i];
if (finger != null && finger.getId() == id) {
for (int i = 0; i < fingers.size(); ++i) {
Finger finger = fingers.get(i);
if (finger.getId() == id) {
return i;
}
}
return -1;
}
private int indexOfFirstEmpty() {
for (int i = 0; i < fingers.length; ++i) {
if (fingers[i] == null) {
return i;
private boolean isLocalIdAvailable(int localId) {
for (int i = 0; i < fingers.size(); ++i) {
Finger finger = fingers.get(i);
if (finger.getLocalId() == localId) {
return false;
}
}
return true;
}
private int nextUnusedLocalId() {
for (int localId = 0; localId < maxFingers; ++localId) {
if (isLocalIdAvailable(localId)) {
return localId;
}
}
return -1;
}
private Finger create(long id) {
public Finger get(int index) {
return fingers.get(index);
}
public int getFingerIndex(long id) {
int index = indexOf(id);
if (index != -1) {
// already exists, return it
return fingers[index];
return index;
}
int firstEmpty = indexOfFirstEmpty();
if (firstEmpty == -1) {
if (fingers.size() >= maxFingers) {
// it's full
return null;
return -1;
}
Finger finger = new Finger(id);
fingers[firstEmpty] = finger;
return finger;
}
public boolean unset(int id) {
int index = indexOf(id);
if (index == -1) {
return false;
// id 0 is reserved for mouse events
int localId = nextUnusedLocalId();
if (localId == -1) {
throw new AssertionError("fingers.size() < maxFingers implies that a local id is available");
}
fingers[index] = null;
return true;
}
public boolean set(int id, Point point, float pressure) {
Finger finger = create(id);
if (finger == null) {
return false;
}
finger.setPoint(point);
finger.setPressure(pressure);
return true;
Finger finger = new Finger(id, localId);
fingers.add(finger);
// return the index of the finger
return fingers.size() - 1;
}
/**
@@ -79,21 +76,26 @@ public class FingersState {
* @return The number of items initialized (the number of fingers).
*/
public int update(MotionEvent.PointerProperties[] props, MotionEvent.PointerCoords[] coords) {
int count = 0;
for (int i = 0; i < fingers.length; ++i) {
Finger finger = fingers[i];
if (finger != null) {
// id 0 is reserved for mouse events
props[count].id = i + 1;
for (int i = 0; i < fingers.size(); ++i) {
Finger finger = fingers.get(i);
Point point = finger.getPoint();
coords[i].x = point.getX();
coords[i].y = point.getY();
coords[i].pressure = finger.getPressure();
// id 0 is reserved for mouse events
props[i].id = finger.getLocalId();
++count;
Point point = finger.getPoint();
coords[i].x = point.getX();
coords[i].y = point.getY();
coords[i].pressure = finger.getPressure();
}
return fingers.size();
}
public void cleanUp() {
for (int i = fingers.size() - 1; i >= 0; --i) {
Finger finger = fingers.get(i);
if (finger.isUp()) {
fingers.remove(i);
}
}
return count;
}
}

View File

@@ -77,6 +77,7 @@ public class ControlMessageReaderTest {
}
@Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseMouseEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader();
@@ -105,6 +106,7 @@ public class ControlMessageReaderTest {
}
@Test
@SuppressWarnings("checkstyle:MagicNumber")
public void testParseTouchEvent() throws IOException {
ControlMessageReader reader = new ControlMessageReader();