Commit 0a0a4782 by aquilescanta Committed by Oliver Woodman

Add a test for SampleQueue capacity increases

Also remove redundant line

PiperOrigin-RevId: 283956203
parent 14897fb6
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
import android.os.Looper; import android.os.Looper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
...@@ -49,7 +50,7 @@ public class SampleQueue implements TrackOutput { ...@@ -49,7 +50,7 @@ public class SampleQueue implements TrackOutput {
public static final int ADVANCE_FAILED = -1; 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 SampleDataQueue sampleDataQueue;
private final SampleExtrasHolder extrasHolder; private final SampleExtrasHolder extrasHolder;
...@@ -652,7 +653,6 @@ public class SampleQueue implements TrackOutput { ...@@ -652,7 +653,6 @@ public class SampleQueue implements TrackOutput {
formats = newFormats; formats = newFormats;
sourceIds = newSourceIds; sourceIds = newSourceIds;
relativeFirstIndex = 0; relativeFirstIndex = 0;
length = capacity;
capacity = newCapacity; capacity = newCapacity;
} }
} }
......
...@@ -158,6 +158,34 @@ public final class SampleQueueTest { ...@@ -158,6 +158,34 @@ public final class SampleQueueTest {
} }
@Test @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() { public void testResetReleasesAllocations() {
writeTestData(); writeTestData();
assertAllocationCount(10); assertAllocationCount(10);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment