Commit 7c551081 by olly Committed by Oliver Woodman

Only pass RendererCapabilities to TrackSelectors

We should only give a TrackSelector access to what it
needs, not the whole Renderer. This is particular true
if [] happens, since more Renderer methods
will become publicly visible.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=127526473
parent 97d9c94c
......@@ -20,7 +20,6 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MediaClock;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException;
......@@ -35,64 +34,7 @@ import java.io.IOException;
* alt="Renderer state transitions"
* border="0"/></p>
*/
public abstract class Renderer implements ExoPlayerComponent {
/**
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #FORMAT_HANDLED}, {@link #FORMAT_EXCEEDS_CAPABILITIES},
* {@link #FORMAT_UNSUPPORTED_SUBTYPE} and {@link #FORMAT_UNSUPPORTED_TYPE}.
*/
public static final int FORMAT_SUPPORT_MASK = 0b11;
/**
* The {@link Renderer} is capable of rendering the format.
*/
public static final int FORMAT_HANDLED = 0b11;
/**
* The {@link Renderer} is capable of rendering formats with the same mimeType, but the
* properties of the format exceed the renderer's capability.
* <p>
* Example: The {@link Renderer} is capable of rendering H264 and the format's mimeType is
* {@link MimeTypes#VIDEO_H264}, but the format's resolution exceeds the maximum limit supported
* by the underlying H264 decoder.
*/
public static final int FORMAT_EXCEEDS_CAPABILITIES = 0b10;
/**
* The {@link Renderer} is a general purpose renderer for formats of the same top-level type,
* but is not capable of rendering the format or any other format with the same mimeType because
* the sub-type is not supported.
* <p>
* Example: The {@link Renderer} is a general purpose audio renderer and the format's
* mimeType matches audio/[subtype], but there does not exist a suitable decoder for [subtype].
*/
public static final int FORMAT_UNSUPPORTED_SUBTYPE = 0b01;
/**
* The {@link Renderer} is not capable of rendering the format, either because it does not
* support the format's top-level type, or because it's a specialized renderer for a different
* mimeType.
* <p>
* Example: The {@link Renderer} is a general purpose video renderer, but the format has an
* audio mimeType.
*/
public static final int FORMAT_UNSUPPORTED_TYPE = 0b00;
/**
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and {@link #ADAPTIVE_NOT_SUPPORTED}.
*/
public static final int ADAPTIVE_SUPPORT_MASK = 0b1100;
/**
* The {@link Renderer} can seamlessly adapt between formats.
*/
public static final int ADAPTIVE_SEAMLESS = 0b1000;
/**
* The {@link Renderer} can adapt between formats, but may suffer a brief discontinuity
* (~50-100ms) when adaptation occurs.
*/
public static final int ADAPTIVE_NOT_SEAMLESS = 0b0100;
/**
* The {@link Renderer} does not support adaptation between formats.
*/
public static final int ADAPTIVE_NOT_SUPPORTED = 0b0000;
public abstract class Renderer implements ExoPlayerComponent, RendererCapabilities {
/**
* The renderer is disabled.
......@@ -159,19 +101,6 @@ public abstract class Renderer implements ExoPlayerComponent {
}
/**
* Returns the extent to which the renderer supports adapting between supported formats that have
* different mimeTypes.
*
* @return The extent to which the renderer supports adapting between supported formats that have
* different mimeTypes. One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.
* @throws ExoPlaybackException If an error occurs.
*/
public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
return ADAPTIVE_NOT_SUPPORTED;
}
/**
* Enable the renderer to consume from the specified {@link SampleStream}.
*
* @param formats The enabled formats.
......@@ -383,36 +312,6 @@ public abstract class Renderer implements ExoPlayerComponent {
// Abstract methods.
/**
* Returns the track type that the renderer handles. For example, a video renderer will return
* {@link C#TRACK_TYPE_VIDEO}, an audio renderer will return {@link C#TRACK_TYPE_AUDIO}, a text
* renderer will return {@link C#TRACK_TYPE_TEXT}, and so on.
*
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
*/
public abstract int getTrackType();
/**
* Returns the extent to which the renderer supports a given format.
* <p>
* The returned value is the bitwise OR of two properties:
* <ul>
* <li>The level of support for the format itself. One of {@code}link #FORMAT_HANDLED},
* {@link #FORMAT_EXCEEDS_CAPABILITIES}, {@link #FORMAT_UNSUPPORTED_SUBTYPE} and
* {@link #FORMAT_UNSUPPORTED_TYPE}.</li>
* <li>The level of support for adapting from the format to another format of the same mimeType.
* One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.</li>
* </ul>
* The individual properties can be retrieved by performing a bitwise AND with
* {@link #FORMAT_SUPPORT_MASK} and {@link #ADAPTIVE_SUPPORT_MASK} respectively.
*
* @param format The format.
* @return The extent to which the renderer is capable of supporting the given format.
* @throws ExoPlaybackException If an error occurs.
*/
public abstract int supportsFormat(Format format) throws ExoPlaybackException;
/**
* Incrementally renders the {@link SampleStream}.
* <p>
* This method should return quickly, and should not block if the renderer is unable to make
......@@ -459,6 +358,13 @@ public abstract class Renderer implements ExoPlayerComponent {
*/
protected abstract boolean isEnded();
// RendererCapabilities implementation
@Override
public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
return ADAPTIVE_NOT_SUPPORTED;
}
// ExoPlayerComponent implementation.
@Override
......
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2;
import com.google.android.exoplayer2.util.MimeTypes;
/**
* Defines the capabilities of a {@link Renderer}.
*/
public interface RendererCapabilities {
/**
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #FORMAT_HANDLED}, {@link #FORMAT_EXCEEDS_CAPABILITIES},
* {@link #FORMAT_UNSUPPORTED_SUBTYPE} and {@link #FORMAT_UNSUPPORTED_TYPE}.
*/
int FORMAT_SUPPORT_MASK = 0b11;
/**
* The {@link Renderer} is capable of rendering the format.
*/
int FORMAT_HANDLED = 0b11;
/**
* The {@link Renderer} is capable of rendering formats with the same mimeType, but the
* properties of the format exceed the renderer's capability.
* <p>
* Example: The {@link Renderer} is capable of rendering H264 and the format's mimeType is
* {@link MimeTypes#VIDEO_H264}, but the format's resolution exceeds the maximum limit supported
* by the underlying H264 decoder.
*/
int FORMAT_EXCEEDS_CAPABILITIES = 0b10;
/**
* The {@link Renderer} is a general purpose renderer for formats of the same top-level type,
* but is not capable of rendering the format or any other format with the same mimeType because
* the sub-type is not supported.
* <p>
* Example: The {@link Renderer} is a general purpose audio renderer and the format's
* mimeType matches audio/[subtype], but there does not exist a suitable decoder for [subtype].
*/
int FORMAT_UNSUPPORTED_SUBTYPE = 0b01;
/**
* The {@link Renderer} is not capable of rendering the format, either because it does not
* support the format's top-level type, or because it's a specialized renderer for a different
* mimeType.
* <p>
* Example: The {@link Renderer} is a general purpose video renderer, but the format has an
* audio mimeType.
*/
int FORMAT_UNSUPPORTED_TYPE = 0b00;
/**
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and {@link #ADAPTIVE_NOT_SUPPORTED}.
*/
int ADAPTIVE_SUPPORT_MASK = 0b1100;
/**
* The {@link Renderer} can seamlessly adapt between formats.
*/
int ADAPTIVE_SEAMLESS = 0b1000;
/**
* The {@link Renderer} can adapt between formats, but may suffer a brief discontinuity
* (~50-100ms) when adaptation occurs.
*/
int ADAPTIVE_NOT_SEAMLESS = 0b0100;
/**
* The {@link Renderer} does not support adaptation between formats.
*/
int ADAPTIVE_NOT_SUPPORTED = 0b0000;
/**
* Returns the track type that the {@link Renderer} handles. For example, a video renderer will
* return {@link C#TRACK_TYPE_VIDEO}, an audio renderer will return {@link C#TRACK_TYPE_AUDIO}, a
* text renderer will return {@link C#TRACK_TYPE_TEXT}, and so on.
*
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
*/
int getTrackType();
/**
* Returns the extent to which the {@link Renderer} supports a given format.
* <p>
* The returned value is the bitwise OR of two properties:
* <ul>
* <li>The level of support for the format itself. One of {@code}link #FORMAT_HANDLED},
* {@link #FORMAT_EXCEEDS_CAPABILITIES}, {@link #FORMAT_UNSUPPORTED_SUBTYPE} and
* {@link #FORMAT_UNSUPPORTED_TYPE}.</li>
* <li>The level of support for adapting from the format to another format of the same mimeType.
* One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.</li>
* </ul>
* The individual properties can be retrieved by performing a bitwise AND with
* {@link #FORMAT_SUPPORT_MASK} and {@link #ADAPTIVE_SUPPORT_MASK} respectively.
*
* @param format The format.
* @return The extent to which the renderer is capable of supporting the given format.
* @throws ExoPlaybackException If an error occurs.
*/
int supportsFormat(Format format) throws ExoPlaybackException;
/**
* Returns the extent to which the {@link Renderer} supports adapting between supported formats
* that have different mimeTypes.
*
* @return The extent to which the renderer supports adapting between supported formats that have
* different mimeTypes. One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.
* @throws ExoPlaybackException If an error occurs.
*/
int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException;
}
......@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.trackselection;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.Util;
......@@ -131,15 +131,15 @@ public class DefaultTrackSelector extends MappingTrackSelector {
// TrackSelectionPolicy implementation.
@Override
protected TrackSelection[] selectTracks(Renderer[] renderers,
protected TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports)
throws ExoPlaybackException {
// Make a track selection for each renderer.
TrackSelection[] rendererTrackSelections = new TrackSelection[renderers.length];
for (int i = 0; i < renderers.length; i++) {
switch (renderers[i].getTrackType()) {
TrackSelection[] rendererTrackSelections = new TrackSelection[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
switch (rendererCapabilities[i].getTrackType()) {
case C.TRACK_TYPE_VIDEO:
rendererTrackSelections[i] = selectTrackForVideoRenderer(renderers[i],
rendererTrackSelections[i] = selectTrackForVideoRenderer(rendererCapabilities[i],
rendererTrackGroupArrays[i], rendererFormatSupports[i], maxVideoWidth, maxVideoHeight,
allowNonSeamlessAdaptiveness, allowMixedMimeAdaptiveness);
if (rendererTrackSelections[i] == null && exceedVideoConstraintsIfNecessary) {
......@@ -166,15 +166,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
// Video track selection implementation.
private static TrackSelection selectTrackForVideoRenderer(Renderer renderer,
TrackGroupArray trackGroups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
private static TrackSelection selectTrackForVideoRenderer(
RendererCapabilities rendererCapabilities, TrackGroupArray trackGroups,
int[][] formatSupport, int maxVideoWidth, int maxVideoHeight,
boolean allowNonSeamlessAdaptiveness, boolean allowMixedMimeAdaptiveness)
throws ExoPlaybackException {
int requiredAdaptiveSupport = allowNonSeamlessAdaptiveness
? (Renderer.ADAPTIVE_NOT_SEAMLESS | Renderer.ADAPTIVE_SEAMLESS)
: Renderer.ADAPTIVE_SEAMLESS;
? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)
: RendererCapabilities.ADAPTIVE_SEAMLESS;
boolean allowMixedMimeTypes = allowMixedMimeAdaptiveness
&& (renderer.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
&& (rendererCapabilities.supportsMixedMimeTypeAdaptation() & requiredAdaptiveSupport) != 0;
int largestAdaptiveGroup = -1;
int[] largestAdaptiveGroupTracks = NO_TRACKS;
for (int i = 0; i < trackGroups.length; i++) {
......@@ -356,7 +357,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
}
private static boolean isSupported(int formatSupport) {
return (formatSupport & Renderer.FORMAT_SUPPORT_MASK) == Renderer.FORMAT_HANDLED;
return (formatSupport & RendererCapabilities.FORMAT_SUPPORT_MASK)
== RendererCapabilities.FORMAT_HANDLED;
}
private static boolean formatHasLanguage(Format format, String language) {
......
......@@ -17,7 +17,7 @@ package com.google.android.exoplayer2.trackselection;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.Assertions;
......@@ -35,8 +35,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
/**
* Base class for {@link TrackSelector}s that first establish a mapping between {@link TrackGroup}s
* and {@link Renderer}s, and then from the mapping create {@link TrackSelection}s for each of the
* {@link Renderer}s.
* and renderers, and then from that mapping create a {@link TrackSelection} for each renderer.
*/
public abstract class MappingTrackSelector extends TrackSelector {
......@@ -226,31 +225,32 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
@Override
public final Pair<TrackSelectionArray, Object> selectTracks(Renderer[] renderers,
TrackGroupArray trackGroups) throws ExoPlaybackException {
public final Pair<TrackSelectionArray, Object> selectTracks(
RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups)
throws ExoPlaybackException {
// Structures into which data will be written during the selection. The extra item at the end
// of each array is to store data associated with track groups that cannot be associated with
// any renderer.
int[] rendererTrackGroupCounts = new int[renderers.length + 1];
TrackGroup[][] rendererTrackGroups = new TrackGroup[renderers.length + 1][];
int[][][] rendererFormatSupports = new int[renderers.length + 1][][];
int[] rendererTrackGroupCounts = new int[rendererCapabilities.length + 1];
TrackGroup[][] rendererTrackGroups = new TrackGroup[rendererCapabilities.length + 1][];
int[][][] rendererFormatSupports = new int[rendererCapabilities.length + 1][][];
for (int i = 0; i < rendererTrackGroups.length; i++) {
rendererTrackGroups[i] = new TrackGroup[trackGroups.length];
rendererFormatSupports[i] = new int[trackGroups.length][];
}
// Determine the extent to which each renderer supports mixed mimeType adaptation.
int[] mixedMimeTypeAdaptationSupport = getMixedMimeTypeAdaptationSupport(renderers);
int[] mixedMimeTypeAdaptationSupport = getMixedMimeTypeAdaptationSupport(rendererCapabilities);
// Associate each track group to a preferred renderer, and evaluate the support that the
// renderer provides for each track in the group.
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
TrackGroup group = trackGroups.get(groupIndex);
// Associate the group to a preferred renderer.
int rendererIndex = findRenderer(renderers, group);
int rendererIndex = findRenderer(rendererCapabilities, group);
// Evaluate the support that the renderer provides for each track in the group.
int[] rendererFormatSupport = rendererIndex == renderers.length ? new int[group.length]
: getFormatSupport(renderers[rendererIndex], group);
int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length
? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
// Stash the results.
int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
......@@ -259,8 +259,8 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
// Create a track group array for each renderer, and trim each rendererFormatSupports entry.
TrackGroupArray[] rendererTrackGroupArrays = new TrackGroupArray[renderers.length];
for (int i = 0; i < renderers.length; i++) {
TrackGroupArray[] rendererTrackGroupArrays = new TrackGroupArray[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
int rendererTrackGroupCount = rendererTrackGroupCounts[i];
rendererTrackGroupArrays[i] = new TrackGroupArray(
Arrays.copyOf(rendererTrackGroups[i], rendererTrackGroupCount));
......@@ -268,15 +268,15 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
// Create a track group array for track groups not associated with a renderer.
int unassociatedTrackGroupCount = rendererTrackGroupCounts[renderers.length];
TrackGroupArray unassociatedTrackGroupArray = new TrackGroupArray(
Arrays.copyOf(rendererTrackGroups[renderers.length], unassociatedTrackGroupCount));
int unassociatedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
TrackGroupArray unassociatedTrackGroupArray = new TrackGroupArray(Arrays.copyOf(
rendererTrackGroups[rendererCapabilities.length], unassociatedTrackGroupCount));
TrackSelection[] rendererTrackSelections = selectTracks(renderers, rendererTrackGroupArrays,
rendererFormatSupports);
TrackSelection[] rendererTrackSelections = selectTracks(rendererCapabilities,
rendererTrackGroupArrays, rendererFormatSupports);
// Apply track disabling and overriding.
for (int i = 0; i < renderers.length; i++) {
for (int i = 0; i < rendererCapabilities.length; i++) {
if (rendererDisabledFlags.get(i)) {
rendererTrackSelections[i] = null;
} else {
......@@ -292,8 +292,8 @@ public abstract class MappingTrackSelector extends TrackSelector {
// The track selections above index into the track group arrays associated to each renderer,
// and not to the original track groups passed to this method. Build the corresponding track
// selections into the original track groups to pass back as the final selection.
TrackSelection[] trackSelections = new TrackSelection[renderers.length];
for (int i = 0; i < renderers.length; i++) {
TrackSelection[] trackSelections = new TrackSelection[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
TrackSelection selection = rendererTrackSelections[i];
if (selection != null) {
TrackGroup group = rendererTrackGroupArrays[i].get(selection.group);
......@@ -310,17 +310,18 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
/**
* Given an array of {@link Renderer}s and a set of {@link TrackGroup}s mapped to each of
* them, provides a {@link TrackSelection} per renderer.
* Given an array of renderers and a set of {@link TrackGroup}s mapped to each of them, provides a
* {@link TrackSelection} per renderer.
*
* @param renderers The available {@link Renderer}s.
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which
* {@link TrackSelection}s are to be generated.
* @param rendererTrackGroupArrays An array of {@link TrackGroupArray}s where each entry
* corresponds to the {@link Renderer} of equal index in {@code renderers}.
* corresponds to the renderer of equal index in {@code renderers}.
* @param rendererFormatSupports Maps every available track to a specific level of support as
* defined by the {@link Renderer} {@code FORMAT_*} constants.
* defined by the renderer {@code FORMAT_*} constants.
* @throws ExoPlaybackException If an error occurs while selecting the tracks.
*/
protected abstract TrackSelection[] selectTracks(Renderer[] renderers,
protected abstract TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports)
throws ExoPlaybackException;
......@@ -328,33 +329,34 @@ public abstract class MappingTrackSelector extends TrackSelector {
* Finds the renderer to which the provided {@link TrackGroup} should be associated.
* <p>
* A {@link TrackGroup} is associated to a renderer that reports
* {@link Renderer#FORMAT_HANDLED} support for one or more of the tracks in the group, or
* {@link Renderer#FORMAT_EXCEEDS_CAPABILITIES} if no such renderer exists, or
* {@link Renderer#FORMAT_UNSUPPORTED_SUBTYPE} if again no such renderer exists. In the case
* that two or more renderers report the same level of support, the renderer with the lowest index
* is associated.
* {@link RendererCapabilities#FORMAT_HANDLED} support for one or more of the tracks in the group,
* or {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES} if no such renderer exists, or
* {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} if again no such renderer exists. In
* the case that two or more renderers report the same level of support, the renderer with the
* lowest index is associated.
* <p>
* If all renderers report {@link Renderer#FORMAT_UNSUPPORTED_TYPE} for all of the tracks in
* the group, then {@code renderers.length} is returned to indicate that no association was made.
* If all renderers report {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} for all of the
* tracks in the group, then {@code renderers.length} is returned to indicate that no association
* was made.
*
* @param renderers The renderers from which to select.
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
* @param group The {@link TrackGroup} whose associated renderer is to be found.
* @return The index of the associated renderer, or {@code renderers.length} if no association
* was made.
* @return The index of the associated renderer, or {@code renderers.length} if no
* association was made.
* @throws ExoPlaybackException If an error occurs finding a renderer.
*/
private static int findRenderer(Renderer[] renderers, TrackGroup group)
private static int findRenderer(RendererCapabilities[] rendererCapabilities, TrackGroup group)
throws ExoPlaybackException {
int bestRendererIndex = renderers.length;
int bestSupportLevel = Renderer.FORMAT_UNSUPPORTED_TYPE;
for (int rendererIndex = 0; rendererIndex < renderers.length; rendererIndex++) {
Renderer renderer = renderers[rendererIndex];
int bestRendererIndex = rendererCapabilities.length;
int bestSupportLevel = RendererCapabilities.FORMAT_UNSUPPORTED_TYPE;
for (int rendererIndex = 0; rendererIndex < rendererCapabilities.length; rendererIndex++) {
RendererCapabilities rendererCapability = rendererCapabilities[rendererIndex];
for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
int trackSupportLevel = renderer.supportsFormat(group.getFormat(trackIndex));
int trackSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex));
if (trackSupportLevel > bestSupportLevel) {
bestRendererIndex = rendererIndex;
bestSupportLevel = trackSupportLevel;
if (bestSupportLevel == Renderer.FORMAT_HANDLED) {
if (bestSupportLevel == RendererCapabilities.FORMAT_HANDLED) {
// We can't do better.
return bestRendererIndex;
}
......@@ -365,38 +367,38 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
/**
* Calls {@link Renderer#supportsFormat(Format)} for each track in the specified
* Calls {@link RendererCapabilities#supportsFormat(Format)} for each track in the specified
* {@link TrackGroup}, returning the results in an array.
*
* @param renderer The renderer to evaluate.
* @param rendererCapabilities The {@link RendererCapabilities} of the renderer.
* @param group The {@link TrackGroup} to evaluate.
* @return An array containing the result of calling {@link Renderer#supportsFormat(Format)}
* on the renderer for each track in the group.
* @return An array containing the result of calling
* {@link RendererCapabilities#supportsFormat(Format)} for each track in the group.
* @throws ExoPlaybackException If an error occurs determining the format support.
*/
private static int[] getFormatSupport(Renderer renderer, TrackGroup group)
private static int[] getFormatSupport(RendererCapabilities rendererCapabilities, TrackGroup group)
throws ExoPlaybackException {
int[] formatSupport = new int[group.length];
for (int i = 0; i < group.length; i++) {
formatSupport[i] = renderer.supportsFormat(group.getFormat(i));
formatSupport[i] = rendererCapabilities.supportsFormat(group.getFormat(i));
}
return formatSupport;
}
/**
* Calls {@link Renderer#supportsMixedMimeTypeAdaptation()} for each renderer, returning
* the results in an array.
* Calls {@link RendererCapabilities#supportsMixedMimeTypeAdaptation()} for each renderer,
* returning the results in an array.
*
* @param renderers The renderers to evaluate.
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers.
* @return An array containing the result of calling
* {@link Renderer#supportsMixedMimeTypeAdaptation()} on each renderer.
* {@link RendererCapabilities#supportsMixedMimeTypeAdaptation()} for each renderer.
* @throws ExoPlaybackException If an error occurs determining the adaptation support.
*/
private static int[] getMixedMimeTypeAdaptationSupport(Renderer[] renderers)
throws ExoPlaybackException {
int[] mixedMimeTypeAdaptationSupport = new int[renderers.length];
private static int[] getMixedMimeTypeAdaptationSupport(
RendererCapabilities[] rendererCapabilities) throws ExoPlaybackException {
int[] mixedMimeTypeAdaptationSupport = new int[rendererCapabilities.length];
for (int i = 0; i < mixedMimeTypeAdaptationSupport.length; i++) {
mixedMimeTypeAdaptationSupport[i] = renderers[i].supportsMixedMimeTypeAdaptation();
mixedMimeTypeAdaptationSupport[i] = rendererCapabilities[i].supportsMixedMimeTypeAdaptation();
}
return mixedMimeTypeAdaptationSupport;
}
......@@ -432,7 +434,7 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
/**
* Provides track information for each {@link Renderer}.
* Provides track information for each renderer.
*/
public static final class TrackInfo {
......@@ -464,9 +466,9 @@ public abstract class MappingTrackSelector extends TrackSelector {
* @param trackGroups The {@link TrackGroupArray}s for each renderer.
* @param trackSelections The current {@link TrackSelection}s for each renderer.
* @param mixedMimeTypeAdaptiveSupport The result of
* {@link Renderer#supportsMixedMimeTypeAdaptation()} for each renderer.
* @param formatSupport The result of {@link Renderer#supportsFormat(Format)} for each
* track, indexed by renderer index, group index and track index (in that order).
* {@link RendererCapabilities#supportsMixedMimeTypeAdaptation()} for each renderer.
* @param formatSupport The result of {@link RendererCapabilities#supportsFormat(Format)} for
* each track, indexed by renderer index, group index and track index (in that order).
* @param unassociatedTrackGroups Contains {@link TrackGroup}s not associated with any renderer.
*/
/* package */ TrackInfo(TrackGroupArray[] trackGroups, TrackSelection[] trackSelections,
......@@ -513,8 +515,8 @@ public abstract class MappingTrackSelector extends TrackSelector {
for (int i = 0; i < rendererFormatSupport.length; i++) {
for (int j = 0; j < rendererFormatSupport[i].length; j++) {
hasTracks = true;
if ((rendererFormatSupport[i][j] & Renderer.FORMAT_SUPPORT_MASK)
== Renderer.FORMAT_HANDLED) {
if ((rendererFormatSupport[i][j] & RendererCapabilities.FORMAT_SUPPORT_MASK)
== RendererCapabilities.FORMAT_HANDLED) {
return RENDERER_SUPPORT_PLAYABLE_TRACKS;
}
}
......@@ -528,14 +530,14 @@ public abstract class MappingTrackSelector extends TrackSelector {
* @param rendererIndex The renderer index.
* @param groupIndex The index of the group to which the track belongs.
* @param trackIndex The index of the track within the group.
* @return One of {@link Renderer#FORMAT_HANDLED},
* {@link Renderer#FORMAT_EXCEEDS_CAPABILITIES},
* {@link Renderer#FORMAT_UNSUPPORTED_SUBTYPE} and
* {@link Renderer#FORMAT_UNSUPPORTED_TYPE}.
* @return One of {@link RendererCapabilities#FORMAT_HANDLED},
* {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES},
* {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} and
* {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE}.
*/
public int getTrackFormatSupport(int rendererIndex, int groupIndex, int trackIndex) {
return formatSupport[rendererIndex][groupIndex][trackIndex]
& Renderer.FORMAT_SUPPORT_MASK;
& RendererCapabilities.FORMAT_SUPPORT_MASK;
}
/**
......@@ -543,21 +545,21 @@ public abstract class MappingTrackSelector extends TrackSelector {
* specified {@link TrackGroup}.
* <p>
* Tracks for which {@link #getTrackFormatSupport(int, int, int)} returns
* {@link Renderer#FORMAT_HANDLED} are always considered.
* {@link RendererCapabilities#FORMAT_HANDLED} are always considered.
* Tracks for which {@link #getTrackFormatSupport(int, int, int)} returns
* {@link Renderer#FORMAT_UNSUPPORTED_TYPE} or
* {@link Renderer#FORMAT_UNSUPPORTED_SUBTYPE} are never considered.
* {@link RendererCapabilities#FORMAT_UNSUPPORTED_TYPE} or
* {@link RendererCapabilities#FORMAT_UNSUPPORTED_SUBTYPE} are never considered.
* Tracks for which {@link #getTrackFormatSupport(int, int, int)} returns
* {@link Renderer#FORMAT_EXCEEDS_CAPABILITIES} are considered only if
* {@link RendererCapabilities#FORMAT_EXCEEDS_CAPABILITIES} are considered only if
* {@code includeCapabilitiesExceededTracks} is set to {@code true}.
*
* @param rendererIndex The renderer index.
* @param groupIndex The index of the group.
* @param includeCapabilitiesExceededTracks True if formats that exceed the capabilities of the
* renderer should be included when determining support. False otherwise.
* @return One of {@link Renderer#ADAPTIVE_SEAMLESS},
* {@link Renderer#ADAPTIVE_NOT_SEAMLESS} and
* {@link Renderer#ADAPTIVE_NOT_SUPPORTED}.
* @return One of {@link RendererCapabilities#ADAPTIVE_SEAMLESS},
* {@link RendererCapabilities#ADAPTIVE_NOT_SEAMLESS} and
* {@link RendererCapabilities#ADAPTIVE_NOT_SUPPORTED}.
*/
public int getAdaptiveSupport(int rendererIndex, int groupIndex,
boolean includeCapabilitiesExceededTracks) {
......@@ -567,8 +569,9 @@ public abstract class MappingTrackSelector extends TrackSelector {
int trackIndexCount = 0;
for (int i = 0; i < trackCount; i++) {
int fixedSupport = getTrackFormatSupport(rendererIndex, groupIndex, i);
if (fixedSupport == Renderer.FORMAT_HANDLED || (includeCapabilitiesExceededTracks
&& fixedSupport == Renderer.FORMAT_EXCEEDS_CAPABILITIES)) {
if (fixedSupport == RendererCapabilities.FORMAT_HANDLED
|| (includeCapabilitiesExceededTracks
&& fixedSupport == RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES)) {
trackIndices[trackIndexCount++] = i;
}
}
......@@ -582,17 +585,17 @@ public abstract class MappingTrackSelector extends TrackSelector {
*
* @param rendererIndex The renderer index.
* @param groupIndex The index of the group.
* @return One of {@link Renderer#ADAPTIVE_SEAMLESS},
* {@link Renderer#ADAPTIVE_NOT_SEAMLESS} and
* {@link Renderer#ADAPTIVE_NOT_SUPPORTED}.
* @return One of {@link RendererCapabilities#ADAPTIVE_SEAMLESS},
* {@link RendererCapabilities#ADAPTIVE_NOT_SEAMLESS} and
* {@link RendererCapabilities#ADAPTIVE_NOT_SUPPORTED}.
*/
public int getAdaptiveSupport(int rendererIndex, int groupIndex, int[] trackIndices) {
TrackGroup trackGroup = trackGroups[rendererIndex].get(groupIndex);
if (!trackGroup.adaptive) {
return Renderer.ADAPTIVE_NOT_SUPPORTED;
return RendererCapabilities.ADAPTIVE_NOT_SUPPORTED;
}
int handledTrackCount = 0;
int adaptiveSupport = Renderer.ADAPTIVE_SEAMLESS;
int adaptiveSupport = RendererCapabilities.ADAPTIVE_SEAMLESS;
boolean multipleMimeTypes = false;
String firstSampleMimeType = null;
for (int i = 0; i < trackIndices.length; i++) {
......@@ -604,8 +607,8 @@ public abstract class MappingTrackSelector extends TrackSelector {
} else {
multipleMimeTypes |= !Util.areEqual(firstSampleMimeType, sampleMimeType);
}
adaptiveSupport = Math.min(adaptiveSupport,
formatSupport[rendererIndex][groupIndex][i] & Renderer.ADAPTIVE_SUPPORT_MASK);
adaptiveSupport = Math.min(adaptiveSupport, formatSupport[rendererIndex][groupIndex][i]
& RendererCapabilities.ADAPTIVE_SUPPORT_MASK);
}
return multipleMimeTypes
? Math.min(adaptiveSupport, mixedMimeTypeAdaptiveSupport[rendererIndex])
......@@ -613,9 +616,9 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
/**
* Gets the {@link TrackGroup}s not associated with any {@link Renderer}.
* Gets the {@link TrackGroup}s not associated with any renderer.
*
* @return The {@link TrackGroup}s not associated with any {@link Renderer}.
* @return The {@link TrackGroup}s not associated with any renderer.
*/
public TrackGroupArray getUnassociatedTrackGroups() {
return unassociatedTrackGroups;
......
......@@ -16,13 +16,13 @@
package com.google.android.exoplayer2.trackselection;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.source.TrackGroupArray;
import android.util.Pair;
/**
* Selects tracks to be consumed by available {@link Renderer}s.
* Selects tracks to be consumed by available renderers.
*/
public abstract class TrackSelector {
......@@ -56,19 +56,21 @@ public abstract class TrackSelector {
* that the selector wishes to receive in an invocation of {@link #onSelectionActivated(Object)}
* should the selection be activated.
*
* @param renderers The renderers.
* @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which
* {@link TrackSelection}s are to be generated.
* @param trackGroups The available track groups.
* @return A {@link TrackSelectionArray} containing a {@link TrackSelection} for each renderer,
* together with an opaque object that will be passed to {@link #onSelectionActivated(Object)}
* if the selection is activated.
* @throws ExoPlaybackException If an error occurs selecting tracks.
*/
public abstract Pair<TrackSelectionArray, Object> selectTracks(Renderer[] renderers,
TrackGroupArray trackGroups) throws ExoPlaybackException;
public abstract Pair<TrackSelectionArray, Object> selectTracks(
RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups)
throws ExoPlaybackException;
/**
* Invoked when a selection previously generated by
* {@link #selectTracks(Renderer[], TrackGroupArray)} is activated.
* {@link #selectTracks(RendererCapabilities[], TrackGroupArray)} is activated.
*
* @param selectionInfo The opaque object associated with the selection.
*/
......
......@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
......@@ -44,7 +45,6 @@ import android.annotation.TargetApi;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import junit.framework.AssertionFailedError;
import java.util.ArrayList;
......@@ -492,14 +492,16 @@ public final class DashTest extends ActivityInstrumentationTestCase2<HostActivit
}
@Override
protected TrackSelection[] selectTracks(Renderer[] renderers,
protected TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports)
throws ExoPlaybackException {
Assertions.checkState(renderers[VIDEO_RENDERER_INDEX].getTrackType() == C.TRACK_TYPE_VIDEO);
Assertions.checkState(renderers[AUDIO_RENDERER_INDEX].getTrackType() == C.TRACK_TYPE_AUDIO);
Assertions.checkState(rendererCapabilities[VIDEO_RENDERER_INDEX].getTrackType()
== C.TRACK_TYPE_VIDEO);
Assertions.checkState(rendererCapabilities[AUDIO_RENDERER_INDEX].getTrackType()
== C.TRACK_TYPE_AUDIO);
Assertions.checkState(rendererTrackGroupArrays[VIDEO_RENDERER_INDEX].length == 1);
Assertions.checkState(rendererTrackGroupArrays[AUDIO_RENDERER_INDEX].length == 1);
TrackSelection[] selections = new TrackSelection[renderers.length];
TrackSelection[] selections = new TrackSelection[rendererCapabilities.length];
selections[VIDEO_RENDERER_INDEX] = new TrackSelection(0,
getTrackIndices(rendererTrackGroupArrays[VIDEO_RENDERER_INDEX].get(0),
rendererFormatSupports[VIDEO_RENDERER_INDEX][0], videoFormatIds,
......
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