mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Rollback of 1ed5d8b563
*** Original commit ***
Rollback of bf5e6c7862
*** Original commit ***
Pass startPositionUs into Renderer.replaceStream
Plumb this down into BaseRenderer.onStreamChanged and use it when
deciding whether to render the first frame of a new period.
***
***
PiperOrigin-RevId: 325251261
This commit is contained in:
parent
60630fe97b
commit
092c66fac3
1 changed files with 29 additions and 4 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.mediacodec;
|
package com.google.android.exoplayer2.mediacodec;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
|
@ -352,6 +353,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
private final TimedValueQueue<Format> formatQueue;
|
private final TimedValueQueue<Format> formatQueue;
|
||||||
private final ArrayList<Long> decodeOnlyPresentationTimestamps;
|
private final ArrayList<Long> decodeOnlyPresentationTimestamps;
|
||||||
private final MediaCodec.BufferInfo outputBufferInfo;
|
private final MediaCodec.BufferInfo outputBufferInfo;
|
||||||
|
private final long[] pendingOutputStreamStartPositionsUs;
|
||||||
private final long[] pendingOutputStreamOffsetsUs;
|
private final long[] pendingOutputStreamOffsetsUs;
|
||||||
private final long[] pendingOutputStreamSwitchTimesUs;
|
private final long[] pendingOutputStreamSwitchTimesUs;
|
||||||
|
|
||||||
|
|
@ -409,6 +411,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
@MediaCodecOperationMode private int mediaCodecOperationMode;
|
@MediaCodecOperationMode private int mediaCodecOperationMode;
|
||||||
@Nullable private ExoPlaybackException pendingPlaybackException;
|
@Nullable private ExoPlaybackException pendingPlaybackException;
|
||||||
protected DecoderCounters decoderCounters;
|
protected DecoderCounters decoderCounters;
|
||||||
|
private long outputStreamStartPositionUs;
|
||||||
private long outputStreamOffsetUs;
|
private long outputStreamOffsetUs;
|
||||||
private int pendingOutputStreamOffsetCount;
|
private int pendingOutputStreamOffsetCount;
|
||||||
|
|
||||||
|
|
@ -439,8 +442,10 @@ 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;
|
||||||
|
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];
|
||||||
|
outputStreamStartPositionUs = C.TIME_UNSET;
|
||||||
outputStreamOffsetUs = C.TIME_UNSET;
|
outputStreamOffsetUs = C.TIME_UNSET;
|
||||||
bypassBatchBuffer = new BatchBuffer();
|
bypassBatchBuffer = new BatchBuffer();
|
||||||
resetCodecStateForRelease();
|
resetCodecStateForRelease();
|
||||||
|
|
@ -685,8 +690,10 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
@Override
|
@Override
|
||||||
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs)
|
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs)
|
||||||
throws ExoPlaybackException {
|
throws ExoPlaybackException {
|
||||||
if (outputStreamOffsetUs == C.TIME_UNSET) {
|
if (this.outputStreamOffsetUs == C.TIME_UNSET) {
|
||||||
outputStreamOffsetUs = offsetUs;
|
checkState(this.outputStreamStartPositionUs == C.TIME_UNSET);
|
||||||
|
this.outputStreamStartPositionUs = startPositionUs;
|
||||||
|
this.outputStreamOffsetUs = offsetUs;
|
||||||
} else {
|
} else {
|
||||||
if (pendingOutputStreamOffsetCount == pendingOutputStreamOffsetsUs.length) {
|
if (pendingOutputStreamOffsetCount == pendingOutputStreamOffsetsUs.length) {
|
||||||
Log.w(
|
Log.w(
|
||||||
|
|
@ -696,6 +703,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
} else {
|
} else {
|
||||||
pendingOutputStreamOffsetCount++;
|
pendingOutputStreamOffsetCount++;
|
||||||
}
|
}
|
||||||
|
pendingOutputStreamStartPositionsUs[pendingOutputStreamOffsetCount - 1] = startPositionUs;
|
||||||
pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1] = offsetUs;
|
pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1] = offsetUs;
|
||||||
pendingOutputStreamSwitchTimesUs[pendingOutputStreamOffsetCount - 1] =
|
pendingOutputStreamSwitchTimesUs[pendingOutputStreamOffsetCount - 1] =
|
||||||
largestQueuedPresentationTimeUs;
|
largestQueuedPresentationTimeUs;
|
||||||
|
|
@ -721,6 +729,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
formatQueue.clear();
|
formatQueue.clear();
|
||||||
if (pendingOutputStreamOffsetCount != 0) {
|
if (pendingOutputStreamOffsetCount != 0) {
|
||||||
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1];
|
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1];
|
||||||
|
outputStreamStartPositionUs =
|
||||||
|
pendingOutputStreamStartPositionsUs[pendingOutputStreamOffsetCount - 1];
|
||||||
pendingOutputStreamOffsetCount = 0;
|
pendingOutputStreamOffsetCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -738,6 +748,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
@Override
|
@Override
|
||||||
protected void onDisabled() {
|
protected void onDisabled() {
|
||||||
inputFormat = null;
|
inputFormat = null;
|
||||||
|
outputStreamStartPositionUs = C.TIME_UNSET;
|
||||||
outputStreamOffsetUs = C.TIME_UNSET;
|
outputStreamOffsetUs = C.TIME_UNSET;
|
||||||
pendingOutputStreamOffsetCount = 0;
|
pendingOutputStreamOffsetCount = 0;
|
||||||
if (sourceDrmSession != null || codecDrmSession != null) {
|
if (sourceDrmSession != null || codecDrmSession != null) {
|
||||||
|
|
@ -1545,8 +1556,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
protected void onProcessedOutputBuffer(long presentationTimeUs) {
|
protected void onProcessedOutputBuffer(long presentationTimeUs) {
|
||||||
while (pendingOutputStreamOffsetCount != 0
|
while (pendingOutputStreamOffsetCount != 0
|
||||||
&& presentationTimeUs >= pendingOutputStreamSwitchTimesUs[0]) {
|
&& presentationTimeUs >= pendingOutputStreamSwitchTimesUs[0]) {
|
||||||
|
outputStreamStartPositionUs = pendingOutputStreamStartPositionsUs[0];
|
||||||
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[0];
|
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[0];
|
||||||
pendingOutputStreamOffsetCount--;
|
pendingOutputStreamOffsetCount--;
|
||||||
|
System.arraycopy(
|
||||||
|
pendingOutputStreamStartPositionsUs,
|
||||||
|
/* srcPos= */ 1,
|
||||||
|
pendingOutputStreamStartPositionsUs,
|
||||||
|
/* destPos= */ 0,
|
||||||
|
pendingOutputStreamOffsetCount);
|
||||||
System.arraycopy(
|
System.arraycopy(
|
||||||
pendingOutputStreamOffsetsUs,
|
pendingOutputStreamOffsetsUs,
|
||||||
/* srcPos= */ 1,
|
/* srcPos= */ 1,
|
||||||
|
|
@ -1945,6 +1963,13 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
return largestQueuedPresentationTimeUs;
|
return largestQueuedPresentationTimeUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the start position of the output {@link SampleStream}, in renderer time microseconds.
|
||||||
|
*/
|
||||||
|
protected final long getOutputStreamStartPositionUs() {
|
||||||
|
return outputStreamStartPositionUs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the offset that should be subtracted from {@code bufferPresentationTimeUs} in {@link
|
* Returns the offset that should be subtracted from {@code bufferPresentationTimeUs} in {@link
|
||||||
* #processOutputBuffer(long, long, MediaCodec, ByteBuffer, int, int, int, long, boolean, boolean,
|
* #processOutputBuffer(long, long, MediaCodec, ByteBuffer, int, int, int, long, boolean, boolean,
|
||||||
|
|
@ -2080,7 +2105,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
BatchBuffer batchBuffer = bypassBatchBuffer;
|
BatchBuffer batchBuffer = bypassBatchBuffer;
|
||||||
|
|
||||||
// Let's process the pending buffer if any.
|
// Let's process the pending buffer if any.
|
||||||
Assertions.checkState(!outputStreamEnded);
|
checkState(!outputStreamEnded);
|
||||||
if (!batchBuffer.isEmpty()) { // Optimisation: Do not process buffer if empty.
|
if (!batchBuffer.isEmpty()) { // Optimisation: Do not process buffer if empty.
|
||||||
if (processOutputBuffer(
|
if (processOutputBuffer(
|
||||||
positionUs,
|
positionUs,
|
||||||
|
|
@ -2119,7 +2144,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now refill the empty buffer for the next iteration.
|
// Now refill the empty buffer for the next iteration.
|
||||||
Assertions.checkState(!inputStreamEnded);
|
checkState(!inputStreamEnded);
|
||||||
FormatHolder formatHolder = getFormatHolder();
|
FormatHolder formatHolder = getFormatHolder();
|
||||||
boolean formatChange = readBatchFromSource(formatHolder, batchBuffer);
|
boolean formatChange = readBatchFromSource(formatHolder, batchBuffer);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue