Commit 2652d0ef by huangdarwin Committed by Ian Baker

Transformer: Move getMaxPendingFrameCount logic to constructor.

Also, use the mediaCodecName passed into the constructor to get the
maxPendingFrameCount.

PiperOrigin-RevId: 491985044
parent 749d77b1
...@@ -64,8 +64,7 @@ public final class DefaultCodec implements Codec { ...@@ -64,8 +64,7 @@ public final class DefaultCodec implements Codec {
private final Format configurationFormat; private final Format configurationFormat;
private final MediaCodec mediaCodec; private final MediaCodec mediaCodec;
@Nullable private final Surface inputSurface; @Nullable private final Surface inputSurface;
private final boolean decoderNeedsFrameDroppingWorkaround; private final int maxPendingFrameCount;
private final boolean requestedHdrToneMapping;
private @MonotonicNonNull Format outputFormat; private @MonotonicNonNull Format outputFormat;
@Nullable private ByteBuffer outputBuffer; @Nullable private ByteBuffer outputBuffer;
...@@ -105,6 +104,7 @@ public final class DefaultCodec implements Codec { ...@@ -105,6 +104,7 @@ public final class DefaultCodec implements Codec {
boolean isVideo = MimeTypes.isVideo(checkNotNull(configurationFormat.sampleMimeType)); boolean isVideo = MimeTypes.isVideo(checkNotNull(configurationFormat.sampleMimeType));
@Nullable MediaCodec mediaCodec = null; @Nullable MediaCodec mediaCodec = null;
@Nullable Surface inputSurface = null; @Nullable Surface inputSurface = null;
boolean requestedHdrToneMapping;
try { try {
requestedHdrToneMapping = requestedHdrToneMapping =
SDK_INT >= 29 && Api29.isSdrToneMappingEnabled(configurationMediaFormat); SDK_INT >= 29 && Api29.isSdrToneMappingEnabled(configurationMediaFormat);
...@@ -135,7 +135,8 @@ public final class DefaultCodec implements Codec { ...@@ -135,7 +135,8 @@ public final class DefaultCodec implements Codec {
} }
this.mediaCodec = mediaCodec; this.mediaCodec = mediaCodec;
this.inputSurface = inputSurface; this.inputSurface = inputSurface;
decoderNeedsFrameDroppingWorkaround = decoderNeedsFrameDroppingWorkaround(context); maxPendingFrameCount =
getMaxPendingFrameCountInternal(context, mediaCodecName, requestedHdrToneMapping);
} }
@Override @Override
...@@ -150,32 +151,7 @@ public final class DefaultCodec implements Codec { ...@@ -150,32 +151,7 @@ public final class DefaultCodec implements Codec {
@Override @Override
public int getMaxPendingFrameCount() { public int getMaxPendingFrameCount() {
if (decoderNeedsFrameDroppingWorkaround) { return maxPendingFrameCount;
// Allow a maximum of one frame to be pending at a time to prevent frame dropping.
// TODO(b/226330223): Investigate increasing this limit.
return 1;
}
if (Ascii.toUpperCase(getName()).startsWith("OMX.")) {
// Some OMX decoders don't correctly track their number of output buffers available, and get
// stuck if too many frames are rendered without being processed, so limit the number of
// pending frames to avoid getting stuck. This value is experimentally determined. See also
// b/213455700, b/230097284, b/229978305, and b/245491744.
//
// OMX video codecs should no longer exist from android.os.Build.DEVICE_INITIAL_SDK_INT 31+.
return 5;
}
if (requestedHdrToneMapping
&& getName().equals("c2.qti.hevc.decoder")
&& MODEL.equals("SM-F936B")) {
// This decoder gets stuck if too many frames are rendered without being processed when
// tone-mapping HDR10. This value is experimentally determined. See also b/260408846.
// TODO(b/260713009): Add API version check after bug is fixed on new API versions.
return 12;
}
// Otherwise don't limit the number of frames that can be pending at a time, to maximize
// throughput.
return UNLIMITED_PENDING_FRAME_COUNT;
} }
@Override @Override
...@@ -488,13 +464,40 @@ public final class DefaultCodec implements Codec { ...@@ -488,13 +464,40 @@ public final class DefaultCodec implements Codec {
TraceUtil.endSection(); TraceUtil.endSection();
} }
private static boolean decoderNeedsFrameDroppingWorkaround(Context context) { private static int getMaxPendingFrameCountInternal(
Context context, String codecName, boolean requestedHdrToneMapping) {
if (SDK_INT < 29
|| context.getApplicationContext().getApplicationInfo().targetSdkVersion < 29) {
// Prior to API 29, decoders may drop frames to keep their output surface from growing out of // Prior to API 29, decoders may drop frames to keep their output surface from growing out of
// bounds. From API 29, if the app targets API 29 or later, the {@link // bounds. From API 29, if the app targets API 29 or later, the {@link
// MediaFormat#KEY_ALLOW_FRAME_DROP} key prevents frame dropping even when the surface is full. // MediaFormat#KEY_ALLOW_FRAME_DROP} key prevents frame dropping even when the surface is
// full.
// Frame dropping is never desired, so a workaround is needed for older API levels. // Frame dropping is never desired, so a workaround is needed for older API levels.
return SDK_INT < 29 // Allow a maximum of one frame to be pending at a time to prevent frame dropping.
|| context.getApplicationContext().getApplicationInfo().targetSdkVersion < 29; // TODO(b/226330223): Investigate increasing this limit.
return 1;
}
if (Ascii.toUpperCase(codecName).startsWith("OMX.")) {
// Some OMX decoders don't correctly track their number of output buffers available, and get
// stuck if too many frames are rendered without being processed, so limit the number of
// pending frames to avoid getting stuck. This value is experimentally determined. See also
// b/213455700, b/230097284, b/229978305, and b/245491744.
//
// OMX video codecs should no longer exist from android.os.Build.DEVICE_INITIAL_SDK_INT 31+.
return 5;
}
if (requestedHdrToneMapping
&& codecName.equals("c2.qti.hevc.decoder")
&& MODEL.equals("SM-F936B")) {
// This decoder gets stuck if too many frames are rendered without being processed when
// tone-mapping HDR10. This value is experimentally determined. See also b/260408846.
// TODO(b/260713009): Add API version check after bug is fixed on new API versions.
return 12;
}
// Otherwise don't limit the number of frames that can be pending at a time, to maximize
// throughput.
return UNLIMITED_PENDING_FRAME_COUNT;
} }
@RequiresApi(29) @RequiresApi(29)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment