Codec: Reduce limit for max decoder pending output frames.

Tentative/experimental value to reduce codec timeouts. We will reconsider using a larger limit after seeing whether this really does reduce error rate.

PiperOrigin-RevId: 534491615
(cherry picked from commit 66554b9b68)
This commit is contained in:
huangdarwin 2023-05-23 19:18:32 +01:00 committed by Tofunmi Adigun-Hameed
parent 38a341a458
commit 9e19c60907
4 changed files with 17 additions and 30 deletions

View file

@ -1036,12 +1036,6 @@ public final class C {
/** See {@link MediaFormat#COLOR_RANGE_FULL}. */
@UnstableApi public static final int COLOR_RANGE_FULL = MediaFormat.COLOR_RANGE_FULL;
/**
* Represents applying no limit to the number of input frames a {@link MediaCodec} encoder
* accepts.
*/
@UnstableApi public static final int UNLIMITED_PENDING_FRAME_COUNT = Integer.MAX_VALUE;
/** Video projection types. */
@UnstableApi
@Documented

View file

@ -16,7 +16,6 @@
package androidx.media3.common.util;
import static android.content.Context.UI_MODE_SERVICE;
import static androidx.media3.common.C.UNLIMITED_PENDING_FRAME_COUNT;
import static androidx.media3.common.Player.COMMAND_PLAY_PAUSE;
import static androidx.media3.common.Player.COMMAND_PREPARE;
import static androidx.media3.common.Player.COMMAND_SEEK_BACK;
@ -2809,25 +2808,20 @@ public final class Util {
// 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")) {
// This decoder drops frames if too many frames are rendered without being processed when
// tone-mapping HDR. 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;
// Limit the maximum amount of frames for all decoders. This is a tentative value that should be
// large enough to avoid significant performance degradation, but small enough to bypass decoder
// issues.
//
// TODO: b/278234847 - Evaluate whether this reduces decoder timeouts, and consider restoring
// prior higher limits as appropriate.
//
// 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. 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;
}
/**

View file

@ -132,10 +132,10 @@ public interface Codec {
/**
* Returns the maximum number of frames that may be pending in the output {@code Codec} at a time,
* or {@link C#UNLIMITED_PENDING_FRAME_COUNT} if it's not necessary to enforce a limit.
* or {@code 5} as a default value.
*/
default int getMaxPendingFrameCount() {
return C.UNLIMITED_PENDING_FRAME_COUNT;
return 5;
}
/**

View file

@ -147,8 +147,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return true;
}
if (maxDecoderPendingFrameCount != C.UNLIMITED_PENDING_FRAME_COUNT
&& sampleConsumer.getPendingVideoFrameCount() == maxDecoderPendingFrameCount) {
if (sampleConsumer.getPendingVideoFrameCount() == maxDecoderPendingFrameCount) {
return false;
}