Skip to content

Commit

Permalink
Downsize on error only before the first frame
Browse files Browse the repository at this point in the history
The purpose of automatic downscaling on error is to make mirroring work
by just starting scrcpy without an explicit -m value, even if the
encoder could not encode at the screen definition.

It is only useful when we detect an encoding failure before the first
frame. Downsizing later could be surprising, so disable it.

PR #2947 <#2947>
  • Loading branch information
rom1v committed Jan 21, 2022
1 parent 3a0ba7d commit 2eb6fe7
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class ScreenEncoder implements Device.RotationListener {
private final boolean downsizeOnError;
private long ptsOrigin;

private boolean firstFrameSent;

public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
boolean downsizeOnError) {
this.sendFrameMeta = sendFrameMeta;
Expand Down Expand Up @@ -99,7 +101,7 @@ private void internalStreamScreen(Device device, FileDescriptor fd) throws IOExc
codec.stop();
} catch (Exception e) {
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
if (!downsizeOnError) {
if (!downsizeOnError || firstFrameSent) {
// Fail immediately
throw e;
}
Expand Down Expand Up @@ -157,6 +159,7 @@ private boolean encode(MediaCodec codec, FileDescriptor fd) throws IOException {
}

IO.writeFully(fd, codecBuffer);
firstFrameSent = true;
}
} finally {
if (outputBufferId >= 0) {
Expand Down

0 comments on commit 2eb6fe7

Please sign in to comment.