Handle camera disconnection
Stop mirroring on camera disconnection. PR #4213 <https://github.com/Genymobile/scrcpy/pull/4213>
This commit is contained in:
parent
d544e577c0
commit
64930e71b9
@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class CameraCapture extends SurfaceCapture {
|
public class CameraCapture extends SurfaceCapture {
|
||||||
|
|
||||||
@ -33,6 +34,8 @@ public class CameraCapture extends SurfaceCapture {
|
|||||||
private CameraDevice cameraDevice;
|
private CameraDevice cameraDevice;
|
||||||
private Executor cameraExecutor;
|
private Executor cameraExecutor;
|
||||||
|
|
||||||
|
private final AtomicBoolean disconnected = new AtomicBoolean();
|
||||||
|
|
||||||
public CameraCapture(String explicitCameraId, Size explicitSize) {
|
public CameraCapture(String explicitCameraId, Size explicitSize) {
|
||||||
this.explicitCameraId = explicitCameraId;
|
this.explicitCameraId = explicitCameraId;
|
||||||
this.explicitSize = explicitSize;
|
this.explicitSize = explicitSize;
|
||||||
@ -97,7 +100,8 @@ public class CameraCapture extends SurfaceCapture {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisconnected(CameraDevice camera) {
|
public void onDisconnected(CameraDevice camera) {
|
||||||
Ln.w("Camera disconnected");
|
Ln.w("Camera disconnected");
|
||||||
// TODO
|
disconnected.set(true);
|
||||||
|
requestReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -177,4 +181,9 @@ public class CameraCapture extends SurfaceCapture {
|
|||||||
}
|
}
|
||||||
}, cameraHandler);
|
}, cameraHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return disconnected.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,13 @@ public abstract class SurfaceCapture {
|
|||||||
* @param maxSize Maximum size
|
* @param maxSize Maximum size
|
||||||
*/
|
*/
|
||||||
public abstract boolean setMaxSize(int maxSize);
|
public abstract boolean setMaxSize(int maxSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate if the capture has been closed internally.
|
||||||
|
*
|
||||||
|
* @return {@code true} is the capture is closed, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isClosed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,11 @@ public class SurfaceEncoder implements AsyncProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (capture.isClosed()) {
|
||||||
|
// The capture might have been closed internally (for example if the camera is disconnected)
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
|
|
||||||
return !eof && alive;
|
return !eof && alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user