Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ojw28 committed Sep 20, 2018
1 parent 1e3c2a6 commit 7d90396
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ public static final class ParametersBuilder {
private boolean allowNonSeamlessAdaptiveness;
private int maxVideoWidth;
private int maxVideoHeight;
private int maxVideoFrameRate;
private int maxVideoBitrate;
private boolean exceedVideoConstraintsIfNecessary;
private boolean exceedRendererCapabilitiesIfNecessary;
private int viewportWidth;
private int viewportHeight;
private boolean viewportOrientationMayChange;
private int tunnelingAudioSessionId;
private int maxFrameRate;

/** Creates a builder with default initial values. */
public ParametersBuilder() {
Expand All @@ -205,14 +205,14 @@ private ParametersBuilder(Parameters initialValues) {
allowNonSeamlessAdaptiveness = initialValues.allowNonSeamlessAdaptiveness;
maxVideoWidth = initialValues.maxVideoWidth;
maxVideoHeight = initialValues.maxVideoHeight;
maxVideoFrameRate = initialValues.maxVideoFrameRate;
maxVideoBitrate = initialValues.maxVideoBitrate;
exceedVideoConstraintsIfNecessary = initialValues.exceedVideoConstraintsIfNecessary;
exceedRendererCapabilitiesIfNecessary = initialValues.exceedRendererCapabilitiesIfNecessary;
viewportWidth = initialValues.viewportWidth;
viewportHeight = initialValues.viewportHeight;
viewportOrientationMayChange = initialValues.viewportOrientationMayChange;
tunnelingAudioSessionId = initialValues.tunnelingAudioSessionId;
maxFrameRate = initialValues.maxFrameRate;
}

/**
Expand Down Expand Up @@ -326,6 +326,16 @@ public ParametersBuilder setMaxVideoSize(int maxVideoWidth, int maxVideoHeight)
return this;
}

/**
* See {@link Parameters#maxVideoFrameRate}.
*
* @return This builder.
*/
public ParametersBuilder setMaxVideoFrameRate(int maxVideoFrameRate) {
this.maxVideoFrameRate = maxVideoFrameRate;
return this;
}

/**
* See {@link Parameters#maxVideoBitrate}.
*
Expand Down Expand Up @@ -523,16 +533,6 @@ public ParametersBuilder setTunnelingAudioSessionId(int tunnelingAudioSessionId)
return this;
}

/**
* See {@link Parameters#maxFrameRate}.
*
* @return This builder.
*/
public ParametersBuilder setMaxFrameRate(int maxFrameRate) {
this.maxFrameRate = maxFrameRate;
return this;
}

/**
* Builds a {@link Parameters} instance with the selected values.
*/
Expand All @@ -550,14 +550,14 @@ public Parameters build() {
allowNonSeamlessAdaptiveness,
maxVideoWidth,
maxVideoHeight,
maxVideoFrameRate,
maxVideoBitrate,
exceedVideoConstraintsIfNecessary,
exceedRendererCapabilitiesIfNecessary,
viewportWidth,
viewportHeight,
viewportOrientationMayChange,
tunnelingAudioSessionId,
maxFrameRate);
tunnelingAudioSessionId);
}

private static SparseArray<Map<TrackGroupArray, SelectionOverride>> cloneSelectionOverrides(
Expand Down Expand Up @@ -626,6 +626,11 @@ public static final class Parameters implements Parcelable {
* #viewportHeight} and {@link #viewportOrientationMayChange}) instead.
*/
public final int maxVideoHeight;
/**
* Maximum allowed video frame rate. The default value is {@link Integer#MAX_VALUE} (i.e. no
* constraint).
*/
public final int maxVideoFrameRate;
/**
* Maximum video bitrate. The default value is {@link Integer#MAX_VALUE} (i.e. no constraint).
*/
Expand Down Expand Up @@ -654,10 +659,6 @@ public static final class Parameters implements Parcelable {
* The default value is {@code true}.
*/
public final boolean viewportOrientationMayChange;
/**
* Maximum video frame rate. The default value is {@link Integer#MAX_VALUE} (i.e. no constraint).
*/
public final int maxFrameRate;

// General
/**
Expand Down Expand Up @@ -711,14 +712,14 @@ private Parameters() {
/* allowNonSeamlessAdaptiveness= */ true,
/* maxVideoWidth= */ Integer.MAX_VALUE,
/* maxVideoHeight= */ Integer.MAX_VALUE,
/* maxVideoFrameRate= */ Integer.MAX_VALUE,
/* maxVideoBitrate= */ Integer.MAX_VALUE,
/* exceedVideoConstraintsIfNecessary= */ true,
/* exceedRendererCapabilitiesIfNecessary= */ true,
/* viewportWidth= */ Integer.MAX_VALUE,
/* viewportHeight= */ Integer.MAX_VALUE,
/* viewportOrientationMayChange= */ true,
/* tunnelingAudioSessionId= */ C.AUDIO_SESSION_ID_UNSET,
/* maxFrameRate= */ Integer.MAX_VALUE);
/* tunnelingAudioSessionId= */ C.AUDIO_SESSION_ID_UNSET);
}

/* package */ Parameters(
Expand All @@ -734,14 +735,14 @@ private Parameters() {
boolean allowNonSeamlessAdaptiveness,
int maxVideoWidth,
int maxVideoHeight,
int maxVideoFrameRate,
int maxVideoBitrate,
boolean exceedVideoConstraintsIfNecessary,
boolean exceedRendererCapabilitiesIfNecessary,
int viewportWidth,
int viewportHeight,
boolean viewportOrientationMayChange,
int tunnelingAudioSessionId,
int maxFrameRate) {
int tunnelingAudioSessionId) {
this.selectionOverrides = selectionOverrides;
this.rendererDisabledFlags = rendererDisabledFlags;
this.preferredAudioLanguage = Util.normalizeLanguageCode(preferredAudioLanguage);
Expand All @@ -754,14 +755,14 @@ private Parameters() {
this.allowNonSeamlessAdaptiveness = allowNonSeamlessAdaptiveness;
this.maxVideoWidth = maxVideoWidth;
this.maxVideoHeight = maxVideoHeight;
this.maxVideoFrameRate = maxVideoFrameRate;
this.maxVideoBitrate = maxVideoBitrate;
this.exceedVideoConstraintsIfNecessary = exceedVideoConstraintsIfNecessary;
this.exceedRendererCapabilitiesIfNecessary = exceedRendererCapabilitiesIfNecessary;
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
this.viewportOrientationMayChange = viewportOrientationMayChange;
this.tunnelingAudioSessionId = tunnelingAudioSessionId;
this.maxFrameRate = maxFrameRate;
}

/* package */ Parameters(Parcel in) {
Expand All @@ -777,14 +778,14 @@ private Parameters() {
this.allowNonSeamlessAdaptiveness = Util.readBoolean(in);
this.maxVideoWidth = in.readInt();
this.maxVideoHeight = in.readInt();
this.maxVideoFrameRate = in.readInt();
this.maxVideoBitrate = in.readInt();
this.exceedVideoConstraintsIfNecessary = Util.readBoolean(in);
this.exceedRendererCapabilitiesIfNecessary = Util.readBoolean(in);
this.viewportWidth = in.readInt();
this.viewportHeight = in.readInt();
this.viewportOrientationMayChange = Util.readBoolean(in);
this.tunnelingAudioSessionId = in.readInt();
this.maxFrameRate = in.readInt();
}

/**
Expand Down Expand Up @@ -846,14 +847,14 @@ public boolean equals(@Nullable Object obj) {
&& allowNonSeamlessAdaptiveness == other.allowNonSeamlessAdaptiveness
&& maxVideoWidth == other.maxVideoWidth
&& maxVideoHeight == other.maxVideoHeight
&& maxVideoFrameRate == other.maxVideoFrameRate
&& exceedVideoConstraintsIfNecessary == other.exceedVideoConstraintsIfNecessary
&& exceedRendererCapabilitiesIfNecessary == other.exceedRendererCapabilitiesIfNecessary
&& viewportOrientationMayChange == other.viewportOrientationMayChange
&& viewportWidth == other.viewportWidth
&& viewportHeight == other.viewportHeight
&& maxVideoBitrate == other.maxVideoBitrate
&& tunnelingAudioSessionId == other.tunnelingAudioSessionId
&& maxFrameRate == other.maxFrameRate
&& TextUtils.equals(preferredAudioLanguage, other.preferredAudioLanguage)
&& TextUtils.equals(preferredTextLanguage, other.preferredTextLanguage)
&& areRendererDisabledFlagsEqual(rendererDisabledFlags, other.rendererDisabledFlags)
Expand All @@ -870,14 +871,14 @@ public int hashCode() {
result = 31 * result + (allowNonSeamlessAdaptiveness ? 1 : 0);
result = 31 * result + maxVideoWidth;
result = 31 * result + maxVideoHeight;
result = 31 * result + maxVideoFrameRate;
result = 31 * result + (exceedVideoConstraintsIfNecessary ? 1 : 0);
result = 31 * result + (exceedRendererCapabilitiesIfNecessary ? 1 : 0);
result = 31 * result + (viewportOrientationMayChange ? 1 : 0);
result = 31 * result + viewportWidth;
result = 31 * result + viewportHeight;
result = 31 * result + maxVideoBitrate;
result = 31 * result + tunnelingAudioSessionId;
result = 31 * result + maxFrameRate;
result =
31 * result + (preferredAudioLanguage == null ? 0 : preferredAudioLanguage.hashCode());
result = 31 * result + (preferredTextLanguage == null ? 0 : preferredTextLanguage.hashCode());
Expand Down Expand Up @@ -905,14 +906,14 @@ public void writeToParcel(Parcel dest, int flags) {
Util.writeBoolean(dest, allowNonSeamlessAdaptiveness);
dest.writeInt(maxVideoWidth);
dest.writeInt(maxVideoHeight);
dest.writeInt(maxVideoFrameRate);
dest.writeInt(maxVideoBitrate);
Util.writeBoolean(dest, exceedVideoConstraintsIfNecessary);
Util.writeBoolean(dest, exceedRendererCapabilitiesIfNecessary);
dest.writeInt(viewportWidth);
dest.writeInt(viewportHeight);
Util.writeBoolean(dest, viewportOrientationMayChange);
dest.writeInt(tunnelingAudioSessionId);
dest.writeInt(maxFrameRate);
}

public static final Parcelable.Creator<Parameters> CREATOR =
Expand Down Expand Up @@ -1457,10 +1458,19 @@ public void setTunnelingAudioSessionId(int tunnelingAudioSessionId) {
&& (mixedMimeTypeAdaptationSupports & requiredAdaptiveSupport) != 0;
for (int i = 0; i < groups.length; i++) {
TrackGroup group = groups.get(i);
int[] adaptiveTracks = getAdaptiveVideoTracksForGroup(group, formatSupport[i],
allowMixedMimeTypes, requiredAdaptiveSupport, params.maxVideoWidth, params.maxVideoHeight,
params.maxVideoBitrate, params.maxFrameRate, params.viewportWidth, params.viewportHeight,
params.viewportOrientationMayChange);
int[] adaptiveTracks =
getAdaptiveVideoTracksForGroup(
group,
formatSupport[i],
allowMixedMimeTypes,
requiredAdaptiveSupport,
params.maxVideoWidth,
params.maxVideoHeight,
params.maxVideoFrameRate,
params.maxVideoBitrate,
params.viewportWidth,
params.viewportHeight,
params.viewportOrientationMayChange);
if (adaptiveTracks.length > 0) {
return Assertions.checkNotNull(adaptiveTrackSelectionFactory)
.createTrackSelection(group, bandwidthMeter, adaptiveTracks);
Expand All @@ -1469,10 +1479,18 @@ public void setTunnelingAudioSessionId(int tunnelingAudioSessionId) {
return null;
}

private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] formatSupport,
boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
int maxVideoHeight, int maxVideoBitrate, int maxFrameRate, int viewportWidth,
int viewportHeight, boolean viewportOrientationMayChange) {
private static int[] getAdaptiveVideoTracksForGroup(
TrackGroup group,
int[] formatSupport,
boolean allowMixedMimeTypes,
int requiredAdaptiveSupport,
int maxVideoWidth,
int maxVideoHeight,
int maxVideoFrameRate,
int maxVideoBitrate,
int viewportWidth,
int viewportHeight,
boolean viewportOrientationMayChange) {
if (group.length < 2) {
return NO_TRACKS;
}
Expand All @@ -1492,9 +1510,17 @@ private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] form
int trackIndex = selectedTrackIndices.get(i);
String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
if (seenMimeTypes.add(sampleMimeType)) {
int countForMimeType = getAdaptiveVideoTrackCountForMimeType(group, formatSupport,
requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
maxVideoBitrate, maxFrameRate, selectedTrackIndices);
int countForMimeType =
getAdaptiveVideoTrackCountForMimeType(
group,
formatSupport,
requiredAdaptiveSupport,
sampleMimeType,
maxVideoWidth,
maxVideoHeight,
maxVideoFrameRate,
maxVideoBitrate,
selectedTrackIndices);
if (countForMimeType > selectedMimeTypeTrackCount) {
selectedMimeType = sampleMimeType;
selectedMimeTypeTrackCount = countForMimeType;
Expand All @@ -1504,8 +1530,15 @@ private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] form
}

// Filter by the selected mime type.
filterAdaptiveVideoTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
selectedMimeType, maxVideoWidth, maxVideoHeight, maxVideoBitrate, maxFrameRate,
filterAdaptiveVideoTrackCountForMimeType(
group,
formatSupport,
requiredAdaptiveSupport,
selectedMimeType,
maxVideoWidth,
maxVideoHeight,
maxVideoFrameRate,
maxVideoBitrate,
selectedTrackIndices);

return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
Expand All @@ -1518,15 +1551,21 @@ private static int getAdaptiveVideoTrackCountForMimeType(
@Nullable String mimeType,
int maxVideoWidth,
int maxVideoHeight,
int maxVideoFrameRate,
int maxVideoBitrate,
int maxFrameRate,
List<Integer> selectedTrackIndices) {
int adaptiveTrackCount = 0;
for (int i = 0; i < selectedTrackIndices.size(); i++) {
int trackIndex = selectedTrackIndices.get(i);
if (isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
maxVideoBitrate, maxFrameRate)) {
if (isSupportedAdaptiveVideoTrack(
group.getFormat(trackIndex),
mimeType,
formatSupport[trackIndex],
requiredAdaptiveSupport,
maxVideoWidth,
maxVideoHeight,
maxVideoFrameRate,
maxVideoBitrate)) {
adaptiveTrackCount++;
}
}
Expand All @@ -1540,14 +1579,20 @@ private static void filterAdaptiveVideoTrackCountForMimeType(
@Nullable String mimeType,
int maxVideoWidth,
int maxVideoHeight,
int maxVideoFrameRate,
int maxVideoBitrate,
int maxFrameRate,
List<Integer> selectedTrackIndices) {
for (int i = selectedTrackIndices.size() - 1; i >= 0; i--) {
int trackIndex = selectedTrackIndices.get(i);
if (!isSupportedAdaptiveVideoTrack(group.getFormat(trackIndex), mimeType,
formatSupport[trackIndex], requiredAdaptiveSupport, maxVideoWidth, maxVideoHeight,
maxVideoBitrate, maxFrameRate)) {
if (!isSupportedAdaptiveVideoTrack(
group.getFormat(trackIndex),
mimeType,
formatSupport[trackIndex],
requiredAdaptiveSupport,
maxVideoWidth,
maxVideoHeight,
maxVideoFrameRate,
maxVideoBitrate)) {
selectedTrackIndices.remove(i);
}
}
Expand All @@ -1560,14 +1605,15 @@ private static boolean isSupportedAdaptiveVideoTrack(
int requiredAdaptiveSupport,
int maxVideoWidth,
int maxVideoHeight,
int maxVideoBitrate,
int maxFrameRate) {
return isSupported(formatSupport, false) && ((formatSupport & requiredAdaptiveSupport) != 0)
int maxVideoFrameRate,
int maxVideoBitrate) {
return isSupported(formatSupport, false)
&& ((formatSupport & requiredAdaptiveSupport) != 0)
&& (mimeType == null || Util.areEqual(format.sampleMimeType, mimeType))
&& (format.width == Format.NO_VALUE || format.width <= maxVideoWidth)
&& (format.height == Format.NO_VALUE || format.height <= maxVideoHeight)
&& (format.bitrate == Format.NO_VALUE || format.bitrate <= maxVideoBitrate)
&& (format.frameRate == Format.NO_VALUE || format.frameRate <= maxFrameRate);
&& (format.frameRate == Format.NO_VALUE || format.frameRate <= maxVideoFrameRate)
&& (format.bitrate == Format.NO_VALUE || format.bitrate <= maxVideoBitrate);
}

private static @Nullable TrackSelection selectFixedVideoTrack(
Expand All @@ -1586,11 +1632,14 @@ private static boolean isSupportedAdaptiveVideoTrack(
if (isSupported(trackFormatSupport[trackIndex],
params.exceedRendererCapabilitiesIfNecessary)) {
Format format = trackGroup.getFormat(trackIndex);
boolean isWithinConstraints = selectedTrackIndices.contains(trackIndex)
&& (format.width == Format.NO_VALUE || format.width <= params.maxVideoWidth)
&& (format.height == Format.NO_VALUE || format.height <= params.maxVideoHeight)
&& (format.bitrate == Format.NO_VALUE || format.bitrate <= params.maxVideoBitrate)
&& (format.frameRate == Format.NO_VALUE || format.frameRate <= params.maxFrameRate);
boolean isWithinConstraints =
selectedTrackIndices.contains(trackIndex)
&& (format.width == Format.NO_VALUE || format.width <= params.maxVideoWidth)
&& (format.height == Format.NO_VALUE || format.height <= params.maxVideoHeight)
&& (format.frameRate == Format.NO_VALUE
|| format.frameRate <= params.maxVideoFrameRate)
&& (format.bitrate == Format.NO_VALUE
|| format.bitrate <= params.maxVideoBitrate);
if (!isWithinConstraints && !params.exceedVideoConstraintsIfNecessary) {
// Track should not be selected.
continue;
Expand Down
Loading

0 comments on commit 7d90396

Please sign in to comment.