History

Pass vizier rc parameter values with range check

This is similar to the change: https://chromium-review.googlesource.com/c/webm/libvpx/+/2771081 Which fails libvpx nightly test. Here we add range check to get rid of the warning of "divided by zero". BUG=webm:1723

Cheng Chen committed 5 years ago

Commit afe1ba71 parent 8b3e5752 files · +89 −24Browse files

Unified · Split

2 files
  1. vp8/vp8_cx_iface.c +25 −12
  2. vp9/vp9_cx_iface.c +64 −12
vp8/vp8_cx_iface.c+25−12
@@ -257,6 +257,19 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, · 256 unmodified lines
257257 ERROR("g_threads cannot be bigger than number of token partitions");
258258 #endif
259259
260+ // The range below shall be further tuned.
261+ RANGE_CHECK(cfg, active_wq_factor.den, 1, 1000);
262+ RANGE_CHECK(cfg, base_err_per_mb.den, 1, 1000);
263+ RANGE_CHECK(cfg, sr_default_decay_limit.den, 1, 1000);
264+ RANGE_CHECK(cfg, sr_diff_factor.den, 1, 1000);
265+ RANGE_CHECK(cfg, kf_err_per_mb.den, 1, 1000);
266+ RANGE_CHECK(cfg, kf_frame_min_boost.den, 1, 1000);
267+ RANGE_CHECK(cfg, kf_frame_max_boost_subs.den, 1, 1000);
268+ RANGE_CHECK(cfg, kf_max_total_boost.den, 1, 1000);
269+ RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000);
270+ RANGE_CHECK(cfg, gf_frame_max_boost.den, 1, 1000);
271+ RANGE_CHECK(cfg, zm_power_factor.den, 1, 1000);
272+
260273 return VPX_CODEC_OK;
261274 }
262275
@@ -1289,18 +1302,18 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = { · 1026 unmodified lines
12891302 { 0 }, /* ts_layer_id */
12901303 { 0 }, /* layer_target_bitrate */
12911304 0, /* temporal_layering_mode */
1292− { 0, 0 }, /* active_wq_factor */
1293− { 0, 0 }, /* base_err_per_mb */
1294− { 0, 0 }, /* sr_default_decay_limit */
1295− { 0, 0 }, /* sr_diff_factor */
1296− { 0, 0 }, /* kf_err_per_mb */
1297− { 0, 0 }, /* kf_frame_min_boost */
1298− { 0, 0 }, /* kf_frame_max_boost_first */
1299− { 0, 0 }, /* kf_frame_max_boost_subs */
1300− { 0, 0 }, /* kf_max_total_boost */
1301− { 0, 0 }, /* gf_max_total_boost */
1302− { 0, 0 }, /* gf_frame_max_boost */
1303− { 0, 0 }, /* zm_power_factor */
1305+ { 0, 1 }, /* active_wq_factor */
1306+ { 0, 1 }, /* base_err_per_mb */
1307+ { 0, 1 }, /* sr_default_decay_limit */
1308+ { 0, 1 }, /* sr_diff_factor */
1309+ { 0, 1 }, /* kf_err_per_mb */
1310+ { 0, 1 }, /* kf_frame_min_boost */
1311+ { 0, 1 }, /* kf_frame_max_boost_first */
1312+ { 0, 1 }, /* kf_frame_max_boost_subs */
1313+ { 0, 1 }, /* kf_max_total_boost */
1314+ { 0, 1 }, /* gf_max_total_boost */
1315+ { 0, 1 }, /* gf_frame_max_boost */
1316+ { 0, 1 }, /* zm_power_factor */
13041317 } },
13051318 };
13061319
vp9/vp9_cx_iface.c+64−12
@@ -348,6 +348,20 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, · 347 unmodified lines
348348 }
349349 RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);
350350 RANGE_CHECK(extra_cfg, color_range, VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);
351+
352+ // The range below shall be further tuned.
353+ RANGE_CHECK(cfg, active_wq_factor.den, 1, 1000);
354+ RANGE_CHECK(cfg, base_err_per_mb.den, 1, 1000);
355+ RANGE_CHECK(cfg, sr_default_decay_limit.den, 1, 1000);
356+ RANGE_CHECK(cfg, sr_diff_factor.den, 1, 1000);
357+ RANGE_CHECK(cfg, kf_err_per_mb.den, 1, 1000);
358+ RANGE_CHECK(cfg, kf_frame_min_boost.den, 1, 1000);
359+ RANGE_CHECK(cfg, kf_frame_max_boost_subs.den, 1, 1000);
360+ RANGE_CHECK(cfg, kf_max_total_boost.den, 1, 1000);
361+ RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000);
362+ RANGE_CHECK(cfg, gf_frame_max_boost.den, 1, 1000);
363+ RANGE_CHECK(cfg, zm_power_factor.den, 1, 1000);
364+
351365 return VPX_CODEC_OK;
352366 }
353367
@@ -638,6 +652,41 @@ static vpx_codec_err_t set_encoder_config( · 284 unmodified lines
638652 return VPX_CODEC_OK;
639653 }
640654
655+static vpx_codec_err_t set_twopass_params_from_config(
656+ const vpx_codec_enc_cfg_t *const cfg, struct VP9_COMP *cpi) {
657+ if (cpi == NULL) return VPX_CODEC_ERROR;
658+
659+ cpi->twopass.active_wq_factor =
660+ (double)cfg->active_wq_factor.num / (double)cfg->active_wq_factor.den;
661+ cpi->twopass.base_err_per_mb =
662+ (double)cfg->base_err_per_mb.num / (double)cfg->base_err_per_mb.den;
663+ cpi->twopass.sr_default_decay_limit =
664+ (double)cfg->sr_default_decay_limit.num /
665+ (double)cfg->sr_default_decay_limit.den;
666+ cpi->twopass.sr_diff_factor =
667+ (double)cfg->sr_diff_factor.num / (double)cfg->sr_diff_factor.den;
668+ cpi->twopass.kf_err_per_mb =
669+ (double)cfg->kf_err_per_mb.num / (double)cfg->kf_err_per_mb.den;
670+ cpi->twopass.kf_frame_min_boost =
671+ (double)cfg->kf_frame_min_boost.num / (double)cfg->kf_frame_min_boost.den;
672+ cpi->twopass.kf_frame_max_boost_first =
673+ (double)cfg->kf_frame_max_boost_first.num /
674+ (double)cfg->kf_frame_max_boost_first.den;
675+ cpi->twopass.kf_frame_max_boost_subs =
676+ (double)cfg->kf_frame_max_boost_subs.num /
677+ (double)cfg->kf_frame_max_boost_subs.den;
678+ cpi->twopass.kf_max_total_boost = (int)((double)cfg->kf_max_total_boost.num /
679+ (double)cfg->kf_max_total_boost.den);
680+ cpi->twopass.gf_max_total_boost = (int)((double)cfg->gf_max_total_boost.num /
681+ (double)cfg->gf_max_total_boost.den);
682+ cpi->twopass.gf_frame_max_boost =
683+ (double)cfg->gf_frame_max_boost.num / (double)cfg->gf_frame_max_boost.den;
684+ cpi->twopass.zm_power_factor =
685+ (double)cfg->zm_power_factor.num / (double)cfg->zm_power_factor.den;
686+
687+ return VPX_CODEC_OK;
688+}
689+
641690 static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
642691 const vpx_codec_enc_cfg_t *cfg) {
643692 vpx_codec_err_t res;
@@ -664,6 +713,7 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, · 20 unmodified lines
664713 if (res == VPX_CODEC_OK) {
665714 ctx->cfg = *cfg;
666715 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
716+ set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
667717 // On profile change, request a key frame
668718 force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
669719 vp9_change_config(ctx->cpi, &ctx->oxcf);
@@ -696,6 +746,7 @@ static vpx_codec_err_t update_extra_cfg(vpx_codec_alg_priv_t *ctx, · 26 unmodified lines
696746 if (res == VPX_CODEC_OK) {
697747 ctx->extra_cfg = *extra_cfg;
698748 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
749+ set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
699750 vp9_change_config(ctx->cpi, &ctx->oxcf);
700751 }
701752 return res;
@@ -940,6 +991,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, · 238 unmodified lines
940991 #endif
941992 priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);
942993 if (priv->cpi == NULL) res = VPX_CODEC_MEM_ERROR;
994+ set_twopass_params_from_config(&priv->cfg, priv->cpi);
943995 }
944996 }
945997
@@ -1891,18 +1943,18 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { · 945 unmodified lines
18911943 { 0 }, // ts_layer_id
18921944 { 0 }, // layer_taget_bitrate
18931945 0, // temporal_layering_mode
1894− { 0, 0 }, // active_wq_factor
1895− { 0, 0 }, // base_err_per_mb
1896− { 0, 0 }, // sr_default_decay_limit
1897− { 0, 0 }, // sr_diff_factor
1898− { 0, 0 }, // kf_err_per_mb
1899− { 0, 0 }, // kf_frame_min_boost
1900− { 0, 0 }, // kf_frame_max_boost_first
1901− { 0, 0 }, // kf_frame_max_boost_subs
1902− { 0, 0 }, // kf_max_total_boost
1903− { 0, 0 }, // gf_max_total_boost
1904− { 0, 0 }, // gf_frame_max_boost
1905− { 0, 0 }, // zm_power_factor
1946+ { 0, 1 }, // active_wq_factor
1947+ { 0, 1 }, // base_err_per_mb
1948+ { 0, 1 }, // sr_default_decay_limit
1949+ { 0, 1 }, // sr_diff_factor
1950+ { 0, 1 }, // kf_err_per_mb
1951+ { 0, 1 }, // kf_frame_min_boost
1952+ { 0, 1 }, // kf_frame_max_boost_first
1953+ { 0, 1 }, // kf_frame_max_boost_subs
1954+ { 0, 1 }, // kf_max_total_boost
1955+ { 0, 1 }, // gf_max_total_boost
1956+ { 0, 1 }, // gf_frame_max_boost
1957+ { 0, 1 }, // zm_power_factor
19061958 } },
19071959 };
19081960

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t