Downscale and retry also on early MediaCodec error
The new retry mechanism with a lower definition only worked if the error occurred during encode(). For example: java.lang.IllegalStateException at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method) at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452) at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114) at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95) at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61) at com.genymobile.scrcpy.Server.scrcpy(Server.java:80) at com.genymobile.scrcpy.Server.main(Server.java:255) However, MediaCodec may also fail before encoding, during configure() or start(). For example: android.media.MediaCodec$CodecException: Error 0xfffffc0e at android.media.MediaCodec.native_configure(Native Method) at android.media.MediaCodec.configure(MediaCodec.java:1956) at android.media.MediaCodec.configure(MediaCodec.java:1885) at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158) at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68) at com.genymobile.scrcpy.Server.scrcpy(Server.java:28) at com.genymobile.scrcpy.Server.main(Server.java:110) Also downscale and retry in these cases. Refs #2947 <https://github.com/Genymobile/scrcpy/pull/2947> Refs #2988 <https://github.com/Genymobile/scrcpy/issues/2988> PR #2990 <https://github.com/Genymobile/scrcpy/pull/2990>
This commit is contained in:
parent
f02f2135cd
commit
c0a75ca746
1 changed files with 10 additions and 6 deletions
|
@ -89,13 +89,15 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
|
||||||
int videoRotation = screenInfo.getVideoRotation();
|
int videoRotation = screenInfo.getVideoRotation();
|
||||||
int layerStack = device.getLayerStack();
|
int layerStack = device.getLayerStack();
|
||||||
|
|
||||||
setSize(format, videoRect.width(), videoRect.height());
|
setSize(format, videoRect.width(), videoRect.height());
|
||||||
|
|
||||||
|
Surface surface = null;
|
||||||
|
try {
|
||||||
configure(codec, format);
|
configure(codec, format);
|
||||||
Surface surface = codec.createInputSurface();
|
surface = codec.createInputSurface();
|
||||||
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
|
||||||
codec.start();
|
codec.start();
|
||||||
try {
|
|
||||||
alive = encode(codec, fd);
|
alive = encode(codec, fd);
|
||||||
// do not call stop() on exception, it would trigger an IllegalStateException
|
// do not call stop() on exception, it would trigger an IllegalStateException
|
||||||
codec.stop();
|
codec.stop();
|
||||||
|
@ -119,8 +121,10 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
} finally {
|
} finally {
|
||||||
destroyDisplay(display);
|
destroyDisplay(display);
|
||||||
codec.release();
|
codec.release();
|
||||||
|
if (surface != null) {
|
||||||
surface.release();
|
surface.release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} while (alive);
|
} while (alive);
|
||||||
} finally {
|
} finally {
|
||||||
device.setRotationListener(null);
|
device.setRotationListener(null);
|
||||||
|
|
Loading…
Reference in a new issue