Commit 122b2a1a by olly Committed by Oliver Woodman

Use single TrackGroup for switchable adaptation sets

Issue: #2431

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157236031
parent 27fc82f0
......@@ -28,8 +28,8 @@ public interface DashChunkSource extends ChunkSource {
interface Factory {
DashChunkSource createDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex,
TrackSelection trackSelection, long elapsedRealtimeOffsetMs,
DashManifest manifest, int periodIndex, int[] adaptationSetIndices,
TrackSelection trackSelection, int type, long elapsedRealtimeOffsetMs,
boolean enableEventMessageTrack, boolean enableCea608Track);
}
......
......@@ -46,6 +46,7 @@ import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -69,20 +70,21 @@ public class DefaultDashChunkSource implements DashChunkSource {
@Override
public DashChunkSource createDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex,
TrackSelection trackSelection, long elapsedRealtimeOffsetMs,
DashManifest manifest, int periodIndex, int[] adaptationSetIndices,
TrackSelection trackSelection, int trackType, long elapsedRealtimeOffsetMs,
boolean enableEventMessageTrack, boolean enableCea608Track) {
DataSource dataSource = dataSourceFactory.createDataSource();
return new DefaultDashChunkSource(manifestLoaderErrorThrower, manifest, periodIndex,
adaptationSetIndex, trackSelection, dataSource, elapsedRealtimeOffsetMs,
adaptationSetIndices, trackSelection, trackType, dataSource, elapsedRealtimeOffsetMs,
maxSegmentsPerLoad, enableEventMessageTrack, enableCea608Track);
}
}
private final LoaderErrorThrower manifestLoaderErrorThrower;
private final int adaptationSetIndex;
private final int[] adaptationSetIndices;
private final TrackSelection trackSelection;
private final int trackType;
private final RepresentationHolder[] representationHolders;
private final DataSource dataSource;
private final long elapsedRealtimeOffsetMs;
......@@ -98,8 +100,9 @@ public class DefaultDashChunkSource implements DashChunkSource {
* @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
* @param manifest The initial manifest.
* @param periodIndex The index of the period in the manifest.
* @param adaptationSetIndex The index of the adaptation set in the period.
* @param adaptationSetIndices The indices of the adaptation sets in the period.
* @param trackSelection The track selection.
* @param trackType The type of the tracks in the selection.
* @param dataSource A {@link DataSource} suitable for loading the media data.
* @param elapsedRealtimeOffsetMs If known, an estimate of the instantaneous difference between
* server-side unix time and {@link SystemClock#elapsedRealtime()} in milliseconds, specified
......@@ -112,26 +115,27 @@ public class DefaultDashChunkSource implements DashChunkSource {
* @param enableCea608Track Whether the chunks generated by the source may output a CEA-608 track.
*/
public DefaultDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex, TrackSelection trackSelection,
DataSource dataSource, long elapsedRealtimeOffsetMs, int maxSegmentsPerLoad,
boolean enableEventMessageTrack, boolean enableCea608Track) {
DashManifest manifest, int periodIndex, int[] adaptationSetIndices,
TrackSelection trackSelection, int trackType, DataSource dataSource,
long elapsedRealtimeOffsetMs, int maxSegmentsPerLoad, boolean enableEventMessageTrack,
boolean enableCea608Track) {
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
this.manifest = manifest;
this.adaptationSetIndex = adaptationSetIndex;
this.adaptationSetIndices = adaptationSetIndices;
this.trackSelection = trackSelection;
this.trackType = trackType;
this.dataSource = dataSource;
this.periodIndex = periodIndex;
this.elapsedRealtimeOffsetMs = elapsedRealtimeOffsetMs;
this.maxSegmentsPerLoad = maxSegmentsPerLoad;
long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
AdaptationSet adaptationSet = getAdaptationSet();
List<Representation> representations = adaptationSet.representations;
List<Representation> representations = getRepresentations();
representationHolders = new RepresentationHolder[trackSelection.length()];
for (int i = 0; i < representationHolders.length; i++) {
Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
representationHolders[i] = new RepresentationHolder(periodDurationUs, representation,
enableEventMessageTrack, enableCea608Track, adaptationSet.type);
enableEventMessageTrack, enableCea608Track);
}
}
......@@ -141,7 +145,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
manifest = newManifest;
periodIndex = newPeriodIndex;
long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
List<Representation> representations = getAdaptationSet().representations;
List<Representation> representations = getRepresentations();
for (int i = 0; i < representationHolders.length; i++) {
Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
representationHolders[i].updateRepresentation(periodDurationUs, representation);
......@@ -248,9 +252,9 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
int maxSegmentCount = Math.min(maxSegmentsPerLoad, lastAvailableSegmentNum - segmentNum + 1);
out.chunk = newMediaChunk(representationHolder, dataSource, trackSelection.getSelectedFormat(),
trackSelection.getSelectionReason(), trackSelection.getSelectionData(), segmentNum,
maxSegmentCount);
out.chunk = newMediaChunk(representationHolder, dataSource, trackType,
trackSelection.getSelectedFormat(), trackSelection.getSelectionReason(),
trackSelection.getSelectionData(), segmentNum, maxSegmentCount);
}
@Override
......@@ -298,8 +302,13 @@ public class DefaultDashChunkSource implements DashChunkSource {
// Private methods.
private AdaptationSet getAdaptationSet() {
return manifest.getPeriod(periodIndex).adaptationSets.get(adaptationSetIndex);
private ArrayList<Representation> getRepresentations() {
List<AdaptationSet> manifestAdapationSets = manifest.getPeriod(periodIndex).adaptationSets;
ArrayList<Representation> representations = new ArrayList<>();
for (int adaptationSetIndex : adaptationSetIndices) {
representations.addAll(manifestAdapationSets.get(adaptationSetIndex).representations);
}
return representations;
}
private long getNowUnixTimeUs() {
......@@ -332,7 +341,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
private static Chunk newMediaChunk(RepresentationHolder representationHolder,
DataSource dataSource, Format trackFormat, int trackSelectionReason,
DataSource dataSource, int trackType, Format trackFormat, int trackSelectionReason,
Object trackSelectionData, int firstSegmentNum, int maxSegmentCount) {
Representation representation = representationHolder.representation;
long startTimeUs = representationHolder.getSegmentStartTimeUs(firstSegmentNum);
......@@ -343,8 +352,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
DataSpec dataSpec = new DataSpec(segmentUri.resolveUri(baseUrl),
segmentUri.start, segmentUri.length, representation.getCacheKey());
return new SingleSampleMediaChunk(dataSource, dataSpec, trackFormat, trackSelectionReason,
trackSelectionData, startTimeUs, endTimeUs, firstSegmentNum,
representationHolder.trackType, trackFormat);
trackSelectionData, startTimeUs, endTimeUs, firstSegmentNum, trackType, trackFormat);
} else {
int segmentCount = 1;
for (int i = 1; i < maxSegmentCount; i++) {
......@@ -371,7 +379,6 @@ public class DefaultDashChunkSource implements DashChunkSource {
protected static final class RepresentationHolder {
public final int trackType;
public final ChunkExtractorWrapper extractorWrapper;
public Representation representation;
......@@ -381,10 +388,9 @@ public class DefaultDashChunkSource implements DashChunkSource {
private int segmentNumShift;
public RepresentationHolder(long periodDurationUs, Representation representation,
boolean enableEventMessageTrack, boolean enableCea608Track, int trackType) {
boolean enableEventMessageTrack, boolean enableCea608Track) {
this.periodDurationUs = periodDurationUs;
this.representation = representation;
this.trackType = trackType;
String containerMimeType = representation.format.containerMimeType;
if (mimeTypeIsRawText(containerMimeType)) {
extractorWrapper = null;
......
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