Allow multiple metadata tracks, assuming multiple metadata renderers

This commit is contained in:
Pierre-Hugues Husson 2019-11-20 16:12:15 +01:00 committed by Pierre-Hugues Husson
parent 95d0921114
commit ad8f6c183d
2 changed files with 48 additions and 12 deletions

View File

@ -1732,6 +1732,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
TextTrackScore selectedTextTrackScore = null;
int selectedTextRendererIndex = C.INDEX_UNSET;
int nIgnore = 0;
for (int i = 0; i < rendererCount; i++) {
int trackType = mappedTrackInfo.getRendererType(i);
switch (trackType) {
@ -1762,7 +1763,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
default:
definitions[i] =
selectOtherTrack(
trackType, mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params);
trackType, mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params, nIgnore);
nIgnore++;
break;
}
}
@ -2297,11 +2299,12 @@ public class DefaultTrackSelector extends MappingTrackSelector {
*/
@Nullable
protected TrackSelection.Definition selectOtherTrack(
int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params, int nIgnore)
throws ExoPlaybackException {
TrackGroup selectedGroup = null;
int selectedTrackIndex = 0;
int selectedTrackScore = 0;
int nAlreadyIgnored = 0;
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
TrackGroup trackGroup = groups.get(groupIndex);
int[] trackFormatSupport = formatSupport[groupIndex];
@ -2315,9 +2318,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
}
if (trackScore > selectedTrackScore) {
selectedGroup = trackGroup;
selectedTrackIndex = trackIndex;
selectedTrackScore = trackScore;
nAlreadyIgnored = 0;
}
if(trackScore == selectedTrackScore) {
if(nAlreadyIgnored == nIgnore) {
selectedGroup = trackGroup;
selectedTrackIndex = trackIndex;
}
nAlreadyIgnored++;
}
}
}

View File

@ -31,7 +31,10 @@ import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
@ -356,15 +359,17 @@ public abstract class MappingTrackSelector extends TrackSelector {
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
TrackGroup group = trackGroups.get(groupIndex);
// Associate the group to a preferred renderer.
int rendererIndex = findRenderer(rendererCapabilities, group);
// Evaluate the support that the renderer provides for each track in the 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;
rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
rendererTrackGroupCounts[rendererIndex]++;
List<Integer> rendererIndexes = findAllRenderers(rendererCapabilities, group);
for(int rendererIndex: rendererIndexes) {
// Evaluate the support that the renderer provides for each track in the 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;
rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
rendererTrackGroupCounts[rendererIndex]++;
}
}
// Create a track group array for each renderer, and trim each rendererFormatSupports entry.
@ -465,6 +470,27 @@ public abstract class MappingTrackSelector extends TrackSelector {
return bestRendererIndex;
}
private static List<Integer> findAllRenderers(RendererCapabilities[] rendererCapabilities, TrackGroup group)
throws ExoPlaybackException {
ArrayList<Integer> result = new ArrayList<>();
int bestFormatSupportLevel = 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 formatSupportLevel = rendererCapability.supportsFormat(group.getFormat(trackIndex))
& RendererCapabilities.FORMAT_SUPPORT_MASK;
if (formatSupportLevel > bestFormatSupportLevel) {
bestFormatSupportLevel = formatSupportLevel;
result.clear();
}
if (formatSupportLevel == bestFormatSupportLevel) {
result.add(rendererIndex);
}
}
}
return result;
}
/**
* Calls {@link RendererCapabilities#supportsFormat} for each track in the specified
* {@link TrackGroup}, returning the results in an array.