Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c

Issue 1217053002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.h ('k') | source/libvpx/vp9/encoder/vp9_avg.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 21 matching lines...) Expand all
32 int time_for_refresh; 32 int time_for_refresh;
33 // Target number of (8x8) blocks that are set for delta-q. 33 // Target number of (8x8) blocks that are set for delta-q.
34 int target_num_seg_blocks; 34 int target_num_seg_blocks;
35 // Actual number of (8x8) blocks that were applied delta-q. 35 // Actual number of (8x8) blocks that were applied delta-q.
36 int actual_num_seg1_blocks; 36 int actual_num_seg1_blocks;
37 int actual_num_seg2_blocks; 37 int actual_num_seg2_blocks;
38 // RD mult. parameters for segment 1. 38 // RD mult. parameters for segment 1.
39 int rdmult; 39 int rdmult;
40 // Cyclic refresh map. 40 // Cyclic refresh map.
41 signed char *map; 41 signed char *map;
42 // Map of the last q a block was coded at.
43 uint8_t *last_coded_q_map;
42 // Thresholds applied to the projected rate/distortion of the coding block, 44 // Thresholds applied to the projected rate/distortion of the coding block,
43 // when deciding whether block should be refreshed. 45 // when deciding whether block should be refreshed.
44 int64_t thresh_rate_sb; 46 int64_t thresh_rate_sb;
45 int64_t thresh_dist_sb; 47 int64_t thresh_dist_sb;
46 // Threshold applied to the motion vector (in units of 1/8 pel) of the 48 // Threshold applied to the motion vector (in units of 1/8 pel) of the
47 // coding block, when deciding whether block should be refreshed. 49 // coding block, when deciding whether block should be refreshed.
48 int16_t motion_thresh; 50 int16_t motion_thresh;
49 // Rate target ratio to set q delta. 51 // Rate target ratio to set q delta.
50 double rate_ratio_qdelta; 52 double rate_ratio_qdelta;
53 // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
54 int rate_boost_fac;
51 double low_content_avg; 55 double low_content_avg;
52 int qindex_delta_seg1; 56 int qindex_delta[3];
53 int qindex_delta_seg2;
54 }; 57 };
55 58
56 CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) { 59 CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) {
60 size_t last_coded_q_map_size;
57 CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr)); 61 CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr));
58 if (cr == NULL) 62 if (cr == NULL)
59 return NULL; 63 return NULL;
60 64
61 cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map)); 65 cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map));
62 if (cr->map == NULL) { 66 if (cr->map == NULL) {
63 vpx_free(cr); 67 vpx_free(cr);
64 return NULL; 68 return NULL;
65 } 69 }
70 last_coded_q_map_size = mi_rows * mi_cols * sizeof(*cr->last_coded_q_map);
71 cr->last_coded_q_map = vpx_malloc(last_coded_q_map_size);
72 if (cr->last_coded_q_map == NULL) {
73 vpx_free(cr);
74 return NULL;
75 }
76 assert(MAXQ <= 255);
77 memset(cr->last_coded_q_map, MAXQ, last_coded_q_map_size);
66 78
67 return cr; 79 return cr;
68 } 80 }
69 81
70 void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr) { 82 void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr) {
71 vpx_free(cr->map); 83 vpx_free(cr->map);
84 vpx_free(cr->last_coded_q_map);
72 vpx_free(cr); 85 vpx_free(cr);
73 } 86 }
74 87
75 // Check if we should turn off cyclic refresh based on bitrate condition. 88 // Check if we should turn off cyclic refresh based on bitrate condition.
76 static int apply_cyclic_refresh_bitrate(const VP9_COMMON *cm, 89 static int apply_cyclic_refresh_bitrate(const VP9_COMMON *cm,
77 const RATE_CONTROL *rc) { 90 const RATE_CONTROL *rc) {
78 // Turn off cyclic refresh if bits available per frame is not sufficiently 91 // Turn off cyclic refresh if bits available per frame is not sufficiently
79 // larger than bit cost of segmentation. Segment map bit cost should scale 92 // larger than bit cost of segmentation. Segment map bit cost should scale
80 // with number of seg blocks, so compare available bits to number of blocks. 93 // with number of seg blocks, so compare available bits to number of blocks.
81 // Average bits available per frame = avg_frame_bandwidth 94 // Average bits available per frame = avg_frame_bandwidth
(...skipping 27 matching lines...) Expand all
109 // 2) mode is an intra-mode 122 // 2) mode is an intra-mode
110 // Otherwise accept for refresh. 123 // Otherwise accept for refresh.
111 if (dist > cr->thresh_dist_sb && 124 if (dist > cr->thresh_dist_sb &&
112 (mv.row > cr->motion_thresh || mv.row < -cr->motion_thresh || 125 (mv.row > cr->motion_thresh || mv.row < -cr->motion_thresh ||
113 mv.col > cr->motion_thresh || mv.col < -cr->motion_thresh || 126 mv.col > cr->motion_thresh || mv.col < -cr->motion_thresh ||
114 !is_inter_block(mbmi))) 127 !is_inter_block(mbmi)))
115 return CR_SEGMENT_ID_BASE; 128 return CR_SEGMENT_ID_BASE;
116 else if (bsize >= BLOCK_16X16 && 129 else if (bsize >= BLOCK_16X16 &&
117 rate < cr->thresh_rate_sb && 130 rate < cr->thresh_rate_sb &&
118 is_inter_block(mbmi) && 131 is_inter_block(mbmi) &&
119 mbmi->mv[0].as_int == 0) 132 mbmi->mv[0].as_int == 0 &&
133 cr->rate_boost_fac > 10)
120 // More aggressive delta-q for bigger blocks with zero motion. 134 // More aggressive delta-q for bigger blocks with zero motion.
121 return CR_SEGMENT_ID_BOOST2; 135 return CR_SEGMENT_ID_BOOST2;
122 else 136 else
123 return CR_SEGMENT_ID_BOOST1; 137 return CR_SEGMENT_ID_BOOST1;
124 } 138 }
125 139
126 // Compute delta-q for the segment. 140 // Compute delta-q for the segment.
127 static int compute_deltaq(const VP9_COMP *cpi, int q, double rate_factor) { 141 static int compute_deltaq(const VP9_COMP *cpi, int q, double rate_factor) {
128 const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; 142 const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
129 const RATE_CONTROL *const rc = &cpi->rc; 143 const RATE_CONTROL *const rc = &cpi->rc;
(...skipping 20 matching lines...) Expand all
150 // Weight for non-base segments: use actual number of blocks refreshed in 164 // Weight for non-base segments: use actual number of blocks refreshed in
151 // previous/just encoded frame. Note number of blocks here is in 8x8 units. 165 // previous/just encoded frame. Note number of blocks here is in 8x8 units.
152 double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl; 166 double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl;
153 double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl; 167 double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl;
154 // Take segment weighted average for estimated bits. 168 // Take segment weighted average for estimated bits.
155 estimated_bits = (int)((1.0 - weight_segment1 - weight_segment2) * 169 estimated_bits = (int)((1.0 - weight_segment1 - weight_segment2) *
156 vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs, 170 vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs,
157 correction_factor, cm->bit_depth) + 171 correction_factor, cm->bit_depth) +
158 weight_segment1 * 172 weight_segment1 *
159 vp9_estimate_bits_at_q(cm->frame_type, 173 vp9_estimate_bits_at_q(cm->frame_type,
160 cm->base_qindex + cr->qindex_delta_seg1, mbs, 174 cm->base_qindex + cr->qindex_delta[1], mbs,
161 correction_factor, cm->bit_depth) + 175 correction_factor, cm->bit_depth) +
162 weight_segment2 * 176 weight_segment2 *
163 vp9_estimate_bits_at_q(cm->frame_type, 177 vp9_estimate_bits_at_q(cm->frame_type,
164 cm->base_qindex + cr->qindex_delta_seg2, mbs, 178 cm->base_qindex + cr->qindex_delta[2], mbs,
165 correction_factor, cm->bit_depth)); 179 correction_factor, cm->bit_depth));
166 return estimated_bits; 180 return estimated_bits;
167 } 181 }
168 182
169 // Prior to encoding the frame, estimate the bits per mb, for a given q = i and 183 // Prior to encoding the frame, estimate the bits per mb, for a given q = i and
170 // a corresponding delta-q (for segment 1). This function is called in the 184 // a corresponding delta-q (for segment 1). This function is called in the
171 // rc_regulate_q() to set the base qp index. 185 // rc_regulate_q() to set the base qp index.
172 // Note: the segment map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or 186 // Note: the segment map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or
173 // to 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock, prior to encoding. 187 // to 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock, prior to encoding.
174 int vp9_cyclic_refresh_rc_bits_per_mb(const VP9_COMP *cpi, int i, 188 int vp9_cyclic_refresh_rc_bits_per_mb(const VP9_COMP *cpi, int i,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 new_map_value = 0; 253 new_map_value = 0;
240 } else { 254 } else {
241 // Leave it marked as block that is not candidate for refresh. 255 // Leave it marked as block that is not candidate for refresh.
242 new_map_value = 1; 256 new_map_value = 1;
243 } 257 }
244 258
245 // Update entries in the cyclic refresh map with new_map_value, and 259 // Update entries in the cyclic refresh map with new_map_value, and
246 // copy mbmi->segment_id into global segmentation map. 260 // copy mbmi->segment_id into global segmentation map.
247 for (y = 0; y < ymis; y++) 261 for (y = 0; y < ymis; y++)
248 for (x = 0; x < xmis; x++) { 262 for (x = 0; x < xmis; x++) {
249 cr->map[block_index + y * cm->mi_cols + x] = new_map_value; 263 int map_offset = block_index + y * cm->mi_cols + x;
250 cpi->segmentation_map[block_index + y * cm->mi_cols + x] = 264 cr->map[map_offset] = new_map_value;
251 mbmi->segment_id; 265 cpi->segmentation_map[map_offset] = mbmi->segment_id;
266 // Inter skip blocks were clearly not coded at the current qindex, so
267 // don't update the map for them. For cases where motion is non-zero or
268 // the reference frame isn't the previous frame, the previous value in
269 // the map for this spatial location is not entirely correct.
270 if (!is_inter_block(mbmi) || !skip)
271 cr->last_coded_q_map[map_offset] = clamp(
272 cm->base_qindex + cr->qindex_delta[mbmi->segment_id], 0, MAXQ);
252 } 273 }
253 } 274 }
254 275
255 // Update the actual number of blocks that were applied the segment delta q. 276 // Update the actual number of blocks that were applied the segment delta q.
256 void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) { 277 void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) {
257 VP9_COMMON *const cm = &cpi->common; 278 VP9_COMMON *const cm = &cpi->common;
258 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; 279 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
259 unsigned char *const seg_map = cpi->segmentation_map; 280 unsigned char *const seg_map = cpi->segmentation_map;
260 int mi_row, mi_col; 281 int mi_row, mi_col;
261 cr->actual_num_seg1_blocks = 0; 282 cr->actual_num_seg1_blocks = 0;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 assert(cr->sb_index < sbs_in_frame); 396 assert(cr->sb_index < sbs_in_frame);
376 i = cr->sb_index; 397 i = cr->sb_index;
377 cr->target_num_seg_blocks = 0; 398 cr->target_num_seg_blocks = 0;
378 do { 399 do {
379 int sum_map = 0; 400 int sum_map = 0;
380 // Get the mi_row/mi_col corresponding to superblock index i. 401 // Get the mi_row/mi_col corresponding to superblock index i.
381 int sb_row_index = (i / sb_cols); 402 int sb_row_index = (i / sb_cols);
382 int sb_col_index = i - sb_row_index * sb_cols; 403 int sb_col_index = i - sb_row_index * sb_cols;
383 int mi_row = sb_row_index * MI_BLOCK_SIZE; 404 int mi_row = sb_row_index * MI_BLOCK_SIZE;
384 int mi_col = sb_col_index * MI_BLOCK_SIZE; 405 int mi_col = sb_col_index * MI_BLOCK_SIZE;
406 int qindex_thresh =
407 cpi->oxcf.content == VP9E_CONTENT_SCREEN
408 ? vp9_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST2, cm->base_qindex)
409 : 0;
385 assert(mi_row >= 0 && mi_row < cm->mi_rows); 410 assert(mi_row >= 0 && mi_row < cm->mi_rows);
386 assert(mi_col >= 0 && mi_col < cm->mi_cols); 411 assert(mi_col >= 0 && mi_col < cm->mi_cols);
387 bl_index = mi_row * cm->mi_cols + mi_col; 412 bl_index = mi_row * cm->mi_cols + mi_col;
388 // Loop through all 8x8 blocks in superblock and update map. 413 // Loop through all 8x8 blocks in superblock and update map.
389 xmis = MIN(cm->mi_cols - mi_col, 414 xmis = MIN(cm->mi_cols - mi_col,
390 num_8x8_blocks_wide_lookup[BLOCK_64X64]); 415 num_8x8_blocks_wide_lookup[BLOCK_64X64]);
391 ymis = MIN(cm->mi_rows - mi_row, 416 ymis = MIN(cm->mi_rows - mi_row,
392 num_8x8_blocks_high_lookup[BLOCK_64X64]); 417 num_8x8_blocks_high_lookup[BLOCK_64X64]);
393 for (y = 0; y < ymis; y++) { 418 for (y = 0; y < ymis; y++) {
394 for (x = 0; x < xmis; x++) { 419 for (x = 0; x < xmis; x++) {
395 const int bl_index2 = bl_index + y * cm->mi_cols + x; 420 const int bl_index2 = bl_index + y * cm->mi_cols + x;
396 // If the block is as a candidate for clean up then mark it 421 // If the block is as a candidate for clean up then mark it
397 // for possible boost/refresh (segment 1). The segment id may get 422 // for possible boost/refresh (segment 1). The segment id may get
398 // reset to 0 later if block gets coded anything other than ZEROMV. 423 // reset to 0 later if block gets coded anything other than ZEROMV.
399 if (cr->map[bl_index2] == 0) { 424 if (cr->map[bl_index2] == 0) {
400 sum_map++; 425 if (cr->last_coded_q_map[bl_index2] > qindex_thresh)
426 sum_map++;
401 } else if (cr->map[bl_index2] < 0) { 427 } else if (cr->map[bl_index2] < 0) {
402 cr->map[bl_index2]++; 428 cr->map[bl_index2]++;
403 } 429 }
404 } 430 }
405 } 431 }
406 // Enforce constant segment over superblock. 432 // Enforce constant segment over superblock.
407 // If segment is at least half of superblock, set to 1. 433 // If segment is at least half of superblock, set to 1.
408 if (sum_map >= xmis * ymis / 2) { 434 if (sum_map >= xmis * ymis / 2) {
409 for (y = 0; y < ymis; y++) 435 for (y = 0; y < ymis; y++)
410 for (x = 0; x < xmis; x++) { 436 for (x = 0; x < xmis; x++) {
411 seg_map[bl_index + y * cm->mi_cols + x] = CR_SEGMENT_ID_BOOST1; 437 seg_map[bl_index + y * cm->mi_cols + x] = CR_SEGMENT_ID_BOOST1;
412 } 438 }
413 cr->target_num_seg_blocks += xmis * ymis; 439 cr->target_num_seg_blocks += xmis * ymis;
414 } 440 }
415 i++; 441 i++;
416 if (i == sbs_in_frame) { 442 if (i == sbs_in_frame) {
417 i = 0; 443 i = 0;
418 } 444 }
419 } while (cr->target_num_seg_blocks < block_count && i != cr->sb_index); 445 } while (cr->target_num_seg_blocks < block_count && i != cr->sb_index);
420 cr->sb_index = i; 446 cr->sb_index = i;
421 } 447 }
422 448
423 // Set/update global/frame level cyclic refresh parameters. 449 // Set cyclic refresh parameters.
424 void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) { 450 void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) {
425 const RATE_CONTROL *const rc = &cpi->rc; 451 const RATE_CONTROL *const rc = &cpi->rc;
452 const VP9_COMMON *const cm = &cpi->common;
426 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; 453 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
427 cr->percent_refresh = 10; 454 cr->percent_refresh = 10;
455 cr->max_qdelta_perc = 50;
456 cr->time_for_refresh = 0;
428 // Use larger delta-qp (increase rate_ratio_qdelta) for first few (~4) 457 // Use larger delta-qp (increase rate_ratio_qdelta) for first few (~4)
429 // periods of the refresh cycle, after a key frame. This corresponds to ~40 458 // periods of the refresh cycle, after a key frame.
430 // frames with cr->percent_refresh = 10. 459 if (rc->frames_since_key < 4 * cr->percent_refresh)
431 if (rc->frames_since_key < 40)
432 cr->rate_ratio_qdelta = 3.0; 460 cr->rate_ratio_qdelta = 3.0;
433 else 461 else
434 cr->rate_ratio_qdelta = 2.0; 462 cr->rate_ratio_qdelta = 2.0;
463 // Adjust some parameters for low resolutions at low bitrates.
464 if (cm->width <= 352 &&
465 cm->height <= 288 &&
466 rc->avg_frame_bandwidth < 3400) {
467 cr->motion_thresh = 4;
468 cr->rate_boost_fac = 10;
469 } else {
470 cr->motion_thresh = 32;
471 cr->rate_boost_fac = 17;
472 }
435 } 473 }
436 474
437 // Setup cyclic background refresh: set delta q and segmentation map. 475 // Setup cyclic background refresh: set delta q and segmentation map.
438 void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { 476 void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) {
439 VP9_COMMON *const cm = &cpi->common; 477 VP9_COMMON *const cm = &cpi->common;
440 const RATE_CONTROL *const rc = &cpi->rc; 478 const RATE_CONTROL *const rc = &cpi->rc;
441 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; 479 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
442 struct segmentation *const seg = &cm->seg; 480 struct segmentation *const seg = &cm->seg;
443 const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc); 481 const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc);
444 if (cm->current_video_frame == 0) 482 if (cm->current_video_frame == 0)
445 cr->low_content_avg = 0.0; 483 cr->low_content_avg = 0.0;
446 // Don't apply refresh on key frame or enhancement layer frames. 484 // Don't apply refresh on key frame or enhancement layer frames.
447 if (!apply_cyclic_refresh || 485 if (!apply_cyclic_refresh ||
448 (cm->frame_type == KEY_FRAME) || 486 (cm->frame_type == KEY_FRAME) ||
449 (cpi->svc.temporal_layer_id > 0) || 487 (cpi->svc.temporal_layer_id > 0) ||
450 (cpi->svc.spatial_layer_id > 0)) { 488 (cpi->svc.spatial_layer_id > 0)) {
451 // Set segmentation map to 0 and disable. 489 // Set segmentation map to 0 and disable.
452 unsigned char *const seg_map = cpi->segmentation_map; 490 unsigned char *const seg_map = cpi->segmentation_map;
453 memset(seg_map, 0, cm->mi_rows * cm->mi_cols); 491 memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
454 vp9_disable_segmentation(&cm->seg); 492 vp9_disable_segmentation(&cm->seg);
455 if (cm->frame_type == KEY_FRAME) 493 if (cm->frame_type == KEY_FRAME) {
494 memset(cr->last_coded_q_map, MAXQ,
495 cm->mi_rows * cm->mi_cols * sizeof(*cr->last_coded_q_map));
456 cr->sb_index = 0; 496 cr->sb_index = 0;
497 }
457 return; 498 return;
458 } else { 499 } else {
459 int qindex_delta = 0; 500 int qindex_delta = 0;
460 int qindex2; 501 int qindex2;
461 const double q = vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth); 502 const double q = vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth);
462 vp9_clear_system_state(); 503 vp9_clear_system_state();
463 cr->max_qdelta_perc = 50;
464 cr->time_for_refresh = 0;
465 // Set rate threshold to some multiple (set to 2 for now) of the target 504 // Set rate threshold to some multiple (set to 2 for now) of the target
466 // rate (target is given by sb64_target_rate and scaled by 256). 505 // rate (target is given by sb64_target_rate and scaled by 256).
467 cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 2; 506 cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 2;
468 // Distortion threshold, quadratic in Q, scale factor to be adjusted. 507 // Distortion threshold, quadratic in Q, scale factor to be adjusted.
469 // q will not exceed 457, so (q * q) is within 32bit; see: 508 // q will not exceed 457, so (q * q) is within 32bit; see:
470 // vp9_convert_qindex_to_q(), vp9_ac_quant(), ac_qlookup*[]. 509 // vp9_convert_qindex_to_q(), vp9_ac_quant(), ac_qlookup*[].
471 cr->thresh_dist_sb = ((int64_t)(q * q)) << 2; 510 cr->thresh_dist_sb = ((int64_t)(q * q)) << 2;
472 cr->motion_thresh = 32; 511
473 // Set up segmentation. 512 // Set up segmentation.
474 // Clear down the segment map. 513 // Clear down the segment map.
475 vp9_enable_segmentation(&cm->seg); 514 vp9_enable_segmentation(&cm->seg);
476 vp9_clearall_segfeatures(seg); 515 vp9_clearall_segfeatures(seg);
477 // Select delta coding method. 516 // Select delta coding method.
478 seg->abs_delta = SEGMENT_DELTADATA; 517 seg->abs_delta = SEGMENT_DELTADATA;
479 518
480 // Note: setting temporal_update has no effect, as the seg-map coding method 519 // Note: setting temporal_update has no effect, as the seg-map coding method
481 // (temporal or spatial) is determined in vp9_choose_segmap_coding_method(), 520 // (temporal or spatial) is determined in vp9_choose_segmap_coding_method(),
482 // based on the coding cost of each method. For error_resilient mode on the 521 // based on the coding cost of each method. For error_resilient mode on the
483 // last_frame_seg_map is set to 0, so if temporal coding is used, it is 522 // last_frame_seg_map is set to 0, so if temporal coding is used, it is
484 // relative to 0 previous map. 523 // relative to 0 previous map.
485 // seg->temporal_update = 0; 524 // seg->temporal_update = 0;
486 525
487 // Segment BASE "Q" feature is disabled so it defaults to the baseline Q. 526 // Segment BASE "Q" feature is disabled so it defaults to the baseline Q.
488 vp9_disable_segfeature(seg, CR_SEGMENT_ID_BASE, SEG_LVL_ALT_Q); 527 vp9_disable_segfeature(seg, CR_SEGMENT_ID_BASE, SEG_LVL_ALT_Q);
489 // Use segment BOOST1 for in-frame Q adjustment. 528 // Use segment BOOST1 for in-frame Q adjustment.
490 vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q); 529 vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q);
491 // Use segment BOOST2 for more aggressive in-frame Q adjustment. 530 // Use segment BOOST2 for more aggressive in-frame Q adjustment.
492 vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q); 531 vp9_enable_segfeature(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q);
493 532
494 // Set the q delta for segment BOOST1. 533 // Set the q delta for segment BOOST1.
495 qindex_delta = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta); 534 qindex_delta = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta);
496 cr->qindex_delta_seg1 = qindex_delta; 535 cr->qindex_delta[1] = qindex_delta;
497 536
498 // Compute rd-mult for segment BOOST1. 537 // Compute rd-mult for segment BOOST1.
499 qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ); 538 qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ);
500 539
501 cr->rdmult = vp9_compute_rd_mult(cpi, qindex2); 540 cr->rdmult = vp9_compute_rd_mult(cpi, qindex2);
502 541
503 vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q, qindex_delta); 542 vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q, qindex_delta);
504 543
505 // Set a more aggressive (higher) q delta for segment BOOST2. 544 // Set a more aggressive (higher) q delta for segment BOOST2.
506 qindex_delta = compute_deltaq(cpi, cm->base_qindex, 545 qindex_delta = compute_deltaq(
507 MIN(CR_MAX_RATE_TARGET_RATIO, 546 cpi, cm->base_qindex, MIN(CR_MAX_RATE_TARGET_RATIO,
508 CR_BOOST2_FAC * cr->rate_ratio_qdelta)); 547 0.1 * cr->rate_boost_fac * cr->rate_ratio_qdelta));
509 cr->qindex_delta_seg2 = qindex_delta; 548 cr->qindex_delta[2] = qindex_delta;
510 vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q, qindex_delta); 549 vp9_set_segdata(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q, qindex_delta);
511 550
512 // Update the segmentation and refresh map. 551 // Update the segmentation and refresh map.
513 cyclic_refresh_update_map(cpi); 552 cyclic_refresh_update_map(cpi);
514 } 553 }
515 } 554 }
516 555
517 int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) { 556 int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) {
518 return cr->rdmult; 557 return cr->rdmult;
519 } 558 }
559
560 void vp9_cyclic_refresh_reset_resize(VP9_COMP *const cpi) {
561 const VP9_COMMON *const cm = &cpi->common;
562 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
563 memset(cr->map, 0, cm->mi_rows * cm->mi_cols);
564 cr->sb_index = 0;
565 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.h ('k') | source/libvpx/vp9/encoder/vp9_avg.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698