Allow partial format for adaptation check
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=212443793
This commit is contained in:
parent
b1d48179e8
commit
35c230f3c6
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user