Keep the same display binder across sessions

Do not destroy/recreate the display when starting a new encoding session
(on device rotation for example).
This commit is contained in:
Romain Vimont 2023-01-27 22:26:01 +01:00
parent 74d32e612d
commit 75d7c01a0c

View file

@ -76,12 +76,12 @@ public class ScreenEncoder implements Device.RotationListener {
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
MediaFormat format = createFormat(bitRate, maxFps, codecOptions);
IBinder display = createDisplay();
device.setRotationListener(this);
boolean alive;
try {
do {
MediaCodec codec = createCodec(encoderName);
IBinder display = createDisplay();
ScreenInfo screenInfo = device.getScreenInfo();
Rect contentRect = screenInfo.getContentRect();
// include the locked video orientation
@ -120,7 +120,6 @@ public class ScreenEncoder implements Device.RotationListener {
device.setMaxSize(newMaxSize);
alive = true;
} finally {
destroyDisplay(display);
codec.release();
if (surface != null) {
surface.release();
@ -129,6 +128,7 @@ public class ScreenEncoder implements Device.RotationListener {
} while (alive);
} finally {
device.setRotationListener(null);
destroyDisplay(display);
}
}