mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +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 AtomicBoolean stopped = new AtomicBoolean();
|
||||||
|
|
||||||
private final CaptureReset reset = new CaptureReset();
|
private final CaptureReset reset = new CaptureReset();
|
||||||
|
private final CaptureIdr requestIdr = new CaptureIdr();
|
||||||
private final AtomicBoolean idrRequested = new AtomicBoolean();
|
|
||||||
|
|
||||||
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, Options options) {
|
public SurfaceEncoder(SurfaceCapture capture, Streamer streamer, Options options) {
|
||||||
this.capture = capture;
|
this.capture = capture;
|
||||||
|
@ -71,6 +70,7 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||||
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
MediaFormat format = createFormat(codec.getMimeType(), videoBitRate, maxFps, codecOptions);
|
||||||
|
|
||||||
capture.init(reset);
|
capture.init(reset);
|
||||||
|
requestIdr.setRunningMediaCodec(mediaCodec);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean alive;
|
boolean alive;
|
||||||
|
@ -202,13 +202,6 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||||
|
|
||||||
boolean eos;
|
boolean eos;
|
||||||
do {
|
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);
|
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
||||||
try {
|
try {
|
||||||
eos = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
|
eos = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
|
||||||
|
@ -335,6 +328,6 @@ public class SurfaceEncoder implements AsyncProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestIdr() {
|
public void requestIdr() {
|
||||||
idrRequested.set(true);
|
requestIdr.requestIdr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue