From 759cb3231545f3bc4cceae43ed77fdf007b28c5f Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 12 Dec 2016 06:13:07 -0800 Subject: [PATCH] Try exceeding renderer capabilities by default Not sure what I think about this, but we're getting quite a lot of issues reported where streams play fine but capabilities indicate they wont. It's probably best just to cross our fingers and hope for the best in such cases, as was the case in V1 when using ExtractorSampleSource. Issue: #2157 Issue: #2034 Issue: #2007 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=141758070 --- .../exoplayer2/demo/PlayerActivity.java | 6 +- .../trackselection/DefaultTrackSelector.java | 4 +- .../trackselection/MappingTrackSelector.java | 77 +++++++++++-------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index 267c54cc05..243fcadce0 100644 --- a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -469,10 +469,12 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay updateButtonVisibilities(); MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); if (mappedTrackInfo != null) { - if (mappedTrackInfo.hasOnlyUnplayableTracks(C.TRACK_TYPE_VIDEO)) { + if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO) + == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_video); } - if (mappedTrackInfo.hasOnlyUnplayableTracks(C.TRACK_TYPE_AUDIO)) { + if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO) + == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_audio); } } diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java index bf139c85a8..79979401f7 100644 --- a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java +++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java @@ -69,12 +69,12 @@ public class DefaultTrackSelector extends MappingTrackSelector { *
  • Non seamless adaptation is allowed.
  • *
  • No max limit for video width/height.
  • *
  • Video constraints are exceeded if no supported selection can be made otherwise.
  • - *
  • Renderer capabilities are not exceeded even if no supported selection can be made.
  • + *
  • Renderer capabilities are exceeded if no supported selection can be made.
  • *
  • No viewport width/height constraints are set.
  • * */ public Parameters() { - this(null, null, false, true, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false, + this(null, null, false, true, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true, Integer.MAX_VALUE, Integer.MAX_VALUE, true); } diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java index 7454ff6801..77df9a2173 100644 --- a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java +++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.trackselection; import android.util.Pair; import android.util.SparseArray; import android.util.SparseBooleanArray; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.source.TrackGroup; @@ -138,8 +139,6 @@ public abstract class MappingTrackSelector extends TrackSelector { * @param groups The {@link TrackGroupArray} for which the override should be applied. * @param override The override. */ - // TODO - Don't allow overrides that select unsupported tracks, unless some flag has been - // explicitly set by the user to indicate that they want this. public final void setSelectionOverride(int rendererIndex, TrackGroupArray groups, SelectionOverride override) { Map overrides = selectionOverrides.get(rendererIndex); @@ -411,13 +410,18 @@ public abstract class MappingTrackSelector extends TrackSelector { */ public static final int RENDERER_SUPPORT_NO_TRACKS = 0; /** - * The renderer has associated tracks, but cannot play any of them. + * The renderer has associated tracks, but all are of unsupported types. */ - public static final int RENDERER_SUPPORT_UNPLAYABLE_TRACKS = 1; + public static final int RENDERER_SUPPORT_UNSUPPORTED_TRACKS = 1; /** - * The renderer has associated tracks, and can play at least one of them. + * The renderer has associated tracks and at least one is of a supported type, but all of the + * tracks whose types are supported exceed the renderer's capabilities. */ - public static final int RENDERER_SUPPORT_PLAYABLE_TRACKS = 2; + public static final int RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS = 2; + /** + * The renderer has associated tracks and can play at least one of them. + */ + public static final int RENDERER_SUPPORT_PLAYABLE_TRACKS = 3; /** * The number of renderers to which tracks are mapped. @@ -465,21 +469,49 @@ public abstract class MappingTrackSelector extends TrackSelector { * * @param rendererIndex The renderer index. * @return One of {@link #RENDERER_SUPPORT_PLAYABLE_TRACKS}, - * {@link #RENDERER_SUPPORT_UNPLAYABLE_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}. + * {@link #RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS}, + * {@link #RENDERER_SUPPORT_UNSUPPORTED_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}. */ public int getRendererSupport(int rendererIndex) { - boolean hasTracks = false; + int bestRendererSupport = RENDERER_SUPPORT_NO_TRACKS; int[][] rendererFormatSupport = formatSupport[rendererIndex]; for (int i = 0; i < rendererFormatSupport.length; i++) { for (int j = 0; j < rendererFormatSupport[i].length; j++) { - hasTracks = true; - if ((rendererFormatSupport[i][j] & RendererCapabilities.FORMAT_SUPPORT_MASK) - == RendererCapabilities.FORMAT_HANDLED) { - return RENDERER_SUPPORT_PLAYABLE_TRACKS; + int trackRendererSupport; + switch (rendererFormatSupport[i][j] & RendererCapabilities.FORMAT_SUPPORT_MASK) { + case RendererCapabilities.FORMAT_HANDLED: + return RENDERER_SUPPORT_PLAYABLE_TRACKS; + case RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES: + trackRendererSupport = RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS; + break; + default: + trackRendererSupport = RENDERER_SUPPORT_UNSUPPORTED_TRACKS; + break; } + bestRendererSupport = Math.max(bestRendererSupport, trackRendererSupport); } } - return hasTracks ? RENDERER_SUPPORT_UNPLAYABLE_TRACKS : RENDERER_SUPPORT_NO_TRACKS; + return bestRendererSupport; + } + + /** + * Returns the best level of support obtained from {@link #getRendererSupport(int)} for all + * renderers of the specified track type. If no renderers exist for the specified type then + * {@link #RENDERER_SUPPORT_NO_TRACKS} is returned. + * + * @param trackType The track type. One of the {@link C} {@code TRACK_TYPE_*} constants. + * @return One of {@link #RENDERER_SUPPORT_PLAYABLE_TRACKS}, + * {@link #RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS}, + * {@link #RENDERER_SUPPORT_UNSUPPORTED_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}. + */ + public int getTrackTypeRendererSupport(int trackType) { + int bestRendererSupport = RENDERER_SUPPORT_NO_TRACKS; + for (int i = 0; i < length; i++) { + if (rendererTrackTypes[i] == trackType) { + bestRendererSupport = Math.max(bestRendererSupport, getRendererSupport(i)); + } + } + return bestRendererSupport; } /** @@ -576,25 +608,6 @@ public abstract class MappingTrackSelector extends TrackSelector { return unassociatedTrackGroups; } - /** - * Returns true if tracks of the specified type exist and have been associated with renderers, - * but are all unplayable. Returns false in all other cases. - * - * @param trackType The track type. - * @return True if tracks of the specified type exist, if at least one renderer exists that - * handles tracks of the specified type, and if all of the tracks if the specified type are - * unplayable. False in all other cases. - */ - public boolean hasOnlyUnplayableTracks(int trackType) { - int rendererSupport = RENDERER_SUPPORT_NO_TRACKS; - for (int i = 0; i < length; i++) { - if (rendererTrackTypes[i] == trackType) { - rendererSupport = Math.max(rendererSupport, getRendererSupport(i)); - } - } - return rendererSupport == RENDERER_SUPPORT_UNPLAYABLE_TRACKS; - } - } }