Skip to content

Commit

Permalink
Test SampleQueue.peek
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 352781639
  • Loading branch information
AquilesCanta authored and kim-vde committed Jan 22, 2021
1 parent 4eaa611 commit 2d3e6d4
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ public void readWithoutWrite() {
assertNoSamplesToRead(null);
}

@Test
public void peekConsumesDownstreamFormat() {
sampleQueue.format(FORMAT_1);
clearFormatHolderAndInputBuffer();
int result =
sampleQueue.peek(
formatHolder, inputBuffer, /* formatRequired= */ false, /* loadingFinished= */ false);
assertThat(result).isEqualTo(RESULT_FORMAT_READ);
// formatHolder should be populated.
assertThat(formatHolder.format).isEqualTo(FORMAT_1);
result =
sampleQueue.peek(
formatHolder, inputBuffer, /* formatRequired= */ false, /* loadingFinished= */ false);
assertThat(result).isEqualTo(RESULT_NOTHING_READ);
}

@Test
public void equalFormatsDeduplicated() {
sampleQueue.format(FORMAT_1);
Expand Down Expand Up @@ -1625,10 +1641,32 @@ private void assertReadSample(
byte[] sampleData,
int offset,
int length) {
// Check that peeks yields the expected values.
clearFormatHolderAndInputBuffer();
int result =
sampleQueue.peek(
formatHolder, inputBuffer, /* formatRequired= */ false, /* loadingFinished= */ false);
assertBufferReadResult(
result, timeUs, isKeyFrame, isDecodeOnly, isEncrypted, sampleData, offset, length);

// Check that read yields the expected values.
clearFormatHolderAndInputBuffer();
result =
sampleQueue.read(
formatHolder, inputBuffer, /* formatRequired= */ false, /* loadingFinished= */ false);
assertBufferReadResult(
result, timeUs, isKeyFrame, isDecodeOnly, isEncrypted, sampleData, offset, length);
}

private void assertBufferReadResult(
int result,
long timeUs,
boolean isKeyFrame,
boolean isDecodeOnly,
boolean isEncrypted,
byte[] sampleData,
int offset,
int length) {
assertThat(result).isEqualTo(RESULT_BUFFER_READ);
// formatHolder should not be populated.
assertThat(formatHolder.format).isNull();
Expand Down

0 comments on commit 2d3e6d4

Please sign in to comment.