mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 22:58:51 +00:00
Adding codecProfile and setCodecProfile to the ScreenEncoder
(cherry picked from commit 25052420394fda937db5973290f564e5c6b13ba5)
(cherry picked from commit a9685d3b56
)
This commit is contained in:
parent
88a00ab28c
commit
15c0d5ee98
2 changed files with 23 additions and 4 deletions
|
@ -30,19 +30,21 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
private int maxFps;
|
private int maxFps;
|
||||||
private int lockedVideoOrientation;
|
private int lockedVideoOrientation;
|
||||||
private int iFrameInterval;
|
private int iFrameInterval;
|
||||||
|
private int codecProfile;
|
||||||
private boolean sendFrameMeta;
|
private boolean sendFrameMeta;
|
||||||
private long ptsOrigin;
|
private long ptsOrigin;
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation, int iFrameInterval) {
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation, int codecProfile, int iFrameInterval) {
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
this.lockedVideoOrientation = lockedVideoOrientation;
|
this.lockedVideoOrientation = lockedVideoOrientation;
|
||||||
|
this.codecProfile = codecProfile;
|
||||||
this.iFrameInterval = iFrameInterval;
|
this.iFrameInterval = iFrameInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation) {
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int lockedVideoOrientation, int codecProfile) {
|
||||||
this(sendFrameMeta, bitRate, maxFps, lockedVideoOrientation, DEFAULT_I_FRAME_INTERVAL);
|
this(sendFrameMeta, bitRate, maxFps, lockedVideoOrientation, codecProfile, DEFAULT_I_FRAME_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,6 +66,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
MediaCodec codec = createCodec();
|
MediaCodec codec = createCodec();
|
||||||
|
setCodecProfile(codec, format);
|
||||||
IBinder display = createDisplay();
|
IBinder display = createDisplay();
|
||||||
ScreenInfo screenInfo = device.getScreenInfo();
|
ScreenInfo screenInfo = device.getScreenInfo();
|
||||||
Rect contentRect = screenInfo.getContentRect();
|
Rect contentRect = screenInfo.getContentRect();
|
||||||
|
@ -139,6 +142,22 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
IO.writeFully(fd, headerBuffer);
|
IO.writeFully(fd, headerBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCodecProfile(MediaCodec codec, MediaFormat format) throws IOException {
|
||||||
|
if(codecProfile == 0) return;
|
||||||
|
int level = 0;
|
||||||
|
for (MediaCodecInfo.CodecProfileLevel profileLevel : codec.getCodecInfo().getCapabilitiesForType("video/avc").profileLevels) {
|
||||||
|
if(profileLevel.profile == codecProfile) {
|
||||||
|
level = Math.max(level, profileLevel.level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(level == 0) throw new IOException("Device doesn't support the requested codec profile.");
|
||||||
|
// Profile (SDK Level 21) and Level (SDK Level 23).
|
||||||
|
format.setInteger(MediaFormat.KEY_PROFILE, codecProfile);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
format.setInteger(MediaFormat.KEY_LEVEL, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static MediaCodec createCodec() throws IOException {
|
private static MediaCodec createCodec() throws IOException {
|
||||||
return MediaCodec.createEncoderByType("video/avc");
|
return MediaCodec.createEncoderByType("video/avc");
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public final class Server {
|
||||||
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.getLockedVideoOrientation());
|
options.getLockedVideoOrientation(), options.getCodecProfile());
|
||||||
|
|
||||||
if (options.getControl()) {
|
if (options.getControl()) {
|
||||||
Controller controller = new Controller(device, connection);
|
Controller controller = new Controller(device, connection);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue