Skip to content

Commit af1f00b

Browse files
committed
Pass all args to ScreenEncoder constructor
There is no good reason to pass some of them in the constructor and some others as parameters of the streamScreen() method.
1 parent 7853c4c commit af1f00b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class ScreenEncoder implements Device.RotationListener {
3131

3232
private final AtomicBoolean rotationChanged = new AtomicBoolean();
3333

34-
private final String videoMimeType;
34+
private final Device device;
35+
private final VideoStreamer streamer;
3536
private final String encoderName;
3637
private final List<CodecOption> codecOptions;
3738
private final int bitRate;
@@ -41,8 +42,10 @@ public class ScreenEncoder implements Device.RotationListener {
4142
private boolean firstFrameSent;
4243
private int consecutiveErrors;
4344

44-
public ScreenEncoder(String videoMimeType, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName, boolean downsizeOnError) {
45-
this.videoMimeType = videoMimeType;
45+
public ScreenEncoder(Device device, VideoStreamer streamer, int bitRate, int maxFps, List<CodecOption> codecOptions, String encoderName,
46+
boolean downsizeOnError) {
47+
this.device = device;
48+
this.streamer = streamer;
4649
this.bitRate = bitRate;
4750
this.maxFps = maxFps;
4851
this.codecOptions = codecOptions;
@@ -59,7 +62,8 @@ public boolean consumeRotationChange() {
5962
return rotationChanged.getAndSet(false);
6063
}
6164

62-
public void streamScreen(Device device, VideoStreamer streamer) throws IOException, ConfigurationException {
65+
public void streamScreen() throws IOException, ConfigurationException {
66+
String videoMimeType = streamer.getCodec().getMimeType();
6367
MediaCodec codec = createCodec(videoMimeType, encoderName);
6468
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
6569
IBinder display = createDisplay();

server/src/main/java/com/genymobile/scrcpy/Server.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ private static void scrcpy(Options options) throws IOException, ConfigurationExc
101101
}
102102

103103
VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), codec, options.getSendCodecId(), options.getSendFrameMeta());
104-
ScreenEncoder screenEncoder = new ScreenEncoder(codec.getMimeType(), options.getBitRate(), options.getMaxFps(), codecOptions,
104+
ScreenEncoder screenEncoder = new ScreenEncoder(device, videoStreamer, options.getBitRate(), options.getMaxFps(), codecOptions,
105105
options.getEncoderName(), options.getDownsizeOnError());
106106
try {
107107
// synchronous
108-
screenEncoder.streamScreen(device, videoStreamer);
108+
screenEncoder.streamScreen();
109109
} catch (IOException e) {
110110
// Broken pipe is expected on close, because the socket is closed by the client
111111
if (!IO.isBrokenPipe(e)) {

server/src/main/java/com/genymobile/scrcpy/VideoStreamer.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public VideoStreamer(FileDescriptor fd, VideoCodec codec, boolean sendCodecId, b
2525
this.sendFrameMeta = sendFrameMeta;
2626
}
2727

28+
public VideoCodec getCodec() {
29+
return codec;
30+
}
31+
2832
public void writeHeader() throws IOException {
2933
if (sendCodecId) {
3034
ByteBuffer buffer = ByteBuffer.allocate(4);

0 commit comments

Comments
 (0)