Skip to content

Commit

Permalink
Pass all args to ScreenEncoder constructor
Browse files Browse the repository at this point in the history
There is no good reason to pass some of them in the constructor and some
others as parameters of the streamScreen() method.
  • Loading branch information
rom1v committed Mar 3, 2023
1 parent 7853c4c commit af1f00b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class ScreenEncoder implements Device.RotationListener {

private final AtomicBoolean rotationChanged = new AtomicBoolean();

private final String videoMimeType;
private final Device device;
private final VideoStreamer streamer;
private final String encoderName;
private final List<CodecOption> codecOptions;
private final int bitRate;
Expand All @@ -41,8 +42,10 @@ public class ScreenEncoder implements Device.RotationListener {
private boolean firstFrameSent;
private int consecutiveErrors;

public ScreenEncoder(String videoMimeType, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName, boolean downsizeOnError) {
this.videoMimeType = videoMimeType;
public ScreenEncoder(Device device, VideoStreamer streamer, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
boolean downsizeOnError) {
this.device = device;
this.streamer = streamer;
this.bitRate = bitRate;
this.maxFps = maxFps;
this.codecOptions = codecOptions;
Expand All @@ -59,7 +62,8 @@ public boolean consumeRotationChange() {
return rotationChanged.getAndSet(false);
}

public void streamScreen(Device device, VideoStreamer streamer) throws IOException, ConfigurationException {
public void streamScreen() throws IOException, ConfigurationException {
String videoMimeType = streamer.getCodec().getMimeType();
MediaCodec codec = createCodec(videoMimeType, encoderName);
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
IBinder display = createDisplay();
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
}

VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), codec, options.getSendCodecId(), options.getSendFrameMeta());
ScreenEncoder screenEncoder = new ScreenEncoder(codec.getMimeType(), options.getBitRate(), options.getMaxFps(), codecOptions,
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getBitRate(), options.getMaxFps(), codecOptions,
options.getEncoderName(), options.getDownsizeOnError());
try {
// synchronous
screenEncoder.streamScreen(device, videoStreamer);
screenEncoder.streamScreen();
} catch (IOException e) {
// Broken pipe is expected on close, because the socket is closed by the client
if (!IO.isBrokenPipe(e)) {
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/VideoStreamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public VideoStreamer(FileDescriptor fd, VideoCodec codec, boolean sendCodecId, b
this.sendFrameMeta = sendFrameMeta;
}

public VideoCodec getCodec() {
return codec;
}

public void writeHeader() throws IOException {
if (sendCodecId) {
ByteBuffer buffer = ByteBuffer.allocate(4);
Expand Down

0 comments on commit af1f00b

Please sign in to comment.