diff --git a/library/core/src/androidTest/java/com/google/android/exoplayer2/extractor/DefaultTrackOutputTest.java b/library/core/src/androidTest/java/com/google/android/exoplayer2/source/SampleQueueTest.java similarity index 80% rename from library/core/src/androidTest/java/com/google/android/exoplayer2/extractor/DefaultTrackOutputTest.java rename to library/core/src/androidTest/java/com/google/android/exoplayer2/source/SampleQueueTest.java index 9c3c22ed87..129f299779 100644 --- a/library/core/src/androidTest/java/com/google/android/exoplayer2/extractor/DefaultTrackOutputTest.java +++ b/library/core/src/androidTest/java/com/google/android/exoplayer2/source/SampleQueueTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.android.exoplayer2.extractor; +package com.google.android.exoplayer2.source; import android.test.MoreAsserts; import com.google.android.exoplayer2.C; @@ -28,9 +28,9 @@ import java.util.Arrays; 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; @@ -42,8 +42,8 @@ public class DefaultTrackOutputTest extends TestCase { /* * 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 - * (as expected by DefaultTrackOutput.sampleMetadata) assuming that TEST_DATA has been written to - * the trackOutput in full. The allocations are filled as follows, where | indicates a boundary + * (as expected by SampleQueue.sampleMetadata) assuming that TEST_DATA has been written to the + * 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: * * x|xx|x|x|||xx| @@ -69,7 +69,7 @@ public class DefaultTrackOutputTest extends TestCase { private static final int TEST_DATA_SECOND_KEYFRAME_INDEX = 4; private Allocator allocator; - private DefaultTrackOutput trackOutput; + private SampleQueue sampleQueue; private FormatHolder formatHolder; private DecoderInputBuffer inputBuffer; @@ -77,7 +77,7 @@ public class DefaultTrackOutputTest extends TestCase { public void setUp() throws Exception { super.setUp(); allocator = new DefaultAllocator(false, ALLOCATION_SIZE); - trackOutput = new DefaultTrackOutput(allocator); + sampleQueue = new SampleQueue(allocator); formatHolder = new FormatHolder(); inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL); } @@ -86,7 +86,7 @@ public class DefaultTrackOutputTest extends TestCase { public void tearDown() throws Exception { super.tearDown(); allocator = null; - trackOutput = null; + sampleQueue = null; formatHolder = null; inputBuffer = null; } @@ -94,7 +94,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testDisableReleasesAllocations() { writeTestData(); assertAllocationCount(10); - trackOutput.disable(); + sampleQueue.disable(); assertAllocationCount(0); } @@ -103,31 +103,31 @@ public class DefaultTrackOutputTest extends TestCase { } public void testReadFormatDeduplicated() { - trackOutput.format(TEST_FORMAT_1); + sampleQueue.format(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). - trackOutput.format(TEST_FORMAT_1); + sampleQueue.format(TEST_FORMAT_1); assertNoSamplesToRead(TEST_FORMAT_1); // 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); } public void testReadSingleSamples() { - trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); + sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); assertAllocationCount(1); // Nothing to read. assertNoSamplesToRead(null); - trackOutput.format(TEST_FORMAT_1); + sampleQueue.format(TEST_FORMAT_1); // Read the format. assertReadFormat(false, TEST_FORMAT_1); // Nothing to read. 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. assertReadFormat(true, TEST_FORMAT_1); @@ -140,19 +140,19 @@ public class DefaultTrackOutputTest extends TestCase { assertNoSamplesToRead(TEST_FORMAT_1); // Write a second sample followed by one byte that does not belong to it. - trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); - trackOutput.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null); + sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); + sampleQueue.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null); // If formatRequired, should read the format rather than the sample. assertReadFormat(true, TEST_FORMAT_1); // Read the sample. 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. assertAllocationCount(1); // 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. assertReadFormat(true, TEST_FORMAT_1); @@ -165,7 +165,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testReadMultiSamples() { writeTestData(); assertEquals(TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1], - trackOutput.getLargestQueuedTimestampUs()); + sampleQueue.getLargestQueuedTimestampUs()); assertAllocationCount(10); assertReadTestData(); assertAllocationCount(0); @@ -182,7 +182,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipAll() { writeTestData(); - trackOutput.skipAll(); + sampleQueue.skipAll(); assertAllocationCount(0); // Despite skipping all samples, we should still read the last format, since this is the // expected format for a subsequent sample. @@ -192,9 +192,9 @@ public class DefaultTrackOutputTest extends TestCase { } public void testSkipAllRetainsUnassignedData() { - trackOutput.format(TEST_FORMAT_1); - trackOutput.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); - trackOutput.skipAll(); + sampleQueue.format(TEST_FORMAT_1); + sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), ALLOCATION_SIZE); + sampleQueue.skipAll(); // Skipping shouldn't discard data that may belong to a sample whose metadata has yet to be // written. assertAllocationCount(1); @@ -203,7 +203,7 @@ public class DefaultTrackOutputTest extends TestCase { // Once the format has been read, there's nothing else to read. 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. assertSampleRead(0, true, TEST_DATA, 0, ALLOCATION_SIZE); assertNoSamplesToRead(TEST_FORMAT_1); @@ -212,7 +212,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipToKeyframeBeforeBuffer() { 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. assertFalse(result); assertReadTestData(); @@ -221,7 +221,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipToKeyframeStartOfBuffer() { 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). assertTrue(result); assertReadTestData(); @@ -230,7 +230,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipToKeyframeEndOfBuffer() { writeTestData(); - boolean result = trackOutput.skipToKeyframeBefore( + boolean result = sampleQueue.skipToKeyframeBefore( TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1], false); // Should succeed and skip to 2nd keyframe. assertTrue(result); @@ -240,7 +240,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipToKeyframeAfterBuffer() { writeTestData(); - boolean result = trackOutput.skipToKeyframeBefore( + boolean result = sampleQueue.skipToKeyframeBefore( TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, false); // Should fail and have no effect. assertFalse(result); @@ -250,7 +250,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testSkipToKeyframeAfterBufferAllowed() { writeTestData(); - boolean result = trackOutput.skipToKeyframeBefore( + boolean result = sampleQueue.skipToKeyframeBefore( TEST_SAMPLE_TIMESTAMPS[TEST_SAMPLE_TIMESTAMPS.length - 1] + 1, true); // Should succeed and skip to 2nd keyframe. assertTrue(result); @@ -260,23 +260,23 @@ public class DefaultTrackOutputTest extends TestCase { public void testDiscardUpstream() { writeTestData(); - trackOutput.discardUpstreamSamples(8); + sampleQueue.discardUpstreamSamples(8); assertAllocationCount(10); - trackOutput.discardUpstreamSamples(7); + sampleQueue.discardUpstreamSamples(7); assertAllocationCount(9); - trackOutput.discardUpstreamSamples(6); + sampleQueue.discardUpstreamSamples(6); assertAllocationCount(8); // Byte not belonging to sample prevents 7. - trackOutput.discardUpstreamSamples(5); + sampleQueue.discardUpstreamSamples(5); assertAllocationCount(5); - trackOutput.discardUpstreamSamples(4); + sampleQueue.discardUpstreamSamples(4); assertAllocationCount(4); - trackOutput.discardUpstreamSamples(3); + sampleQueue.discardUpstreamSamples(3); assertAllocationCount(3); - trackOutput.discardUpstreamSamples(2); + sampleQueue.discardUpstreamSamples(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. - trackOutput.discardUpstreamSamples(0); + sampleQueue.discardUpstreamSamples(0); assertAllocationCount(1); // Byte not belonging to sample prevents 0. assertReadFormat(false, TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2); @@ -284,9 +284,9 @@ public class DefaultTrackOutputTest extends TestCase { public void testDiscardUpstreamMulti() { writeTestData(); - trackOutput.discardUpstreamSamples(4); + sampleQueue.discardUpstreamSamples(4); assertAllocationCount(4); - trackOutput.discardUpstreamSamples(0); + sampleQueue.discardUpstreamSamples(0); assertAllocationCount(1); // Byte not belonging to sample prevents 0. assertReadFormat(false, TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2); @@ -294,7 +294,7 @@ public class DefaultTrackOutputTest extends TestCase { public void testDiscardUpstreamBeforeRead() { writeTestData(); - trackOutput.discardUpstreamSamples(4); + sampleQueue.discardUpstreamSamples(4); assertAllocationCount(4); assertReadTestData(null, 0, 4); assertReadFormat(false, TEST_FORMAT_2); @@ -304,17 +304,17 @@ public class DefaultTrackOutputTest extends TestCase { public void testDiscardUpstreamAfterRead() { writeTestData(); assertReadTestData(null, 0, 3); - trackOutput.discardUpstreamSamples(8); + sampleQueue.discardUpstreamSamples(8); assertAllocationCount(7); - trackOutput.discardUpstreamSamples(7); + sampleQueue.discardUpstreamSamples(7); assertAllocationCount(6); - trackOutput.discardUpstreamSamples(6); + sampleQueue.discardUpstreamSamples(6); assertAllocationCount(5); // Byte not belonging to sample prevents 4. - trackOutput.discardUpstreamSamples(5); + sampleQueue.discardUpstreamSamples(5); assertAllocationCount(2); - trackOutput.discardUpstreamSamples(4); + sampleQueue.discardUpstreamSamples(4); assertAllocationCount(1); - trackOutput.discardUpstreamSamples(3); + sampleQueue.discardUpstreamSamples(3); assertAllocationCount(0); assertReadFormat(false, TEST_FORMAT_2); assertNoSamplesToRead(TEST_FORMAT_2); @@ -323,43 +323,42 @@ public class DefaultTrackOutputTest extends TestCase { // Internal methods. /** - * Writes standard test data to {@code trackOutput}. + * Writes standard test data to {@code sampleQueue}. */ @SuppressWarnings("ReferenceEquality") private void writeTestData() { - trackOutput.sampleData(new ParsableByteArray(TEST_DATA), TEST_DATA.length); + sampleQueue.sampleData(new ParsableByteArray(TEST_DATA), TEST_DATA.length); Format format = null; for (int i = 0; i < TEST_SAMPLE_TIMESTAMPS.length; i++) { if (TEST_SAMPLE_FORMATS[i] != format) { - trackOutput.format(TEST_SAMPLE_FORMATS[i]); + sampleQueue.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); } } /** - * Asserts correct reading of standard test data from {@code trackOutput}. + * Asserts correct reading of standard test data from {@code sampleQueue}. */ private void assertReadTestData() { 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) { 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 firstSampleIndex The index of the first sample that's expected to be read. + * @param startFormat The format of the last sample previously read from {@code sampleQueue}. */ private void assertReadTestData(Format startFormat, int firstSampleIndex) { assertReadTestData(startFormat, firstSampleIndex, @@ -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 sampleCount The number of samples to read. */ @@ -377,7 +376,7 @@ public class DefaultTrackOutputTest extends TestCase { Format format = startFormat; for (int i = firstSampleIndex; i < firstSampleIndex + sampleCount; i++) { // 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 the format has changed, we should read it. assertReadFormat(false, TEST_SAMPLE_FORMATS[i]); @@ -395,11 +394,11 @@ public class DefaultTrackOutputTest extends TestCase { } /** - * Asserts {@link DefaultTrackOutput#readData} is behaving correctly, given there are no samples - * to read and the last format to be written to the output is {@code endFormat}. + * Asserts {@link SampleQueue#readData} is behaving correctly, given there are no samples + * 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 - * written. + * @param endFormat The last format to be written to the sample queue, or null of no format has + * been written. */ private void assertNoSamplesToRead(Format endFormat) { // If not formatRequired or loadingFinished, should read nothing. @@ -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. */ private void assertReadNothing(boolean formatRequired) { 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); // formatHolder should not be populated. assertNull(formatHolder.format); @@ -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. * * @param formatRequired The value of {@code formatRequired} passed to readData. */ private void assertReadEndOfStream(boolean formatRequired) { 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); // formatHolder should not be populated. assertNull(formatHolder.format); @@ -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}. * * @param formatRequired The value of {@code formatRequired} passed to readData. @@ -466,7 +465,7 @@ public class DefaultTrackOutputTest extends TestCase { */ private void assertReadFormat(boolean formatRequired, Format format) { 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); // formatHolder should be populated. assertEquals(format, formatHolder.format); @@ -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. * * @param timeUs The expected buffer timestamp. @@ -488,7 +487,7 @@ public class DefaultTrackOutputTest extends TestCase { private void assertSampleRead(long timeUs, boolean isKeyframe, byte[] sampleData, int offset, int length) { 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); // formatHolder should not be populated. assertNull(formatHolder.format); @@ -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. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java index 8eaa9cae5a..62b1e85456 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaPeriod.java @@ -23,14 +23,13 @@ import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.decoder.DecoderInputBuffer; 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.ExtractorInput; import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.PositionHolder; import com.google.android.exoplayer2.extractor.SeekMap; 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.upstream.Allocator; import com.google.android.exoplayer2.upstream.DataSource; @@ -71,7 +70,7 @@ import java.io.IOException; private final Runnable maybeFinishPrepareRunnable; private final Runnable onContinueLoadingRequestedRunnable; private final Handler handler; - private final SparseArray sampleQueues; + private final SparseArray sampleQueues; private Callback callback; private SeekMap seekMap; @@ -345,7 +344,7 @@ import java.io.IOException; } /* package */ void skipData(int track, long positionUs) { - DefaultTrackOutput sampleQueue = sampleQueues.valueAt(track); + SampleQueue sampleQueue = sampleQueues.valueAt(track); if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { sampleQueue.skipAll(); } else { @@ -402,9 +401,9 @@ import java.io.IOException; @Override public TrackOutput track(int id, int type) { - DefaultTrackOutput trackOutput = sampleQueues.get(id); + SampleQueue trackOutput = sampleQueues.get(id); if (trackOutput == null) { - trackOutput = new DefaultTrackOutput(allocator); + trackOutput = new SampleQueue(allocator); trackOutput.setUpstreamFormatChangeListener(this); sampleQueues.put(id, trackOutput); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/SampleMetadataQueue.java b/library/core/src/main/java/com/google/android/exoplayer2/source/SampleMetadataQueue.java similarity index 99% rename from library/core/src/main/java/com/google/android/exoplayer2/extractor/SampleMetadataQueue.java rename to library/core/src/main/java/com/google/android/exoplayer2/source/SampleMetadataQueue.java index 40aaa295a0..a114c6eae3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/SampleMetadataQueue.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/SampleMetadataQueue.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * 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.Format; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java b/library/core/src/main/java/com/google/android/exoplayer2/source/SampleQueue.java similarity index 98% rename from library/core/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java rename to library/core/src/main/java/com/google/android/exoplayer2/source/SampleQueue.java index c768b06277..fc72fac364 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/SampleQueue.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.android.exoplayer2.extractor; +package com.google.android.exoplayer2.source; import android.support.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; 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.Allocator; import com.google.android.exoplayer2.util.ParsableByteArray; @@ -30,10 +32,9 @@ import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicInteger; /** - * A {@link TrackOutput} that buffers extracted samples in a queue and allows for consumption from - * that queue. + * A queue of media samples. */ -public final class DefaultTrackOutput implements TrackOutput { +public final class SampleQueue implements TrackOutput { /** * A listener for changes to the upstream format. @@ -81,7 +82,7 @@ public final class DefaultTrackOutput implements TrackOutput { /** * @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; allocationLength = allocator.getIndividualAllocationLength(); metadataQueue = new SampleMetadataQueue(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BaseMediaChunkOutput.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BaseMediaChunkOutput.java index 3882a330f9..9531aaf32e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BaseMediaChunkOutput.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BaseMediaChunkOutput.java @@ -16,9 +16,9 @@ package com.google.android.exoplayer2.source.chunk; import android.util.Log; -import com.google.android.exoplayer2.extractor.DefaultTrackOutput; import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput; +import com.google.android.exoplayer2.source.SampleQueue; import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOutputProvider; /** @@ -29,22 +29,22 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut private static final String TAG = "BaseMediaChunkOutput"; private final int[] trackTypes; - private final DefaultTrackOutput[] trackOutputs; + private final SampleQueue[] sampleQueues; /** * @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.trackOutputs = trackOutputs; + this.sampleQueues = sampleQueues; } @Override public TrackOutput track(int id, int type) { for (int i = 0; i < trackTypes.length; i++) { if (type == trackTypes[i]) { - return trackOutputs[i]; + return sampleQueues[i]; } } Log.e(TAG, "Unmatched track of type: " + type); @@ -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() { - int[] writeIndices = new int[trackOutputs.length]; - for (int i = 0; i < trackOutputs.length; i++) { - if (trackOutputs[i] != null) { - writeIndices[i] = trackOutputs[i].getWriteIndex(); + int[] writeIndices = new int[sampleQueues.length]; + for (int i = 0; i < sampleQueues.length; i++) { + if (sampleQueues[i] != null) { + writeIndices[i] = sampleQueues[i].getWriteIndex(); } } return writeIndices; @@ -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 - * subsequently written to the track outputs. + * subsequently written to the sample queues. */ public void setSampleOffsetUs(long sampleOffsetUs) { - for (DefaultTrackOutput trackOutput : trackOutputs) { - if (trackOutput != null) { - trackOutput.setSampleOffsetUs(sampleOffsetUs); + for (SampleQueue sampleQueue : sampleQueues) { + if (sampleQueue != null) { + sampleQueue.setSampleOffsetUs(sampleOffsetUs); } } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java index b4399f0f81..d7c9174a89 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java @@ -19,8 +19,8 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; 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.SampleQueue; import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SequenceableLoader; import com.google.android.exoplayer2.upstream.Allocator; @@ -49,8 +49,8 @@ public class ChunkSampleStream implements SampleStream, S private final ChunkHolder nextChunkHolder; private final LinkedList mediaChunks; private final List readOnlyMediaChunks; - private final DefaultTrackOutput primarySampleQueue; - private final DefaultTrackOutput[] embeddedSampleQueues; + private final SampleQueue primarySampleQueue; + private final SampleQueue[] embeddedSampleQueues; private final BaseMediaChunkOutput mediaChunkOutput; private Format primaryDownstreamTrackFormat; @@ -85,19 +85,19 @@ public class ChunkSampleStream implements SampleStream, S readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks); int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length; - embeddedSampleQueues = new DefaultTrackOutput[embeddedTrackCount]; + embeddedSampleQueues = new SampleQueue[embeddedTrackCount]; embeddedTracksSelected = new boolean[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; sampleQueues[0] = primarySampleQueue; for (int i = 0; i < embeddedTrackCount; i++) { - DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator); - embeddedSampleQueues[i] = trackOutput; - sampleQueues[i + 1] = trackOutput; + SampleQueue sampleQueue = new SampleQueue(allocator); + embeddedSampleQueues[i] = sampleQueue; + sampleQueues[i + 1] = sampleQueue; trackTypes[i + 1] = embeddedTrackTypes[i]; } @@ -192,7 +192,7 @@ public class ChunkSampleStream implements SampleStream, S } // 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. - for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { + for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.skipToKeyframeBefore(positionUs, true); } } else { @@ -204,7 +204,7 @@ public class ChunkSampleStream implements SampleStream, S loader.cancelLoading(); } else { primarySampleQueue.reset(true); - for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { + for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.reset(true); } } @@ -218,7 +218,7 @@ public class ChunkSampleStream implements SampleStream, S */ public void release() { primarySampleQueue.disable(); - for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { + for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.disable(); } loader.release(); @@ -280,7 +280,7 @@ public class ChunkSampleStream implements SampleStream, S loadable.bytesLoaded()); if (!released) { primarySampleQueue.reset(true); - for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) { + for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { embeddedSampleQueue.reset(true); } callback.onContinueLoadingRequested(this); @@ -439,10 +439,10 @@ public class ChunkSampleStream implements SampleStream, S public final ChunkSampleStream parent; - private final DefaultTrackOutput sampleQueue; + private final SampleQueue sampleQueue; private final int index; - public EmbeddedSampleStream(ChunkSampleStream parent, DefaultTrackOutput sampleQueue, + public EmbeddedSampleStream(ChunkSampleStream parent, SampleQueue sampleQueue, int index) { this.parent = parent; this.sampleQueue = sampleQueue; diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java index a73553263b..0e8567b846 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java @@ -22,11 +22,11 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.FormatHolder; 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.SeekMap; 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.SequenceableLoader; import com.google.android.exoplayer2.source.TrackGroup; @@ -81,7 +81,7 @@ import java.util.LinkedList; private final Loader loader; private final EventDispatcher eventDispatcher; private final HlsChunkSource.HlsChunkHolder nextChunkHolder; - private final SparseArray sampleQueues; + private final SparseArray sampleQueues; private final LinkedList mediaChunks; private final Runnable maybeFinishPrepareRunnable; private final Handler handler; @@ -315,7 +315,7 @@ import java.util.LinkedList; } /* package */ void skipData(int group, long positionUs) { - DefaultTrackOutput sampleQueue = sampleQueues.valueAt(group); + SampleQueue sampleQueue = sampleQueues.valueAt(group); if (loadingFinished && positionUs > sampleQueue.getLargestQueuedTimestampUs()) { sampleQueue.skipAll(); } else { @@ -471,15 +471,15 @@ import java.util.LinkedList; // ExtractorOutput implementation. Called by the loading thread. @Override - public DefaultTrackOutput track(int id, int type) { + public SampleQueue track(int id, int type) { if (sampleQueues.indexOfKey(id) >= 0) { return sampleQueues.get(id); } - DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator); - trackOutput.setUpstreamFormatChangeListener(this); - trackOutput.sourceId(upstreamChunkUid); - sampleQueues.put(id, trackOutput); - return trackOutput; + SampleQueue sampleQueue = new SampleQueue(allocator); + sampleQueue.setUpstreamFormatChangeListener(this); + sampleQueue.sourceId(upstreamChunkUid); + sampleQueues.put(id, sampleQueue); + return sampleQueue; } @Override