BUG=webm:1685
Unified · Split
| @@ -63,15 +63,10 @@ TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) { · 62 unmodified lines | ||
| 63 | 63 | EXPECT_EQ(kFramesToEncode, frame_packets_); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | −// TODO(https://crbug.com/webm/1685): the following passes -fsanitize=undefined | |
| 67 | −// with bitrate set to 140000000 for vp8 and 128000 for vp9. There are | |
| 68 | −// additional failures with lower bitrates using -fsanitize=integer. | |
| 69 | −TEST_P(RealtimeTest, DISABLED_IntegerOverflow) { | |
| 66 | +TEST_P(RealtimeTest, IntegerOverflow) { | |
| 70 | 67 | ::libvpx_test::RandomVideoSource video; |
| 71 | 68 | video.SetSize(800, 480); |
| 72 | 69 | video.set_limit(20); |
| 73 | − // TODO(https://crbug.com/webm/1685): this should be silently capped | |
| 74 | − // internally to the raw yuv rate or below. | |
| 75 | 70 | cfg_.rc_target_bitrate = 140000000; |
| 76 | 71 | ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 77 | 72 | } |
| @@ -222,7 +222,7 @@ void vp8_pack_tokens(vp8_writer *w, const TOKENEXTRA *p, int xcount) { · 221 unmodified lines | ||
| 222 | 222 | |
| 223 | 223 | validate_buffer(w->buffer + w->pos, 1, w->buffer_end, w->error); |
| 224 | 224 | |
| 225 | − w->buffer[w->pos++] = (lowvalue >> (24 - offset)); | |
| 225 | + w->buffer[w->pos++] = (lowvalue >> (24 - offset)) & 0xff; | |
| 226 | 226 | lowvalue <<= offset; |
| 227 | 227 | shift = count; |
| 228 | 228 | lowvalue &= 0xffffff; |
| @@ -1430,6 +1430,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { · 1429 unmodified lines | ||
| 1430 | 1430 | VP8_COMMON *cm = &cpi->common; |
| 1431 | 1431 | int last_w, last_h; |
| 1432 | 1432 | unsigned int prev_number_of_layers; |
| 1433 | + unsigned int raw_target_rate; | |
| 1433 | 1434 | |
| 1434 | 1435 | if (!cpi) return; |
| 1435 | 1436 | |
| @@ -1570,6 +1571,10 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { · 134 unmodified lines | ||
| 1570 | 1571 | cpi->oxcf.maximum_buffer_size_in_ms = 240000; |
| 1571 | 1572 | } |
| 1572 | 1573 | |
| 1574 | + raw_target_rate = (unsigned int)((int64_t)cpi->oxcf.Width * cpi->oxcf.Height * | |
| 1575 | + 8 * 3 * cpi->framerate / 1000); | |
| 1576 | + if (cpi->oxcf.target_bandwidth > raw_target_rate) | |
| 1577 | + cpi->oxcf.target_bandwidth = raw_target_rate; | |
| 1573 | 1578 | /* Convert target bandwidth from Kbit/s to Bit/s */ |
| 1574 | 1579 | cpi->oxcf.target_bandwidth *= 1000; |
| 1575 | 1580 | |
| @@ -3615,7 +3620,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, · 2039 unmodified lines | ||
| 3615 | 3620 | if (cpi->this_key_frame_forced) { |
| 3616 | 3621 | if (cpi->active_best_quality > cpi->avg_frame_qindex * 7 / 8) { |
| 3617 | 3622 | cpi->active_best_quality = cpi->avg_frame_qindex * 7 / 8; |
| 3618 | − } else if (cpi->active_best_quality<cpi->avg_frame_qindex>> 2) { | |
| 3623 | + } else if (cpi->active_best_quality < (cpi->avg_frame_qindex >> 2)) { | |
| 3619 | 3624 | cpi->active_best_quality = cpi->avg_frame_qindex >> 2; |
| 3620 | 3625 | } |
| 3621 | 3626 | } |
| @@ -1127,7 +1127,7 @@ static INLINE void update_thresh_freq_fact_row_mt( · 1126 unmodified lines | ||
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | static INLINE void update_thresh_freq_fact( |
| 1130 | − VP9_COMP *cpi, TileDataEnc *tile_data, int source_variance, | |
| 1130 | + VP9_COMP *cpi, TileDataEnc *tile_data, unsigned int source_variance, | |
| 1131 | 1131 | BLOCK_SIZE bsize, MV_REFERENCE_FRAME ref_frame, THR_MODES best_mode_idx, |
| 1132 | 1132 | PREDICTION_MODE mode) { |
| 1133 | 1133 | THR_MODES thr_mode_idx = mode_idx[ref_frame][mode_offset(mode)]; |
| @@ -1695,8 +1695,10 @@ void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target, · 1694 unmodified lines | ||
| 1695 | 1695 | } else { |
| 1696 | 1696 | // For very small rate targets where the fractional adjustment |
| 1697 | 1697 | // may be tiny make sure there is at least a minimum range. |
| 1698 | − const int tol_low = (cpi->sf.recode_tolerance_low * frame_target) / 100; | |
| 1699 | − const int tol_high = (cpi->sf.recode_tolerance_high * frame_target) / 100; | |
| 1698 | + const int tol_low = | |
| 1699 | + (int)(((int64_t)cpi->sf.recode_tolerance_low * frame_target) / 100); | |
| 1700 | + const int tol_high = | |
| 1701 | + (int)(((int64_t)cpi->sf.recode_tolerance_high * frame_target) / 100); | |
| 1700 | 1702 | *frame_under_shoot_limit = VPXMAX(frame_target - tol_low - 100, 0); |
| 1701 | 1703 | *frame_over_shoot_limit = |
| 1702 | 1704 | VPXMIN(frame_target + tol_high + 100, cpi->rc.max_frame_bandwidth); |
| @@ -470,10 +470,11 @@ static vpx_rational64_t get_g_timebase_in_ts(vpx_rational_t g_timebase) { · 469 unmodified lines | ||
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | static vpx_codec_err_t set_encoder_config( |
| 473 | − VP9EncoderConfig *oxcf, const vpx_codec_enc_cfg_t *cfg, | |
| 473 | + VP9EncoderConfig *oxcf, vpx_codec_enc_cfg_t *cfg, | |
| 474 | 474 | const struct vp9_extracfg *extra_cfg) { |
| 475 | 475 | const int is_vbr = cfg->rc_end_usage == VPX_VBR; |
| 476 | 476 | int sl, tl; |
| 477 | + unsigned int raw_target_rate; | |
| 477 | 478 | oxcf->profile = cfg->g_profile; |
| 478 | 479 | oxcf->max_threads = (int)cfg->g_threads; |
| 479 | 480 | oxcf->width = cfg->g_w; |
| @@ -500,8 +501,14 @@ static vpx_codec_err_t set_encoder_config( · 20 unmodified lines | ||
| 500 | 501 | cfg->g_pass == VPX_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames; |
| 501 | 502 | oxcf->rc_mode = cfg->rc_end_usage; |
| 502 | 503 | |
| 504 | + raw_target_rate = | |
| 505 | + (unsigned int)((int64_t)oxcf->width * oxcf->height * oxcf->bit_depth * 3 * | |
| 506 | + oxcf->init_framerate / 1000); | |
| 507 | + // Cap target bitrate to raw rate | |
| 508 | + cfg->rc_target_bitrate = VPXMIN(raw_target_rate, cfg->rc_target_bitrate); | |
| 509 | + | |
| 503 | 510 | // Convert target bandwidth from Kbit/s to Bit/s |
| 504 | − oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate; | |
| 511 | + oxcf->target_bandwidth = 1000 * (int64_t)cfg->rc_target_bitrate; | |
| 505 | 512 | oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; |
| 506 | 513 | oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct; |
| 507 | 514 | oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct; |