Commit 3213f969 by apodob Committed by Ian Baker

Add handling end of stream in the ExoplayerCuesDecoder

Empty buffer with flag C.BUFFER_FLAG_END_OF_STREAM is send at the end
of the stream. Handling that flag properly is necessary to make the
ExoplayerCuesDecoder work properly with components like TextRenderer.

PiperOrigin-RevId: 394472642
parent 373db56a
...@@ -93,11 +93,15 @@ public final class ExoplayerCuesDecoder implements SubtitleDecoder { ...@@ -93,11 +93,15 @@ public final class ExoplayerCuesDecoder implements SubtitleDecoder {
if (inputBufferState != INPUT_BUFFER_QUEUED || availableOutputBuffers.isEmpty()) { if (inputBufferState != INPUT_BUFFER_QUEUED || availableOutputBuffers.isEmpty()) {
return null; return null;
} }
SingleEventSubtitle subtitle =
new SingleEventSubtitle(
inputBuffer.timeUs, cueDecoder.decode(checkNotNull(inputBuffer.data).array()));
SubtitleOutputBuffer outputBuffer = availableOutputBuffers.removeFirst(); SubtitleOutputBuffer outputBuffer = availableOutputBuffers.removeFirst();
outputBuffer.setContent(inputBuffer.timeUs, subtitle, /* subsampleOffsetUs=*/ 0); if (inputBuffer.isEndOfStream()) {
outputBuffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
} else {
SingleEventSubtitle subtitle =
new SingleEventSubtitle(
inputBuffer.timeUs, cueDecoder.decode(checkNotNull(inputBuffer.data).array()));
outputBuffer.setContent(inputBuffer.timeUs, subtitle, /* subsampleOffsetUs=*/ 0);
}
inputBuffer.clear(); inputBuffer.clear();
inputBufferState = INPUT_BUFFER_AVAILABLE; inputBufferState = INPUT_BUFFER_AVAILABLE;
return outputBuffer; return outputBuffer;
......
...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -94,6 +95,17 @@ public class ExoplayerCuesDecoderTest { ...@@ -94,6 +95,17 @@ public class ExoplayerCuesDecoderTest {
} }
@Test @Test
public void dequeueOutputBuffer_queuedOnEndOfStreamInputBuffer_returnsEndOfStreamOutputBuffer()
throws Exception {
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
inputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
decoder.queueInputBuffer(inputBuffer);
SubtitleOutputBuffer outputBuffer = decoder.dequeueOutputBuffer();
assertThat(outputBuffer.isEndOfStream()).isTrue();
}
@Test
public void dequeueInputBuffer_withQueuedInput_returnsNull() throws Exception { public void dequeueInputBuffer_withQueuedInput_returnsNull() throws Exception {
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer(); SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
writeDataToInputBuffer(inputBuffer, /* timeUs=*/ 1000, ENCODED_CUES); writeDataToInputBuffer(inputBuffer, /* timeUs=*/ 1000, ENCODED_CUES);
......
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