Add RendererCapabilities.isFormatSupported helper method
This makes the same method that currently exists as DefaultTrackSelector.isSupported more widely available as a utility. PiperOrigin-RevId: 629991830
This commit is contained in:
parent
ec9b38b817
commit
0893275841
@ -415,6 +415,26 @@ public interface RendererCapabilities {
|
|||||||
return supportFlags & FORMAT_SUPPORT_MASK;
|
return supportFlags & FORMAT_SUPPORT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the {@link C.FormatSupport} from the combined {@link Capabilities} indicates
|
||||||
|
* the format is supported.
|
||||||
|
*
|
||||||
|
* <p>A format is considered supported if its {@link C.FormatSupport} value is {@link
|
||||||
|
* C#FORMAT_HANDLED}, or optionally {@link C#FORMAT_EXCEEDS_CAPABILITIES} if enabled by {@code
|
||||||
|
* allowExceedsCapabilities}.
|
||||||
|
*
|
||||||
|
* @param supportFlags The combined {@link Capabilities}.
|
||||||
|
* @param allowExceedsCapabilities Whether {@link C#FORMAT_EXCEEDS_CAPABILITIES} should be
|
||||||
|
* considered as supported.
|
||||||
|
* @return Whether the {@link Capabilities} indicate a format is supported.
|
||||||
|
*/
|
||||||
|
static boolean isFormatSupported(
|
||||||
|
@Capabilities int supportFlags, boolean allowExceedsCapabilities) {
|
||||||
|
@C.FormatSupport int formatSupport = getFormatSupport(supportFlags);
|
||||||
|
return formatSupport == C.FORMAT_HANDLED
|
||||||
|
|| (allowExceedsCapabilities && formatSupport == C.FORMAT_EXCEEDS_CAPABILITIES);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link AdaptiveSupport} from the combined {@link Capabilities}.
|
* Returns the {@link AdaptiveSupport} from the combined {@link Capabilities}.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ import static androidx.media3.common.util.Util.castNonNull;
|
|||||||
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_GAPLESS_SUPPORTED;
|
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_GAPLESS_SUPPORTED;
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_NOT_SUPPORTED;
|
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_NOT_SUPPORTED;
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_SPEED_CHANGE_SUPPORTED;
|
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_SPEED_CHANGE_SUPPORTED;
|
||||||
|
import static androidx.media3.exoplayer.RendererCapabilities.isFormatSupported;
|
||||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
import static java.util.Collections.max;
|
import static java.util.Collections.max;
|
||||||
|
|
||||||
@ -45,7 +46,6 @@ import androidx.annotation.RequiresApi;
|
|||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
import androidx.media3.common.Bundleable;
|
import androidx.media3.common.Bundleable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.C.FormatSupport;
|
|
||||||
import androidx.media3.common.C.RoleFlags;
|
import androidx.media3.common.C.RoleFlags;
|
||||||
import androidx.media3.common.Format;
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.MimeTypes;
|
import androidx.media3.common.MimeTypes;
|
||||||
@ -2951,7 +2951,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
TrackGroup trackGroup = groups.get(groupIndex);
|
TrackGroup trackGroup = groups.get(groupIndex);
|
||||||
@Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
|
@Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
|
||||||
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||||
if (isSupported(
|
if (isFormatSupported(
|
||||||
trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
|
trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
|
||||||
Format format = trackGroup.getFormat(trackIndex);
|
Format format = trackGroup.getFormat(trackIndex);
|
||||||
OtherTrackScore trackScore = new OtherTrackScore(format, trackFormatSupport[trackIndex]);
|
OtherTrackScore trackScore = new OtherTrackScore(format, trackFormatSupport[trackIndex]);
|
||||||
@ -3316,22 +3316,12 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the {@link FormatSupport} in the given {@link Capabilities} is {@link
|
* @deprecated Use {@link RendererCapabilities#isFormatSupported} instead.
|
||||||
* C#FORMAT_HANDLED} or if {@code allowExceedsCapabilities} is set and the format support is
|
|
||||||
* {@link C#FORMAT_EXCEEDS_CAPABILITIES}.
|
|
||||||
*
|
|
||||||
* @param formatSupport {@link Capabilities}.
|
|
||||||
* @param allowExceedsCapabilities Whether to return true if {@link FormatSupport} is {@link
|
|
||||||
* C#FORMAT_EXCEEDS_CAPABILITIES}.
|
|
||||||
* @return True if {@link FormatSupport} is {@link C#FORMAT_HANDLED}, or if {@code
|
|
||||||
* allowExceedsCapabilities} is set and the format support is {@link
|
|
||||||
* C#FORMAT_EXCEEDS_CAPABILITIES}.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected static boolean isSupported(
|
protected static boolean isSupported(
|
||||||
@Capabilities int formatSupport, boolean allowExceedsCapabilities) {
|
@Capabilities int formatSupport, boolean allowExceedsCapabilities) {
|
||||||
@FormatSupport int maskedSupport = RendererCapabilities.getFormatSupport(formatSupport);
|
return isFormatSupported(formatSupport, allowExceedsCapabilities);
|
||||||
return maskedSupport == C.FORMAT_HANDLED
|
|
||||||
|| (allowExceedsCapabilities && maskedSupport == C.FORMAT_EXCEEDS_CAPABILITIES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3607,7 +3597,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
&& (format.bitrate == Format.NO_VALUE
|
&& (format.bitrate == Format.NO_VALUE
|
||||||
|| format.bitrate >= parameters.minVideoBitrate);
|
|| format.bitrate >= parameters.minVideoBitrate);
|
||||||
isWithinRendererCapabilities =
|
isWithinRendererCapabilities =
|
||||||
isSupported(formatSupport, /* allowExceedsCapabilities= */ false);
|
isFormatSupported(formatSupport, /* allowExceedsCapabilities= */ false);
|
||||||
hasReasonableFrameRate =
|
hasReasonableFrameRate =
|
||||||
format.frameRate != Format.NO_VALUE && format.frameRate >= MIN_REASONABLE_FRAME_RATE;
|
format.frameRate != Format.NO_VALUE && format.frameRate >= MIN_REASONABLE_FRAME_RATE;
|
||||||
bitrate = format.bitrate;
|
bitrate = format.bitrate;
|
||||||
@ -3654,13 +3644,13 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
// Ignore trick-play tracks for now.
|
// Ignore trick-play tracks for now.
|
||||||
return SELECTION_ELIGIBILITY_NO;
|
return SELECTION_ELIGIBILITY_NO;
|
||||||
}
|
}
|
||||||
if (!isSupported(rendererSupport, parameters.exceedRendererCapabilitiesIfNecessary)) {
|
if (!isFormatSupported(rendererSupport, parameters.exceedRendererCapabilitiesIfNecessary)) {
|
||||||
return SELECTION_ELIGIBILITY_NO;
|
return SELECTION_ELIGIBILITY_NO;
|
||||||
}
|
}
|
||||||
if (!isWithinMaxConstraints && !parameters.exceedVideoConstraintsIfNecessary) {
|
if (!isWithinMaxConstraints && !parameters.exceedVideoConstraintsIfNecessary) {
|
||||||
return SELECTION_ELIGIBILITY_NO;
|
return SELECTION_ELIGIBILITY_NO;
|
||||||
}
|
}
|
||||||
return isSupported(rendererSupport, /* allowExceedsCapabilities= */ false)
|
return isFormatSupported(rendererSupport, /* allowExceedsCapabilities= */ false)
|
||||||
&& isWithinMinConstraints
|
&& isWithinMinConstraints
|
||||||
&& isWithinMaxConstraints
|
&& isWithinMaxConstraints
|
||||||
&& format.bitrate != Format.NO_VALUE
|
&& format.bitrate != Format.NO_VALUE
|
||||||
@ -3810,7 +3800,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
&& (mixedMimeTypeAdaptationSupport & requiredAdaptiveSupport) != 0;
|
&& (mixedMimeTypeAdaptationSupport & requiredAdaptiveSupport) != 0;
|
||||||
this.language = normalizeUndeterminedLanguageToNull(format.language);
|
this.language = normalizeUndeterminedLanguageToNull(format.language);
|
||||||
isWithinRendererCapabilities =
|
isWithinRendererCapabilities =
|
||||||
isSupported(formatSupport, /* allowExceedsCapabilities= */ false);
|
isFormatSupported(formatSupport, /* allowExceedsCapabilities= */ false);
|
||||||
int bestLanguageScore = 0;
|
int bestLanguageScore = 0;
|
||||||
int bestLanguageIndex = Integer.MAX_VALUE;
|
int bestLanguageIndex = Integer.MAX_VALUE;
|
||||||
for (int i = 0; i < parameters.preferredAudioLanguages.size(); i++) {
|
for (int i = 0; i < parameters.preferredAudioLanguages.size(); i++) {
|
||||||
@ -3951,7 +3941,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
@Capabilities int rendererSupport,
|
@Capabilities int rendererSupport,
|
||||||
boolean hasMappedVideoTracks,
|
boolean hasMappedVideoTracks,
|
||||||
@AdaptiveSupport int requiredAdaptiveSupport) {
|
@AdaptiveSupport int requiredAdaptiveSupport) {
|
||||||
if (!isSupported(rendererSupport, parameters.exceedRendererCapabilitiesIfNecessary)) {
|
if (!isFormatSupported(rendererSupport, parameters.exceedRendererCapabilitiesIfNecessary)) {
|
||||||
return SELECTION_ELIGIBILITY_NO;
|
return SELECTION_ELIGIBILITY_NO;
|
||||||
}
|
}
|
||||||
if (!isWithinConstraints && !parameters.exceedAudioConstraintsIfNecessary) {
|
if (!isWithinConstraints && !parameters.exceedAudioConstraintsIfNecessary) {
|
||||||
@ -3961,7 +3951,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
&& !rendererSupportsOffload(parameters, rendererSupport, format)) {
|
&& !rendererSupportsOffload(parameters, rendererSupport, format)) {
|
||||||
return SELECTION_ELIGIBILITY_NO;
|
return SELECTION_ELIGIBILITY_NO;
|
||||||
}
|
}
|
||||||
return isSupported(rendererSupport, /* allowExceedsCapabilities= */ false)
|
return isFormatSupported(rendererSupport, /* allowExceedsCapabilities= */ false)
|
||||||
&& isWithinConstraints
|
&& isWithinConstraints
|
||||||
&& format.bitrate != Format.NO_VALUE
|
&& format.bitrate != Format.NO_VALUE
|
||||||
&& !parameters.forceHighestSupportedBitrate
|
&& !parameters.forceHighestSupportedBitrate
|
||||||
@ -4021,7 +4011,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
@Nullable String selectedAudioLanguage) {
|
@Nullable String selectedAudioLanguage) {
|
||||||
super(rendererIndex, trackGroup, trackIndex);
|
super(rendererIndex, trackGroup, trackIndex);
|
||||||
isWithinRendererCapabilities =
|
isWithinRendererCapabilities =
|
||||||
isSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
|
isFormatSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
|
||||||
int maskedSelectionFlags = format.selectionFlags & ~parameters.ignoredTextSelectionFlags;
|
int maskedSelectionFlags = format.selectionFlags & ~parameters.ignoredTextSelectionFlags;
|
||||||
isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
|
isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
|
||||||
isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
|
isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
|
||||||
@ -4059,7 +4049,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
|| isDefault
|
|| isDefault
|
||||||
|| (isForced && selectedAudioLanguageScore > 0);
|
|| (isForced && selectedAudioLanguageScore > 0);
|
||||||
selectionEligibility =
|
selectionEligibility =
|
||||||
isSupported(trackFormatSupport, parameters.exceedRendererCapabilitiesIfNecessary)
|
isFormatSupported(trackFormatSupport, parameters.exceedRendererCapabilitiesIfNecessary)
|
||||||
&& isWithinConstraints
|
&& isWithinConstraints
|
||||||
? SELECTION_ELIGIBILITY_FIXED
|
? SELECTION_ELIGIBILITY_FIXED
|
||||||
: SELECTION_ELIGIBILITY_NO;
|
: SELECTION_ELIGIBILITY_NO;
|
||||||
@ -4137,7 +4127,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
@Capabilities int trackFormatSupport) {
|
@Capabilities int trackFormatSupport) {
|
||||||
super(rendererIndex, trackGroup, trackIndex);
|
super(rendererIndex, trackGroup, trackIndex);
|
||||||
selectionEligibility =
|
selectionEligibility =
|
||||||
isSupported(trackFormatSupport, parameters.exceedRendererCapabilitiesIfNecessary)
|
isFormatSupported(trackFormatSupport, parameters.exceedRendererCapabilitiesIfNecessary)
|
||||||
? SELECTION_ELIGIBILITY_FIXED
|
? SELECTION_ELIGIBILITY_FIXED
|
||||||
: SELECTION_ELIGIBILITY_NO;
|
: SELECTION_ELIGIBILITY_NO;
|
||||||
pixelCount = format.getPixelCount();
|
pixelCount = format.getPixelCount();
|
||||||
@ -4171,7 +4161,7 @@ public class DefaultTrackSelector extends MappingTrackSelector
|
|||||||
public OtherTrackScore(Format format, @Capabilities int trackFormatSupport) {
|
public OtherTrackScore(Format format, @Capabilities int trackFormatSupport) {
|
||||||
isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
|
isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
|
||||||
isWithinRendererCapabilities =
|
isWithinRendererCapabilities =
|
||||||
isSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
|
isFormatSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user