Java Code Examples for com.google.android.exoplayer2.util.Util#toArray()

The following examples show how to use com.google.android.exoplayer2.util.Util#toArray() . 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: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean viewportOrientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, viewportOrientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<@NullableType String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      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, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
Example 2
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean viewportOrientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, viewportOrientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<@NullableType String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      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, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
Example 3
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private static int[] getVideoTrackIndices(TrackGroup trackGroup, int[] formatSupport,
    String[] formatIds, boolean canIncludeAdditionalFormats) {
  List<Integer> trackIndices = new ArrayList<>();

  // Always select explicitly listed representations.
  for (String formatId : formatIds) {
    int trackIndex = getTrackIndex(trackGroup, formatId);
    Log.d(TAG, "Adding base video format: "
        + Format.toLogString(trackGroup.getFormat(trackIndex)));
    trackIndices.add(trackIndex);
  }

  // Select additional video representations, if supported by the device.
  if (canIncludeAdditionalFormats) {
    for (int i = 0; i < trackGroup.length; i++) {
      if (!trackIndices.contains(i) && isFormatHandled(formatSupport[i])) {
        Log.d(TAG, "Adding extra video format: "
            + Format.toLogString(trackGroup.getFormat(i)));
        trackIndices.add(i);
      }
    }
  }

  int[] trackIndicesArray = Util.toArray(trackIndices);
  Arrays.sort(trackIndicesArray);
  return trackIndicesArray;
}
 
Example 4
Source File: DefaultTrackSelector.java    From K-Sonic with MIT License 5 votes vote down vote up
private static int[] getAdaptiveTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType = getAdaptiveTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            maxVideoBitrate, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
Example 5
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static int[] getAdaptiveVideoTracksForGroup(
    TrackGroup group,
    @Capabilities 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;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, viewportOrientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<@NullableType String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType =
            getAdaptiveVideoTrackCountForMimeType(
                group,
                formatSupport,
                requiredAdaptiveSupport,
                sampleMimeType,
                maxVideoWidth,
                maxVideoHeight,
                maxVideoFrameRate,
                maxVideoBitrate,
                selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
Example 6
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
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;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, viewportOrientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<@NullableType String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType =
            getAdaptiveVideoTrackCountForMimeType(
                group,
                formatSupport,
                requiredAdaptiveSupport,
                sampleMimeType,
                maxVideoWidth,
                maxVideoHeight,
                maxVideoFrameRate,
                maxVideoBitrate,
                selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
Example 7
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
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;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, viewportOrientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<@NullableType String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType =
            getAdaptiveVideoTrackCountForMimeType(
                group,
                formatSupport,
                requiredAdaptiveSupport,
                sampleMimeType,
                maxVideoWidth,
                maxVideoHeight,
                maxVideoFrameRate,
                maxVideoBitrate,
                selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

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

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}