Skip to content

Commit

Permalink
Update the DefaultExtractorInput's peek buffer length on each write
Browse files Browse the repository at this point in the history
This prevents leaving an inconsistent state after a EOF exception.

Issue:#5039

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=219785275
  • Loading branch information
AquilesCanta authored and ojw28 committed Nov 2, 2018
1 parent b055531 commit 32927bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 5 additions & 2 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
reader factory flags
* 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)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ public void peekFully(byte[] target, int offset, int length)
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ public void testPeekFully() throws Exception {
}
}

@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();
Expand Down

0 comments on commit 32927bb

Please sign in to comment.