Skip to content

Commit

Permalink
Improve error message for unknown encoder
Browse files Browse the repository at this point in the history
The provided encoder name depends on the selected codec. Improve the
error message and the suggestions.

PR #3757 <#3757>
  • Loading branch information
rom1v committed Mar 3, 2023
1 parent 883a998 commit e068fe4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public boolean consumeRotationChange() {
}

public void streamScreen() throws IOException, ConfigurationException {
String videoMimeType = streamer.getCodec().getMimeType();
MediaCodec mediaCodec = createMediaCodec(videoMimeType, encoderName);
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
Codec codec = streamer.getCodec();
MediaCodec mediaCodec = createMediaCodec(codec, encoderName);
MediaFormat format = createFormat(codec.getMimeType(), bitRate, maxFps, codecOptions);
IBinder display = createDisplay();
device.setRotationListener(this);

Expand Down Expand Up @@ -210,28 +210,28 @@ private static MediaCodecInfo[] listEncoders(String videoMimeType) {
return result.toArray(new MediaCodecInfo[result.size()]);
}

private static MediaCodec createMediaCodec(String videoMimeType, String encoderName) throws IOException, ConfigurationException {
private static MediaCodec createMediaCodec(Codec codec, String encoderName) throws IOException, ConfigurationException {
if (encoderName != null) {
Ln.d("Creating encoder by name: '" + encoderName + "'");
try {
return MediaCodec.createByCodecName(encoderName);
} catch (IllegalArgumentException e) {
Ln.e(buildUnknownEncoderMessage(videoMimeType, encoderName));
Ln.e(buildUnknownEncoderMessage(codec, encoderName));
throw new ConfigurationException("Unknown encoder: " + encoderName);
}
}
MediaCodec mediaCodec = MediaCodec.createEncoderByType(videoMimeType);
MediaCodec mediaCodec = MediaCodec.createEncoderByType(codec.getMimeType());
Ln.d("Using encoder: '" + mediaCodec.getName() + "'");
return mediaCodec;
}

private static String buildUnknownEncoderMessage(String videoMimeType, String encoderName) {
StringBuilder msg = new StringBuilder("Encoder '").append(encoderName).append("' not found");
MediaCodecInfo[] encoders = listEncoders(videoMimeType);
private static String buildUnknownEncoderMessage(Codec codec, String encoderName) {
StringBuilder msg = new StringBuilder("Encoder '").append(encoderName).append("' for ").append(codec.getName()).append(" not found");
MediaCodecInfo[] encoders = listEncoders(codec.getMimeType());
if (encoders != null && encoders.length > 0) {
msg.append("\nTry to use one of the available encoders:");
for (MediaCodecInfo encoder : encoders) {
msg.append("\n scrcpy --encoder='").append(encoder.getName()).append("'");
msg.append("\n scrcpy --codec=").append(codec.getName()).append(" --encoder='").append(encoder.getName()).append("'");
}
}
return msg.toString();
Expand Down

0 comments on commit e068fe4

Please sign in to comment.