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