use of androidx.media3.extractor.text.SubtitleOutputBuffer 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.SubtitleOutputBuffer in project media by androidx.
the class Cea608Decoder method dequeueOutputBuffer.
@Nullable
@Override
public SubtitleOutputBuffer dequeueOutputBuffer() throws SubtitleDecoderException {
SubtitleOutputBuffer outputBuffer = super.dequeueOutputBuffer();
if (outputBuffer != null) {
return outputBuffer;
}
if (shouldClearStuckCaptions()) {
outputBuffer = getAvailableOutputBuffer();
if (outputBuffer != null) {
cues = Collections.emptyList();
lastCueUpdateUs = C.TIME_UNSET;
Subtitle subtitle = createSubtitle();
outputBuffer.setContent(getPositionUs(), subtitle, Format.OFFSET_SAMPLE_RELATIVE);
return outputBuffer;
}
}
return null;
}
use of androidx.media3.extractor.text.SubtitleOutputBuffer 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.SubtitleOutputBuffer 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);
}
use of androidx.media3.extractor.text.SubtitleOutputBuffer in project media by androidx.
the class ExoplayerCuesDecoderTest method decoder_outputsSubtitle.
@Test
public void decoder_outputsSubtitle() throws Exception {
SubtitleInputBuffer inputBuffer = decoder.dequeueInputBuffer();
writeDataToInputBuffer(inputBuffer, /* timeUs=*/
1000, ENCODED_CUES);
decoder.queueInputBuffer(inputBuffer);
SubtitleOutputBuffer outputBuffer = decoder.dequeueOutputBuffer();
assertThat(outputBuffer.getCues(/* timeUs=*/
999)).isEmpty();
assertThat(outputBuffer.getCues(1001)).hasSize(1);
assertThat(outputBuffer.getCues(/* timeUs=*/
1000)).hasSize(1);
assertThat(outputBuffer.getCues(/* timeUs=*/
1000).get(0).text.toString()).isEqualTo("text");
outputBuffer.release();
}
Aggregations