diff options
author | James Zern <jzern@google.com> | 2022-05-27 21:50:11 -0700 |
---|---|---|
committer | Jerome Jiang <jianj@google.com> | 2022-06-03 10:18:21 -0400 |
commit | 6e7f6363965b959f026956903fcd2aeb55698110 (patch) | |
tree | 3649202c6c84e5cd2d465fda5be4b24d5567aec1 | |
parent | 386f25be5353978c28866e442f844f6bd2a1537e (diff) | |
download | libvpx-6e7f6363965b959f026956903fcd2aeb55698110.tar.gz |
vp9e_set_config: setjmp before calling vp9_change_config
vp9_change_config may call functions that perform allocations which
expect failures detected by CHECK_MEM_ERROR to not return.
Change-Id: I1dd1eca9c661ed157d51b4a6a77fc9f88236d794
(cherry picked from commit 3997d9bc6286ba075879353b87678986cdbfa347)
-rw-r--r-- | vp9/vp9_cx_iface.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index b809ab3e6..63d8f4487 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -780,7 +780,7 @@ static vpx_codec_err_t set_twopass_params_from_config( static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, const vpx_codec_enc_cfg_t *cfg) { vpx_codec_err_t res; - int force_key = 0; + volatile int force_key = 0; if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) { if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS) @@ -799,19 +799,28 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, ERROR("Cannot increase lag_in_frames"); res = validate_config(ctx, cfg, &ctx->extra_cfg); + if (res != VPX_CODEC_OK) return res; - if (res == VPX_CODEC_OK) { - ctx->cfg = *cfg; - set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); - set_twopass_params_from_config(&ctx->cfg, ctx->cpi); - // On profile change, request a key frame - force_key |= ctx->cpi->common.profile != ctx->oxcf.profile; - vp9_change_config(ctx->cpi, &ctx->oxcf); + if (setjmp(ctx->cpi->common.error.jmp)) { + const vpx_codec_err_t codec_err = + update_error_state(ctx, &ctx->cpi->common.error); + ctx->cpi->common.error.setjmp = 0; + vpx_clear_system_state(); + assert(codec_err != VPX_CODEC_OK); + return codec_err; } + ctx->cfg = *cfg; + set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); + set_twopass_params_from_config(&ctx->cfg, ctx->cpi); + // On profile change, request a key frame + force_key |= ctx->cpi->common.profile != ctx->oxcf.profile; + vp9_change_config(ctx->cpi, &ctx->oxcf); + if (force_key) ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF; - return res; + ctx->cpi->common.error.setjmp = 0; + return VPX_CODEC_OK; } static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx, |