Skip to content

Commit

Permalink
Use output start time instead of deprecated isDecodeOnly in CeaDecoder
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 619133908
  • Loading branch information
tonihei authored and copybara-github committed Mar 26, 2024
1 parent c3c9646 commit 0f42dd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -507,6 +509,7 @@ private void releaseSubtitleDecoder() {
private void initSubtitleDecoder() {
waitingForKeyFrame = true;
subtitleDecoder = subtitleDecoderFactory.createDecoder(checkNotNull(streamFormat));
subtitleDecoder.setOutputStartTimeUs(getLastResetPositionUs());
}

private void replaceSubtitleDecoder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@Nullable private CeaInputBuffer dequeuedInputBuffer;
private long playbackPositionUs;
private long queuedInputBufferCount;
private long outputStartTimeUs;

@SuppressWarnings("nullness:methodref.receiver.bound")
public CeaDecoder() {
Expand All @@ -53,14 +54,15 @@ public CeaDecoder() {
availableOutputBuffers.add(new CeaOutputBuffer(this::releaseOutputBuffer));
}
queuedInputBuffers = new PriorityQueue<>();
outputStartTimeUs = C.TIME_UNSET;
}

@Override
public abstract String getName();

@Override
public final void setOutputStartTimeUs(long outputStartTimeUs) {
// Do nothing.
this.outputStartTimeUs = outputStartTimeUs;
}

@Override
Expand All @@ -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 {
Expand Down

0 comments on commit 0f42dd4

Please sign in to comment.