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.
scrcpy/server/src/main/java/com/genymobile/scrcpy/ScreenStreamer.java

40 lines
1.3 KiB
Java

package com.genymobile.scrcpy;
import java.io.IOException;
import java.io.InterruptedIOException;
public class ScreenStreamer {
private final Device device;
private final DesktopConnection connection;
private ScreenStreamerSession currentStreamer; // protected by 'this'
public ScreenStreamer(Device device, DesktopConnection connection) {
this.device = device;
this.connection = connection;
}
private synchronized ScreenStreamerSession newScreenStreamerSession() {
currentStreamer = new ScreenStreamerSession(device, connection);
return currentStreamer;
}
public void streamScreen() throws IOException {
while (true) {
try {
ScreenStreamerSession screenStreamer = newScreenStreamerSession();
screenStreamer.streamScreen();
} catch (InterruptedIOException e) {
// the current screenrecord process has probably been killed due to reset(), start a new one without failing
}
}
}
public synchronized void reset() {
if (currentStreamer != null) {
// it will stop the blocking call to streamScreen(), so a new streamer will be started
currentStreamer.stop();
}
}
}