mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
373db56a52
commit
3213f969c0
2 changed files with 20 additions and 4 deletions
|
|
@ -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;
|
||||||
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;
|
||||||
|
|
@ -93,6 +94,17 @@ public class ExoplayerCuesDecoderTest {
|
||||||
assertThat(decoder.dequeueOutputBuffer()).isNotNull();
|
assertThat(decoder.dequeueOutputBuffer()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void dequeueInputBuffer_withQueuedInput_returnsNull() throws Exception {
|
public void dequeueInputBuffer_withQueuedInput_returnsNull() throws Exception {
|
||||||
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
|
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue