Add a test for SampleQueue capacity increases

Also remove redundant line

PiperOrigin-RevId: 283956203
This commit is contained in:
aquilescanta 2019-12-05 13:46:05 +00:00 committed by Oliver Woodman
parent 9376479553
commit 96ea436759
2 changed files with 30 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
import android.os.Looper;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
@ -49,7 +50,7 @@ public class SampleQueue implements TrackOutput {
public static final int ADVANCE_FAILED = -1;
private static final int SAMPLE_CAPACITY_INCREMENT = 1000;
@VisibleForTesting /* package */ static final int SAMPLE_CAPACITY_INCREMENT = 1000;
private final SampleDataQueue sampleDataQueue;
private final SampleExtrasHolder extrasHolder;
@ -652,7 +653,6 @@ public class SampleQueue implements TrackOutput {
formats = newFormats;
sourceIds = newSourceIds;
relativeFirstIndex = 0;
length = capacity;
capacity = newCapacity;
}
}

View File

@ -157,6 +157,34 @@ public final class SampleQueueTest {
inputBuffer = null;
}
@Test
public void testCapacityIncreases() {
int numberOfSamplesToInput = 3 * SampleQueue.SAMPLE_CAPACITY_INCREMENT + 1;
sampleQueue.format(FORMAT_1);
sampleQueue.sampleData(
new ParsableByteArray(numberOfSamplesToInput), /* length= */ numberOfSamplesToInput);
for (int i = 0; i < numberOfSamplesToInput; i++) {
sampleQueue.sampleMetadata(
/* timeUs= */ i * 1000,
/* flags= */ C.BUFFER_FLAG_KEY_FRAME,
/* size= */ 1,
/* offset= */ numberOfSamplesToInput - i - 1,
/* cryptoData= */ null);
}
assertReadFormat(/* formatRequired= */ false, FORMAT_1);
for (int i = 0; i < numberOfSamplesToInput; i++) {
assertReadSample(
/* timeUs= */ i * 1000,
/* isKeyFrame= */ true,
/* isEncrypted= */ false,
/* sampleData= */ new byte[1],
/* offset= */ 0,
/* length= */ 1);
}
assertReadNothing(/* formatRequired= */ false);
}
@Test
public void testResetReleasesAllocations() {
writeTestData();