Skip to content

Commit

Permalink
Handle C.TIME_END_OF_SOURCE buffer timestamps in CeaDecoder
Browse files Browse the repository at this point in the history
The behaviour was changed in 1.4.0 with 0f42dd4,
so that the buffer timestamp is compared to `outputStartTimeUs` when
deciding whether to discard a "decode only" buffer before decoding
(instead of the deprecated/removed `isDecodeOnly` property). This breaks
when the buffer timestamp is `TIME_END_OF_SOURCE` (which is
`Long.MIN_VALUE`), because `TIME_END_OF_SOURCE < outputStartTimeUs` is
always true, so the end-of-stream buffer is never passed to the decoder
and on to `TextRenderer` where it is used to
[set `inputStreamEnded = true`](https://github.com/androidx/media/blob/40f187e4b47c445af5049a5a49ee4633ce4c1a76/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/TextRenderer.java#L434-L436)
and so playback hangs.

Issue: #1863
PiperOrigin-RevId: 695767247
(cherry picked from commit 19b38c8)
  • Loading branch information
icbaker committed Nov 19, 2024
1 parent f109a81 commit a46716c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Text:
* Fix garbled CEA-608 subtitles in content with more than one SEI message
per sample.
* Fix playback hanging on DASH multi-period streams when CEA-608 subtitles
are enabled ([#1863](https://github.com/androidx/media/issues/1863)).

## 1.5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public SubtitleInputBuffer dequeueInputBuffer() throws SubtitleDecoderException
public void queueInputBuffer(SubtitleInputBuffer inputBuffer) throws SubtitleDecoderException {
Assertions.checkArgument(inputBuffer == dequeuedInputBuffer);
CeaInputBuffer ceaInputBuffer = (CeaInputBuffer) inputBuffer;
if (outputStartTimeUs != C.TIME_UNSET && ceaInputBuffer.timeUs < outputStartTimeUs) {
if (ceaInputBuffer.timeUs != C.TIME_END_OF_SOURCE
&& 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
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ public void serviceSwitchOnField2Handled() throws Exception {
assertThat(getOnlyCue(firstSubtitle).text.toString()).isEqualTo("test");
}

// https://github.com/androidx/media/issues/1863
@Test
public void endOfStreamBuffer_flagPassedThrough() throws Exception {
Cea608Decoder decoder =
new Cea608Decoder(
MimeTypes.APPLICATION_CEA608,
/* accessibilityChannel= */ 1,
Cea608Decoder.MIN_DATA_CHANNEL_TIMEOUT_MS);

SubtitleInputBuffer inputBuffer = checkNotNull(decoder.dequeueInputBuffer());
inputBuffer.timeUs = C.TIME_END_OF_SOURCE;
inputBuffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
decoder.setOutputStartTimeUs(0);
decoder.queueInputBuffer(inputBuffer);
decoder.setPositionUs(123);
SubtitleOutputBuffer outputBuffer = decoder.dequeueOutputBuffer();

assertThat(outputBuffer.isEndOfStream()).isTrue();
}

private static byte[] createPacket(int header, int cc1, int cc2) {
return new byte[] {
UnsignedBytes.checkedCast(header),
Expand Down

0 comments on commit a46716c

Please sign in to comment.