Commit 9f81b722 by olly Committed by Oliver Woodman

Fix GTS playback test timestamp verifications

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143549680
parent b7746609
...@@ -19,6 +19,7 @@ import android.annotation.TargetApi; ...@@ -19,6 +19,7 @@ import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.LoadControl; import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.Renderer; import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.SimpleExoPlayer;
...@@ -66,16 +67,14 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer { ...@@ -66,16 +67,14 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer {
private int startIndex; private int startIndex;
private int queueSize; private int queueSize;
private int bufferCount; private int bufferCount;
private int minimumInsertIndex;
public DebugMediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, public DebugMediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs, Handler eventHandler, long allowedJoiningTimeMs, Handler eventHandler,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
VideoRendererEventListener eventListener, VideoRendererEventListener eventListener, int maxDroppedFrameCountToNotify) {
int maxDroppedFrameCountToNotify) {
super(context, mediaCodecSelector, allowedJoiningTimeMs, drmSessionManager, false, super(context, mediaCodecSelector, allowedJoiningTimeMs, drmSessionManager, false,
eventHandler, eventListener, maxDroppedFrameCountToNotify); eventHandler, eventListener, maxDroppedFrameCountToNotify);
startIndex = 0;
queueSize = 0;
} }
@Override @Override
...@@ -91,6 +90,14 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer { ...@@ -91,6 +90,14 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer {
} }
@Override @Override
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
super.onInputFormatChanged(newFormat);
// Ensure timestamps of buffers queued after this format change are never inserted into the
// queue of expected output timestamps before those of buffers that have already been queued.
minimumInsertIndex = startIndex + queueSize;
}
@Override
protected void onQueueInputBuffer(DecoderInputBuffer buffer) { protected void onQueueInputBuffer(DecoderInputBuffer buffer) {
insertTimestamp(buffer.timeUs); insertTimestamp(buffer.timeUs);
maybeShiftTimestampsList(); maybeShiftTimestampsList();
...@@ -111,10 +118,11 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer { ...@@ -111,10 +118,11 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer {
startIndex = 0; startIndex = 0;
queueSize = 0; queueSize = 0;
bufferCount = 0; bufferCount = 0;
minimumInsertIndex = 0;
} }
private void insertTimestamp(long presentationTimeUs) { private void insertTimestamp(long presentationTimeUs) {
for (int i = startIndex + queueSize - 1; i >= startIndex; i--) { for (int i = startIndex + queueSize - 1; i >= minimumInsertIndex; i--) {
if (presentationTimeUs >= timestampsList[i]) { if (presentationTimeUs >= timestampsList[i]) {
timestampsList[i + 1] = presentationTimeUs; timestampsList[i + 1] = presentationTimeUs;
queueSize++; queueSize++;
...@@ -122,20 +130,22 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer { ...@@ -122,20 +130,22 @@ public class DebugSimpleExoPlayer extends SimpleExoPlayer {
} }
timestampsList[i + 1] = timestampsList[i]; timestampsList[i + 1] = timestampsList[i];
} }
timestampsList[startIndex] = presentationTimeUs; timestampsList[minimumInsertIndex] = presentationTimeUs;
queueSize++; queueSize++;
} }
private void maybeShiftTimestampsList() { private void maybeShiftTimestampsList() {
if (startIndex + queueSize == ARRAY_SIZE) { if (startIndex + queueSize == ARRAY_SIZE) {
System.arraycopy(timestampsList, startIndex, timestampsList, 0, queueSize); System.arraycopy(timestampsList, startIndex, timestampsList, 0, queueSize);
minimumInsertIndex -= startIndex;
startIndex = 0; startIndex = 0;
} }
} }
private long dequeueTimestamp() { private long dequeueTimestamp() {
startIndex++;
queueSize--; queueSize--;
startIndex++;
minimumInsertIndex = Math.max(minimumInsertIndex, startIndex);
return timestampsList[startIndex - 1]; return timestampsList[startIndex - 1];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment