diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java b/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java index 98113228aa..ca3ed9f8b5 100644 --- a/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java +++ b/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java @@ -123,7 +123,7 @@ import java.util.Locale; TrackGroup group = trackGroups.get(groupIndex); trackViews[groupIndex] = new CheckedTextView[group.length]; for (int trackIndex = 0; trackIndex < group.length; trackIndex++) { - if (trackIndex == 0 || !group.adaptive) { + if (trackIndex == 0) { root.addView(inflater.inflate(R.layout.list_divider, root, false)); } int trackViewLayoutId = group.length < 2 || !trackGroupsAdaptive[groupIndex] diff --git a/library/src/main/java/com/google/android/exoplayer2/source/TrackGroup.java b/library/src/main/java/com/google/android/exoplayer2/source/TrackGroup.java index d83d6df047..b9fd3719fe 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/TrackGroup.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/TrackGroup.java @@ -20,24 +20,21 @@ import com.google.android.exoplayer2.util.Assertions; import java.util.Arrays; +// TODO: Add an allowMultipleStreams boolean to indicate where the one stream per group restriction +// does not apply. /** * Defines a group of tracks exposed by a {@link MediaPeriod}. *

* A {@link MediaPeriod} is only able to provide one {@link SampleStream} corresponding to a group - * at any given time. If {@link #adaptive} is true this {@link SampleStream} can adapt between - * multiple tracks within the group. If {@link #adaptive} is false then it's only possible to - * consume one track from the group at a given time. + * at any given time, however this {@link SampleStream} may adapt between multiple tracks within the + * group. */ public final class TrackGroup { /** - * The number of tracks in the group. Always greater than zero. + * The number of tracks in the group. */ public final int length; - /** - * Whether it's possible to adapt between multiple tracks in the group. - */ - public final boolean adaptive; private final Format[] formats; @@ -45,19 +42,10 @@ public final class TrackGroup { private int hashCode; /** - * @param format The format of the single track. + * @param formats The track formats. Must not be null or contain null elements. */ - public TrackGroup(Format format) { - this(false, Assertions.checkNotNull(format)); - } - - /** - * @param adaptive Whether it's possible to adapt between multiple tracks in the group. - * @param formats The track formats. Must not be null or empty. Must not contain null elements. - */ - public TrackGroup(boolean adaptive, Format... formats) { + public TrackGroup(Format... formats) { Assertions.checkState(formats.length > 0); - this.adaptive = adaptive; this.formats = formats; this.length = formats.length; } @@ -91,7 +79,6 @@ public final class TrackGroup { public int hashCode() { if (hashCode == 0) { int result = 17; - result = 31 * result + (adaptive ? 1231 : 1237); result = 31 * result + Arrays.hashCode(formats); hashCode = result; } @@ -107,8 +94,7 @@ public final class TrackGroup { return false; } TrackGroup other = (TrackGroup) obj; - return adaptive == other.adaptive && length == other.length - && Arrays.equals(formats, other.formats); + return length == other.length && Arrays.equals(formats, other.formats); } } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java index 2e6a0398b7..94007af12f 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java @@ -33,10 +33,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Loader; -import android.util.Pair; - import java.io.IOException; -import java.util.Arrays; import java.util.List; /** @@ -52,7 +49,6 @@ import java.util.List; private final Loader loader; private final long durationUs; private final TrackGroupArray trackGroups; - private final int[] trackGroupAdaptationSetIndices; private ChunkSampleStream[] sampleStreams; private CompositeSequenceableLoader sequenceableLoader; @@ -74,9 +70,7 @@ import java.util.List; this.loader = loader; durationUs = manifest.dynamic ? C.UNSET_TIME_US : manifest.getPeriodDuration(index) * 1000; period = manifest.getPeriod(index); - Pair trackGroupsAndAdaptationSetIndices = buildTrackGroups(period); - trackGroups = trackGroupsAndAdaptationSetIndices.first; - trackGroupAdaptationSetIndices = trackGroupsAndAdaptationSetIndices.second; + trackGroups = buildTrackGroups(period); } public void updateManifest(DashManifest manifest, int index) { @@ -206,37 +200,23 @@ import java.util.List; // Internal methods. - private static Pair buildTrackGroups(Period period) { - int trackGroupCount = 0; - int[] trackGroupAdaptationSetIndices = new int[period.adaptationSets.size()]; + private static TrackGroupArray buildTrackGroups(Period period) { TrackGroup[] trackGroupArray = new TrackGroup[period.adaptationSets.size()]; for (int i = 0; i < period.adaptationSets.size(); i++) { AdaptationSet adaptationSet = period.adaptationSets.get(i); - int adaptationSetType = adaptationSet.type; List representations = adaptationSet.representations; - if (!representations.isEmpty() && (adaptationSetType == C.TRACK_TYPE_AUDIO - || adaptationSetType == C.TRACK_TYPE_VIDEO || adaptationSetType == C.TRACK_TYPE_TEXT)) { - Format[] formats = new Format[representations.size()]; - for (int j = 0; j < formats.length; j++) { - formats[j] = representations.get(j).format; - } - trackGroupAdaptationSetIndices[trackGroupCount] = i; - boolean adaptive = adaptationSetType == C.TRACK_TYPE_VIDEO; - trackGroupArray[trackGroupCount++] = new TrackGroup(adaptive, formats); + Format[] formats = new Format[representations.size()]; + for (int j = 0; j < formats.length; j++) { + formats[j] = representations.get(j).format; } + trackGroupArray[i] = new TrackGroup(formats); } - if (trackGroupCount < trackGroupArray.length) { - trackGroupAdaptationSetIndices = Arrays.copyOf(trackGroupAdaptationSetIndices, - trackGroupCount); - trackGroupArray = Arrays.copyOf(trackGroupArray, trackGroupCount); - } - TrackGroupArray trackGroups = new TrackGroupArray(trackGroupArray); - return Pair.create(trackGroups, trackGroupAdaptationSetIndices); + return new TrackGroupArray(trackGroupArray); } private ChunkSampleStream buildSampleStream(TrackSelection selection, long positionUs) { - int adaptationSetIndex = trackGroupAdaptationSetIndices[trackGroups.indexOf(selection.group)]; + int adaptationSetIndex = trackGroups.indexOf(selection.group); AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex); DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(loader, manifest, index, adaptationSetIndex, selection, elapsedRealtimeOffset); diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java index 83e761bf76..488e9e6a62 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java @@ -126,7 +126,7 @@ public class HlsChunkSource { variantFormats[i] = variants[i].format; initialTrackSelection[i] = i; } - trackGroup = new TrackGroup(formatEvaluator != null, variantFormats); + trackGroup = new TrackGroup(variantFormats); selectTracksInternal(new TrackSelection(trackGroup, initialTrackSelection), false); } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java index bfe328f7c7..b44807eeb5 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java @@ -543,7 +543,7 @@ import java.util.List; for (int j = 0; j < chunkSourceTrackCount; j++) { formats[j] = getSampleFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat); } - trackGroups[i] = new TrackGroup(chunkSourceTrackGroup.adaptive, formats); + trackGroups[i] = new TrackGroup(formats); primaryTrackGroupIndex = i; } else { Format trackFormat = null; diff --git a/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java index a98ff3c45a..b19e22dd09 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java @@ -49,7 +49,6 @@ import android.os.SystemClock; import android.util.Base64; import java.io.IOException; -import java.util.Arrays; import java.util.List; /** @@ -90,7 +89,6 @@ public final class SsMediaSource implements MediaPeriod, MediaSource, private long durationUs; private TrackEncryptionBox[] trackEncryptionBoxes; private TrackGroupArray trackGroups; - private int[] trackGroupElementIndices; public SsMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, SsChunkSource.Factory chunkSourceFactory, Handler eventHandler, @@ -254,7 +252,6 @@ public final class SsMediaSource implements MediaPeriod, MediaSource, durationUs = 0; trackEncryptionBoxes = null; trackGroups = null; - trackGroupElementIndices = null; } // SequenceableLoader.Callback implementation @@ -337,30 +334,18 @@ public final class SsMediaSource implements MediaPeriod, MediaSource, } private void buildTrackGroups(SsManifest manifest) { - int trackGroupCount = 0; - trackGroupElementIndices = new int[manifest.streamElements.length]; TrackGroup[] trackGroupArray = new TrackGroup[manifest.streamElements.length]; for (int i = 0; i < manifest.streamElements.length; i++) { StreamElement streamElement = manifest.streamElements[i]; - int streamElementType = streamElement.type; Format[] formats = streamElement.formats; - if (formats.length > 0 && (streamElementType == C.TRACK_TYPE_AUDIO - || streamElementType == C.TRACK_TYPE_VIDEO || streamElementType == C.TRACK_TYPE_TEXT)) { - trackGroupElementIndices[trackGroupCount] = i; - boolean adaptive = streamElementType == C.TRACK_TYPE_VIDEO; - trackGroupArray[trackGroupCount++] = new TrackGroup(adaptive, formats); - } - } - if (trackGroupCount < trackGroupArray.length) { - trackGroupElementIndices = Arrays.copyOf(trackGroupElementIndices, trackGroupCount); - trackGroupArray = Arrays.copyOf(trackGroupArray, trackGroupCount); + trackGroupArray[i] = new TrackGroup(formats); } trackGroups = new TrackGroupArray(trackGroupArray); } private ChunkSampleStream buildSampleStream(TrackSelection selection, long positionUs) { - int streamElementIndex = trackGroupElementIndices[trackGroups.indexOf(selection.group)]; + int streamElementIndex = trackGroups.indexOf(selection.group); SsChunkSource chunkSource = chunkSourceFactory.createChunkSource(manifestLoader, manifest, streamElementIndex, selection, trackEncryptionBoxes); return new ChunkSampleStream<>(manifest.streamElements[streamElementIndex].type, chunkSource, diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java index 4c2f0cbf8d..8d91ef5516 100644 --- a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java +++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java @@ -208,10 +208,6 @@ public class DefaultTrackSelector extends MappingTrackSelector { private static int[] getAdaptiveTracksOfGroup(TrackGroup trackGroup, int[] formatSupport, boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth, int maxVideoHeight) { - if (!trackGroup.adaptive) { - return NO_TRACKS; - } - String mimeType = null; int adaptiveTracksCount = 0; if (allowMixedMimeTypes) { diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java index 7c596c1894..72d360e27d 100644 --- a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java +++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java @@ -560,10 +560,6 @@ public abstract class MappingTrackSelector extends TrackSelector { * {@link RendererCapabilities#ADAPTIVE_NOT_SUPPORTED}. */ public int getAdaptiveSupport(int rendererIndex, int groupIndex, int[] trackIndices) { - TrackGroup trackGroup = trackGroups[rendererIndex].get(groupIndex); - if (!trackGroup.adaptive) { - return RendererCapabilities.ADAPTIVE_NOT_SUPPORTED; - } int handledTrackCount = 0; int adaptiveSupport = RendererCapabilities.ADAPTIVE_SEAMLESS; boolean multipleMimeTypes = false;