use of androidx.media3.extractor.text.SubtitleInputBuffer in project media by androidx.
the class SubtitleExtractor method decode.
/**
* Decodes the subtitle data and stores the samples in the memory of the extractor.
*/
private void decode() throws IOException {
try {
@Nullable SubtitleInputBuffer inputBuffer = subtitleDecoder.dequeueInputBuffer();
while (inputBuffer == null) {
Thread.sleep(5);
inputBuffer = subtitleDecoder.dequeueInputBuffer();
}
inputBuffer.ensureSpaceForWrite(bytesRead);
inputBuffer.data.put(subtitleData.getData(), /* offset= */
0, bytesRead);
inputBuffer.data.limit(bytesRead);
subtitleDecoder.queueInputBuffer(inputBuffer);
@Nullable SubtitleOutputBuffer outputBuffer = subtitleDecoder.dequeueOutputBuffer();
while (outputBuffer == null) {
Thread.sleep(5);
outputBuffer = subtitleDecoder.dequeueOutputBuffer();
}
for (int i = 0; i < outputBuffer.getEventTimeCount(); i++) {
List<Cue> cues = outputBuffer.getCues(outputBuffer.getEventTime(i));
byte[] cuesSample = cueEncoder.encode(cues);
timestamps.add(outputBuffer.getEventTime(i));
samples.add(new ParsableByteArray(cuesSample));
}
outputBuffer.release();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException();
} catch (SubtitleDecoderException e) {
throw ParserException.createForMalformedContainer("SubtitleDecoder failed.", e);
}
}
use of androidx.media3.extractor.text.SubtitleInputBuffer in project media by androidx.
the class ExoplayerCuesDecoderTest method dequeueOutputBuffer_queuedOnEndOfStreamInputBuffer_returnsEndOfStreamOutputBuffer.
@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();
}
use of androidx.media3.extractor.text.SubtitleInputBuffer in project media by androidx.
the class ExoplayerCuesDecoderTest method dequeueInputBuffer_withQueuedInput_returnsNull.
@Test
public void dequeueInputBuffer_withQueuedInput_returnsNull() throws Exception {
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
writeDataToInputBuffer(inputBuffer, /* timeUs=*/
1000, ENCODED_CUES);
decoder.queueInputBuffer(inputBuffer);
assertThat(decoder.dequeueInputBuffer()).isNull();
}
use of androidx.media3.extractor.text.SubtitleInputBuffer in project media by androidx.
the class ExoplayerCuesDecoderTest method flush_makesAllInputBuffersAvailable.
@Test
public void flush_makesAllInputBuffersAvailable() throws Exception {
List<SubtitleInputBuffer> inputBuffers = new ArrayList<>();
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
while (inputBuffer != null) {
inputBuffers.add(inputBuffer);
inputBuffer = decoder.dequeueInputBuffer();
}
for (int i = 0; i < inputBuffers.size(); i++) {
writeDataToInputBuffer(inputBuffers.get(i), /* timeUs=*/
1000, ENCODED_CUES);
decoder.queueInputBuffer(inputBuffers.get(i));
}
decoder.flush();
for (int i = 0; i < inputBuffers.size(); i++) {
assertThat(decoder.dequeueInputBuffer().data.position()).isEqualTo(0);
}
}
use of androidx.media3.extractor.text.SubtitleInputBuffer in project media by androidx.
the class ExoplayerCuesDecoderTest method releaseOutputBuffer_calledTwice_fails.
@Test
public void releaseOutputBuffer_calledTwice_fails() throws Exception {
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
writeDataToInputBuffer(inputBuffer, /* timeUs=*/
1000, ENCODED_CUES);
decoder.queueInputBuffer(inputBuffer);
SubtitleOutputBuffer outputBuffer = decoder.dequeueOutputBuffer();
outputBuffer.release();
assertThrows(IllegalStateException.class, outputBuffer::release);
}
Aggregations