package androidx.media3.exoplayer.trackselection; import android.os.SystemClock; import androidx.media3.common.TrackGroup; import androidx.media3.common.Tracks; import androidx.media3.exoplayer.source.TrackGroupArray; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; import androidx.media3.exoplayer.trackselection.ExoTrackSelection; import androidx.media3.exoplayer.trackselection.MappingTrackSelector; import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy; import com.google.common.collect.ImmutableList; import java.util.Arrays; import java.util.List; /* loaded from: classes2.dex */ public final class TrackSelectionUtil { /* loaded from: classes2.dex */ public interface AdaptiveTrackSelectionFactory { ExoTrackSelection createAdaptiveTrackSelection(ExoTrackSelection.Definition definition); } private TrackSelectionUtil() { } public static ExoTrackSelection[] createTrackSelectionsForDefinitions(ExoTrackSelection.Definition[] definitionArr, AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory) { ExoTrackSelection[] exoTrackSelectionArr = new ExoTrackSelection[definitionArr.length]; boolean z = false; for (int i = 0; i < definitionArr.length; i++) { ExoTrackSelection.Definition definition = definitionArr[i]; if (definition != null) { if (definition.tracks.length > 1 && !z) { exoTrackSelectionArr[i] = adaptiveTrackSelectionFactory.createAdaptiveTrackSelection(definition); z = true; } else { exoTrackSelectionArr[i] = new FixedTrackSelection(definition.group, definition.tracks[0], definition.type); } } } return exoTrackSelectionArr; } public static DefaultTrackSelector.Parameters updateParametersWithOverride(DefaultTrackSelector.Parameters parameters, int i, TrackGroupArray trackGroupArray, boolean z, DefaultTrackSelector.SelectionOverride selectionOverride) { DefaultTrackSelector.Parameters.Builder rendererDisabled = parameters.buildUpon().clearSelectionOverrides(i).setRendererDisabled(i, z); if (selectionOverride != null) { rendererDisabled.setSelectionOverride(i, trackGroupArray, selectionOverride); } return rendererDisabled.build(); } public static LoadErrorHandlingPolicy.FallbackOptions createFallbackOptions(ExoTrackSelection exoTrackSelection) { long elapsedRealtime = SystemClock.elapsedRealtime(); int length = exoTrackSelection.length(); int i = 0; for (int i2 = 0; i2 < length; i2++) { if (exoTrackSelection.isTrackExcluded(i2, elapsedRealtime)) { i++; } } return new LoadErrorHandlingPolicy.FallbackOptions(1, 0, length, i); } public static Tracks buildTracks(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, TrackSelection[] trackSelectionArr) { List[] listArr = new List[trackSelectionArr.length]; for (int i = 0; i < trackSelectionArr.length; i++) { TrackSelection trackSelection = trackSelectionArr[i]; listArr[i] = trackSelection != null ? ImmutableList.of(trackSelection) : ImmutableList.of(); } return buildTracks(mappedTrackInfo, (List[]) listArr); } public static Tracks buildTracks(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, List[] listArr) { boolean z; ImmutableList.Builder builder = new ImmutableList.Builder(); for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) { TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i); List list = listArr[i]; for (int i2 = 0; i2 < trackGroups.length; i2++) { TrackGroup trackGroup = trackGroups.get(i2); boolean z2 = mappedTrackInfo.getAdaptiveSupport(i, i2, false) != 0; int[] iArr = new int[trackGroup.length]; boolean[] zArr = new boolean[trackGroup.length]; for (int i3 = 0; i3 < trackGroup.length; i3++) { iArr[i3] = mappedTrackInfo.getTrackSupport(i, i2, i3); int i4 = 0; while (true) { if (i4 >= list.size()) { z = false; break; } TrackSelection trackSelection = list.get(i4); if (trackSelection.getTrackGroup().equals(trackGroup) && trackSelection.indexOf(i3) != -1) { z = true; break; } i4++; } zArr[i3] = z; } builder.add((ImmutableList.Builder) new Tracks.Group(trackGroup, z2, iArr, zArr)); } } TrackGroupArray unmappedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups(); for (int i5 = 0; i5 < unmappedTrackGroups.length; i5++) { TrackGroup trackGroup2 = unmappedTrackGroups.get(i5); int[] iArr2 = new int[trackGroup2.length]; Arrays.fill(iArr2, 0); builder.add((ImmutableList.Builder) new Tracks.Group(trackGroup2, false, iArr2, new boolean[trackGroup2.length])); } return new Tracks(builder.build()); } }