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 9531aaf32e..0b6c196d7c 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 @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2.source.chunk; +import android.support.annotation.Nullable; import android.util.Log; import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput; @@ -32,12 +33,23 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut private final SampleQueue[] sampleQueues; /** - * @param trackTypes The track types of the individual track outputs. - * @param sampleQueues The individual sample queues. + * @param primaryTrackType The type of the primary track. + * @param primarySampleQueue The primary track sample queues. + * @param embeddedTrackTypes The types of any embedded tracks, or null. + * @param embeddedSampleQueues The track sample queues for any embedded tracks, or null. */ - public BaseMediaChunkOutput(int[] trackTypes, SampleQueue[] sampleQueues) { - this.trackTypes = trackTypes; - this.sampleQueues = sampleQueues; + @SuppressWarnings("ConstantConditions") + public BaseMediaChunkOutput(int primaryTrackType, SampleQueue primarySampleQueue, + @Nullable int[] embeddedTrackTypes, @Nullable SampleQueue[] embeddedSampleQueues) { + int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length; + trackTypes = new int[1 + embeddedTrackCount]; + sampleQueues = new SampleQueue[1 + embeddedTrackCount]; + trackTypes[0] = primaryTrackType; + sampleQueues[0] = primarySampleQueue; + for (int i = 0; i < embeddedTrackCount; i++) { + trackTypes[i + 1] = embeddedTrackTypes[i]; + sampleQueues[i + 1] = embeddedSampleQueues[i]; + } } @Override @@ -51,6 +63,11 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut return new DummyTrackOutput(); } + @Override + public boolean isPrimaryTrack(int type) { + return type == trackTypes[0]; + } + /** * Returns the current absolute write indices of the individual sample queues. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractorWrapper.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractorWrapper.java index 07d1cce8cb..eda9ed3cf7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractorWrapper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractorWrapper.java @@ -45,13 +45,22 @@ public final class ChunkExtractorWrapper implements ExtractorOutput { *
* The same {@link TrackOutput} is returned if multiple calls are made with the same {@code id}.
*
- * @param id A track identifier.
- * @param type The type of the track. Typically one of the
- * {@link com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
+ * @param id The track identifier.
+ * @param type The track type. Typically one of the {@link com.google.android.exoplayer2.C}
+ * {@code TRACK_TYPE_*} constants.
* @return The {@link TrackOutput} for the given track identifier.
*/
TrackOutput track(int id, int type);
+ /**
+ * Returns whether the specified type corresponds to the primary track.
+ *
+ * @param type The track type. Typically one of the {@link com.google.android.exoplayer2.C}
+ * {@code TRACK_TYPE_*} constants.
+ * @return Whether {@code type} corresponds to the primary track.
+ */
+ boolean isPrimaryTrack(int type);
+
}
public final Extractor extractor;
@@ -146,6 +155,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
private final Format manifestFormat;
public Format sampleFormat;
+ private boolean isPrimaryTrack;
private TrackOutput trackOutput;
public BindingTrackOutput(int id, int type, Format manifestFormat) {
@@ -159,17 +169,17 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
trackOutput = new DummyTrackOutput();
return;
}
+ isPrimaryTrack = trackOutputProvider.isPrimaryTrack(type);
trackOutput = trackOutputProvider.track(id, type);
- if (trackOutput != null) {
+ if (sampleFormat != null) {
trackOutput.format(sampleFormat);
}
}
@Override
public void format(Format format) {
- // TODO: This should only happen for the primary track. Additional metadata/text tracks need
- // to be copied with different manifest derived formats.
- sampleFormat = format.copyWithManifestFormatInfo(manifestFormat);
+ // TODO: Non-primary tracks should be copied with data from their own manifest formats.
+ sampleFormat = isPrimaryTrack ? format.copyWithManifestFormatInfo(manifestFormat) : format;
trackOutput.format(sampleFormat);
}
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 f2609a0ffd..e8586f7230 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
@@ -87,21 +87,15 @@ public class ChunkSampleStream