|
20 | 20 |
|
21 | 21 | import androidx.media3.common.Format;
|
22 | 22 | import androidx.media3.common.MimeTypes;
|
| 23 | +import androidx.media3.common.util.Consumer; |
23 | 24 | import androidx.media3.common.util.Util;
|
24 | 25 | import androidx.media3.extractor.Extractor;
|
25 | 26 | import androidx.media3.extractor.text.webvtt.WebvttParser;
|
|
28 | 29 | import androidx.media3.test.utils.FakeTrackOutput;
|
29 | 30 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
30 | 31 | import com.google.common.primitives.Ints;
|
| 32 | +import java.util.concurrent.atomic.AtomicInteger; |
31 | 33 | import org.junit.Before;
|
32 | 34 | import org.junit.Test;
|
33 | 35 | import org.junit.runner.RunWith;
|
@@ -188,6 +190,45 @@ public void extractor_seekBetweenReads_outputsCues() throws Exception {
|
188 | 190 | assertThat(cues2.cues.get(0).text.toString()).isEqualTo("This is the third subtitle.");
|
189 | 191 | }
|
190 | 192 |
|
| 193 | + @Test |
| 194 | + public void extractor_unknownLengthInput_passesNumberOfBytesReadToSubtitleParser() |
| 195 | + throws Exception { |
| 196 | + FakeExtractorOutput output = new FakeExtractorOutput(); |
| 197 | + byte[] inputData = Util.getUtf8Bytes(TEST_DATA); |
| 198 | + FakeExtractorInput input = |
| 199 | + new FakeExtractorInput.Builder() |
| 200 | + .setData(inputData) |
| 201 | + .setSimulatePartialReads(true) |
| 202 | + .setSimulateUnknownLength(true) |
| 203 | + .build(); |
| 204 | + AtomicInteger lengthFromParse = new AtomicInteger(); |
| 205 | + SubtitleParser fakeSubtitleParser = |
| 206 | + new SubtitleParser() { |
| 207 | + @Override |
| 208 | + public void parse( |
| 209 | + byte[] data, |
| 210 | + int offset, |
| 211 | + int length, |
| 212 | + OutputOptions outputOptions, |
| 213 | + Consumer<CuesWithTiming> output) { |
| 214 | + lengthFromParse.set(length); |
| 215 | + } |
| 216 | + |
| 217 | + @Override |
| 218 | + public @Format.CueReplacementBehavior int getCueReplacementBehavior() { |
| 219 | + return Format.CUE_REPLACEMENT_BEHAVIOR_MERGE; |
| 220 | + } |
| 221 | + }; |
| 222 | + SubtitleExtractor extractor = |
| 223 | + new SubtitleExtractor( |
| 224 | + fakeSubtitleParser, new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).build()); |
| 225 | + |
| 226 | + extractor.init(output); |
| 227 | + while (extractor.read(input, null) != Extractor.RESULT_END_OF_INPUT) {} |
| 228 | + |
| 229 | + assertThat(lengthFromParse.get()).isEqualTo(inputData.length); |
| 230 | + } |
| 231 | + |
191 | 232 | @Test
|
192 | 233 | public void read_withoutInit_fails() {
|
193 | 234 | FakeExtractorInput input = new FakeExtractorInput.Builder().setData(new byte[0]).build();
|
|
0 commit comments