mirror of
https://github.com/androidx/media.git
synced 2025-05-09 16:40:55 +08:00
Bring back setRenderTimeLimitMs
PiperOrigin-RevId: 333712782
This commit is contained in:
parent
973d23543e
commit
300bee5f0b
@ -363,6 +363,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
@Nullable private DrmSession sourceDrmSession;
|
@Nullable private DrmSession sourceDrmSession;
|
||||||
@Nullable private MediaCrypto mediaCrypto;
|
@Nullable private MediaCrypto mediaCrypto;
|
||||||
private boolean mediaCryptoRequiresSecureDecoder;
|
private boolean mediaCryptoRequiresSecureDecoder;
|
||||||
|
private long renderTimeLimitMs;
|
||||||
private float operatingRate;
|
private float operatingRate;
|
||||||
@Nullable private MediaCodec codec;
|
@Nullable private MediaCodec codec;
|
||||||
@Nullable private MediaCodecAdapter codecAdapter;
|
@Nullable private MediaCodecAdapter codecAdapter;
|
||||||
@ -442,6 +443,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
outputBufferInfo = new MediaCodec.BufferInfo();
|
outputBufferInfo = new MediaCodec.BufferInfo();
|
||||||
operatingRate = 1f;
|
operatingRate = 1f;
|
||||||
mediaCodecOperationMode = OPERATION_MODE_SYNCHRONOUS;
|
mediaCodecOperationMode = OPERATION_MODE_SYNCHRONOUS;
|
||||||
|
renderTimeLimitMs = C.TIME_UNSET;
|
||||||
pendingOutputStreamStartPositionsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
pendingOutputStreamStartPositionsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
||||||
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
||||||
pendingOutputStreamSwitchTimesUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
pendingOutputStreamSwitchTimesUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
||||||
@ -451,6 +453,19 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
resetCodecStateForRelease();
|
resetCodecStateForRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a limit on the time a single {@link #render(long, long)} call can spend draining and
|
||||||
|
* filling the decoder.
|
||||||
|
*
|
||||||
|
* <p>This method should be called right after creating an instance of this class.
|
||||||
|
*
|
||||||
|
* @param renderTimeLimitMs The render time limit in milliseconds, or {@link C#TIME_UNSET} for no
|
||||||
|
* limit.
|
||||||
|
*/
|
||||||
|
public void setRenderTimeLimitMs(long renderTimeLimitMs) {
|
||||||
|
this.renderTimeLimitMs = renderTimeLimitMs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the mode of operation of the underlying {@link MediaCodec}.
|
* Set the mode of operation of the underlying {@link MediaCodec}.
|
||||||
*
|
*
|
||||||
@ -837,9 +852,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
while (bypassRender(positionUs, elapsedRealtimeUs)) {}
|
while (bypassRender(positionUs, elapsedRealtimeUs)) {}
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
} else if (codec != null) {
|
} else if (codec != null) {
|
||||||
|
long renderStartTimeMs = SystemClock.elapsedRealtime();
|
||||||
TraceUtil.beginSection("drainAndFeed");
|
TraceUtil.beginSection("drainAndFeed");
|
||||||
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
|
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)
|
||||||
while (feedInputBuffer()) {}
|
&& shouldContinueRendering(renderStartTimeMs)) {}
|
||||||
|
while (feedInputBuffer() && shouldContinueRendering(renderStartTimeMs)) {}
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
} else {
|
} else {
|
||||||
decoderCounters.skippedInputBufferCount += skipSource(positionUs);
|
decoderCounters.skippedInputBufferCount += skipSource(positionUs);
|
||||||
@ -1171,6 +1188,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
onCodecInitialized(codecName, codecInitializedTimestamp, elapsed);
|
onCodecInitialized(codecName, codecInitializedTimestamp, elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldContinueRendering(long renderStartTimeMs) {
|
||||||
|
return renderTimeLimitMs == C.TIME_UNSET
|
||||||
|
|| SystemClock.elapsedRealtime() - renderStartTimeMs < renderTimeLimitMs;
|
||||||
|
}
|
||||||
|
|
||||||
private void getCodecBuffers(MediaCodec codec) {
|
private void getCodecBuffers(MediaCodec codec) {
|
||||||
if (Util.SDK_INT < 21) {
|
if (Util.SDK_INT < 21) {
|
||||||
inputBuffers = codec.getInputBuffers();
|
inputBuffers = codec.getInputBuffers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user