mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-03-27 14:34:30 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2dc6a2e30c | ||
|
|
80233b7b72 | ||
|
|
60c882841f | ||
|
|
348c478359 | ||
|
|
c90247ffb6 | ||
|
|
f31010f4ee | ||
|
|
280891837e | ||
|
|
49b2e63d13 | ||
|
|
c12c64ed41 | ||
|
|
2f66acd75d | ||
|
|
1846d2f078 | ||
|
|
1a0139321b | ||
|
|
8890750681 | ||
|
|
aac9d5057f | ||
|
|
f705a73149 | ||
|
|
27a9bd3424 | ||
|
|
cf121a0f65 | ||
|
|
c8a5f9dc63 |
@@ -38,7 +38,8 @@ release: clean zip-win32 zip-win64 sums
|
||||
|
||||
clean:
|
||||
$(GRADLE) clean
|
||||
rm -rf "$(SERVER_BUILD_DIR)" "$(WIN32_BUILD_DIR)" "$(WIN64_BUILD_DIR)" "$(DIST)"
|
||||
rm -rf "$(SERVER_BUILD_DIR)" "$(WIN32_BUILD_DIR)" "$(WIN64_BUILD_DIR)" \
|
||||
"$(WIN32_NOCONSOLE_BUILD_DIR)" "$(WIN64_NOCONSOLE_BUILD_DIR)" "$(DIST)"
|
||||
|
||||
build-server:
|
||||
[ -d "$(SERVER_BUILD_DIR)" ] || ( mkdir "$(SERVER_BUILD_DIR)" && \
|
||||
@@ -54,6 +55,7 @@ build-win32: prepare-deps-win32
|
||||
meson "$(WIN32_BUILD_DIR)" \
|
||||
--cross-file cross_win32.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcrossbuild_windows=true \
|
||||
-Dbuild_server=false \
|
||||
-Doverride_server_path=scrcpy-server.jar )
|
||||
ninja -C "$(WIN32_BUILD_DIR)"
|
||||
@@ -63,6 +65,7 @@ build-win32-noconsole: prepare-deps-win32
|
||||
meson "$(WIN32_NOCONSOLE_BUILD_DIR)" \
|
||||
--cross-file cross_win32.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcrossbuild_windows=true \
|
||||
-Dbuild_server=false \
|
||||
-Dwindows_noconsole=true \
|
||||
-Doverride_server_path=scrcpy-server.jar )
|
||||
@@ -76,6 +79,7 @@ build-win64: prepare-deps-win64
|
||||
meson "$(WIN64_BUILD_DIR)" \
|
||||
--cross-file cross_win64.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcrossbuild_windows=true \
|
||||
-Dbuild_server=false \
|
||||
-Doverride_server_path=scrcpy-server.jar )
|
||||
ninja -C "$(WIN64_BUILD_DIR)"
|
||||
@@ -85,6 +89,7 @@ build-win64-noconsole: prepare-deps-win64
|
||||
meson "$(WIN64_NOCONSOLE_BUILD_DIR)" \
|
||||
--cross-file cross_win64.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcrossbuild_windows=true \
|
||||
-Dbuild_server=false \
|
||||
-Dwindows_noconsole=true \
|
||||
-Doverride_server_path=scrcpy-server.jar )
|
||||
|
||||
36
README.md
36
README.md
@@ -1,4 +1,4 @@
|
||||
# scrcpy
|
||||
# scrcpy (v1.2)
|
||||
|
||||
This application provides display and control of Android devices connected on
|
||||
USB (or [over TCP/IP][article-tcpip]). It does not require any _root_ access.
|
||||
@@ -14,12 +14,7 @@ The Android part requires at least API 21 (Android 5.0).
|
||||
You need [adb]. It is available in the [Android SDK platform
|
||||
tools][platform-tools], or packaged in your distribution (`android-adb-tools`).
|
||||
|
||||
On Windows, if you use the [prebuilt application](#windows), it is already
|
||||
included. Otherwise, just download the [platform-tools][platform-tools-windows]
|
||||
and extract the following files to a directory accessible from your `PATH`:
|
||||
- `adb.exe`
|
||||
- `AdbWinApi.dll`
|
||||
- `AdbWinUsbApi.dll`
|
||||
On Windows, just [download scrcpy for Windows](#windows), `adb` is included.
|
||||
|
||||
Make sure you [enabled adb debugging][enable-adb] on your device(s).
|
||||
|
||||
@@ -81,18 +76,25 @@ Two [AUR] packages have been created by users:
|
||||
|
||||
#### Windows
|
||||
|
||||
For Windows, for simplicity, a prebuilt archive with all the dependencies
|
||||
(including `adb`) is available:
|
||||
For Windows, for simplicity, prebuilt archives with all the dependencies
|
||||
(including `adb`) are available:
|
||||
|
||||
- [`scrcpy-windows-with-deps-v1.1.zip`][direct-windows-with-deps].
|
||||
_(SHA-256: 27eb36c15937601d1062c1dc0b45faae0e06fefea2019aadeb4fa7f76a07bb4c)_
|
||||
- [`scrcpy-win32-v1.2.zip`][direct-win32].
|
||||
_(SHA-256: a1fe1de67ec75dcf970ca5d97a04c26ff0f2d61871f2ef51b6f2f0bf666966b2)_
|
||||
- [`scrcpy-win64-v1.2.zip`][direct-win64].
|
||||
_(SHA-256: 35ae3bcee51771e7c51b8a8be87aef2295c9f267606a7cf83ebb0a4d583ef536)_
|
||||
|
||||
[direct-windows-with-deps]: https://github.com/Genymobile/scrcpy/releases/download/v1.1/scrcpy-windows-with-deps-v1.1.zip
|
||||
|
||||
_(It's just a portable version including _dll_ copied from MSYS2.)_
|
||||
[direct-win32]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-win32-v1.2.zip
|
||||
[direct-win64]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-win64-v1.2.zip
|
||||
|
||||
Instead, you may want to build it manually.
|
||||
|
||||
In that case, download the [platform-tools][platform-tools-windows] and extract
|
||||
the following files to a directory accessible from your `PATH`:
|
||||
- `adb.exe`
|
||||
- `AdbWinApi.dll`
|
||||
- `AdbWinUsbApi.dll`
|
||||
|
||||
##### Cross-compile from Linux
|
||||
|
||||
This is the preferred method (and the way the release is built).
|
||||
@@ -245,10 +247,10 @@ Since the server binary, that will be pushed to the Android device, does not
|
||||
depend on your system and architecture, you may want to use the prebuilt binary
|
||||
instead:
|
||||
|
||||
- [`scrcpy-server-v1.1.jar`][direct-scrcpy-server].
|
||||
_(SHA-256: 14826512bf38447ec94adf3b531676ce038d19e7e06757fb4e537882b17e77b3)_
|
||||
- [`scrcpy-server-v1.2.jar`][direct-scrcpy-server].
|
||||
_(SHA-256: cb39654ed2fda3d30ddff292806950ccc5c394375ea12b974f790c7f38f61f60)_
|
||||
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.1/scrcpy-server-v1.1.jar
|
||||
[direct-scrcpy-server]: https://github.com/Genymobile/scrcpy/releases/download/v1.2/scrcpy-server-v1.2.jar
|
||||
|
||||
In that case, the build does not require Java or the Android SDK.
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ src = [
|
||||
'src/tinyxpm.c',
|
||||
]
|
||||
|
||||
if not meson.is_cross_build()
|
||||
if not get_option('crossbuild_windows')
|
||||
|
||||
# native build
|
||||
dependencies = [
|
||||
|
||||
@@ -29,52 +29,58 @@ static struct point get_mouse_point(struct screen *screen) {
|
||||
};
|
||||
}
|
||||
|
||||
static void send_keycode(struct controller *controller, enum android_keycode keycode, const char *name) {
|
||||
static const int ACTION_DOWN = 1;
|
||||
static const int ACTION_UP = 1 << 1;
|
||||
|
||||
static void send_keycode(struct controller *controller, enum android_keycode keycode, int actions, const char *name) {
|
||||
// send DOWN event
|
||||
struct control_event control_event;
|
||||
control_event.type = CONTROL_EVENT_TYPE_KEYCODE;
|
||||
control_event.keycode_event.action = AKEY_EVENT_ACTION_DOWN;
|
||||
control_event.keycode_event.keycode = keycode;
|
||||
control_event.keycode_event.metastate = 0;
|
||||
|
||||
if (!controller_push_event(controller, &control_event)) {
|
||||
LOGW("Cannot send %s (DOWN)", name);
|
||||
return;
|
||||
if (actions & ACTION_DOWN) {
|
||||
control_event.keycode_event.action = AKEY_EVENT_ACTION_DOWN;
|
||||
if (!controller_push_event(controller, &control_event)) {
|
||||
LOGW("Cannot send %s (DOWN)", name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// send UP event
|
||||
control_event.keycode_event.action = AKEY_EVENT_ACTION_UP;
|
||||
if (!controller_push_event(controller, &control_event)) {
|
||||
LOGW("Cannot send %s (UP)", name);
|
||||
if (actions & ACTION_UP) {
|
||||
control_event.keycode_event.action = AKEY_EVENT_ACTION_UP;
|
||||
if (!controller_push_event(controller, &control_event)) {
|
||||
LOGW("Cannot send %s (UP)", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void action_home(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_HOME, "HOME");
|
||||
static inline void action_home(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_HOME, actions, "HOME");
|
||||
}
|
||||
|
||||
static inline void action_back(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_BACK, "BACK");
|
||||
static inline void action_back(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_BACK, actions, "BACK");
|
||||
}
|
||||
|
||||
static inline void action_app_switch(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_APP_SWITCH, "APP_SWITCH");
|
||||
static inline void action_app_switch(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_APP_SWITCH, actions, "APP_SWITCH");
|
||||
}
|
||||
|
||||
static inline void action_power(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_POWER, "POWER");
|
||||
static inline void action_power(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_POWER, actions, "POWER");
|
||||
}
|
||||
|
||||
static inline void action_volume_up(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_UP, "VOLUME_UP");
|
||||
static inline void action_volume_up(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_UP, actions, "VOLUME_UP");
|
||||
}
|
||||
|
||||
static inline void action_volume_down(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_DOWN, "VOLUME_DOWN");
|
||||
static inline void action_volume_down(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_VOLUME_DOWN, actions, "VOLUME_DOWN");
|
||||
}
|
||||
|
||||
static inline void action_menu(struct controller *controller) {
|
||||
send_keycode(controller, AKEYCODE_MENU, "MENU");
|
||||
static inline void action_menu(struct controller *controller, int actions) {
|
||||
send_keycode(controller, AKEYCODE_MENU, actions, "MENU");
|
||||
}
|
||||
|
||||
// turn the screen on if it was off, press BACK otherwise
|
||||
@@ -141,57 +147,74 @@ void input_manager_process_key(struct input_manager *input_manager,
|
||||
|
||||
// capture all Ctrl events
|
||||
if (ctrl) {
|
||||
SDL_bool repeat = event->repeat;
|
||||
|
||||
// only consider keydown events, and ignore repeated events
|
||||
if (repeat || event->type != SDL_KEYDOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT);
|
||||
if (shift) {
|
||||
// currently, there is no shortcut implying SHIFT
|
||||
// currently, there is no shortcut involving SHIFT
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Keycode keycode = event->keysym.sym;
|
||||
int action = event->type == SDL_KEYDOWN ? ACTION_DOWN : ACTION_UP;
|
||||
SDL_bool repeat = event->repeat;
|
||||
switch (keycode) {
|
||||
case SDLK_h:
|
||||
action_home(input_manager->controller);
|
||||
if (!repeat) {
|
||||
action_home(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_b: // fall-through
|
||||
case SDLK_BACKSPACE:
|
||||
action_back(input_manager->controller);
|
||||
if (!repeat) {
|
||||
action_back(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_s:
|
||||
action_app_switch(input_manager->controller);
|
||||
if (!repeat) {
|
||||
action_app_switch(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_m:
|
||||
action_menu(input_manager->controller);
|
||||
if (!repeat) {
|
||||
action_menu(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_p:
|
||||
action_power(input_manager->controller);
|
||||
if (!repeat) {
|
||||
action_power(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_DOWN:
|
||||
action_volume_down(input_manager->controller);
|
||||
// forward repeated events
|
||||
action_volume_down(input_manager->controller, action);
|
||||
return;
|
||||
case SDLK_UP:
|
||||
action_volume_up(input_manager->controller);
|
||||
// forward repeated events
|
||||
action_volume_up(input_manager->controller, action);
|
||||
return;
|
||||
case SDLK_v:
|
||||
clipboard_paste(input_manager->controller);
|
||||
if (!repeat && event->type == SDL_KEYDOWN) {
|
||||
clipboard_paste(input_manager->controller);
|
||||
}
|
||||
return;
|
||||
case SDLK_f:
|
||||
screen_switch_fullscreen(input_manager->screen);
|
||||
if (!repeat && event->type == SDL_KEYDOWN) {
|
||||
screen_switch_fullscreen(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_x:
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
if (!repeat && event->type == SDL_KEYDOWN) {
|
||||
screen_resize_to_fit(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_g:
|
||||
screen_resize_to_pixel_perfect(input_manager->screen);
|
||||
if (!repeat && event->type == SDL_KEYDOWN) {
|
||||
screen_resize_to_pixel_perfect(input_manager->screen);
|
||||
}
|
||||
return;
|
||||
case SDLK_i:
|
||||
switch_fps_counter_state(input_manager->frames);
|
||||
if (!repeat && event->type == SDL_KEYDOWN) {
|
||||
switch_fps_counter_state(input_manager->frames);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -228,7 +251,7 @@ void input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||
return;
|
||||
}
|
||||
if (event->button == SDL_BUTTON_MIDDLE) {
|
||||
action_home(input_manager->controller);
|
||||
action_home(input_manager->controller, ACTION_DOWN | ACTION_UP);
|
||||
return;
|
||||
}
|
||||
// double-click on black borders resize to fit the device screen
|
||||
|
||||
@@ -79,6 +79,8 @@ SDL_bool installer_init(struct installer *installer, const char *serial) {
|
||||
installer->initialized = SDL_FALSE;
|
||||
|
||||
installer->stopped = SDL_FALSE;
|
||||
installer->current_process = PROCESS_NONE;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "command.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include "log.h"
|
||||
|
||||
pid_t cmd_execute(const char *path, const char *const argv[]) {
|
||||
pid_t pid = fork();
|
||||
@@ -20,6 +22,10 @@ pid_t cmd_execute(const char *path, const char *const argv[]) {
|
||||
}
|
||||
|
||||
SDL_bool cmd_terminate(pid_t pid) {
|
||||
if (pid <= 0) {
|
||||
LOGC("Requested to kill %d, this is an error. Please report the bug.\n", (int) pid);
|
||||
abort();
|
||||
}
|
||||
return kill(pid, SIGTERM) != -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
classpath 'com.android.tools.build:gradle:3.1.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Jan 29 16:38:49 CET 2018
|
||||
#Mon Jun 04 11:48:32 CEST 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
project('scrcpy', 'c', meson_version: '>= 0.37')
|
||||
project('scrcpy', 'c', meson_version: '>= 0.37', default_options : 'c_std=c99')
|
||||
|
||||
if get_option('build_app')
|
||||
subdir('app')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
option('build_app', type: 'boolean', value: true, description: 'Build the client')
|
||||
option('build_server', type: 'boolean', value: true, description: 'Build the server')
|
||||
option('crossbuild_windows', type: 'boolean', value: false, description: 'Build for Windows from Linux')
|
||||
option('windows_noconsole', type: 'boolean', value: false, description: 'Disable console on Windows (pass -mwindows flag)')
|
||||
option('prebuilt_server', type: 'string', description: 'Path of the prebuilt server')
|
||||
option('override_server_path', type: 'string', description: 'Hardcoded path to find the server at runtime')
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genymobile.scrcpy;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.view.IRotationWatcher;
|
||||
@@ -18,14 +19,32 @@ public final class Device {
|
||||
|
||||
private ScreenInfo screenInfo;
|
||||
private RotationListener rotationListener;
|
||||
private boolean rotated;
|
||||
|
||||
public Device(Options options) {
|
||||
screenInfo = computeScreenInfo(options.getMaxSize());
|
||||
options.setCrop(new Rect(0, 0, 1280, 1440));
|
||||
|
||||
// TODO crop the crop to the device size!!!
|
||||
|
||||
final int maxSize = options.getMaxSize();
|
||||
final Rect crop = options.getCrop();
|
||||
|
||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
||||
rotated = (displayInfo.getRotation() & 1) != 0;
|
||||
|
||||
screenInfo = ScreenInfo.create(displayInfo.getSize(), maxSize, crop, rotated);
|
||||
registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) throws RemoteException {
|
||||
public void onRotationChanged(int rotation) {
|
||||
boolean rotated = (rotation & 1) != 0;
|
||||
synchronized (Device.this) {
|
||||
screenInfo = screenInfo.withRotation(rotation);
|
||||
// Do not call getDisplayInfo(), the resulting rotation may be inconsistent with
|
||||
// the rotation parameter (race condition).
|
||||
// Instead, compute the new size from the (rotated) old size.
|
||||
Size oldSize = screenInfo.getDeviceSize();
|
||||
Size newSize = rotated != Device.this.rotated ? oldSize.rotate() : oldSize;
|
||||
screenInfo = ScreenInfo.create(newSize, maxSize, crop, rotated);
|
||||
Device.this.rotated = rotated;
|
||||
|
||||
// notify
|
||||
if (rotationListener != null) {
|
||||
@@ -40,40 +59,9 @@ public final class Device {
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private ScreenInfo computeScreenInfo(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;
|
||||
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
|
||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
||||
boolean rotated = (displayInfo.getRotation() & 1) != 0;
|
||||
Size deviceSize = displayInfo.getSize();
|
||||
int w = deviceSize.getWidth() & ~7; // in case it's not a multiple of 8
|
||||
int h = deviceSize.getHeight() & ~7;
|
||||
if (maxSize > 0) {
|
||||
if (BuildConfig.DEBUG && maxSize % 8 != 0) {
|
||||
throw new AssertionError("Max size must be a multiple of 8");
|
||||
}
|
||||
boolean portrait = h > w;
|
||||
int major = portrait ? h : w;
|
||||
int minor = portrait ? w : h;
|
||||
if (major > maxSize) {
|
||||
int minorExact = minor * maxSize / major;
|
||||
// +4 to round the value to the nearest multiple of 8
|
||||
minor = (minorExact + 4) & ~7;
|
||||
major = maxSize;
|
||||
}
|
||||
w = portrait ? minor : major;
|
||||
h = portrait ? major : minor;
|
||||
}
|
||||
Size videoSize = new Size(w, h);
|
||||
return new ScreenInfo(deviceSize, videoSize, rotated);
|
||||
}
|
||||
|
||||
public Point getPhysicalPoint(Position position) {
|
||||
@SuppressWarnings("checkstyle:HiddenField") // it hides the field on purpose, to read it with a lock
|
||||
// it hides the field on purpose, to read it with a lock
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
ScreenInfo screenInfo = getScreenInfo(); // read with synchronization
|
||||
Size videoSize = screenInfo.getVideoSize();
|
||||
Size clientVideoSize = position.getScreenSize();
|
||||
@@ -82,11 +70,11 @@ public final class Device {
|
||||
// the device may have been rotated since the event was generated, so ignore the event
|
||||
return null;
|
||||
}
|
||||
Size deviceSize = screenInfo.getDeviceSize();
|
||||
Rect contentRect = screenInfo.getContentRect();
|
||||
Point point = position.getPoint();
|
||||
int scaledX = point.x * deviceSize.getWidth() / videoSize.getWidth();
|
||||
int scaledY = point.y * deviceSize.getHeight() / videoSize.getHeight();
|
||||
return new Point(scaledX, scaledY);
|
||||
int deviceX = contentRect.left + point.x * contentRect.width() / videoSize.getWidth();
|
||||
int deviceY = contentRect.top + point.y * contentRect.height() / videoSize.getHeight();
|
||||
return new Point(deviceX, deviceY);
|
||||
}
|
||||
|
||||
public static String getDeviceName() {
|
||||
|
||||
@@ -16,5 +16,16 @@ public final class DisplayInfo {
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public DisplayInfo withRotation(int rotation) {
|
||||
if (rotation == this.rotation) {
|
||||
return this;
|
||||
}
|
||||
Size newSize = size;
|
||||
if ((rotation & 1) != (this.rotation & 1)) {
|
||||
newSize = size.rotate();
|
||||
}
|
||||
return new DisplayInfo(newSize, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class Options {
|
||||
private int maxSize;
|
||||
private int bitRate;
|
||||
private boolean tunnelForward;
|
||||
private Rect crop;
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
@@ -28,4 +31,12 @@ public class Options {
|
||||
public void setTunnelForward(boolean tunnelForward) {
|
||||
this.tunnelForward = tunnelForward;
|
||||
}
|
||||
|
||||
public Rect getCrop() {
|
||||
return crop;
|
||||
}
|
||||
|
||||
public void setCrop(Rect crop) {
|
||||
this.crop = crop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||
do {
|
||||
MediaCodec codec = createCodec();
|
||||
IBinder display = createDisplay();
|
||||
Rect deviceRect = device.getScreenInfo().getDeviceSize().toRect();
|
||||
Rect contentRect = device.getScreenInfo().getContentRect();
|
||||
Rect videoRect = device.getScreenInfo().getVideoSize().toRect();
|
||||
setSize(format, videoRect.width(), videoRect.height());
|
||||
configure(codec, format);
|
||||
Surface surface = codec.createInputSurface();
|
||||
setDisplaySurface(display, surface, deviceRect, videoRect);
|
||||
setDisplaySurface(display, surface, contentRect, videoRect);
|
||||
codec.start();
|
||||
try {
|
||||
alive = encode(codec, outputStream);
|
||||
|
||||
@@ -1,14 +1,60 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
public final class ScreenInfo {
|
||||
private final Size deviceSize;
|
||||
private final Size videoSize;
|
||||
private final boolean rotated;
|
||||
private final Rect crop;
|
||||
|
||||
public ScreenInfo(Size deviceSize, Size videoSize, boolean rotated) {
|
||||
private ScreenInfo(Size deviceSize, Size videoSize, Rect crop, boolean rotated) {
|
||||
this.deviceSize = deviceSize;
|
||||
this.videoSize = videoSize;
|
||||
this.rotated = rotated;
|
||||
this.crop = crop;
|
||||
}
|
||||
|
||||
public static ScreenInfo create(Size deviceSize, int maxSize, Rect crop, boolean rotated) {
|
||||
Size inputSize;
|
||||
if (crop == null) {
|
||||
inputSize = deviceSize;
|
||||
} else {
|
||||
if (rotated) {
|
||||
// the crop (provided by the user) is expressed in the natural orientation
|
||||
// the device size (provided by the system) already takes the rotation into account
|
||||
crop = rotateCrop(crop, deviceSize);
|
||||
}
|
||||
inputSize = new Size(crop.width(), crop.height());
|
||||
}
|
||||
Size videoSize = computeVideoSize(inputSize, maxSize);
|
||||
return new ScreenInfo(deviceSize, videoSize, crop, rotated);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private static Size computeVideoSize(Size inputSize, 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;
|
||||
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
|
||||
int w = inputSize.getWidth() & ~7; // in case it's not a multiple of 8
|
||||
int h = inputSize.getHeight() & ~7;
|
||||
if (maxSize > 0) {
|
||||
if (BuildConfig.DEBUG && maxSize % 8 != 0) {
|
||||
throw new AssertionError("Max size must be a multiple of 8");
|
||||
}
|
||||
boolean portrait = h > w;
|
||||
int major = portrait ? h : w;
|
||||
int minor = portrait ? w : h;
|
||||
if (major > maxSize) {
|
||||
int minorExact = minor * maxSize / major;
|
||||
// +4 to round the value to the nearest multiple of 8
|
||||
minor = (minorExact + 4) & ~7;
|
||||
major = maxSize;
|
||||
}
|
||||
w = portrait ? minor : major;
|
||||
h = portrait ? major : minor;
|
||||
}
|
||||
return new Size(w, h);
|
||||
}
|
||||
|
||||
public Size getDeviceSize() {
|
||||
@@ -19,11 +65,17 @@ public final class ScreenInfo {
|
||||
return videoSize;
|
||||
}
|
||||
|
||||
public ScreenInfo withRotation(int rotation) {
|
||||
boolean newRotated = (rotation & 1) != 0;
|
||||
if (rotated == newRotated) {
|
||||
return this;
|
||||
}
|
||||
return new ScreenInfo(deviceSize.rotate(), videoSize.rotate(), newRotated);
|
||||
public Rect getCrop() {
|
||||
return crop;
|
||||
}
|
||||
|
||||
public Rect getContentRect() {
|
||||
Rect crop = getCrop();
|
||||
return crop != null ? crop : deviceSize.toRect();
|
||||
}
|
||||
|
||||
private static Rect rotateCrop(Rect crop, Size rotatedSize) {
|
||||
int w = rotatedSize.getHeight(); // the size is already rotated
|
||||
return new Rect(crop.top, w - crop.right, crop.bottom, w - crop.left);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user