Commit 3e762270 by olly Committed by Oliver Woodman

Don't copy primary-track format to non-primary tracks

Copying non-primary-track formats to non-primary tracks
looks non-trivial (I tried; went down a dead-end), so
leaving that for now.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166843123
parent ba6d208f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.source.chunk; package com.google.android.exoplayer2.source.chunk;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
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;
...@@ -32,12 +33,23 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut ...@@ -32,12 +33,23 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut
private final SampleQueue[] sampleQueues; private final SampleQueue[] sampleQueues;
/** /**
* @param trackTypes The track types of the individual track outputs. * @param primaryTrackType The type of the primary track.
* @param sampleQueues The individual sample queues. * @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) { @SuppressWarnings("ConstantConditions")
this.trackTypes = trackTypes; public BaseMediaChunkOutput(int primaryTrackType, SampleQueue primarySampleQueue,
this.sampleQueues = sampleQueues; @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 @Override
...@@ -51,6 +63,11 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut ...@@ -51,6 +63,11 @@ import com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper.TrackOut
return new DummyTrackOutput(); return new DummyTrackOutput();
} }
@Override
public boolean isPrimaryTrack(int type) {
return type == trackTypes[0];
}
/** /**
* Returns the current absolute write indices of the individual sample queues. * Returns the current absolute write indices of the individual sample queues.
*/ */
......
...@@ -45,13 +45,22 @@ public final class ChunkExtractorWrapper implements ExtractorOutput { ...@@ -45,13 +45,22 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
* <p> * <p>
* The same {@link TrackOutput} is returned if multiple calls are made with the same {@code id}. * The same {@link TrackOutput} is returned if multiple calls are made with the same {@code id}.
* *
* @param id A track identifier. * @param id The track identifier.
* @param type The type of the track. Typically one of the * @param type The track type. Typically one of the {@link com.google.android.exoplayer2.C}
* {@link com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants. * {@code TRACK_TYPE_*} constants.
* @return The {@link TrackOutput} for the given track identifier. * @return The {@link TrackOutput} for the given track identifier.
*/ */
TrackOutput track(int id, int type); 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; public final Extractor extractor;
...@@ -146,6 +155,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput { ...@@ -146,6 +155,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
private final Format manifestFormat; private final Format manifestFormat;
public Format sampleFormat; public Format sampleFormat;
private boolean isPrimaryTrack;
private TrackOutput trackOutput; private TrackOutput trackOutput;
public BindingTrackOutput(int id, int type, Format manifestFormat) { public BindingTrackOutput(int id, int type, Format manifestFormat) {
...@@ -159,17 +169,17 @@ public final class ChunkExtractorWrapper implements ExtractorOutput { ...@@ -159,17 +169,17 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
trackOutput = new DummyTrackOutput(); trackOutput = new DummyTrackOutput();
return; return;
} }
isPrimaryTrack = trackOutputProvider.isPrimaryTrack(type);
trackOutput = trackOutputProvider.track(id, type); trackOutput = trackOutputProvider.track(id, type);
if (trackOutput != null) { if (sampleFormat != null) {
trackOutput.format(sampleFormat); trackOutput.format(sampleFormat);
} }
} }
@Override @Override
public void format(Format format) { public void format(Format format) {
// TODO: This should only happen for the primary track. Additional metadata/text tracks need // TODO: Non-primary tracks should be copied with data from their own manifest formats.
// to be copied with different manifest derived formats. sampleFormat = isPrimaryTrack ? format.copyWithManifestFormatInfo(manifestFormat) : format;
sampleFormat = format.copyWithManifestFormatInfo(manifestFormat);
trackOutput.format(sampleFormat); trackOutput.format(sampleFormat);
} }
......
...@@ -87,21 +87,15 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -87,21 +87,15 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length; int embeddedTrackCount = embeddedTrackTypes == null ? 0 : embeddedTrackTypes.length;
embeddedSampleQueues = new SampleQueue[embeddedTrackCount]; embeddedSampleQueues = new SampleQueue[embeddedTrackCount];
embeddedTracksSelected = new boolean[embeddedTrackCount]; embeddedTracksSelected = new boolean[embeddedTrackCount];
int[] trackTypes = new int[1 + embeddedTrackCount];
SampleQueue[] sampleQueues = new SampleQueue[1 + embeddedTrackCount];
primarySampleQueue = new SampleQueue(allocator); primarySampleQueue = new SampleQueue(allocator);
trackTypes[0] = primaryTrackType;
sampleQueues[0] = primarySampleQueue;
for (int i = 0; i < embeddedTrackCount; i++) { for (int i = 0; i < embeddedTrackCount; i++) {
SampleQueue sampleQueue = new SampleQueue(allocator); SampleQueue sampleQueue = new SampleQueue(allocator);
embeddedSampleQueues[i] = sampleQueue; embeddedSampleQueues[i] = sampleQueue;
sampleQueues[i + 1] = sampleQueue;
trackTypes[i + 1] = embeddedTrackTypes[i];
} }
mediaChunkOutput = new BaseMediaChunkOutput(trackTypes, sampleQueues); mediaChunkOutput = new BaseMediaChunkOutput(primaryTrackType, primarySampleQueue,
embeddedTrackTypes, embeddedSampleQueues);
pendingResetPositionUs = positionUs; pendingResetPositionUs = positionUs;
lastSeekPositionUs = positionUs; lastSeekPositionUs = positionUs;
} }
......
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