mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 06:39:39 +00:00
Adding to server.
This commit is contained in:
parent
323f2a1bd8
commit
3ee3cd7c5c
3 changed files with 47 additions and 6 deletions
|
@ -12,6 +12,7 @@ public class Options {
|
||||||
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
||||||
private boolean control;
|
private boolean control;
|
||||||
private int displayId;
|
private int displayId;
|
||||||
|
private String codecOptions;
|
||||||
|
|
||||||
public int getMaxSize() {
|
public int getMaxSize() {
|
||||||
return maxSize;
|
return maxSize;
|
||||||
|
@ -84,4 +85,12 @@ public class Options {
|
||||||
public void setDisplayId(int displayId) {
|
public void setDisplayId(int displayId) {
|
||||||
this.displayId = displayId;
|
this.displayId = displayId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCodecOptions() {
|
||||||
|
return codecOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodecOptions(String codecOptions) {
|
||||||
|
this.codecOptions = codecOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,17 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
private final AtomicBoolean rotationChanged = new AtomicBoolean();
|
||||||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
||||||
|
|
||||||
|
private String codecOptions;
|
||||||
private int bitRate;
|
private int bitRate;
|
||||||
private int maxFps;
|
private int maxFps;
|
||||||
private boolean sendFrameMeta;
|
private boolean sendFrameMeta;
|
||||||
private long ptsOrigin;
|
private long ptsOrigin;
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps) {
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, String codecOptions) {
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
|
this.codecOptions = codecOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,7 +51,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
Workarounds.prepareMainLooper();
|
Workarounds.prepareMainLooper();
|
||||||
Workarounds.fillAppInfo();
|
Workarounds.fillAppInfo();
|
||||||
|
|
||||||
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
|
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL, codecOptions);
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
try {
|
||||||
|
@ -139,7 +141,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
return MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
|
return MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval) {
|
private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInterval, String codecOptions) {
|
||||||
MediaFormat format = new MediaFormat();
|
MediaFormat format = new MediaFormat();
|
||||||
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC);
|
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC);
|
||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
|
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
|
||||||
|
@ -155,6 +157,33 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
// <https://github.com/Genymobile/scrcpy/issues/488#issuecomment-567321437>
|
// <https://github.com/Genymobile/scrcpy/issues/488#issuecomment-567321437>
|
||||||
format.setFloat(KEY_MAX_FPS_TO_ENCODER, maxFps);
|
format.setFloat(KEY_MAX_FPS_TO_ENCODER, maxFps);
|
||||||
}
|
}
|
||||||
|
// Adding additional options specified by the user
|
||||||
|
if(!"-".equals(codecOptions)) {
|
||||||
|
for (String pair : codecOptions.split(",")) {
|
||||||
|
String[] option = pair.split("=");
|
||||||
|
String key = option[0];
|
||||||
|
if(format.containsKey(key)) {
|
||||||
|
if (option.length < 2) {
|
||||||
|
Ln.w("No value specified for codec option - " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] valueAndType = option[1].split(":");
|
||||||
|
String value = valueAndType[0];
|
||||||
|
String type = valueAndType.length < 2 ? "" : valueAndType[1].toLowerCase();
|
||||||
|
if (type.contains("str")) {
|
||||||
|
format.setString(key, value);
|
||||||
|
} else if (type.contains("long")) {
|
||||||
|
format.setLong(key, Long.parseLong(value));
|
||||||
|
} else if (type.contains("float")) {
|
||||||
|
format.setFloat(key, Float.parseFloat(value));
|
||||||
|
} else {
|
||||||
|
format.setInteger(key, Integer.parseInt(value));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ln.w("Codec format doesn't contain the requested codec option - " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public final class Server {
|
||||||
final Device device = new Device(options);
|
final Device device = new Device(options);
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
||||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps());
|
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), options.getCodecOptions());
|
||||||
|
|
||||||
if (options.getControl()) {
|
if (options.getControl()) {
|
||||||
Controller controller = new Controller(device, connection);
|
Controller controller = new Controller(device, connection);
|
||||||
|
@ -79,8 +79,8 @@ public final class Server {
|
||||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length != 10) {
|
if (args.length != 11) {
|
||||||
throw new IllegalArgumentException("Expecting 10 parameters");
|
throw new IllegalArgumentException("Expecting 11 parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
@ -113,6 +113,9 @@ public final class Server {
|
||||||
int displayId = Integer.parseInt(args[9]);
|
int displayId = Integer.parseInt(args[9]);
|
||||||
options.setDisplayId(displayId);
|
options.setDisplayId(displayId);
|
||||||
|
|
||||||
|
String codecOptions = args[10];
|
||||||
|
options.setCodecOptions(codecOptions);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue