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
257 ERROR("g_threads cannot be bigger than number of token partitions");257 ERROR("g_threads cannot be bigger than number of token partitions");
258#endif258#endif
259 259
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
260 return VPX_CODEC_OK;273 return VPX_CODEC_OK;
261}274}
262 275
@@ -1289,18 +1302,18 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = { · 1026 unmodified lines
1289 { 0 }, /* ts_layer_id */1302 { 0 }, /* ts_layer_id */
1290 { 0 }, /* layer_target_bitrate */1303 { 0 }, /* layer_target_bitrate */
1291 0, /* temporal_layering_mode */1304 0, /* temporal_layering_mode */
1292 { 0, 0 }, /* active_wq_factor */1305 { 0, 1 }, /* active_wq_factor */
1293 { 0, 0 }, /* base_err_per_mb */1306 { 0, 1 }, /* base_err_per_mb */
1294 { 0, 0 }, /* sr_default_decay_limit */1307 { 0, 1 }, /* sr_default_decay_limit */
1295 { 0, 0 }, /* sr_diff_factor */1308 { 0, 1 }, /* sr_diff_factor */
1296 { 0, 0 }, /* kf_err_per_mb */1309 { 0, 1 }, /* kf_err_per_mb */
1297 { 0, 0 }, /* kf_frame_min_boost */1310 { 0, 1 }, /* kf_frame_min_boost */
1298 { 0, 0 }, /* kf_frame_max_boost_first */1311 { 0, 1 }, /* kf_frame_max_boost_first */
1299 { 0, 0 }, /* kf_frame_max_boost_subs */1312 { 0, 1 }, /* kf_frame_max_boost_subs */
1300 { 0, 0 }, /* kf_max_total_boost */1313 { 0, 1 }, /* kf_max_total_boost */
1301 { 0, 0 }, /* gf_max_total_boost */1314 { 0, 1 }, /* gf_max_total_boost */
1302 { 0, 0 }, /* gf_frame_max_boost */1315 { 0, 1 }, /* gf_frame_max_boost */
1303 { 0, 0 }, /* zm_power_factor */1316 { 0, 1 }, /* zm_power_factor */
1304 } },1317 } },
1305};1318};
1306 1319
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
348 }348 }
349 RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);349 RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);
350 RANGE_CHECK(extra_cfg, color_range, VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);350 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
351 return VPX_CODEC_OK;365 return VPX_CODEC_OK;
352}366}
353 367
@@ -638,6 +652,41 @@ static vpx_codec_err_t set_encoder_config( · 284 unmodified lines
638 return VPX_CODEC_OK;652 return VPX_CODEC_OK;
639}653}
640 654
655static 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
641static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,690static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
642 const vpx_codec_enc_cfg_t *cfg) {691 const vpx_codec_enc_cfg_t *cfg) {
643 vpx_codec_err_t res;692 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
664 if (res == VPX_CODEC_OK) {713 if (res == VPX_CODEC_OK) {
665 ctx->cfg = *cfg;714 ctx->cfg = *cfg;
666 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);715 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
716 set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
667 // On profile change, request a key frame717 // On profile change, request a key frame
668 force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;718 force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
669 vp9_change_config(ctx->cpi, &ctx->oxcf);719 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
696 if (res == VPX_CODEC_OK) {746 if (res == VPX_CODEC_OK) {
697 ctx->extra_cfg = *extra_cfg;747 ctx->extra_cfg = *extra_cfg;
698 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);748 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
749 set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
699 vp9_change_config(ctx->cpi, &ctx->oxcf);750 vp9_change_config(ctx->cpi, &ctx->oxcf);
700 }751 }
701 return res;752 return res;
@@ -940,6 +991,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, · 238 unmodified lines
940#endif991#endif
941 priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);992 priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);
942 if (priv->cpi == NULL) res = VPX_CODEC_MEM_ERROR;993 if (priv->cpi == NULL) res = VPX_CODEC_MEM_ERROR;
994 set_twopass_params_from_config(&priv->cfg, priv->cpi);
943 }995 }
944 }996 }
945 997
@@ -1891,18 +1943,18 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { · 945 unmodified lines
1891 { 0 }, // ts_layer_id1943 { 0 }, // ts_layer_id
1892 { 0 }, // layer_taget_bitrate1944 { 0 }, // layer_taget_bitrate
1893 0, // temporal_layering_mode1945 0, // temporal_layering_mode
1894 { 0, 0 }, // active_wq_factor1946 { 0, 1 }, // active_wq_factor
1895 { 0, 0 }, // base_err_per_mb1947 { 0, 1 }, // base_err_per_mb
1896 { 0, 0 }, // sr_default_decay_limit1948 { 0, 1 }, // sr_default_decay_limit
1897 { 0, 0 }, // sr_diff_factor1949 { 0, 1 }, // sr_diff_factor
1898 { 0, 0 }, // kf_err_per_mb1950 { 0, 1 }, // kf_err_per_mb
1899 { 0, 0 }, // kf_frame_min_boost1951 { 0, 1 }, // kf_frame_min_boost
1900 { 0, 0 }, // kf_frame_max_boost_first1952 { 0, 1 }, // kf_frame_max_boost_first
1901 { 0, 0 }, // kf_frame_max_boost_subs1953 { 0, 1 }, // kf_frame_max_boost_subs
1902 { 0, 0 }, // kf_max_total_boost1954 { 0, 1 }, // kf_max_total_boost
1903 { 0, 0 }, // gf_max_total_boost1955 { 0, 1 }, // gf_max_total_boost
1904 { 0, 0 }, // gf_frame_max_boost1956 { 0, 1 }, // gf_frame_max_boost
1905 { 0, 0 }, // zm_power_factor1957 { 0, 1 }, // zm_power_factor
1906 } },1958 } },
1907};1959};
1908 1960

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