Update the DefaultExtractorInput's peek buffer length on each write
This prevents leaving an inconsistent state after a EOF exception. Issue:#5039 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219785275
This commit is contained in:
parent
b0555315cb
commit
32927bb62c
@ -27,8 +27,11 @@
|
||||
* Fix handling of streams with appended data
|
||||
([#4954](https://github.com/google/ExoPlayer/issues/4954)).
|
||||
* DASH: Parse ProgramInformation element if present in the manifest.
|
||||
* HLS: Add constructor to `DefaultHlsExtractorFactory` for adding TS payload
|
||||
* HLS:
|
||||
* Add constructor to `DefaultHlsExtractorFactory` for adding TS payload
|
||||
reader factory flags
|
||||
* Fix bug in segment sniffing
|
||||
([#5039](https://github.com/google/ExoPlayer/issues/5039)).
|
||||
([#4861](https://github.com/google/ExoPlayer/issues/4861)).
|
||||
* SubRip: Add support for alignment tags, and remove tags from the displayed
|
||||
captions ([#4306](https://github.com/google/ExoPlayer/issues/4306)).
|
||||
|
@ -130,16 +130,16 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
public boolean advancePeekPosition(int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
ensureSpaceForPeek(length);
|
||||
int bytesPeeked = Math.min(peekBufferLength - peekBufferPosition, length);
|
||||
int bytesPeeked = peekBufferLength - peekBufferPosition;
|
||||
while (bytesPeeked < length) {
|
||||
bytesPeeked = readFromDataSource(peekBuffer, peekBufferPosition, length, bytesPeeked,
|
||||
allowEndOfInput);
|
||||
if (bytesPeeked == C.RESULT_END_OF_INPUT) {
|
||||
return false;
|
||||
}
|
||||
peekBufferLength = peekBufferPosition + bytesPeeked;
|
||||
}
|
||||
peekBufferPosition += length;
|
||||
peekBufferLength = Math.max(peekBufferLength, peekBufferPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -338,6 +338,23 @@ public class DefaultExtractorInputTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPeekFullyAfterEofExceptionPeeksAsExpected() throws Exception {
|
||||
DefaultExtractorInput input = createDefaultExtractorInput();
|
||||
byte[] target = new byte[TEST_DATA.length + 10];
|
||||
|
||||
try {
|
||||
input.peekFully(target, /* offset= */ 0, target.length);
|
||||
fail();
|
||||
} catch (EOFException expected) {
|
||||
// Do nothing. Expected.
|
||||
}
|
||||
input.peekFully(target, /* offset= */ 0, /* length= */ TEST_DATA.length);
|
||||
|
||||
assertThat(input.getPeekPosition()).isEqualTo(TEST_DATA.length);
|
||||
assertThat(Arrays.equals(TEST_DATA, Arrays.copyOf(target, TEST_DATA.length))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetPeekPosition() throws Exception {
|
||||
DefaultExtractorInput input = createDefaultExtractorInput();
|
||||
|
Loading…
x
Reference in New Issue
Block a user