Allow multiple metadata tracks, assuming multiple metadata renderers
This commit is contained in:
parent
95d0921114
commit
ad8f6c183d
@ -1732,6 +1732,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||||||
|
|
||||||
TextTrackScore selectedTextTrackScore = null;
|
TextTrackScore selectedTextTrackScore = null;
|
||||||
int selectedTextRendererIndex = C.INDEX_UNSET;
|
int selectedTextRendererIndex = C.INDEX_UNSET;
|
||||||
|
int nIgnore = 0;
|
||||||
for (int i = 0; i < rendererCount; i++) {
|
for (int i = 0; i < rendererCount; i++) {
|
||||||
int trackType = mappedTrackInfo.getRendererType(i);
|
int trackType = mappedTrackInfo.getRendererType(i);
|
||||||
switch (trackType) {
|
switch (trackType) {
|
||||||
@ -1762,7 +1763,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||||||
default:
|
default:
|
||||||
definitions[i] =
|
definitions[i] =
|
||||||
selectOtherTrack(
|
selectOtherTrack(
|
||||||
trackType, mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params);
|
trackType, mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params, nIgnore);
|
||||||
|
nIgnore++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2297,11 +2299,12 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected TrackSelection.Definition selectOtherTrack(
|
protected TrackSelection.Definition selectOtherTrack(
|
||||||
int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
|
int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params, int nIgnore)
|
||||||
throws ExoPlaybackException {
|
throws ExoPlaybackException {
|
||||||
TrackGroup selectedGroup = null;
|
TrackGroup selectedGroup = null;
|
||||||
int selectedTrackIndex = 0;
|
int selectedTrackIndex = 0;
|
||||||
int selectedTrackScore = 0;
|
int selectedTrackScore = 0;
|
||||||
|
int nAlreadyIgnored = 0;
|
||||||
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
||||||
TrackGroup trackGroup = groups.get(groupIndex);
|
TrackGroup trackGroup = groups.get(groupIndex);
|
||||||
int[] trackFormatSupport = formatSupport[groupIndex];
|
int[] trackFormatSupport = formatSupport[groupIndex];
|
||||||
@ -2315,9 +2318,16 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
|||||||
trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
|
trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
|
||||||
}
|
}
|
||||||
if (trackScore > selectedTrackScore) {
|
if (trackScore > selectedTrackScore) {
|
||||||
selectedGroup = trackGroup;
|
|
||||||
selectedTrackIndex = trackIndex;
|
selectedTrackIndex = trackIndex;
|
||||||
selectedTrackScore = trackScore;
|
selectedTrackScore = trackScore;
|
||||||
|
nAlreadyIgnored = 0;
|
||||||
|
}
|
||||||
|
if(trackScore == selectedTrackScore) {
|
||||||
|
if(nAlreadyIgnored == nIgnore) {
|
||||||
|
selectedGroup = trackGroup;
|
||||||
|
selectedTrackIndex = trackIndex;
|
||||||
|
}
|
||||||
|
nAlreadyIgnored++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,10 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
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++) {
|
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
|
||||||
TrackGroup group = trackGroups.get(groupIndex);
|
TrackGroup group = trackGroups.get(groupIndex);
|
||||||
// Associate the group to a preferred renderer.
|
// Associate the group to a preferred renderer.
|
||||||
int rendererIndex = findRenderer(rendererCapabilities, group);
|
List<Integer> rendererIndexes = findAllRenderers(rendererCapabilities, group);
|
||||||
// Evaluate the support that the renderer provides for each track in the group.
|
for(int rendererIndex: rendererIndexes) {
|
||||||
int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length
|
// Evaluate the support that the renderer provides for each track in the group.
|
||||||
? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
|
int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length
|
||||||
// Stash the results.
|
? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
|
||||||
int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
|
// Stash the results.
|
||||||
rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
|
int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
|
||||||
rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
|
rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
|
||||||
rendererTrackGroupCounts[rendererIndex]++;
|
rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
|
||||||
|
rendererTrackGroupCounts[rendererIndex]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a track group array for each renderer, and trim each rendererFormatSupports entry.
|
// 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;
|
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
|
* Calls {@link RendererCapabilities#supportsFormat} for each track in the specified
|
||||||
* {@link TrackGroup}, returning the results in an array.
|
* {@link TrackGroup}, returning the results in an array.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user