History

Cap target bitrate to raw rate internally

BUG=webm:1685

Jerome Jiang committed 6 years ago

Commit 3e833dd1 parent a97e3326 files · +22 −13Browse files

Unified · Split

6 files
  1. test/realtime_test.cc +1 −6
  2. vp8/encoder/bitstream.c +1 −1
  3. vp8/encoder/onyx_if.c +6 −1
  4. vp9/encoder/vp9_pickmode.c +1 −1
  5. vp9/encoder/vp9_ratectrl.c +4 −2
  6. vp9/vp9_cx_iface.c +9 −2
test/realtime_test.cc+1−6
@@ -63,15 +63,10 @@ TEST_P(RealtimeTest, RealtimeFirstPassProducesFrames) { · 62 unmodified lines
6363 EXPECT_EQ(kFramesToEncode, frame_packets_);
6464 }
6565
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) {
7067 ::libvpx_test::RandomVideoSource video;
7168 video.SetSize(800, 480);
7269 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.
7570 cfg_.rc_target_bitrate = 140000000;
7671 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
7772 }
vp8/encoder/bitstream.c+1−1
@@ -222,7 +222,7 @@ void vp8_pack_tokens(vp8_writer *w, const TOKENEXTRA *p, int xcount) { · 221 unmodified lines
222222
223223 validate_buffer(w->buffer + w->pos, 1, w->buffer_end, w->error);
224224
225− w->buffer[w->pos++] = (lowvalue >> (24 - offset));
225+ w->buffer[w->pos++] = (lowvalue >> (24 - offset)) & 0xff;
226226 lowvalue <<= offset;
227227 shift = count;
228228 lowvalue &= 0xffffff;
vp8/encoder/onyx_if.c+6−1
@@ -1430,6 +1430,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { · 1429 unmodified lines
14301430 VP8_COMMON *cm = &cpi->common;
14311431 int last_w, last_h;
14321432 unsigned int prev_number_of_layers;
1433+ unsigned int raw_target_rate;
14331434
14341435 if (!cpi) return;
14351436
@@ -1570,6 +1571,10 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { · 134 unmodified lines
15701571 cpi->oxcf.maximum_buffer_size_in_ms = 240000;
15711572 }
15721573
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;
15731578 /* Convert target bandwidth from Kbit/s to Bit/s */
15741579 cpi->oxcf.target_bandwidth *= 1000;
15751580
@@ -3615,7 +3620,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, · 2039 unmodified lines
36153620 if (cpi->this_key_frame_forced) {
36163621 if (cpi->active_best_quality > cpi->avg_frame_qindex * 7 / 8) {
36173622 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)) {
36193624 cpi->active_best_quality = cpi->avg_frame_qindex >> 2;
36203625 }
36213626 }
vp9/encoder/vp9_pickmode.c+1−1
@@ -1127,7 +1127,7 @@ static INLINE void update_thresh_freq_fact_row_mt( · 1126 unmodified lines
11271127 }
11281128
11291129 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,
11311131 BLOCK_SIZE bsize, MV_REFERENCE_FRAME ref_frame, THR_MODES best_mode_idx,
11321132 PREDICTION_MODE mode) {
11331133 THR_MODES thr_mode_idx = mode_idx[ref_frame][mode_offset(mode)];
vp9/encoder/vp9_ratectrl.c+4−2
@@ -1695,8 +1695,10 @@ void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target, · 1694 unmodified lines
16951695 } else {
16961696 // For very small rate targets where the fractional adjustment
16971697 // 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);
17001702 *frame_under_shoot_limit = VPXMAX(frame_target - tol_low - 100, 0);
17011703 *frame_over_shoot_limit =
17021704 VPXMIN(frame_target + tol_high + 100, cpi->rc.max_frame_bandwidth);
vp9/vp9_cx_iface.c+9−2
@@ -470,10 +470,11 @@ static vpx_rational64_t get_g_timebase_in_ts(vpx_rational_t g_timebase) { · 469 unmodified lines
470470 }
471471
472472 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,
474474 const struct vp9_extracfg *extra_cfg) {
475475 const int is_vbr = cfg->rc_end_usage == VPX_VBR;
476476 int sl, tl;
477+ unsigned int raw_target_rate;
477478 oxcf->profile = cfg->g_profile;
478479 oxcf->max_threads = (int)cfg->g_threads;
479480 oxcf->width = cfg->g_w;
@@ -500,8 +501,14 @@ static vpx_codec_err_t set_encoder_config( · 20 unmodified lines
500501 cfg->g_pass == VPX_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames;
501502 oxcf->rc_mode = cfg->rc_end_usage;
502503
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+
503510 // 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;
505512 oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
506513 oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct;
507514 oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct;

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