mirror of https://github.com/Genymobile/scrcpy
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
Java
59 lines
1.8 KiB
Java
package com.genymobile.scrcpy;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class ScrCpyServer {
|
|
|
|
private static final String TAG = "scrcpy";
|
|
|
|
private static void scrcpy(Options options) throws IOException {
|
|
final Device device = new Device(options);
|
|
try (DesktopConnection connection = DesktopConnection.open(device)) {
|
|
final ScreenStreamer streamer = new ScreenStreamer(device, connection);
|
|
device.setRotationListener(new Device.RotationListener() {
|
|
@Override
|
|
public void onRotationChanged(int rotation) {
|
|
streamer.reset();
|
|
}
|
|
});
|
|
|
|
// asynchronous
|
|
startEventController(device, connection);
|
|
|
|
try {
|
|
// synchronous
|
|
streamer.streamScreen();
|
|
} catch (IOException e) {
|
|
Ln.e("Screen streaming interrupted", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void startEventController(final Device device, final DesktopConnection connection) {
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
new EventController(device, connection).control();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
public static void main(String... args) throws Exception {
|
|
Options options = new Options();
|
|
if (args.length > 0) {
|
|
int maximumSize = Integer.parseInt(args[0]) & ~7; // multiple of 8
|
|
options.setMaximumSize(maximumSize);
|
|
}
|
|
try {
|
|
scrcpy(options);
|
|
} catch (Throwable t) {
|
|
t.printStackTrace();
|
|
throw t;
|
|
}
|
|
}
|
|
}
|