mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-19 19:15:08 +00:00
request IDR immediately
This commit is contained in:
parent
48b780e95b
commit
a8e690df79
2 changed files with 24 additions and 10 deletions
|
@ -0,0 +1,21 @@
|
|||
package com.genymobile.scrcpy.video;
|
||||
|
||||
import android.media.MediaCodec;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class CaptureIdr {
|
||||
|
||||
// Current instance of MediaCodec to "interrupt" on reset
|
||||
private MediaCodec runningMediaCodec;
|
||||
|
||||
public synchronized void requestIdr() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(MediaCodec.PARAMETER_KEY_REQUEST_SYNC_FRAME, 0);
|
||||
this.runningMediaCodec.setParameters(bundle);
|
||||
}
|
||||
|
||||
public synchronized void setRunningMediaCodec(MediaCodec runningMediaCodec) {
|
||||
this.runningMediaCodec = runningMediaCodec;
|
||||
}
|
||||
|
||||
}
|
|
@ -52,8 +52,7 @@ public class SurfaceEncoder implements AsyncProcessor {
|
|||
private final AtomicBoolean stopped = new AtomicBoolean();
|
||||
|
||||
private final CaptureReset reset = new CaptureReset();
|
||||
|
||||
private final AtomicBoolean idrRequested = new AtomicBoolean();
|
||||
private final CaptureIdr requestIdr = new CaptureIdr();
|
||||
|
||||
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, Options options) {
|
||||
this.capture = capture;
|
||||
|
@ -71,6 +70,7 @@ public class SurfaceEncoder implements AsyncProcessor {
|
|||
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
||||
|
||||
capture.init(reset);
|
||||
requestIdr.setRunningMediaCodec(mediaCodec);
|
||||
|
||||
try {
|
||||
boolean alive;
|
||||
|
@ -202,13 +202,6 @@ public class SurfaceEncoder implements AsyncProcessor {
|
|||
|
||||
boolean eos;
|
||||
do {
|
||||
if (idrRequested.get()) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(MediaCodec.PARAMETER_KEY_REQUEST_SYNC_FRAME, 0);
|
||||
codec.setParameters(bundle);
|
||||
idrRequested.set(false);
|
||||
}
|
||||
|
||||
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
||||
try {
|
||||
eos = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
|
||||
|
@ -335,6 +328,6 @@ public class SurfaceEncoder implements AsyncProcessor {
|
|||
}
|
||||
|
||||
public void requestIdr() {
|
||||
idrRequested.set(true);
|
||||
requestIdr.requestIdr();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue