From 35c230f3c6ed9c249dfed1b5ea18f3e17bb7990e Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Tue, 11 Sep 2018 06:51:22 -0700 Subject: [PATCH] Allow partial format for adaptation check ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=212443793 --- .../exoplayer2/audio/MediaCodecAudioRenderer.java | 6 ++++-- .../exoplayer2/mediacodec/MediaCodecInfo.java | 15 ++++++++++----- .../exoplayer2/video/MediaCodecVideoRenderer.java | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java index 23cf893b8a..96ae1c529c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java @@ -363,7 +363,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media protected @KeepCodecResult int canKeepCodec( MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) { if (getCodecMaxInputSize(codecInfo, newFormat) <= codecMaxInputSize - && codecInfo.isSeamlessAdaptationSupported(oldFormat, newFormat) + && codecInfo.isSeamlessAdaptationSupported( + oldFormat, newFormat, /* isNewFormatComplete= */ true) && oldFormat.encoderDelay == 0 && oldFormat.encoderPadding == 0 && newFormat.encoderDelay == 0 @@ -681,7 +682,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media return maxInputSize; } for (Format streamFormat : streamFormats) { - if (codecInfo.isSeamlessAdaptationSupported(format, streamFormat)) { + if (codecInfo.isSeamlessAdaptationSupported( + format, streamFormat, /* isNewFormatComplete= */ false)) { maxInputSize = Math.max(maxInputSize, getCodecMaxInputSize(codecInfo, streamFormat)); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java index 727dfaf1d5..81f07921c1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java @@ -262,8 +262,8 @@ public final class MediaCodecInfo { * Returns whether it may be possible to adapt to playing a different format when the codec is * configured to play media in the specified {@code format}. For adaptation to succeed, the codec * must also be configured with appropriate maximum values and {@link - * #isSeamlessAdaptationSupported(Format, Format)} must return {@code true} for the old/new - * formats. + * #isSeamlessAdaptationSupported(Format, Format, boolean)} must return {@code true} for the + * old/new formats. * * @param format The format of media for which the decoder will be configured. * @return Whether adaptation may be possible @@ -280,19 +280,24 @@ public final class MediaCodecInfo { /** * Returns whether it is possible to adapt the decoder seamlessly from {@code oldFormat} to {@code - * newFormat}. + * newFormat}. If {@code newFormat} may not be completely populated, pass {@code false} for {@code + * isNewFormatComplete}. * * @param oldFormat The format being decoded. * @param newFormat The new format. + * @param isNewFormatComplete Whether {@code newFormat} is populated with format-specific + * metadata. * @return Whether it is possible to adapt the decoder seamlessly. */ - public boolean isSeamlessAdaptationSupported(Format oldFormat, Format newFormat) { + public boolean isSeamlessAdaptationSupported( + Format oldFormat, Format newFormat, boolean isNewFormatComplete) { if (isVideo) { return oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) && oldFormat.rotationDegrees == newFormat.rotationDegrees && (adaptive || (oldFormat.width == newFormat.width && oldFormat.height == newFormat.height)) - && Util.areEqual(oldFormat.colorInfo, newFormat.colorInfo); + && ((!isNewFormatComplete && newFormat.colorInfo == null) + || Util.areEqual(oldFormat.colorInfo, newFormat.colorInfo)); } else { if (!MimeTypes.AUDIO_AAC.equals(mimeType) || !oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java index d1cda57ce0..5c308ab71b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/MediaCodecVideoRenderer.java @@ -485,7 +485,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { @Override protected @KeepCodecResult int canKeepCodec( MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) { - if (codecInfo.isSeamlessAdaptationSupported(oldFormat, newFormat) + if (codecInfo.isSeamlessAdaptationSupported( + oldFormat, newFormat, /* isNewFormatComplete= */ true) && newFormat.width <= codecMaxValues.width && newFormat.height <= codecMaxValues.height && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) { @@ -1081,7 +1082,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { } boolean haveUnknownDimensions = false; for (Format streamFormat : streamFormats) { - if (codecInfo.isSeamlessAdaptationSupported(format, streamFormat)) { + if (codecInfo.isSeamlessAdaptationSupported( + format, streamFormat, /* isNewFormatComplete= */ false)) { haveUnknownDimensions |= (streamFormat.width == Format.NO_VALUE || streamFormat.height == Format.NO_VALUE); maxWidth = Math.max(maxWidth, streamFormat.width);