Allow partial format for adaptation check

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=212443793
This commit is contained in:
andrewlewis 2018-09-11 06:51:22 -07:00 committed by Oliver Woodman
parent b1d48179e8
commit 35c230f3c6
3 changed files with 18 additions and 9 deletions

View File

@ -363,7 +363,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
protected @KeepCodecResult int canKeepCodec( protected @KeepCodecResult int canKeepCodec(
MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) { MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
if (getCodecMaxInputSize(codecInfo, newFormat) <= codecMaxInputSize if (getCodecMaxInputSize(codecInfo, newFormat) <= codecMaxInputSize
&& codecInfo.isSeamlessAdaptationSupported(oldFormat, newFormat) && codecInfo.isSeamlessAdaptationSupported(
oldFormat, newFormat, /* isNewFormatComplete= */ true)
&& oldFormat.encoderDelay == 0 && oldFormat.encoderDelay == 0
&& oldFormat.encoderPadding == 0 && oldFormat.encoderPadding == 0
&& newFormat.encoderDelay == 0 && newFormat.encoderDelay == 0
@ -681,7 +682,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
return maxInputSize; return maxInputSize;
} }
for (Format streamFormat : streamFormats) { for (Format streamFormat : streamFormats) {
if (codecInfo.isSeamlessAdaptationSupported(format, streamFormat)) { if (codecInfo.isSeamlessAdaptationSupported(
format, streamFormat, /* isNewFormatComplete= */ false)) {
maxInputSize = Math.max(maxInputSize, getCodecMaxInputSize(codecInfo, streamFormat)); maxInputSize = Math.max(maxInputSize, getCodecMaxInputSize(codecInfo, streamFormat));
} }
} }

View File

@ -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 * 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 * 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 * must also be configured with appropriate maximum values and {@link
* #isSeamlessAdaptationSupported(Format, Format)} must return {@code true} for the old/new * #isSeamlessAdaptationSupported(Format, Format, boolean)} must return {@code true} for the
* formats. * old/new formats.
* *
* @param format The format of media for which the decoder will be configured. * @param format The format of media for which the decoder will be configured.
* @return Whether adaptation may be possible * @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 * 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 oldFormat The format being decoded.
* @param newFormat The new format. * @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. * @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) { if (isVideo) {
return oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) return oldFormat.sampleMimeType.equals(newFormat.sampleMimeType)
&& oldFormat.rotationDegrees == newFormat.rotationDegrees && oldFormat.rotationDegrees == newFormat.rotationDegrees
&& (adaptive && (adaptive
|| (oldFormat.width == newFormat.width && oldFormat.height == newFormat.height)) || (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 { } else {
if (!MimeTypes.AUDIO_AAC.equals(mimeType) if (!MimeTypes.AUDIO_AAC.equals(mimeType)
|| !oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) || !oldFormat.sampleMimeType.equals(newFormat.sampleMimeType)

View File

@ -485,7 +485,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@Override @Override
protected @KeepCodecResult int canKeepCodec( protected @KeepCodecResult int canKeepCodec(
MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) { 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.width <= codecMaxValues.width
&& newFormat.height <= codecMaxValues.height && newFormat.height <= codecMaxValues.height
&& getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) { && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
@ -1081,7 +1082,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
boolean haveUnknownDimensions = false; boolean haveUnknownDimensions = false;
for (Format streamFormat : streamFormats) { for (Format streamFormat : streamFormats) {
if (codecInfo.isSeamlessAdaptationSupported(format, streamFormat)) { if (codecInfo.isSeamlessAdaptationSupported(
format, streamFormat, /* isNewFormatComplete= */ false)) {
haveUnknownDimensions |= haveUnknownDimensions |=
(streamFormat.width == Format.NO_VALUE || streamFormat.height == Format.NO_VALUE); (streamFormat.width == Format.NO_VALUE || streamFormat.height == Format.NO_VALUE);
maxWidth = Math.max(maxWidth, streamFormat.width); maxWidth = Math.max(maxWidth, streamFormat.width);