Commit 28b6ffeac0 for aom
commit 28b6ffeac03c61462e226285566db864c151d886
Author: James Zern <jzern@google.com>
Date: Wed Jan 7 10:47:34 2026 -0800
av1_receive_raw_frame: move error checks up
Move profile/colorspace checks earlier in the function to avoid
buffering an invalid input frame. This avoids a crash with lagged
encoding on flush.
This is the same change that was made in libvpx:
84e8b23bd vp9_receive_raw_frame: move error checks up
Bug: 471095598
Change-Id: I55e878802843183c90741d4f11fa07aa589346c1
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 56591c3c0b..e32bd64e81 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4661,6 +4661,33 @@ int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
const int subsampling_y = sd->subsampling_y;
const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
+ // Note: Regarding profile setting, the following checks are added to help
+ // choose a proper profile for the input video. The criterion is that all
+ // bitstreams must be designated as the lowest profile that match its content.
+ // E.G. A bitstream that contains 4:4:4 video must be designated as High
+ // Profile in the seq header, and likewise a bitstream that contains 4:2:2
+ // bitstream must be designated as Professional Profile in the sequence
+ // header.
+ if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome &&
+ (subsampling_x != 1 || subsampling_y != 1)) {
+ aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
+ "Non-4:2:0 color format requires profile 1 or 2");
+ return -1;
+ }
+ if ((seq_params->profile == PROFILE_1) &&
+ !(subsampling_x == 0 && subsampling_y == 0)) {
+ aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
+ "Profile 1 requires 4:4:4 color format");
+ return -1;
+ }
+ if ((seq_params->profile == PROFILE_2) &&
+ (seq_params->bit_depth <= AOM_BITS_10) &&
+ !(subsampling_x == 1 && subsampling_y == 0)) {
+ aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
+ "Profile 2 bit-depth <= 10 requires 4:2:2 color format");
+ return -1;
+ }
+
#if CONFIG_TUNE_VMAF
if (!is_stat_generation_stage(cpi) &&
cpi->oxcf.tune_cfg.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING) {
@@ -4723,33 +4750,6 @@ int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
cpi->ppi->total_time_receive_data += aom_usec_timer_elapsed(&timer);
#endif
- // Note: Regarding profile setting, the following checks are added to help
- // choose a proper profile for the input video. The criterion is that all
- // bitstreams must be designated as the lowest profile that match its content.
- // E.G. A bitstream that contains 4:4:4 video must be designated as High
- // Profile in the seq header, and likewise a bitstream that contains 4:2:2
- // bitstream must be designated as Professional Profile in the sequence
- // header.
- if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome &&
- (subsampling_x != 1 || subsampling_y != 1)) {
- aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
- "Non-4:2:0 color format requires profile 1 or 2");
- res = -1;
- }
- if ((seq_params->profile == PROFILE_1) &&
- !(subsampling_x == 0 && subsampling_y == 0)) {
- aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
- "Profile 1 requires 4:4:4 color format");
- res = -1;
- }
- if ((seq_params->profile == PROFILE_2) &&
- (seq_params->bit_depth <= AOM_BITS_10) &&
- !(subsampling_x == 1 && subsampling_y == 0)) {
- aom_set_error(cm->error, AOM_CODEC_INVALID_PARAM,
- "Profile 2 bit-depth <= 10 requires 4:2:2 color format");
- res = -1;
- }
-
return res;
}