mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 04:25:01 +00:00
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.
This commit is contained in:
parent
46759d3f63
commit
a52b1f025d
3 changed files with 14 additions and 6 deletions
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -59,7 +62,8 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
return rotationChanged.getAndSet(false);
|
||||
}
|
||||
|
||||
public void streamScreen(Device device, VideoStreamer streamer) throws IOException {
|
||||
public void streamScreen() throws IOException {
|
||||
String videoMimeType = streamer.getCodec().getMimeType();
|
||||
MediaCodec codec = createCodec(videoMimeType, encoderName);
|
||||
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
|
||||
IBinder display = createDisplay();
|
||||
|
|
|
@ -101,11 +101,11 @@ public final class Server {
|
|||
}
|
||||
|
||||
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) {
|
||||
// this is expected on close
|
||||
} finally {
|
||||
|
|
|
@ -25,6 +25,10 @@ public final class VideoStreamer {
|
|||
this.sendFrameMeta = sendFrameMeta;
|
||||
}
|
||||
|
||||
public VideoCodec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
|
||||
public void writeHeader() throws IOException {
|
||||
if (sendCodecId) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
|
|
Loading…
Add table
Reference in a new issue