Java Code Examples for com.google.android.exoplayer2.Format#getPixelCount()
The following examples show how to use
com.google.android.exoplayer2.Format#getPixelCount() .
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 MediaSDK with Apache License 2.0 | 4 votes |
@Nullable private static TrackSelection.Definition selectFixedVideoTrack( TrackGroupArray groups, @Capabilities int[][] formatSupports, Parameters params) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, params.viewportWidth, params.viewportHeight, params.viewportOrientationMayChange); @Capabilities int[] trackFormatSupport = formatSupports[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { 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.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; } int trackScore = isWithinConstraints ? 2 : 1; boolean isWithinCapabilities = isSupported(trackFormatSupport[trackIndex], false); if (isWithinCapabilities) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { int bitrateComparison = compareFormatValues(format.bitrate, selectedBitrate); if (params.forceLowestBitrate && bitrateComparison != 0) { // Use bitrate as a tie breaker, preferring the lower bitrate. selectTrack = bitrateComparison < 0; } else { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If // we're within constraints prefer a higher pixel count (or bitrate), else prefer a // lower count (or bitrate). If still tied then prefer the first track (i.e. the one // that's already selected). int formatPixelCount = format.getPixelCount(); int comparisonResult = formatPixelCount != selectedPixelCount ? compareFormatValues(formatPixelCount, selectedPixelCount) : compareFormatValues(format.bitrate, selectedBitrate); selectTrack = isWithinCapabilities && isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new TrackSelection.Definition(selectedGroup, selectedTrackIndex); }
Example 2
Source File: DefaultTrackSelector.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private static @Nullable TrackSelection selectFixedVideoTrack( TrackGroupArray groups, int[][] formatSupports, Parameters params) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, params.viewportWidth, params.viewportHeight, params.viewportOrientationMayChange); int[] trackFormatSupport = formatSupports[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { 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); if (!isWithinConstraints && !params.exceedVideoConstraintsIfNecessary) { // Track should not be selected. continue; } int trackScore = isWithinConstraints ? 2 : 1; boolean isWithinCapabilities = isSupported(trackFormatSupport[trackIndex], false); if (isWithinCapabilities) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { if (params.forceLowestBitrate) { // Use bitrate as a tie breaker, preferring the lower bitrate. selectTrack = compareFormatValues(format.bitrate, selectedBitrate) < 0; } else { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If // we're within constraints prefer a higher pixel count (or bitrate), else prefer a // lower count (or bitrate). If still tied then prefer the first track (i.e. the one // that's already selected). int formatPixelCount = format.getPixelCount(); int comparisonResult = formatPixelCount != selectedPixelCount ? compareFormatValues(formatPixelCount, selectedPixelCount) : compareFormatValues(format.bitrate, selectedBitrate); selectTrack = isWithinCapabilities && isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex); }
Example 3
Source File: DefaultTrackSelector.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private static @Nullable TrackSelection selectFixedVideoTrack( TrackGroupArray groups, int[][] formatSupports, Parameters params) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, params.viewportWidth, params.viewportHeight, params.viewportOrientationMayChange); int[] trackFormatSupport = formatSupports[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { 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); if (!isWithinConstraints && !params.exceedVideoConstraintsIfNecessary) { // Track should not be selected. continue; } int trackScore = isWithinConstraints ? 2 : 1; boolean isWithinCapabilities = isSupported(trackFormatSupport[trackIndex], false); if (isWithinCapabilities) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { if (params.forceLowestBitrate) { // Use bitrate as a tie breaker, preferring the lower bitrate. selectTrack = compareFormatValues(format.bitrate, selectedBitrate) < 0; } else { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If // we're within constraints prefer a higher pixel count (or bitrate), else prefer a // lower count (or bitrate). If still tied then prefer the first track (i.e. the one // that's already selected). int formatPixelCount = format.getPixelCount(); int comparisonResult = formatPixelCount != selectedPixelCount ? compareFormatValues(formatPixelCount, selectedPixelCount) : compareFormatValues(format.bitrate, selectedBitrate); selectTrack = isWithinCapabilities && isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex); }
Example 4
Source File: DefaultTrackSelector.java From K-Sonic with MIT License | 4 votes |
private static TrackSelection selectFixedVideoTrack(TrackGroupArray groups, int[][] formatSupport, int maxVideoWidth, int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight, boolean orientationMayChange, boolean exceedConstraintsIfNecessary, boolean exceedRendererCapabilitiesIfNecessary) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, viewportWidth, viewportHeight, orientationMayChange); int[] trackFormatSupport = formatSupport[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) { Format format = trackGroup.getFormat(trackIndex); boolean isWithinConstraints = selectedTrackIndices.contains(trackIndex) && (format.width == Format.NO_VALUE || format.width <= maxVideoWidth) && (format.height == Format.NO_VALUE || format.height <= maxVideoHeight) && (format.bitrate == Format.NO_VALUE || format.bitrate <= maxVideoBitrate); if (!isWithinConstraints && !exceedConstraintsIfNecessary) { // Track should not be selected. continue; } int trackScore = isWithinConstraints ? 2 : 1; if (isSupported(trackFormatSupport[trackIndex], false)) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If we're // within constraints prefer a higher pixel count (or bitrate), else prefer a lower // count (or bitrate). If still tied then prefer the first track (i.e. the one that's // already selected). int comparisonResult; int formatPixelCount = format.getPixelCount(); if (formatPixelCount != selectedPixelCount) { comparisonResult = compareFormatValues(format.getPixelCount(), selectedPixelCount); } else { comparisonResult = compareFormatValues(format.bitrate, selectedBitrate); } selectTrack = isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new FixedTrackSelection(selectedGroup, selectedTrackIndex); }
Example 5
Source File: DefaultTrackSelector.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Nullable private static TrackSelection.Definition selectFixedVideoTrack( TrackGroupArray groups, int[][] formatSupports, Parameters params) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, params.viewportWidth, params.viewportHeight, params.viewportOrientationMayChange); int[] trackFormatSupport = formatSupports[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { 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.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; } int trackScore = isWithinConstraints ? 2 : 1; boolean isWithinCapabilities = isSupported(trackFormatSupport[trackIndex], false); if (isWithinCapabilities) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { int bitrateComparison = compareFormatValues(format.bitrate, selectedBitrate); if (params.forceLowestBitrate && bitrateComparison != 0) { // Use bitrate as a tie breaker, preferring the lower bitrate. selectTrack = bitrateComparison < 0; } else { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If // we're within constraints prefer a higher pixel count (or bitrate), else prefer a // lower count (or bitrate). If still tied then prefer the first track (i.e. the one // that's already selected). int formatPixelCount = format.getPixelCount(); int comparisonResult = formatPixelCount != selectedPixelCount ? compareFormatValues(formatPixelCount, selectedPixelCount) : compareFormatValues(format.bitrate, selectedBitrate); selectTrack = isWithinCapabilities && isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new TrackSelection.Definition(selectedGroup, selectedTrackIndex); }
Example 6
Source File: DefaultTrackSelector.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Nullable private static TrackSelection.Definition selectFixedVideoTrack( TrackGroupArray groups, int[][] formatSupports, Parameters params) { TrackGroup selectedGroup = null; int selectedTrackIndex = 0; int selectedTrackScore = 0; int selectedBitrate = Format.NO_VALUE; int selectedPixelCount = Format.NO_VALUE; for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(trackGroup, params.viewportWidth, params.viewportHeight, params.viewportOrientationMayChange); int[] trackFormatSupport = formatSupports[groupIndex]; for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { 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.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; } int trackScore = isWithinConstraints ? 2 : 1; boolean isWithinCapabilities = isSupported(trackFormatSupport[trackIndex], false); if (isWithinCapabilities) { trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS; } boolean selectTrack = trackScore > selectedTrackScore; if (trackScore == selectedTrackScore) { int bitrateComparison = compareFormatValues(format.bitrate, selectedBitrate); if (params.forceLowestBitrate && bitrateComparison != 0) { // Use bitrate as a tie breaker, preferring the lower bitrate. selectTrack = bitrateComparison < 0; } else { // Use the pixel count as a tie breaker (or bitrate if pixel counts are tied). If // we're within constraints prefer a higher pixel count (or bitrate), else prefer a // lower count (or bitrate). If still tied then prefer the first track (i.e. the one // that's already selected). int formatPixelCount = format.getPixelCount(); int comparisonResult = formatPixelCount != selectedPixelCount ? compareFormatValues(formatPixelCount, selectedPixelCount) : compareFormatValues(format.bitrate, selectedBitrate); selectTrack = isWithinCapabilities && isWithinConstraints ? comparisonResult > 0 : comparisonResult < 0; } } if (selectTrack) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; selectedBitrate = format.bitrate; selectedPixelCount = format.getPixelCount(); } } } } return selectedGroup == null ? null : new TrackSelection.Definition(selectedGroup, selectedTrackIndex); }