From a3871130cc540e1391e6576ae55fd0a5902e4b07 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 16 Mar 2023 20:18:52 +0100 Subject: [PATCH] List available encoders on failure When the creation of an encoder fails, log an explicit error message with the list of available encoders. --- .../com/genymobile/scrcpy/AudioEncoder.java | 17 +++++++++++++---- .../com/genymobile/scrcpy/ScreenEncoder.java | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java index d3459831..f2bba772 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioEncoder.java @@ -271,13 +271,22 @@ public final class AudioEncoder implements AsyncProcessor { try { return MediaCodec.createByCodecName(encoderName); } catch (IllegalArgumentException e) { - Ln.e("Encoder '" + encoderName + "' for " + codec.getName() + " not found\n" + LogUtils.buildAudioEncoderListMessage()); + Ln.e("Audio encoder '" + encoderName + "' for " + codec.getName() + " not found\n" + LogUtils.buildAudioEncoderListMessage()); throw new ConfigurationException("Unknown encoder: " + encoderName); + } catch (IOException e) { + Ln.e("Could not create audio encoder '" + encoderName + "' for " + codec.getName() + "\n" + LogUtils.buildAudioEncoderListMessage()); + throw e; } } - MediaCodec mediaCodec = MediaCodec.createEncoderByType(codec.getMimeType()); - Ln.d("Using audio encoder: '" + mediaCodec.getName() + "'"); - return mediaCodec; + + try { + MediaCodec mediaCodec = MediaCodec.createEncoderByType(codec.getMimeType()); + Ln.d("Using audio encoder: '" + mediaCodec.getName() + "'"); + return mediaCodec; + } catch (IOException | IllegalArgumentException e) { + Ln.e("Could not create default audio encoder for " + codec.getName() + "\n" + LogUtils.buildAudioEncoderListMessage()); + throw e; + } } private class EncoderCallback extends MediaCodec.Callback { diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index 015cc993..528cd327 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -202,13 +202,22 @@ public class ScreenEncoder implements Device.RotationListener { try { return MediaCodec.createByCodecName(encoderName); } catch (IllegalArgumentException e) { - Ln.e("Encoder '" + encoderName + "' for " + codec.getName() + " not found\n" + LogUtils.buildVideoEncoderListMessage()); + Ln.e("Video encoder '" + encoderName + "' for " + codec.getName() + " not found\n" + LogUtils.buildVideoEncoderListMessage()); throw new ConfigurationException("Unknown encoder: " + encoderName); + } catch (IOException e) { + Ln.e("Could not create video encoder '" + encoderName + "' for " + codec.getName() + "\n" + LogUtils.buildVideoEncoderListMessage()); + throw e; } } - MediaCodec mediaCodec = MediaCodec.createEncoderByType(codec.getMimeType()); - Ln.d("Using encoder: '" + mediaCodec.getName() + "'"); - return mediaCodec; + + try { + MediaCodec mediaCodec = MediaCodec.createEncoderByType(codec.getMimeType()); + Ln.d("Using video encoder: '" + mediaCodec.getName() + "'"); + return mediaCodec; + } catch (IOException | IllegalArgumentException e) { + Ln.e("Could not create default video encoder for " + codec.getName() + "\n" + LogUtils.buildVideoEncoderListMessage()); + throw e; + } } private static MediaFormat createFormat(String videoMimeType, int bitRate, int maxFps, List codecOptions) {