From 0f42dd47526c70e38b1048bb18c994c281800485 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 26 Mar 2024 03:43:53 -0700 Subject: [PATCH] Use output start time instead of deprecated isDecodeOnly in CeaDecoder PiperOrigin-RevId: 619133908 --- .../java/androidx/media3/exoplayer/text/TextRenderer.java | 5 ++++- .../androidx/media3/extractor/text/cea/CeaDecoder.java | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java index 8fde25bef6a..3bd87d620f5 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java @@ -241,7 +241,9 @@ protected void onPositionReset(long positionUs, boolean joining) { replaceSubtitleDecoder(); } else { releaseSubtitleBuffers(); - checkNotNull(subtitleDecoder).flush(); + SubtitleDecoder subtitleDecoder = checkNotNull(this.subtitleDecoder); + subtitleDecoder.flush(); + subtitleDecoder.setOutputStartTimeUs(getLastResetPositionUs()); } } } @@ -507,6 +509,7 @@ private void releaseSubtitleDecoder() { private void initSubtitleDecoder() { waitingForKeyFrame = true; subtitleDecoder = subtitleDecoderFactory.createDecoder(checkNotNull(streamFormat)); + subtitleDecoder.setOutputStartTimeUs(getLastResetPositionUs()); } private void replaceSubtitleDecoder() { diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/text/cea/CeaDecoder.java b/libraries/extractor/src/main/java/androidx/media3/extractor/text/cea/CeaDecoder.java index 84ec3bee421..846baeb8d96 100644 --- a/libraries/extractor/src/main/java/androidx/media3/extractor/text/cea/CeaDecoder.java +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/text/cea/CeaDecoder.java @@ -41,6 +41,7 @@ @Nullable private CeaInputBuffer dequeuedInputBuffer; private long playbackPositionUs; private long queuedInputBufferCount; + private long outputStartTimeUs; @SuppressWarnings("nullness:methodref.receiver.bound") public CeaDecoder() { @@ -53,6 +54,7 @@ public CeaDecoder() { availableOutputBuffers.add(new CeaOutputBuffer(this::releaseOutputBuffer)); } queuedInputBuffers = new PriorityQueue<>(); + outputStartTimeUs = C.TIME_UNSET; } @Override @@ -60,7 +62,7 @@ public CeaDecoder() { @Override public final void setOutputStartTimeUs(long outputStartTimeUs) { - // Do nothing. + this.outputStartTimeUs = outputStartTimeUs; } @Override @@ -79,13 +81,11 @@ public SubtitleInputBuffer dequeueInputBuffer() throws SubtitleDecoderException return dequeuedInputBuffer; } - // Still using deprecated decoder-only flag until this decoder is replaced by a SubtitleParser. - @SuppressWarnings("deprecation") @Override public void queueInputBuffer(SubtitleInputBuffer inputBuffer) throws SubtitleDecoderException { Assertions.checkArgument(inputBuffer == dequeuedInputBuffer); CeaInputBuffer ceaInputBuffer = (CeaInputBuffer) inputBuffer; - if (ceaInputBuffer.isDecodeOnly()) { + if (outputStartTimeUs != C.TIME_UNSET && ceaInputBuffer.timeUs < outputStartTimeUs) { // We can start decoding anywhere in CEA formats, so discarding on the input side is fine. releaseInputBuffer(ceaInputBuffer); } else {