Java Code Examples for com.google.android.exoplayer2.C#SELECTION_FLAG_DEFAULT

The following examples show how to use com.google.android.exoplayer2.C#SELECTION_FLAG_DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HlsPlaylistParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@C.SelectionFlags
private static int parseSelectionFlags(String line) {
  int flags = 0;
  if (parseOptionalBooleanAttribute(line, REGEX_DEFAULT, false)) {
    flags |= C.SELECTION_FLAG_DEFAULT;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_FORCED, false)) {
    flags |= C.SELECTION_FLAG_FORCED;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_AUTOSELECT, false)) {
    flags |= C.SELECTION_FLAG_AUTOSELECT;
  }
  return flags;
}
 
Example 2
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Parses a Role element.
 *
 * @param xpp The parser from which to read.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return {@link C.SelectionFlags} parsed from the element.
 */
protected int parseRole(XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "Role"));
  return "urn:mpeg:dash:role:2011".equals(schemeIdUri) && "main".equals(value)
      ? C.SELECTION_FLAG_DEFAULT : 0;
}
 
Example 3
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each mapped
 *     track, indexed by track group index and track index (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected TrackSelection.Definition selectOtherTrack(
    int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null
      ? null
      : new TrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
 
Example 4
Source File: DefaultTrackSelector.java    From K-Sonic with MIT License 5 votes vote down vote up
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups,
    int[][] formatSupport, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
Example 5
Source File: DefaultTrackSelector.java    From K-Sonic with MIT License 5 votes vote down vote up
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore;
        if (formatHasLanguage(format, preferredAudioLanguage)) {
          if (isDefault) {
            trackScore = 4;
          } else {
            trackScore = 3;
          }
        } else if (isDefault) {
          trackScore = 2;
        } else {
          trackScore = 1;
        }
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
Example 6
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a Role element.
 *
 * @param xpp The parser from which to read.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return {@link C.SelectionFlags} parsed from the element.
 */
protected int parseRole(XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "Role"));
  return "urn:mpeg:dash:role:2011".equals(schemeIdUri) && "main".equals(value)
      ? C.SELECTION_FLAG_DEFAULT : 0;
}
 
Example 7
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each mapped
 *     track, indexed by track group index and track index (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected TrackSelection.Definition selectOtherTrack(
    int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null
      ? null
      : new TrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
 
Example 8
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public TextTrackScore(
    Format format,
    Parameters parameters,
    int trackFormatSupport,
    @Nullable String selectedAudioLanguage) {
  isWithinRendererCapabilities =
      isSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
  int maskedSelectionFlags =
      format.selectionFlags & ~parameters.disabledTextTrackSelectionFlags;
  isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
  boolean isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
  preferredLanguageScore =
      getFormatLanguageScore(
          format, parameters.preferredTextLanguage, parameters.selectUndeterminedTextLanguage);
  preferredRoleFlagsScore =
      Integer.bitCount(format.roleFlags & parameters.preferredTextRoleFlags);
  hasCaptionRoleFlags =
      (format.roleFlags & (C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND)) != 0;
  // Prefer non-forced to forced if a preferred text language has been matched. Where both are
  // provided the non-forced track will usually contain the forced subtitles as a subset.
  // Otherwise, prefer a forced track.
  hasPreferredIsForcedFlag =
      (preferredLanguageScore > 0 && !isForced) || (preferredLanguageScore == 0 && isForced);
  boolean selectedAudioLanguageUndetermined =
      normalizeUndeterminedLanguageToNull(selectedAudioLanguage) == null;
  selectedAudioLanguageScore =
      getFormatLanguageScore(format, selectedAudioLanguage, selectedAudioLanguageUndetermined);
  isWithinConstraints =
      preferredLanguageScore > 0
          || (parameters.preferredTextLanguage == null && preferredRoleFlagsScore > 0)
          || isDefault
          || (isForced && selectedAudioLanguageScore > 0);
}
 
Example 9
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each mapped
 *     track, indexed by track group index and track index (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
protected @Nullable TrackSelection selectOtherTrack(
    int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
Example 10
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The {@link Capabilities} for each mapped track, indexed by renderer, track
 *     group and track (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected TrackSelection.Definition selectOtherTrack(
    int trackType, TrackGroupArray groups, @Capabilities int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    @Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null
      ? null
      : new TrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
 
Example 11
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a Role element.
 *
 * @param xpp The parser from which to read.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return {@link C.SelectionFlags} parsed from the element.
 */
protected int parseRole(XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "Role"));
  return "urn:mpeg:dash:role:2011".equals(schemeIdUri) && "main".equals(value)
      ? C.SELECTION_FLAG_DEFAULT : 0;
}
 
Example 12
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public AudioTrackScore(Format format, Parameters parameters, int formatSupport) {
  this.parameters = parameters;
  this.language = normalizeUndeterminedLanguageToNull(format.language);
  isWithinRendererCapabilities = isSupported(formatSupport, false);
  preferredLanguageScore =
      getFormatLanguageScore(
          format,
          parameters.preferredAudioLanguage,
          /* allowUndeterminedFormatLanguage= */ false);
  isDefaultSelectionFlag = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
  channelCount = format.channelCount;
  sampleRate = format.sampleRate;
  bitrate = format.bitrate;
  isWithinConstraints =
      (format.bitrate == Format.NO_VALUE || format.bitrate <= parameters.maxAudioBitrate)
          && (format.channelCount == Format.NO_VALUE
              || format.channelCount <= parameters.maxAudioChannelCount);
  String[] localeLanguages = Util.getSystemLanguageCodes();
  int bestMatchIndex = Integer.MAX_VALUE;
  int bestMatchScore = 0;
  for (int i = 0; i < localeLanguages.length; i++) {
    int score =
        getFormatLanguageScore(
            format, localeLanguages[i], /* allowUndeterminedFormatLanguage= */ false);
    if (score > 0) {
      bestMatchIndex = i;
      bestMatchScore = score;
      break;
    }
  }
  localeLanguageMatchIndex = bestMatchIndex;
  localeLanguageScore = bestMatchScore;
}
 
Example 13
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public AudioTrackScore(Format format, Parameters parameters, int formatSupport) {
  this.parameters = parameters;
  withinRendererCapabilitiesScore = isSupported(formatSupport, false) ? 1 : 0;
  matchLanguageScore = formatHasLanguage(format, parameters.preferredAudioLanguage) ? 1 : 0;
  defaultSelectionFlagScore = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0 ? 1 : 0;
  channelCount = format.channelCount;
  sampleRate = format.sampleRate;
  bitrate = format.bitrate;
}
 
Example 14
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public AudioTrackScore(Format format, Parameters parameters, int formatSupport) {
  this.parameters = parameters;
  this.language = normalizeUndeterminedLanguageToNull(format.language);
  isWithinRendererCapabilities = isSupported(formatSupport, false);
  preferredLanguageScore =
      getFormatLanguageScore(
          format,
          parameters.preferredAudioLanguage,
          /* allowUndeterminedFormatLanguage= */ false);
  isDefaultSelectionFlag = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
  channelCount = format.channelCount;
  sampleRate = format.sampleRate;
  bitrate = format.bitrate;
  isWithinConstraints =
      (format.bitrate == Format.NO_VALUE || format.bitrate <= parameters.maxAudioBitrate)
          && (format.channelCount == Format.NO_VALUE
              || format.channelCount <= parameters.maxAudioChannelCount);
  String[] localeLanguages = Util.getSystemLanguageCodes();
  int bestMatchIndex = Integer.MAX_VALUE;
  int bestMatchScore = 0;
  for (int i = 0; i < localeLanguages.length; i++) {
    int score =
        getFormatLanguageScore(
            format, localeLanguages[i], /* allowUndeterminedFormatLanguage= */ false);
    if (score > 0) {
      bestMatchIndex = i;
      bestMatchScore = score;
      break;
    }
  }
  localeLanguageMatchIndex = bestMatchIndex;
  localeLanguageScore = bestMatchScore;
}
 
Example 15
Source File: HlsPlaylistParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@C.SelectionFlags
private static int parseSelectionFlags(String line) {
  int flags = 0;
  if (parseOptionalBooleanAttribute(line, REGEX_DEFAULT, false)) {
    flags |= C.SELECTION_FLAG_DEFAULT;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_FORCED, false)) {
    flags |= C.SELECTION_FLAG_FORCED;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_AUTOSELECT, false)) {
    flags |= C.SELECTION_FLAG_AUTOSELECT;
  }
  return flags;
}
 
Example 16
Source File: HlsPlaylistParser.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@C.SelectionFlags
private static int parseSelectionFlags(String line) {
  int flags = 0;
  if (parseOptionalBooleanAttribute(line, REGEX_DEFAULT, false)) {
    flags |= C.SELECTION_FLAG_DEFAULT;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_FORCED, false)) {
    flags |= C.SELECTION_FLAG_FORCED;
  }
  if (parseOptionalBooleanAttribute(line, REGEX_AUTOSELECT, false)) {
    flags |= C.SELECTION_FLAG_AUTOSELECT;
  }
  return flags;
}
 
Example 17
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public TextTrackScore(
    Format format,
    Parameters parameters,
    @Capabilities int trackFormatSupport,
    @Nullable String selectedAudioLanguage) {
  isWithinRendererCapabilities =
      isSupported(trackFormatSupport, /* allowExceedsCapabilities= */ false);
  int maskedSelectionFlags =
      format.selectionFlags & ~parameters.disabledTextTrackSelectionFlags;
  isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
  boolean isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
  preferredLanguageScore =
      getFormatLanguageScore(
          format, parameters.preferredTextLanguage, parameters.selectUndeterminedTextLanguage);
  preferredRoleFlagsScore =
      Integer.bitCount(format.roleFlags & parameters.preferredTextRoleFlags);
  hasCaptionRoleFlags =
      (format.roleFlags & (C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND)) != 0;
  // Prefer non-forced to forced if a preferred text language has been matched. Where both are
  // provided the non-forced track will usually contain the forced subtitles as a subset.
  // Otherwise, prefer a forced track.
  hasPreferredIsForcedFlag =
      (preferredLanguageScore > 0 && !isForced) || (preferredLanguageScore == 0 && isForced);
  boolean selectedAudioLanguageUndetermined =
      normalizeUndeterminedLanguageToNull(selectedAudioLanguage) == null;
  selectedAudioLanguageScore =
      getFormatLanguageScore(format, selectedAudioLanguage, selectedAudioLanguageUndetermined);
  isWithinConstraints =
      preferredLanguageScore > 0
          || (parameters.preferredTextLanguage == null && preferredRoleFlagsScore > 0)
          || isDefault
          || (isForced && selectedAudioLanguageScore > 0);
}
 
Example 18
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public AudioTrackScore(Format format, Parameters parameters, @Capabilities int formatSupport) {
  this.parameters = parameters;
  this.language = normalizeUndeterminedLanguageToNull(format.language);
  isWithinRendererCapabilities = isSupported(formatSupport, false);
  preferredLanguageScore =
      getFormatLanguageScore(
          format,
          parameters.preferredAudioLanguage,
          /* allowUndeterminedFormatLanguage= */ false);
  isDefaultSelectionFlag = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
  channelCount = format.channelCount;
  sampleRate = format.sampleRate;
  bitrate = format.bitrate;
  isWithinConstraints =
      (format.bitrate == Format.NO_VALUE || format.bitrate <= parameters.maxAudioBitrate)
          && (format.channelCount == Format.NO_VALUE
              || format.channelCount <= parameters.maxAudioChannelCount);
  String[] localeLanguages = Util.getSystemLanguageCodes();
  int bestMatchIndex = Integer.MAX_VALUE;
  int bestMatchScore = 0;
  for (int i = 0; i < localeLanguages.length; i++) {
    int score =
        getFormatLanguageScore(
            format, localeLanguages[i], /* allowUndeterminedFormatLanguage= */ false);
    if (score > 0) {
      bestMatchIndex = i;
      bestMatchScore = score;
      break;
    }
  }
  localeLanguageMatchIndex = bestMatchIndex;
  localeLanguageScore = bestMatchScore;
}
 
Example 19
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a text renderer.
 *
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each mapped
 *     track, indexed by track group index and track index (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
protected @Nullable TrackSelection selectTextTrack(
    TrackGroupArray groups, int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        int maskedSelectionFlags =
            format.selectionFlags & ~params.disabledTextTrackSelectionFlags;
        boolean isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        boolean isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0;
        int trackScore;
        boolean preferredLanguageFound = formatHasLanguage(format, params.preferredTextLanguage);
        if (preferredLanguageFound
            || (params.selectUndeterminedTextLanguage && formatHasNoLanguage(format))) {
          if (isDefault) {
            trackScore = 8;
          } else if (!isForced) {
            // Prefer non-forced to forced if a preferred text language has been specified. Where
            // both are provided the non-forced track will usually contain the forced subtitles as
            // a subset.
            trackScore = 6;
          } else {
            trackScore = 4;
          }
          trackScore += preferredLanguageFound ? 1 : 0;
        } else if (isDefault) {
          trackScore = 3;
        } else if (isForced) {
          if (formatHasLanguage(format, params.preferredAudioLanguage)) {
            trackScore = 2;
          } else {
            trackScore = 1;
          }
        } else {
          // Track should not be selected.
          continue;
        }
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
Example 20
Source File: DefaultTrackSelector.java    From K-Sonic with MIT License 4 votes vote down vote up
protected TrackSelection selectTextTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredTextLanguage, String preferredAudioLanguage,
    boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        boolean isForced = (format.selectionFlags & C.SELECTION_FLAG_FORCED) != 0;
        int trackScore;
        if (formatHasLanguage(format, preferredTextLanguage)) {
          if (isDefault) {
            trackScore = 6;
          } else if (!isForced) {
            // Prefer non-forced to forced if a preferred text language has been specified. Where
            // both are provided the non-forced track will usually contain the forced subtitles as
            // a subset.
            trackScore = 5;
          } else {
            trackScore = 4;
          }
        } else if (isDefault) {
          trackScore = 3;
        } else if (isForced) {
          if (formatHasLanguage(format, preferredAudioLanguage)) {
            trackScore = 2;
          } else {
            trackScore = 1;
          }
        } else {
          // Track should not be selected.
          continue;
        }
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}