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
ae9b08b905
commit
c226797991
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, 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();
|
||||
|
|
|
@ -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) {
|
||||
// Broken pipe is expected on close, because the socket is closed by the client
|
||||
if (!IO.isBrokenPipe(e)) {
|
||||
|
|
|
@ -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…
Reference in a new issue