| OLD | NEW |
| 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 |
| 11 #include <limits.h> | 11 #include <limits.h> |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 | 13 |
| 14 #include "vpx_dsp/vpx_dsp_common.h" |
| 14 #include "vpx_ports/system_state.h" | 15 #include "vpx_ports/system_state.h" |
| 15 | 16 |
| 16 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" | 17 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" |
| 17 | 18 |
| 18 #include "vp9/common/vp9_seg_common.h" | 19 #include "vp9/common/vp9_seg_common.h" |
| 19 | 20 |
| 20 #include "vp9/encoder/vp9_ratectrl.h" | 21 #include "vp9/encoder/vp9_ratectrl.h" |
| 21 #include "vp9/encoder/vp9_segmentation.h" | 22 #include "vp9/encoder/vp9_segmentation.h" |
| 22 | 23 |
| 23 struct CYCLIC_REFRESH { | |
| 24 // Percentage of blocks per frame that are targeted as candidates | |
| 25 // for cyclic refresh. | |
| 26 int percent_refresh; | |
| 27 // Maximum q-delta as percentage of base q. | |
| 28 int max_qdelta_perc; | |
| 29 // Superblock starting index for cycling through the frame. | |
| 30 int sb_index; | |
| 31 // Controls how long block will need to wait to be refreshed again, in | |
| 32 // excess of the cycle time, i.e., in the case of all zero motion, block | |
| 33 // will be refreshed every (100/percent_refresh + time_for_refresh) frames. | |
| 34 int time_for_refresh; | |
| 35 // Target number of (8x8) blocks that are set for delta-q. | |
| 36 int target_num_seg_blocks; | |
| 37 // Actual number of (8x8) blocks that were applied delta-q. | |
| 38 int actual_num_seg1_blocks; | |
| 39 int actual_num_seg2_blocks; | |
| 40 // RD mult. parameters for segment 1. | |
| 41 int rdmult; | |
| 42 // Cyclic refresh map. | |
| 43 signed char *map; | |
| 44 // Map of the last q a block was coded at. | |
| 45 uint8_t *last_coded_q_map; | |
| 46 // Thresholds applied to the projected rate/distortion of the coding block, | |
| 47 // when deciding whether block should be refreshed. | |
| 48 int64_t thresh_rate_sb; | |
| 49 int64_t thresh_dist_sb; | |
| 50 // Threshold applied to the motion vector (in units of 1/8 pel) of the | |
| 51 // coding block, when deciding whether block should be refreshed. | |
| 52 int16_t motion_thresh; | |
| 53 // Rate target ratio to set q delta. | |
| 54 double rate_ratio_qdelta; | |
| 55 // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2. | |
| 56 int rate_boost_fac; | |
| 57 double low_content_avg; | |
| 58 int qindex_delta[3]; | |
| 59 }; | |
| 60 | |
| 61 CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) { | 24 CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) { |
| 62 size_t last_coded_q_map_size; | 25 size_t last_coded_q_map_size; |
| 63 CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr)); | 26 CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr)); |
| 64 if (cr == NULL) | 27 if (cr == NULL) |
| 65 return NULL; | 28 return NULL; |
| 66 | 29 |
| 67 cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map)); | 30 cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map)); |
| 68 if (cr->map == NULL) { | 31 if (cr->map == NULL) { |
| 69 vpx_free(cr); | 32 vpx_free(cr); |
| 70 return NULL; | 33 return NULL; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 int map_offset = block_index + y * cm->mi_cols + x; | 228 int map_offset = block_index + y * cm->mi_cols + x; |
| 266 cr->map[map_offset] = new_map_value; | 229 cr->map[map_offset] = new_map_value; |
| 267 cpi->segmentation_map[map_offset] = mbmi->segment_id; | 230 cpi->segmentation_map[map_offset] = mbmi->segment_id; |
| 268 // Inter skip blocks were clearly not coded at the current qindex, so | 231 // Inter skip blocks were clearly not coded at the current qindex, so |
| 269 // don't update the map for them. For cases where motion is non-zero or | 232 // don't update the map for them. For cases where motion is non-zero or |
| 270 // the reference frame isn't the previous frame, the previous value in | 233 // the reference frame isn't the previous frame, the previous value in |
| 271 // the map for this spatial location is not entirely correct. | 234 // the map for this spatial location is not entirely correct. |
| 272 if (!is_inter_block(mbmi) || !skip) | 235 if (!is_inter_block(mbmi) || !skip) |
| 273 cr->last_coded_q_map[map_offset] = clamp( | 236 cr->last_coded_q_map[map_offset] = clamp( |
| 274 cm->base_qindex + cr->qindex_delta[mbmi->segment_id], 0, MAXQ); | 237 cm->base_qindex + cr->qindex_delta[mbmi->segment_id], 0, MAXQ); |
| 238 else if (is_inter_block(mbmi) && skip) { |
| 239 cr->last_coded_q_map[map_offset] = VPXMIN( |
| 240 clamp(cm->base_qindex + cr->qindex_delta[mbmi->segment_id], |
| 241 0, MAXQ), |
| 242 cr->last_coded_q_map[map_offset]); |
| 243 } |
| 275 } | 244 } |
| 276 } | 245 } |
| 277 | 246 |
| 278 // Update the actual number of blocks that were applied the segment delta q. | 247 // Update the actual number of blocks that were applied the segment delta q. |
| 279 void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) { | 248 void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) { |
| 280 VP9_COMMON *const cm = &cpi->common; | 249 VP9_COMMON *const cm = &cpi->common; |
| 281 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; | 250 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; |
| 282 unsigned char *const seg_map = cpi->segmentation_map; | 251 unsigned char *const seg_map = cpi->segmentation_map; |
| 283 int mi_row, mi_col; | 252 int mi_row, mi_col; |
| 284 cr->actual_num_seg1_blocks = 0; | 253 cr->actual_num_seg1_blocks = 0; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return cr->rdmult; | 535 return cr->rdmult; |
| 567 } | 536 } |
| 568 | 537 |
| 569 void vp9_cyclic_refresh_reset_resize(VP9_COMP *const cpi) { | 538 void vp9_cyclic_refresh_reset_resize(VP9_COMP *const cpi) { |
| 570 const VP9_COMMON *const cm = &cpi->common; | 539 const VP9_COMMON *const cm = &cpi->common; |
| 571 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; | 540 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; |
| 572 memset(cr->map, 0, cm->mi_rows * cm->mi_cols); | 541 memset(cr->map, 0, cm->mi_rows * cm->mi_cols); |
| 573 cr->sb_index = 0; | 542 cr->sb_index = 0; |
| 574 cpi->refresh_golden_frame = 1; | 543 cpi->refresh_golden_frame = 1; |
| 575 } | 544 } |
| OLD | NEW |