mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-02 22:29:25 +00:00
support udt timeout codec option
Non-negative timeout had been specified in the call to dequeueOutputBuffer, indicates that the call timed out, this will fix idr req not return frame bug
This commit is contained in:
parent
d3a74b8e8b
commit
08b477e698
1 changed files with 23 additions and 1 deletions
|
@ -145,7 +145,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
|
|
||||||
while (!consumeRotationChange() && !eof) {
|
while (!consumeRotationChange() && !eof) {
|
||||||
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, timeoutUS);
|
||||||
eof = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
|
eof = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
|
||||||
try {
|
try {
|
||||||
if (consumeRotationChange()) {
|
if (consumeRotationChange()) {
|
||||||
|
@ -165,6 +165,9 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
firstFrameSent = true;
|
firstFrameSent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (outputBufferId == MediaCodec.INFO_TRY_AGAIN_LATER) {
|
||||||
|
Ln.d("wait dequeueOutputBuffer timeout, retry again later");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (outputBufferId >= 0) {
|
if (outputBufferId >= 0) {
|
||||||
codec.releaseOutputBuffer(outputBufferId, false);
|
codec.releaseOutputBuffer(outputBufferId, false);
|
||||||
|
@ -256,6 +259,9 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
|
|
||||||
if (codecOptions != null) {
|
if (codecOptions != null) {
|
||||||
for (CodecOption option : codecOptions) {
|
for (CodecOption option : codecOptions) {
|
||||||
|
if (setUdtCodecOption(format, option)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
setCodecOption(format, option);
|
setCodecOption(format, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +304,9 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
private MediaCodec codec;
|
private MediaCodec codec;
|
||||||
private Device.CodecChangeLister codecChangeLister;
|
private Device.CodecChangeLister codecChangeLister;
|
||||||
|
|
||||||
|
private static final String KEY_TIMEOUT = "timeout";
|
||||||
|
private static long timeoutUS = -1;
|
||||||
|
|
||||||
private void initCodec(MediaCodec codec) {
|
private void initCodec(MediaCodec codec) {
|
||||||
this.codec = codec;
|
this.codec = codec;
|
||||||
}
|
}
|
||||||
|
@ -325,4 +334,17 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
}
|
}
|
||||||
return codecChangeLister;
|
return codecChangeLister;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean setUdtCodecOption(MediaFormat format, CodecOption codecOption) {
|
||||||
|
String key = codecOption.getKey();
|
||||||
|
if (KEY_TIMEOUT.equals(key)) {
|
||||||
|
Object value = codecOption.getValue();
|
||||||
|
if (value instanceof Integer) {
|
||||||
|
timeoutUS = (Integer) value * 1000 * 1000;
|
||||||
|
Ln.d("Udt Codec option set: " + key + " (" + value.getClass().getSimpleName() + ") = " + value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue