-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codec options #1325
Closed
Closed
Codec options #1325
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,17 @@ public class ScreenEncoder implements Device.RotationListener { | |
private final AtomicBoolean rotationChanged = new AtomicBoolean(); | ||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12); | ||
|
||
private String codecOptions; | ||
private int bitRate; | ||
private int maxFps; | ||
private boolean sendFrameMeta; | ||
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.bitRate = bitRate; | ||
this.maxFps = maxFps; | ||
this.codecOptions = codecOptions; | ||
} | ||
|
||
@Override | ||
|
@@ -49,7 +51,7 @@ public void streamScreen(Device device, FileDescriptor fd) throws IOException { | |
Workarounds.prepareMainLooper(); | ||
Workarounds.fillAppInfo(); | ||
|
||
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL); | ||
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL, codecOptions); | ||
device.setRotationListener(this); | ||
boolean alive; | ||
try { | ||
|
@@ -139,7 +141,7 @@ private static MediaCodec createCodec() throws IOException { | |
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(); | ||
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_VIDEO_AVC); | ||
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate); | ||
|
@@ -155,6 +157,33 @@ private static MediaFormat createFormat(int bitRate, int maxFps, int iFrameInter | |
// <https://github.com/Genymobile/scrcpy/issues/488#issuecomment-567321437> | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could not pass a String containing a |
||
} 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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, contrary to what I said in a previous PR, this does not do what I expected (in fact it just test whether we already set the key, so in practice this is always false).