2017-12-12 15:12:07 +01:00
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
public class ScrCpyServer {
|
|
|
|
|
|
2018-01-04 14:49:21 +01:00
|
|
|
private static final String TAG = "scrcpy";
|
|
|
|
|
|
2017-12-14 11:38:44 +01:00
|
|
|
private static void scrcpy() throws IOException {
|
2017-12-12 15:06:49 +01:00
|
|
|
String deviceName = DeviceUtil.getDeviceName();
|
|
|
|
|
ScreenInfo initialScreenInfo = DeviceUtil.getScreenInfo();
|
2017-12-12 15:12:07 +01:00
|
|
|
int width = initialScreenInfo.getLogicalWidth();
|
|
|
|
|
int height = initialScreenInfo.getLogicalHeight();
|
2017-12-12 15:06:49 +01:00
|
|
|
try (DesktopConnection connection = DesktopConnection.open(deviceName, width, height)) {
|
2017-12-12 15:12:07 +01:00
|
|
|
try {
|
2017-12-14 11:38:44 +01:00
|
|
|
// asynchronous
|
|
|
|
|
startEventController(connection);
|
|
|
|
|
// synchronous
|
2017-12-12 15:12:07 +01:00
|
|
|
new ScreenStreamer(connection).streamScreen();
|
|
|
|
|
} catch (IOException e) {
|
2018-01-04 14:49:21 +01:00
|
|
|
Ln.e("Screen streaming interrupted", e);
|
2017-12-12 15:12:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 11:38:44 +01:00
|
|
|
private static void startEventController(final DesktopConnection connection) {
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
new EventController(connection).control();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 15:12:07 +01:00
|
|
|
public static void main(String... args) throws Exception {
|
|
|
|
|
try {
|
|
|
|
|
scrcpy();
|
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
t.printStackTrace();
|
|
|
|
|
throw t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|