Commit 3c6ca19c by tonihei Committed by Oliver Woodman

Fix track selection nullability issues.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199266768
parent 6a82f99c
......@@ -54,6 +54,7 @@ android {
dependencies {
implementation 'com.android.support:support-annotations:' + supportLibraryVersion
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
androidTestImplementation 'com.google.dexmaker:dexmaker:' + dexmakerVersion
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:' + dexmakerVersion
androidTestImplementation 'com.google.truth:truth:' + truthVersion
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.trackselection;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup;
......@@ -242,9 +243,11 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
this.minTimeBetweenBufferReevaluationMs = minTimeBetweenBufferReevaluationMs;
this.clock = clock;
playbackSpeed = 1f;
selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
reason = C.SELECTION_REASON_INITIAL;
lastBufferEvaluationMs = C.TIME_UNSET;
@SuppressWarnings("nullness:method.invocation.invalid")
int selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
this.selectedIndex = selectedIndex;
}
@Override
......@@ -301,7 +304,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
}
@Override
public Object getSelectionData() {
public @Nullable Object getSelectionData() {
return null;
}
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.trackselection;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.util.Assertions;
......@@ -30,7 +31,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
public static final class Factory implements TrackSelection.Factory {
private final int reason;
private final Object data;
private final @Nullable Object data;
public Factory() {
this.reason = C.SELECTION_REASON_UNKNOWN;
......@@ -41,7 +42,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
* @param reason A reason for the track selection.
* @param data Optional data associated with the track selection.
*/
public Factory(int reason, Object data) {
public Factory(int reason, @Nullable Object data) {
this.reason = reason;
this.data = data;
}
......@@ -51,11 +52,10 @@ public final class FixedTrackSelection extends BaseTrackSelection {
Assertions.checkArgument(tracks.length == 1);
return new FixedTrackSelection(group, tracks[0], reason, data);
}
}
private final int reason;
private final Object data;
private final @Nullable Object data;
/**
* @param group The {@link TrackGroup}. Must not be null.
......@@ -71,7 +71,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
* @param reason A reason for the track selection.
* @param data Optional data associated with the track selection.
*/
public FixedTrackSelection(TrackGroup group, int track, int reason, Object data) {
public FixedTrackSelection(TrackGroup group, int track, int reason, @Nullable Object data) {
super(group, track);
this.reason = reason;
this.data = data;
......@@ -94,7 +94,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
}
@Override
public Object getSelectionData() {
public @Nullable Object getSelectionData() {
return data;
}
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.trackselection;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
......@@ -28,6 +29,7 @@ import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
* Base class for {@link TrackSelector}s that first establish a mapping between {@link TrackGroup}s
......@@ -301,13 +303,13 @@ public abstract class MappingTrackSelector extends TrackSelector {
}
private MappedTrackInfo currentMappedTrackInfo;
private @Nullable MappedTrackInfo currentMappedTrackInfo;
/**
* Returns the mapping information for the currently active track selection, or null if no
* selection is currently active.
*/
public final MappedTrackInfo getCurrentMappedTrackInfo() {
public final @Nullable MappedTrackInfo getCurrentMappedTrackInfo() {
return currentMappedTrackInfo;
}
......@@ -357,9 +359,11 @@ public abstract class MappingTrackSelector extends TrackSelector {
int[] rendererTrackTypes = new int[rendererCapabilities.length];
for (int i = 0; i < rendererCapabilities.length; i++) {
int rendererTrackGroupCount = rendererTrackGroupCounts[i];
rendererTrackGroupArrays[i] = new TrackGroupArray(
Arrays.copyOf(rendererTrackGroups[i], rendererTrackGroupCount));
rendererFormatSupports[i] = Arrays.copyOf(rendererFormatSupports[i], rendererTrackGroupCount);
rendererTrackGroupArrays[i] =
new TrackGroupArray(
Util.nullSafeArrayCopy(rendererTrackGroups[i], rendererTrackGroupCount));
rendererFormatSupports[i] =
Util.nullSafeArrayCopy(rendererFormatSupports[i], rendererTrackGroupCount);
rendererTrackTypes[i] = rendererCapabilities[i].getTrackType();
}
......@@ -367,7 +371,7 @@ public abstract class MappingTrackSelector extends TrackSelector {
int unmappedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
TrackGroupArray unmappedTrackGroupArray =
new TrackGroupArray(
Arrays.copyOf(
Util.nullSafeArrayCopy(
rendererTrackGroups[rendererCapabilities.length], unmappedTrackGroupCount));
// Package up the track information and selections.
......@@ -379,7 +383,7 @@ public abstract class MappingTrackSelector extends TrackSelector {
rendererFormatSupports,
unmappedTrackGroupArray);
Pair<RendererConfiguration[], TrackSelection[]> result =
Pair<@NullableType RendererConfiguration[], @NullableType TrackSelection[]> result =
selectTracks(
mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports);
return new TrackSelectorResult(result.first, result.second, mappedTrackInfo);
......@@ -399,11 +403,12 @@ public abstract class MappingTrackSelector extends TrackSelector {
* RendererCapabilities#getTrackType()} is {@link C#TRACK_TYPE_NONE}.
* @throws ExoPlaybackException If an error occurs while selecting the tracks.
*/
protected abstract Pair<RendererConfiguration[], TrackSelection[]> selectTracks(
MappedTrackInfo mappedTrackInfo,
int[][][] rendererFormatSupports,
int[] rendererMixedMimeTypeAdaptationSupport)
throws ExoPlaybackException;
protected abstract Pair<@NullableType RendererConfiguration[], @NullableType TrackSelection[]>
selectTracks(
MappedTrackInfo mappedTrackInfo,
int[][][] rendererFormatSupports,
int[] rendererMixedMimeTypeAdaptationSupport)
throws ExoPlaybackException;
/**
* Finds the renderer to which the provided {@link TrackGroup} should be mapped.
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.trackselection;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.TrackGroup;
import java.util.Random;
......@@ -47,7 +48,6 @@ public final class RandomTrackSelection extends BaseTrackSelection {
public RandomTrackSelection createTrackSelection(TrackGroup group, int... tracks) {
return new RandomTrackSelection(group, tracks, random);
}
}
private final Random random;
......@@ -123,7 +123,7 @@ public final class RandomTrackSelection extends BaseTrackSelection {
}
@Override
public Object getSelectionData() {
public @Nullable Object getSelectionData() {
return null;
}
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.trackselection;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup;
......@@ -129,10 +130,8 @@ public interface TrackSelection {
*/
int getSelectionReason();
/**
* Returns optional data associated with the current track selection.
*/
Object getSelectionData();
/** Returns optional data associated with the current track selection. */
@Nullable Object getSelectionData();
// Adaptation.
......
......@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.trackselection;
import android.support.annotation.Nullable;
import java.util.Arrays;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/** An array of {@link TrackSelection}s. */
public final class TrackSelectionArray {
......@@ -24,15 +25,13 @@ public final class TrackSelectionArray {
/** The length of this array. */
public final int length;
private final TrackSelection[] trackSelections;
private final @NullableType TrackSelection[] trackSelections;
// Lazily initialized hashcode.
private int hashCode;
/**
* @param trackSelections The selections. Must not be null, but may contain null elements.
*/
public TrackSelectionArray(TrackSelection... trackSelections) {
/** @param trackSelections The selections. Must not be null, but may contain null elements. */
public TrackSelectionArray(@NullableType TrackSelection... trackSelections) {
this.trackSelections = trackSelections;
this.length = trackSelections.length;
}
......@@ -43,14 +42,12 @@ public final class TrackSelectionArray {
* @param index The index of the selection.
* @return The selection.
*/
public TrackSelection get(int index) {
public @Nullable TrackSelection get(int index) {
return trackSelections[index];
}
/**
* Returns the selections in a newly allocated array.
*/
public TrackSelection[] getAll() {
/** Returns the selections in a newly allocated array. */
public @NullableType TrackSelection[] getAll() {
return trackSelections.clone();
}
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.trackselection;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Renderer;
......@@ -89,7 +90,7 @@ public abstract class TrackSelector {
}
private InvalidationListener listener;
private @Nullable InvalidationListener listener;
/**
* Called by the player to initialize the selector.
......
......@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.trackselection;
import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.util.Util;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
* The result of a {@link TrackSelector} operation.
......@@ -29,7 +30,7 @@ public final class TrackSelectorResult {
* A {@link RendererConfiguration} for each renderer. A null entry indicates the corresponding
* renderer should be disabled.
*/
public final RendererConfiguration[] rendererConfigurations;
public final @NullableType RendererConfiguration[] rendererConfigurations;
/**
* A {@link TrackSelectionArray} containing the track selection for each renderer.
*/
......@@ -48,7 +49,9 @@ public final class TrackSelectorResult {
* TrackSelector#onSelectionActivated(Object)} should the selection be activated.
*/
public TrackSelectorResult(
RendererConfiguration[] rendererConfigurations, TrackSelection[] selections, Object info) {
@NullableType RendererConfiguration[] rendererConfigurations,
@NullableType TrackSelection[] selections,
Object info) {
this.rendererConfigurations = rendererConfigurations;
this.selections = new TrackSelectionArray(selections);
this.info = info;
......
......@@ -311,10 +311,10 @@ public final class Util {
* Returns a normalized RFC 639-2/T code for {@code language}.
*
* @param language A case-insensitive ISO 639 alpha-2 or alpha-3 language code.
* @return The all-lowercase normalized code, or null if the input was null, or
* {@code language.toLowerCase()} if the language could not be normalized.
* @return The all-lowercase normalized code, or null if the input was null, or {@code
* language.toLowerCase()} if the language could not be normalized.
*/
public static String normalizeLanguageCode(String language) {
public static @Nullable String normalizeLanguageCode(@Nullable String language) {
try {
return language == null ? null : new Locale(language).getISO3Language();
} catch (MissingResourceException e) {
......
......@@ -203,7 +203,9 @@ public class TrackSelectionView extends LinearLayout {
removeViewAt(i);
}
if (trackSelector == null) {
MappingTrackSelector.MappedTrackInfo trackInfo =
trackSelector == null ? null : trackSelector.getCurrentMappedTrackInfo();
if (trackSelector == null || trackInfo == null) {
// The view is not initialized.
disableView.setEnabled(false);
defaultView.setEnabled(false);
......@@ -212,7 +214,6 @@ public class TrackSelectionView extends LinearLayout {
disableView.setEnabled(true);
defaultView.setEnabled(true);
MappingTrackSelector.MappedTrackInfo trackInfo = trackSelector.getCurrentMappedTrackInfo();
trackGroups = trackInfo.getTrackGroups(rendererIndex);
DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
......
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