Commit e4617567 by olly Committed by Oliver Woodman

Rename DefaultTrackOutput to SampleQueue

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158842843
parent 6362dfeb
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.extractor; package com.google.android.exoplayer2.source;
import android.test.MoreAsserts; import android.test.MoreAsserts;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -28,9 +28,9 @@ import java.util.Arrays; ...@@ -28,9 +28,9 @@ import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* Test for {@link DefaultTrackOutput}. * Test for {@link SampleQueue}.
*/ */
public class DefaultTrackOutputTest extends TestCase { public class SampleQueueTest extends TestCase {
private static final int ALLOCATION_SIZE = 16; private static final int ALLOCATION_SIZE = 16;
...@@ -42,8 +42,8 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -42,8 +42,8 @@ public class DefaultTrackOutputTest extends TestCase {
/* /*
* TEST_SAMPLE_SIZES and TEST_SAMPLE_OFFSETS are intended to test various boundary cases (with * TEST_SAMPLE_SIZES and TEST_SAMPLE_OFFSETS are intended to test various boundary cases (with
* respect to the allocation size). TEST_SAMPLE_OFFSETS values are defined as the backward offsets * respect to the allocation size). TEST_SAMPLE_OFFSETS values are defined as the backward offsets
* (as expected by DefaultTrackOutput.sampleMetadata) assuming that TEST_DATA has been written to * (as expected by SampleQueue.sampleMetadata) assuming that TEST_DATA has been written to the
* the trackOutput in full. The allocations are filled as follows, where | indicates a boundary * sampleQueue in full. The allocations are filled as follows, where | indicates a boundary
* between allocations and x indicates a byte that doesn't belong to a sample: * between allocations and x indicates a byte that doesn't belong to a sample:
* *
* x<s1>|x<s2>x|x<s3>|<s4>x|<s5>|<s6|s6>|x<s7|s7>x|<s8> * x<s1>|x<s2>x|x<s3>|<s4>x|<s5>|<s6|s6>|x<s7|s7>x|<s8>
...@@ -69,7 +69,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -69,7 +69,7 @@ public class DefaultTrackOutputTest extends TestCase {
private static final int TEST_DATA_SECOND_KEYFRAME_INDEX = 4; private static final int TEST_DATA_SECOND_KEYFRAME_INDEX = 4;
private Allocator allocator; private Allocator allocator;
private DefaultTrackOutput trackOutput; private SampleQueue sampleQueue;
private FormatHolder formatHolder; private FormatHolder formatHolder;
private DecoderInputBuffer inputBuffer; private DecoderInputBuffer inputBuffer;
...@@ -77,7 +77,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -77,7 +77,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
allocator = new DefaultAllocator(false, ALLOCATION_SIZE); allocator = new DefaultAllocator(false, ALLOCATION_SIZE);
trackOutput = new DefaultTrackOutput(allocator); sampleQueue = new SampleQueue(allocator);
formatHolder = new FormatHolder(); formatHolder = new FormatHolder();
inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL); inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
} }
...@@ -86,7 +86,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -86,7 +86,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
allocator = null; allocator = null;
trackOutput = null; sampleQueue = null;
formatHolder = null; formatHolder = null;
inputBuffer = null; inputBuffer = null;
} }
...@@ -94,7 +94,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -94,7 +94,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testDisableReleasesAllocations() { public void testDisableReleasesAllocations() {
writeTestData(); writeTestData();
assertAllocationCount(10); assertAllocationCount(10);
trackOutput.disable(); sampleQueue.disable();
assertAllocationCount(0); assertAllocationCount(0);
} }
...@@ -103,31 +103,31 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -103,31 +103,31 @@ public class DefaultTrackOutputTest extends TestCase {
} }
public void testReadFormatDeduplicated() { public void testReadFormatDeduplicated() {
trackOutput.format(TEST_FORMAT_1); sampleQueue.format(TEST_FORMAT_1);
assertReadFormat(false, TEST_FORMAT_1); assertReadFormat(false, TEST_FORMAT_1);
// If the same format is input then it should be de-duplicated (i.e. not output again). // If the same format is input then it should be de-duplicated (i.e. not output again).
trackOutput.format(TEST_FORMAT_1); sampleQueue.format(TEST_FORMAT_1);
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
// The same applies for a format that's equal (but a different object). // The same applies for a format that's equal (but a different object).
trackOutput.format(TEST_FORMAT_1_COPY); sampleQueue.format(TEST_FORMAT_1_COPY);
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
} }
public void testReadSingleSamples() { public void testReadSingleSamples() {
trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE);
assertAllocationCount(1); assertAllocationCount(1);
// Nothing to read. // Nothing to read.
assertNoSamplesToRead(null); assertNoSamplesToRead(null);
trackOutput.format(TEST_FORMAT_1); sampleQueue.format(TEST_FORMAT_1);
// Read the format. // Read the format.
assertReadFormat(false, TEST_FORMAT_1); assertReadFormat(false, TEST_FORMAT_1);
// Nothing to read. // Nothing to read.
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
trackOutput.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null); sampleQueue.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
// If formatRequired, should read the format rather than the sample. // If formatRequired, should read the format rather than the sample.
assertReadFormat(true, TEST_FORMAT_1); assertReadFormat(true, TEST_FORMAT_1);
...@@ -140,19 +140,19 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -140,19 +140,19 @@ public class DefaultTrackOutputTest extends TestCase {
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
// Write a second sample followed by one byte that does not belong to it. // Write a second sample followed by one byte that does not belong to it.
trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE);
trackOutput.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null); sampleQueue.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null);
// If formatRequired, should read the format rather than the sample. // If formatRequired, should read the format rather than the sample.
assertReadFormat(true, TEST_FORMAT_1); assertReadFormat(true, TEST_FORMAT_1);
// Read the sample. // Read the sample.
assertSampleRead(2000, false, TEST_DATA, 0, ALLOCATION_SIZE - 1); assertSampleRead(2000, false, TEST_DATA, 0, ALLOCATION_SIZE - 1);
// The last byte written to the output may belong to a sample whose metadata has yet to be // The last byte written to the sample queue may belong to a sample whose metadata has yet to be
// written, so an allocation should still be held. // written, so an allocation should still be held.
assertAllocationCount(1); assertAllocationCount(1);
// Write metadata for a third sample containing the remaining byte. // Write metadata for a third sample containing the remaining byte.
trackOutput.sampleMetadata(3000, 0, 1, 0, null); sampleQueue.sampleMetadata(3000, 0, 1, 0, null);
// If formatRequired, should read the format rather than the sample. // If formatRequired, should read the format rather than the sample.
assertReadFormat(true, TEST_FORMAT_1); assertReadFormat(true, TEST_FORMAT_1);
...@@ -165,7 +165,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -165,7 +165,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testReadMultiSamples() { public void testReadMultiSamples() {
writeTestData(); writeTestData();
assertEquals(TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1], assertEquals(TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1],
trackOutput.getLargestQueuedTimestampUs()); sampleQueue.getLargestQueuedTimestampUs());
assertAllocationCount(10); assertAllocationCount(10);
assertReadTestData(); assertReadTestData();
assertAllocationCount(0); assertAllocationCount(0);
...@@ -182,7 +182,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -182,7 +182,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipAll() { public void testSkipAll() {
writeTestData(); writeTestData();
trackOutput.skipAll(); sampleQueue.skipAll();
assertAllocationCount(0); assertAllocationCount(0);
// Despite skipping all samples, we should still read the last format, since this is the // Despite skipping all samples, we should still read the last format, since this is the
// expected format for a subsequent sample. // expected format for a subsequent sample.
...@@ -192,9 +192,9 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -192,9 +192,9 @@ public class DefaultTrackOutputTest extends TestCase {
} }
public void testSkipAllRetainsUnassignedData() { public void testSkipAllRetainsUnassignedData() {
trackOutput.format(TEST_FORMAT_1); sampleQueue.format(TEST_FORMAT_1);
trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE);
trackOutput.skipAll(); sampleQueue.skipAll();
// Skipping shouldn't discard data that may belong to a sample whose metadata has yet to be // Skipping shouldn't discard data that may belong to a sample whose metadata has yet to be
// written. // written.
assertAllocationCount(1); assertAllocationCount(1);
...@@ -203,7 +203,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -203,7 +203,7 @@ public class DefaultTrackOutputTest extends TestCase {
// Once the format has been read, there's nothing else to read. // Once the format has been read, there's nothing else to read.
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
trackOutput.sampleMetadata(0, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null); sampleQueue.sampleMetadata(0, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
// Once the metadata has been written, check the sample can be read as expected. // Once the metadata has been written, check the sample can be read as expected.
assertSampleRead(0, true, TEST_DATA, 0, ALLOCATION_SIZE); assertSampleRead(0, true, TEST_DATA, 0, ALLOCATION_SIZE);
assertNoSamplesToRead(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1);
...@@ -212,7 +212,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -212,7 +212,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipToKeyframeBeforeBuffer() { public void testSkipToKeyframeBeforeBuffer() {
writeTestData(); writeTestData();
boolean result = trackOutput.skipToKeyframeBefore(TEST_SAMPLE_TIMESTAMPS[0] - 1, false); boolean result = sampleQueue.skipToKeyframeBefore(TEST_SAMPLE_TIMESTAMPS[0] - 1, false);
// Should fail and have no effect. // Should fail and have no effect.
assertFalse(result); assertFalse(result);
assertReadTestData(); assertReadTestData();
...@@ -221,7 +221,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -221,7 +221,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipToKeyframeStartOfBuffer() { public void testSkipToKeyframeStartOfBuffer() {
writeTestData(); writeTestData();
boolean result = trackOutput.skipToKeyframeBefore(TEST_SAMPLE_TIMESTAMPS[0], false); boolean result = sampleQueue.skipToKeyframeBefore(TEST_SAMPLE_TIMESTAMPS[0], false);
// Should succeed but have no effect (we're already at the first frame). // Should succeed but have no effect (we're already at the first frame).
assertTrue(result); assertTrue(result);
assertReadTestData(); assertReadTestData();
...@@ -230,7 +230,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -230,7 +230,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipToKeyframeEndOfBuffer() { public void testSkipToKeyframeEndOfBuffer() {
writeTestData(); writeTestData();
boolean result = trackOutput.skipToKeyframeBefore( boolean result = sampleQueue.skipToKeyframeBefore(
TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1], false); TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1], false);
// Should succeed and skip to 2nd keyframe. // Should succeed and skip to 2nd keyframe.
assertTrue(result); assertTrue(result);
...@@ -240,7 +240,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -240,7 +240,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipToKeyframeAfterBuffer() { public void testSkipToKeyframeAfterBuffer() {
writeTestData(); writeTestData();
boolean result = trackOutput.skipToKeyframeBefore( boolean result = sampleQueue.skipToKeyframeBefore(
TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, false); TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, false);
// Should fail and have no effect. // Should fail and have no effect.
assertFalse(result); assertFalse(result);
...@@ -250,7 +250,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -250,7 +250,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testSkipToKeyframeAfterBufferAllowed() { public void testSkipToKeyframeAfterBufferAllowed() {
writeTestData(); writeTestData();
boolean result = trackOutput.skipToKeyframeBefore( boolean result = sampleQueue.skipToKeyframeBefore(
TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, true); TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, true);
// Should succeed and skip to 2nd keyframe. // Should succeed and skip to 2nd keyframe.
assertTrue(result); assertTrue(result);
...@@ -260,23 +260,23 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -260,23 +260,23 @@ public class DefaultTrackOutputTest extends TestCase {
public void testDiscardUpstream() { public void testDiscardUpstream() {
writeTestData(); writeTestData();
trackOutput.discardUpstreamSamples(8); sampleQueue.discardUpstreamSamples(8);
assertAllocationCount(10); assertAllocationCount(10);
trackOutput.discardUpstreamSamples(7); sampleQueue.discardUpstreamSamples(7);
assertAllocationCount(9); assertAllocationCount(9);
trackOutput.discardUpstreamSamples(6); sampleQueue.discardUpstreamSamples(6);
assertAllocationCount(8); // Byte not belonging to sample prevents 7. assertAllocationCount(8); // Byte not belonging to sample prevents 7.
trackOutput.discardUpstreamSamples(5); sampleQueue.discardUpstreamSamples(5);
assertAllocationCount(5); assertAllocationCount(5);
trackOutput.discardUpstreamSamples(4); sampleQueue.discardUpstreamSamples(4);
assertAllocationCount(4); assertAllocationCount(4);
trackOutput.discardUpstreamSamples(3); sampleQueue.discardUpstreamSamples(3);
assertAllocationCount(3); assertAllocationCount(3);
trackOutput.discardUpstreamSamples(2); sampleQueue.discardUpstreamSamples(2);
assertAllocationCount(3); // Byte not belonging to sample prevents 2. assertAllocationCount(3); // Byte not belonging to sample prevents 2.
trackOutput.discardUpstreamSamples(1); sampleQueue.discardUpstreamSamples(1);
assertAllocationCount(2); // Byte not belonging to sample prevents 1. assertAllocationCount(2); // Byte not belonging to sample prevents 1.
trackOutput.discardUpstreamSamples(0); sampleQueue.discardUpstreamSamples(0);
assertAllocationCount(1); // Byte not belonging to sample prevents 0. assertAllocationCount(1); // Byte not belonging to sample prevents 0.
assertReadFormat(false, TEST_FORMAT_2); assertReadFormat(false, TEST_FORMAT_2);
assertNoSamplesToRead(TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2);
...@@ -284,9 +284,9 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -284,9 +284,9 @@ public class DefaultTrackOutputTest extends TestCase {
public void testDiscardUpstreamMulti() { public void testDiscardUpstreamMulti() {
writeTestData(); writeTestData();
trackOutput.discardUpstreamSamples(4); sampleQueue.discardUpstreamSamples(4);
assertAllocationCount(4); assertAllocationCount(4);
trackOutput.discardUpstreamSamples(0); sampleQueue.discardUpstreamSamples(0);
assertAllocationCount(1); // Byte not belonging to sample prevents 0. assertAllocationCount(1); // Byte not belonging to sample prevents 0.
assertReadFormat(false, TEST_FORMAT_2); assertReadFormat(false, TEST_FORMAT_2);
assertNoSamplesToRead(TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2);
...@@ -294,7 +294,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -294,7 +294,7 @@ public class DefaultTrackOutputTest extends TestCase {
public void testDiscardUpstreamBeforeRead() { public void testDiscardUpstreamBeforeRead() {
writeTestData(); writeTestData();
trackOutput.discardUpstreamSamples(4); sampleQueue.discardUpstreamSamples(4);
assertAllocationCount(4); assertAllocationCount(4);
assertReadTestData(null, 0, 4); assertReadTestData(null, 0, 4);
assertReadFormat(false, TEST_FORMAT_2); assertReadFormat(false, TEST_FORMAT_2);
...@@ -304,17 +304,17 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -304,17 +304,17 @@ public class DefaultTrackOutputTest extends TestCase {
public void testDiscardUpstreamAfterRead() { public void testDiscardUpstreamAfterRead() {
writeTestData(); writeTestData();
assertReadTestData(null, 0, 3); assertReadTestData(null, 0, 3);
trackOutput.discardUpstreamSamples(8); sampleQueue.discardUpstreamSamples(8);
assertAllocationCount(7); assertAllocationCount(7);
trackOutput.discardUpstreamSamples(7); sampleQueue.discardUpstreamSamples(7);
assertAllocationCount(6); assertAllocationCount(6);
trackOutput.discardUpstreamSamples(6); sampleQueue.discardUpstreamSamples(6);
assertAllocationCount(5); // Byte not belonging to sample prevents 4. assertAllocationCount(5); // Byte not belonging to sample prevents 4.
trackOutput.discardUpstreamSamples(5); sampleQueue.discardUpstreamSamples(5);
assertAllocationCount(2); assertAllocationCount(2);
trackOutput.discardUpstreamSamples(4); sampleQueue.discardUpstreamSamples(4);
assertAllocationCount(1); assertAllocationCount(1);
trackOutput.discardUpstreamSamples(3); sampleQueue.discardUpstreamSamples(3);
assertAllocationCount(0); assertAllocationCount(0);
assertReadFormat(false, TEST_FORMAT_2); assertReadFormat(false, TEST_FORMAT_2);
assertNoSamplesToRead(TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2);
...@@ -323,43 +323,42 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -323,43 +323,42 @@ public class DefaultTrackOutputTest extends TestCase {
// Internal methods. // Internal methods.
/** /**
* Writes standard test data to {@code trackOutput}. * Writes standard test data to {@code sampleQueue}.
*/ */
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
private void writeTestData() { private void writeTestData() {
trackOutput.sampleData(new ParsableByteArray(TEST_DATA), TEST_DATA.length); sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), TEST_DATA.length);
Format format = null; Format format = null;
for (int i = 0; i < TEST_SAMPLE_TIMESTAMPS.length; i++) { for (int i = 0; i < TEST_SAMPLE_TIMESTAMPS.length; i++) {
if (TEST_SAMPLE_FORMATS[i] != format) { if (TEST_SAMPLE_FORMATS[i] != format) {
trackOutput.format(TEST_SAMPLE_FORMATS[i]); sampleQueue.format(TEST_SAMPLE_FORMATS[i]);
format = TEST_SAMPLE_FORMATS[i]; format = TEST_SAMPLE_FORMATS[i];
} }
trackOutput.sampleMetadata(TEST_SAMPLE_TIMESTAMPS[i], TEST_SAMPLE_FLAGS[i], sampleQueue.sampleMetadata(TEST_SAMPLE_TIMESTAMPS[i], TEST_SAMPLE_FLAGS[i],
TEST_SAMPLE_SIZES[i], TEST_SAMPLE_OFFSETS[i], null); TEST_SAMPLE_SIZES[i], TEST_SAMPLE_OFFSETS[i], null);
} }
} }
/** /**
* Asserts correct reading of standard test data from {@code trackOutput}. * Asserts correct reading of standard test data from {@code sampleQueue}.
*/ */
private void assertReadTestData() { private void assertReadTestData() {
assertReadTestData(null, 0); assertReadTestData(null, 0);
} }
/** /**
* Asserts correct reading of standard test data from {@code trackOutput}. * Asserts correct reading of standard test data from {@code sampleQueue}.
* *
* @param startFormat The format of the last sample previously read from {@code trackOutput}. * @param startFormat The format of the last sample previously read from {@code sampleQueue}.
*/ */
private void assertReadTestData(Format startFormat) { private void assertReadTestData(Format startFormat) {
assertReadTestData(startFormat, 0); assertReadTestData(startFormat, 0);
} }
/** /**
* Asserts correct reading of standard test data from {@code trackOutput}. * Asserts correct reading of standard test data from {@code sampleQueue}.
* *
* @param startFormat The format of the last sample previously read from {@code trackOutput}. * @param startFormat The format of the last sample previously read from {@code sampleQueue}.
* @param firstSampleIndex The index of the first sample that's expected to be read.
*/ */
private void assertReadTestData(Format startFormat, int firstSampleIndex) { private void assertReadTestData(Format startFormat, int firstSampleIndex) {
assertReadTestData(startFormat, firstSampleIndex, assertReadTestData(startFormat, firstSampleIndex,
...@@ -367,9 +366,9 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -367,9 +366,9 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts correct reading of standard test data from {@code trackOutput}. * Asserts correct reading of standard test data from {@code sampleQueue}.
* *
* @param startFormat The format of the last sample previously read from {@code trackOutput}. * @param startFormat The format of the last sample previously read from {@code sampleQueue}.
* @param firstSampleIndex The index of the first sample that's expected to be read. * @param firstSampleIndex The index of the first sample that's expected to be read.
* @param sampleCount The number of samples to read. * @param sampleCount The number of samples to read.
*/ */
...@@ -377,7 +376,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -377,7 +376,7 @@ public class DefaultTrackOutputTest extends TestCase {
Format format = startFormat; Format format = startFormat;
for (int i = firstSampleIndex; i < firstSampleIndex + sampleCount; i++) { for (int i = firstSampleIndex; i < firstSampleIndex + sampleCount; i++) {
// Use equals() on the read side despite using referential equality on the write side, since // Use equals() on the read side despite using referential equality on the write side, since
// trackOutput de-duplicates written formats using equals(). // sampleQueue de-duplicates written formats using equals().
if (!TEST_SAMPLE_FORMATS[i].equals(format)) { if (!TEST_SAMPLE_FORMATS[i].equals(format)) {
// If the format has changed, we should read it. // If the format has changed, we should read it.
assertReadFormat(false, TEST_SAMPLE_FORMATS[i]); assertReadFormat(false, TEST_SAMPLE_FORMATS[i]);
...@@ -395,11 +394,11 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -395,11 +394,11 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts {@link DefaultTrackOutput#readData} is behaving correctly, given there are no samples * Asserts {@link SampleQueue#readData} is behaving correctly, given there are no samples
* to read and the last format to be written to the output is {@code endFormat}. * to read and the last format to be written to the sample queue is {@code endFormat}.
* *
* @param endFormat The last format to be written to the output, or null of no format has been * @param endFormat The last format to be written to the sample queue, or null of no format has
* written. * been written.
*/ */
private void assertNoSamplesToRead(Format endFormat) { private void assertNoSamplesToRead(Format endFormat) {
// If not formatRequired or loadingFinished, should read nothing. // If not formatRequired or loadingFinished, should read nothing.
...@@ -423,13 +422,13 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -423,13 +422,13 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts {@link DefaultTrackOutput#readData} returns {@link C#RESULT_NOTHING_READ}. * Asserts {@link SampleQueue#readData} returns {@link C#RESULT_NOTHING_READ}.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
*/ */
private void assertReadNothing(boolean formatRequired) { private void assertReadNothing(boolean formatRequired) {
clearFormatHolderAndInputBuffer(); clearFormatHolderAndInputBuffer();
int result = trackOutput.readData(formatHolder, inputBuffer, formatRequired, false, 0); int result = sampleQueue.readData(formatHolder, inputBuffer, formatRequired, false, 0);
assertEquals(C.RESULT_NOTHING_READ, result); assertEquals(C.RESULT_NOTHING_READ, result);
// formatHolder should not be populated. // formatHolder should not be populated.
assertNull(formatHolder.format); assertNull(formatHolder.format);
...@@ -439,14 +438,14 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -439,14 +438,14 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts {@link DefaultTrackOutput#readData} returns {@link C#RESULT_BUFFER_READ} and that the * Asserts {@link SampleQueue#readData} returns {@link C#RESULT_BUFFER_READ} and that the
* {@link DecoderInputBuffer#isEndOfStream()} is set. * {@link DecoderInputBuffer#isEndOfStream()} is set.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
*/ */
private void assertReadEndOfStream(boolean formatRequired) { private void assertReadEndOfStream(boolean formatRequired) {
clearFormatHolderAndInputBuffer(); clearFormatHolderAndInputBuffer();
int result = trackOutput.readData(formatHolder, inputBuffer, formatRequired, true, 0); int result = sampleQueue.readData(formatHolder, inputBuffer, formatRequired, true, 0);
assertEquals(C.RESULT_BUFFER_READ, result); assertEquals(C.RESULT_BUFFER_READ, result);
// formatHolder should not be populated. // formatHolder should not be populated.
assertNull(formatHolder.format); assertNull(formatHolder.format);
...@@ -458,7 +457,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -458,7 +457,7 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts {@link DefaultTrackOutput#readData} returns {@link C#RESULT_FORMAT_READ} and that the * Asserts {@link SampleQueue#readData} returns {@link C#RESULT_FORMAT_READ} and that the
* format holder is filled with a {@link Format} that equals {@code format}. * format holder is filled with a {@link Format} that equals {@code format}.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
...@@ -466,7 +465,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -466,7 +465,7 @@ public class DefaultTrackOutputTest extends TestCase {
*/ */
private void assertReadFormat(boolean formatRequired, Format format) { private void assertReadFormat(boolean formatRequired, Format format) {
clearFormatHolderAndInputBuffer(); clearFormatHolderAndInputBuffer();
int result = trackOutput.readData(formatHolder, inputBuffer, formatRequired, false, 0); int result = sampleQueue.readData(formatHolder, inputBuffer, formatRequired, false, 0);
assertEquals(C.RESULT_FORMAT_READ, result); assertEquals(C.RESULT_FORMAT_READ, result);
// formatHolder should be populated. // formatHolder should be populated.
assertEquals(format, formatHolder.format); assertEquals(format, formatHolder.format);
...@@ -476,7 +475,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -476,7 +475,7 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts {@link DefaultTrackOutput#readData} returns {@link C#RESULT_BUFFER_READ} and that the * Asserts {@link SampleQueue#readData} returns {@link C#RESULT_BUFFER_READ} and that the
* buffer is filled with the specified sample data. * buffer is filled with the specified sample data.
* *
* @param timeUs The expected buffer timestamp. * @param timeUs The expected buffer timestamp.
...@@ -488,7 +487,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -488,7 +487,7 @@ public class DefaultTrackOutputTest extends TestCase {
private void assertSampleRead(long timeUs, boolean isKeyframe, byte[] sampleData, int offset, private void assertSampleRead(long timeUs, boolean isKeyframe, byte[] sampleData, int offset,
int length) { int length) {
clearFormatHolderAndInputBuffer(); clearFormatHolderAndInputBuffer();
int result = trackOutput.readData(formatHolder, inputBuffer, false, false, 0); int result = sampleQueue.readData(formatHolder, inputBuffer, false, false, 0);
assertEquals(C.RESULT_BUFFER_READ, result); assertEquals(C.RESULT_BUFFER_READ, result);
// formatHolder should not be populated. // formatHolder should not be populated.
assertNull(formatHolder.format); assertNull(formatHolder.format);
...@@ -505,7 +504,7 @@ public class DefaultTrackOutputTest extends TestCase { ...@@ -505,7 +504,7 @@ public class DefaultTrackOutputTest extends TestCase {
} }
/** /**
* Asserts the number of allocations currently in use by {@code trackOutput}. * Asserts the number of allocations currently in use by {@code sampleQueue}.
* *
* @param count The expected number of allocations. * @param count The expected number of allocations.
*/ */
......
...@@ -23,14 +23,13 @@ import com.google.android.exoplayer2.Format; ...@@ -23,14 +23,13 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.extractor.DefaultExtractorInput; import com.google.android.exoplayer2.extractor.DefaultExtractorInput;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput.UpstreamFormatChangedListener;
import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorInput; import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.PositionHolder; import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.source.SampleQueue.UpstreamFormatChangedListener;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
...@@ -71,7 +70,7 @@ import java.io.IOException; ...@@ -71,7 +70,7 @@ import java.io.IOException;
private final Runnable maybeFinishPrepareRunnable; private final Runnable maybeFinishPrepareRunnable;
private final Runnable onContinueLoadingRequestedRunnable; private final Runnable onContinueLoadingRequestedRunnable;
private final Handler handler; private final Handler handler;
private final SparseArray<DefaultTrackOutput> sampleQueues; private final SparseArray<SampleQueue> sampleQueues;
private Callback callback; private Callback callback;
private SeekMap seekMap; private SeekMap seekMap;
...@@ -345,7 +344,7 @@ import java.io.IOException; ...@@ -345,7 +344,7 @@ import java.io.IOException;
} }
/* package */ void skipData(int track, long positionUs) { /* package */ void skipData(int track, long positionUs) {
DefaultTrackOutput sampleQueue = sampleQueues.valueAt(track); SampleQueue sampleQueue = sampleQueues.valueAt(track);
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
sampleQueue.skipAll(); sampleQueue.skipAll();
} else { } else {
...@@ -402,9 +401,9 @@ import java.io.IOException; ...@@ -402,9 +401,9 @@ import java.io.IOException;
@Override @Override
public TrackOutput track(int id, int type) { public TrackOutput track(int id, int type) {
DefaultTrackOutput trackOutput = sampleQueues.get(id); SampleQueue trackOutput = sampleQueues.get(id);
if (trackOutput == null) { if (trackOutput == null) {
trackOutput = new DefaultTrackOutput(allocator); trackOutput = new SampleQueue(allocator);
trackOutput.setUpstreamFormatChangeListener(this); trackOutput.setUpstreamFormatChangeListener(this);
sampleQueues.put(id, trackOutput); sampleQueues.put(id, trackOutput);
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.extractor; package com.google.android.exoplayer2.source;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
......
...@@ -13,14 +13,16 @@ ...@@ -13,14 +13,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.extractor; package com.google.android.exoplayer2.source;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
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;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.extractor.SampleMetadataQueue.SampleExtrasHolder; import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.source.SampleMetadataQueue.SampleExtrasHolder;
import com.google.android.exoplayer2.upstream.Allocation; import com.google.android.exoplayer2.upstream.Allocation;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
...@@ -30,10 +32,9 @@ import java.nio.ByteBuffer; ...@@ -30,10 +32,9 @@ import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* A {@link TrackOutput} that buffers extracted samples in a queue and allows for consumption from * A queue of media samples.
* that queue.
*/ */
public final class DefaultTrackOutput implements TrackOutput { public final class SampleQueue implements TrackOutput {
/** /**
* A listener for changes to the upstream format. * A listener for changes to the upstream format.
...@@ -81,7 +82,7 @@ public final class DefaultTrackOutput implements TrackOutput { ...@@ -81,7 +82,7 @@ public final class DefaultTrackOutput implements TrackOutput {
/** /**
* @param allocator An {@link Allocator} from which allocations for sample data can be obtained. * @param allocator An {@link Allocator} from which allocations for sample data can be obtained.
*/ */
public DefaultTrackOutput(Allocator allocator) { public SampleQueue(Allocator allocator) {
this.allocator = allocator; this.allocator = allocator;
allocationLength = allocator.getIndividualAllocationLength(); allocationLength = allocator.getIndividualAllocationLength();
metadataQueue = new SampleMetadataQueue(); metadataQueue = new SampleMetadataQueue();
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
package com.google.android.exoplayer2.source.chunk; package com.google.android.exoplayer2.source.chunk;
import android.util.Log; import android.util.Log;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput;
import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.DummyTrackOutput;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOutputProvider; import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOutputProvider;
/** /**
...@@ -29,22 +29,22 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut ...@@ -29,22 +29,22 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut
private static final String TAG = "BaseMediaChunkOutput"; private static final String TAG = "BaseMediaChunkOutput";
private final int[] trackTypes; private final int[] trackTypes;
private final DefaultTrackOutput[] trackOutputs; private final SampleQueue[] sampleQueues;
/** /**
* @param trackTypes The track types of the individual track outputs. * @param trackTypes The track types of the individual track outputs.
* @param trackOutputs The individual track outputs. * @param sampleQueues The individual sample queues.
*/ */
public BaseMediaChunkOutput(int[] trackTypes, DefaultTrackOutput[] trackOutputs) { public BaseMediaChunkOutput(int[] trackTypes, SampleQueue[] sampleQueues) {
this.trackTypes = trackTypes; this.trackTypes = trackTypes;
this.trackOutputs = trackOutputs; this.sampleQueues = sampleQueues;
} }
@Override @Override
public TrackOutput track(int id, int type) { public TrackOutput track(int id, int type) {
for (int i = 0; i < trackTypes.length; i++) { for (int i = 0; i < trackTypes.length; i++) {
if (type == trackTypes[i]) { if (type == trackTypes[i]) {
return trackOutputs[i]; return sampleQueues[i];
} }
} }
Log.e(TAG, "Unmatched track of type: " + type); Log.e(TAG, "Unmatched track of type: " + type);
...@@ -52,13 +52,13 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut ...@@ -52,13 +52,13 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut
} }
/** /**
* Returns the current absolute write indices of the individual track outputs. * Returns the current absolute write indices of the individual sample queues.
*/ */
public int[] getWriteIndices() { public int[] getWriteIndices() {
int[] writeIndices = new int[trackOutputs.length]; int[] writeIndices = new int[sampleQueues.length];
for (int i = 0; i < trackOutputs.length; i++) { for (int i = 0; i < sampleQueues.length; i++) {
if (trackOutputs[i] != null) { if (sampleQueues[i] != null) {
writeIndices[i] = trackOutputs[i].getWriteIndex(); writeIndices[i] = sampleQueues[i].getWriteIndex();
} }
} }
return writeIndices; return writeIndices;
...@@ -66,12 +66,12 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut ...@@ -66,12 +66,12 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut
/** /**
* Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples * Sets an offset that will be added to the timestamps (and sub-sample timestamps) of samples
* subsequently written to the track outputs. * subsequently written to the sample queues.
*/ */
public void setSampleOffsetUs(long sampleOffsetUs) { public void setSampleOffsetUs(long sampleOffsetUs) {
for (DefaultTrackOutput trackOutput : trackOutputs) { for (SampleQueue sampleQueue : sampleQueues) {
if (trackOutput != null) { if (sampleQueue != null) {
trackOutput.setSampleOffsetUs(sampleOffsetUs); sampleQueue.setSampleOffsetUs(sampleOffsetUs);
} }
} }
} }
......
...@@ -19,8 +19,8 @@ import com.google.android.exoplayer2.C; ...@@ -19,8 +19,8 @@ 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;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher; import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.source.SequenceableLoader; import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
...@@ -49,8 +49,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -49,8 +49,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
private final ChunkHolder nextChunkHolder; private final ChunkHolder nextChunkHolder;
private final LinkedList<BaseMediaChunk> mediaChunks; private final LinkedList<BaseMediaChunk> mediaChunks;
private final List<BaseMediaChunk> readOnlyMediaChunks; private final List<BaseMediaChunk> readOnlyMediaChunks;
private final DefaultTrackOutput primarySampleQueue; private final SampleQueue primarySampleQueue;
private final DefaultTrackOutput[] embeddedSampleQueues; private final SampleQueue[] embeddedSampleQueues;
private final BaseMediaChunkOutput mediaChunkOutput; private final BaseMediaChunkOutput mediaChunkOutput;
private Format primaryDownstreamTrackFormat; private Format primaryDownstreamTrackFormat;
...@@ -85,19 +85,19 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -85,19 +85,19 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks); readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length; int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length;
embeddedSampleQueues = new DefaultTrackOutput[embeddedTrackCount]; embeddedSampleQueues = new SampleQueue[embeddedTrackCount];
embeddedTracksSelected = new boolean[embeddedTrackCount]; embeddedTracksSelected = new boolean[embeddedTrackCount];
int[] trackTypes = new int[1 + embeddedTrackCount]; int[] trackTypes = new int[1 + embeddedTrackCount];
DefaultTrackOutput[] sampleQueues = new DefaultTrackOutput[1 + embeddedTrackCount]; SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount];
primarySampleQueue = new DefaultTrackOutput(allocator); primarySampleQueue = new SampleQueue(allocator);
trackTypes[0] = primaryTrackType; trackTypes[0] = primaryTrackType;
sampleQueues[0] = primarySampleQueue; sampleQueues[0] = primarySampleQueue;
for (int i = 0; i < embeddedTrackCount; i++) { for (int i = 0; i < embeddedTrackCount; i++) {
DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator); SampleQueue sampleQueue = new SampleQueue(allocator);
embeddedSampleQueues[i] = trackOutput; embeddedSampleQueues[i] = sampleQueue;
sampleQueues[i + 1] = trackOutput; sampleQueues[i + 1] = sampleQueue;
trackTypes[i + 1] = embeddedTrackTypes[i]; trackTypes[i + 1] = embeddedTrackTypes[i];
} }
...@@ -192,7 +192,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -192,7 +192,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
} }
// TODO: For this to work correctly, the embedded streams must not discard anything from their // TODO: For this to work correctly, the embedded streams must not discard anything from their
// sample queues beyond the current read position of the primary stream. // sample queues beyond the current read position of the primary stream.
for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.skipToKeyframeBefore(positionUs, true); embeddedSampleQueue.skipToKeyframeBefore(positionUs, true);
} }
} else { } else {
...@@ -204,7 +204,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -204,7 +204,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
loader.cancelLoading(); loader.cancelLoading();
} else { } else {
primarySampleQueue.reset(true); primarySampleQueue.reset(true);
for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.reset(true); embeddedSampleQueue.reset(true);
} }
} }
...@@ -218,7 +218,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -218,7 +218,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
*/ */
public void release() { public void release() {
primarySampleQueue.disable(); primarySampleQueue.disable();
for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.disable(); embeddedSampleQueue.disable();
} }
loader.release(); loader.release();
...@@ -280,7 +280,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -280,7 +280,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
loadable.bytesLoaded()); loadable.bytesLoaded());
if (!released) { if (!released) {
primarySampleQueue.reset(true); primarySampleQueue.reset(true);
for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.reset(true); embeddedSampleQueue.reset(true);
} }
callback.onContinueLoadingRequested(this); callback.onContinueLoadingRequested(this);
...@@ -439,10 +439,10 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -439,10 +439,10 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
public final ChunkSampleStream<T> parent; public final ChunkSampleStream<T> parent;
private final DefaultTrackOutput sampleQueue; private final SampleQueue sampleQueue;
private final int index; private final int index;
public EmbeddedSampleStream(ChunkSampleStream<T> parent, DefaultTrackOutput sampleQueue, public EmbeddedSampleStream(ChunkSampleStream<T> parent, SampleQueue sampleQueue,
int index) { int index) {
this.parent = parent; this.parent = parent;
this.sampleQueue = sampleQueue; this.sampleQueue = sampleQueue;
......
...@@ -22,11 +22,11 @@ import com.google.android.exoplayer2.C; ...@@ -22,11 +22,11 @@ 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;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput;
import com.google.android.exoplayer2.extractor.DefaultTrackOutput.UpstreamFormatChangedListener;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher; import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.SampleQueue.UpstreamFormatChangedListener;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.source.SequenceableLoader; import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
...@@ -81,7 +81,7 @@ import java.util.LinkedList; ...@@ -81,7 +81,7 @@ import java.util.LinkedList;
private final Loader loader; private final Loader loader;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final HlsChunkSource.HlsChunkHolder nextChunkHolder; private final HlsChunkSource.HlsChunkHolder nextChunkHolder;
private final SparseArray<DefaultTrackOutput> sampleQueues; private final SparseArray<SampleQueue> sampleQueues;
private final LinkedList<HlsMediaChunk> mediaChunks; private final LinkedList<HlsMediaChunk> mediaChunks;
private final Runnable maybeFinishPrepareRunnable; private final Runnable maybeFinishPrepareRunnable;
private final Handler handler; private final Handler handler;
...@@ -315,7 +315,7 @@ import java.util.LinkedList; ...@@ -315,7 +315,7 @@ import java.util.LinkedList;
} }
/* package */ void skipData(int group, long positionUs) { /* package */ void skipData(int group, long positionUs) {
DefaultTrackOutput sampleQueue = sampleQueues.valueAt(group); SampleQueue sampleQueue = sampleQueues.valueAt(group);
if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) {
sampleQueue.skipAll(); sampleQueue.skipAll();
} else { } else {
...@@ -471,15 +471,15 @@ import java.util.LinkedList; ...@@ -471,15 +471,15 @@ import java.util.LinkedList;
// ExtractorOutput implementation. Called by the loading thread. // ExtractorOutput implementation. Called by the loading thread.
@Override @Override
public DefaultTrackOutput track(int id, int type) { public SampleQueue track(int id, int type) {
if (sampleQueues.indexOfKey(id) >= 0) { if (sampleQueues.indexOfKey(id) >= 0) {
return sampleQueues.get(id); return sampleQueues.get(id);
} }
DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator); SampleQueue sampleQueue = new SampleQueue(allocator);
trackOutput.setUpstreamFormatChangeListener(this); sampleQueue.setUpstreamFormatChangeListener(this);
trackOutput.sourceId(upstreamChunkUid); sampleQueue.sourceId(upstreamChunkUid);
sampleQueues.put(id, trackOutput); sampleQueues.put(id, sampleQueue);
return trackOutput; return sampleQueue;
} }
@Override @Override
......
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