Add checkNotNull for all getVideoCapabilities and similar calls

PiperOrigin-RevId: 735358217
This commit is contained in:
sheenachhabra 2025-03-10 06:49:34 -07:00 committed by Copybara-Service
parent 15fa27cd9a
commit 66995a8816
2 changed files with 40 additions and 35 deletions

View File

@ -165,23 +165,23 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/* requiresSecureDecoder= */ requiresSecureDecoder, /* requiresSecureDecoder= */ requiresSecureDecoder,
/* requiresTunnelingDecoder= */ false); /* requiresTunnelingDecoder= */ false);
for (int i = 0; i < decoderInfos.size(); i++) { for (int i = 0; i < decoderInfos.size(); i++) {
if (decoderInfos.get(i).capabilities != null if (decoderInfos.get(i).capabilities != null) {
&& decoderInfos.get(i).capabilities.getVideoCapabilities() != null) { VideoCapabilities videoCapabilities =
decoderInfos.get(i).capabilities.getVideoCapabilities();
if (videoCapabilities != null) {
List<PerformancePoint> performancePointListH264 = List<PerformancePoint> performancePointListH264 =
decoderInfos videoCapabilities.getSupportedPerformancePoints();
.get(i)
.capabilities
.getVideoCapabilities()
.getSupportedPerformancePoints();
if (performancePointListH264 != null && !performancePointListH264.isEmpty()) { if (performancePointListH264 != null && !performancePointListH264.isEmpty()) {
PerformancePoint targetPerformancePointH264 = PerformancePoint targetPerformancePointH264 =
new PerformancePoint(/* width= */ 1280, /* height= */ 720, /* frameRate= */ 60); new PerformancePoint(
/* width= */ 1280, /* height= */ 720, /* frameRate= */ 60);
return evaluatePerformancePointCoverage( return evaluatePerformancePointCoverage(
performancePointListH264, targetPerformancePointH264); performancePointListH264, targetPerformancePointH264);
} }
} }
} }
} }
}
return COVERAGE_RESULT_NO_PERFORMANCE_POINTS_UNSUPPORTED; return COVERAGE_RESULT_NO_PERFORMANCE_POINTS_UNSUPPORTED;
} catch (MediaCodecUtil.DecoderQueryException ignored) { } catch (MediaCodecUtil.DecoderQueryException ignored) {
return COVERAGE_RESULT_NO_PERFORMANCE_POINTS_UNSUPPORTED; return COVERAGE_RESULT_NO_PERFORMANCE_POINTS_UNSUPPORTED;

View File

@ -16,6 +16,7 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static java.lang.Math.floor; import static java.lang.Math.floor;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.round; import static java.lang.Math.round;
@ -194,13 +195,15 @@ public final class EncoderUtil {
return ImmutableList.of(); return ImmutableList.of();
} }
/** Returns whether the {@linkplain MediaCodecInfo encoder} supports the given resolution. */ /**
* Returns whether the {@linkplain MediaCodecInfo encoder} supports the given resolution for a
* specific {@link MimeTypes video MIME type}.
*/
public static boolean isSizeSupported( public static boolean isSizeSupported(
MediaCodecInfo encoderInfo, String mimeType, int width, int height) { MediaCodecInfo encoderInfo, String mimeType, int width, int height) {
if (encoderInfo MediaCodecInfo.VideoCapabilities videoCapabilities =
.getCapabilitiesForType(mimeType) checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities());
.getVideoCapabilities() if (videoCapabilities.isSizeSupported(width, height)) {
.isSizeSupported(width, height)) {
return true; return true;
} }
@ -219,27 +222,26 @@ public final class EncoderUtil {
/** /**
* Returns a {@link Range} of supported heights for the given {@link MediaCodecInfo encoder}, * Returns a {@link Range} of supported heights for the given {@link MediaCodecInfo encoder},
* {@linkplain MimeTypes MIME type} and {@code width}. * {@linkplain MimeTypes video MIME type} and {@code width}.
* *
* @throws IllegalArgumentException When the width is not in the range of {@linkplain * @throws IllegalArgumentException When the width is not in the range of {@linkplain
* #getSupportedResolutionRanges supported widths}. * #getSupportedResolutionRanges supported widths}.
*/ */
public static Range<Integer> getSupportedHeights( public static Range<Integer> getSupportedHeights(
MediaCodecInfo encoderInfo, String mimeType, int width) { MediaCodecInfo encoderInfo, String mimeType, int width) {
return encoderInfo MediaCodecInfo.VideoCapabilities videoCapabilities =
.getCapabilitiesForType(mimeType) checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities());
.getVideoCapabilities() return videoCapabilities.getSupportedHeightsFor(width);
.getSupportedHeightsFor(width);
} }
/** /**
* Returns a {@link Pair} of supported width and height {@link Range ranges} for the given {@link * Returns a {@link Pair} of supported width and height {@link Range ranges} for the given {@link
* MediaCodecInfo encoder} and {@linkplain MimeTypes MIME type}. * MediaCodecInfo encoder} and {@linkplain MimeTypes video MIME type}.
*/ */
public static Pair<Range<Integer>, Range<Integer>> getSupportedResolutionRanges( public static Pair<Range<Integer>, Range<Integer>> getSupportedResolutionRanges(
MediaCodecInfo encoderInfo, String mimeType) { MediaCodecInfo encoderInfo, String mimeType) {
MediaCodecInfo.VideoCapabilities videoCapabilities = MediaCodecInfo.VideoCapabilities videoCapabilities =
encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities(); checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities());
return Pair.create( return Pair.create(
videoCapabilities.getSupportedWidths(), videoCapabilities.getSupportedHeights()); videoCapabilities.getSupportedWidths(), videoCapabilities.getSupportedHeights());
} }
@ -257,7 +259,7 @@ public final class EncoderUtil {
* required size alignment. * required size alignment.
* *
* @param encoderInfo The {@link MediaCodecInfo} of the encoder. * @param encoderInfo The {@link MediaCodecInfo} of the encoder.
* @param mimeType The output MIME type. * @param mimeType The output {@linkplain MimeTypes video MIME type}.
* @param width The original width. * @param width The original width.
* @param height The original height. * @param height The original height.
* @return A {@linkplain Size supported resolution}, or {@code null} if unable to find a fallback. * @return A {@linkplain Size supported resolution}, or {@code null} if unable to find a fallback.
@ -266,7 +268,7 @@ public final class EncoderUtil {
public static Size getSupportedResolution( public static Size getSupportedResolution(
MediaCodecInfo encoderInfo, String mimeType, int width, int height) { MediaCodecInfo encoderInfo, String mimeType, int width, int height) {
MediaCodecInfo.VideoCapabilities videoCapabilities = MediaCodecInfo.VideoCapabilities videoCapabilities =
encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities(); checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities());
int widthAlignment = videoCapabilities.getWidthAlignment(); int widthAlignment = videoCapabilities.getWidthAlignment();
int heightAlignment = videoCapabilities.getHeightAlignment(); int heightAlignment = videoCapabilities.getHeightAlignment();
@ -340,19 +342,22 @@ public final class EncoderUtil {
return maxSupportedLevel; return maxSupportedLevel;
} }
/** Returns the range of supported bitrates for the given {@linkplain MimeTypes MIME type}. */ /**
* Returns the range of supported bitrates for the given {@linkplain MimeTypes video MIME type}.
*/
public static Range<Integer> getSupportedBitrateRange( public static Range<Integer> getSupportedBitrateRange(
MediaCodecInfo encoderInfo, String mimeType) { MediaCodecInfo encoderInfo, String mimeType) {
return encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities().getBitrateRange(); MediaCodecInfo.VideoCapabilities videoCapabilities =
checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getVideoCapabilities());
return videoCapabilities.getBitrateRange();
} }
/** Returns whether the bitrate mode is supported by the encoder. */ /** Returns whether the bitrate mode is supported by the encoder. */
public static boolean isBitrateModeSupported( public static boolean isBitrateModeSupported(
MediaCodecInfo encoderInfo, String mimeType, int bitrateMode) { MediaCodecInfo encoderInfo, String mimeType, int bitrateMode) {
return encoderInfo MediaCodecInfo.EncoderCapabilities encoderCapabilities =
.getCapabilitiesForType(mimeType) checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getEncoderCapabilities());
.getEncoderCapabilities() return encoderCapabilities.isBitrateModeSupported(bitrateMode);
.isBitrateModeSupported(bitrateMode);
} }
/** /**
@ -368,12 +373,12 @@ public final class EncoderUtil {
/** /**
* Returns the sample rate supported by the provided {@linkplain MediaCodecInfo encoder} that is * Returns the sample rate supported by the provided {@linkplain MediaCodecInfo encoder} that is
* closest to the provided sample rate. * closest to the provided sample rate for a given {@linkplain MimeTypes audio MIME type}.
*/ */
public static int getClosestSupportedSampleRate( public static int getClosestSupportedSampleRate(
MediaCodecInfo encoderInfo, String mimeType, int requestedSampleRate) { MediaCodecInfo encoderInfo, String mimeType, int requestedSampleRate) {
MediaCodecInfo.AudioCapabilities audioCapabilities = MediaCodecInfo.AudioCapabilities audioCapabilities =
encoderInfo.getCapabilitiesForType(mimeType).getAudioCapabilities(); checkNotNull(encoderInfo.getCapabilitiesForType(mimeType).getAudioCapabilities());
@Nullable int[] supportedSampleRates = audioCapabilities.getSupportedSampleRates(); @Nullable int[] supportedSampleRates = audioCapabilities.getSupportedSampleRates();
int closestSampleRate = Integer.MAX_VALUE; int closestSampleRate = Integer.MAX_VALUE;
if (supportedSampleRates != null) { if (supportedSampleRates != null) {