diff options
author | Dmitry Kovalev <dkovalev@google.com> | 2014-03-26 11:00:35 -0700 |
---|---|---|
committer | Dmitry Kovalev <dkovalev@google.com> | 2014-03-26 11:00:35 -0700 |
commit | fc25e4dc525ed92679daefa5cb93012fcc6b523f (patch) | |
tree | 951e26d3959c604a7370899a3f332b70fc2978f2 | |
parent | 2ec04d1f84aba18359eb28e0f781994aecba3527 (diff) | |
download | libvpx-fc25e4dc525ed92679daefa5cb93012fcc6b523f.tar libvpx-fc25e4dc525ed92679daefa5cb93012fcc6b523f.tar.gz libvpx-fc25e4dc525ed92679daefa5cb93012fcc6b523f.tar.bz2 libvpx-fc25e4dc525ed92679daefa5cb93012fcc6b523f.zip |
Encapsulating CYCLIC_REFRESH struct into .c file.
Change-Id: I32695ad703dcbbbbf5f122b403f3d3120a0be366
-rw-r--r-- | vp9/encoder/vp9_aq_cyclicrefresh.c | 71 | ||||
-rw-r--r-- | vp9/encoder/vp9_aq_cyclicrefresh.h | 51 | ||||
-rw-r--r-- | vp9/encoder/vp9_encodeframe.c | 40 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_if.c | 16 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_int.h | 2 |
5 files changed, 109 insertions, 71 deletions
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c index 231276b3e..7442d0178 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -19,6 +19,51 @@ #include "vp9/encoder/vp9_rdopt.h" #include "vp9/encoder/vp9_segmentation.h" +struct CYCLIC_REFRESH { + // Target percentage of blocks per frame that are cyclicly refreshed. + int max_mbs_perframe; + // Maximum q-delta as percentage of base q. + int max_qdelta_perc; + // Block size below which we don't apply cyclic refresh. + BLOCK_SIZE min_block_size; + // Macroblock starting index (unit of 8x8) for cycling through the frame. + int mb_index; + // Controls how long a block will need to wait to be refreshed again. + int time_for_refresh; + // Actual number of blocks that were applied delta-q (segment 1). + int num_seg_blocks; + // Actual encoding bits for segment 1. + int actual_seg_bits; + // RD mult. parameters for segment 1. + int rdmult; + // Cyclic refresh map. + signed char *map; + // Projected rate and distortion for the current superblock. + int64_t projected_rate_sb; + int64_t projected_dist_sb; + // Thresholds applied to projected rate/distortion of the superblock. + int64_t thresh_rate_sb; + int64_t thresh_dist_sb; +}; + +CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) { + CYCLIC_REFRESH *const cr = vpx_calloc(1, sizeof(*cr)); + if (cr == NULL) + return NULL; + + cr->map = vpx_calloc(mi_rows * mi_cols, sizeof(*cr->map)); + if (cr->map == NULL) { + vpx_free(cr); + return NULL; + } + + return cr; +} + +void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr) { + vpx_free(cr->map); + vpx_free(cr); +} // Check if we should turn off cyclic refresh based on bitrate condition. static int apply_cyclic_refresh_bitrate(const VP9_COMMON *cm, @@ -73,14 +118,12 @@ static int candidate_refresh_aq(const CYCLIC_REFRESH *cr, // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col), // check if we should reset the segment_id, and update the cyclic_refresh map // and segmentation map. -void vp9_update_segment_aq(VP9_COMP *const cpi, - MB_MODE_INFO *const mbmi, - int mi_row, - int mi_col, - BLOCK_SIZE bsize, - int use_rd) { +void vp9_cyclic_refresh_update_segment(VP9_COMP *const cpi, + MB_MODE_INFO *const mbmi, + int mi_row, int mi_col, + BLOCK_SIZE bsize, int use_rd) { const VP9_COMMON *const cm = &cpi->common; - CYCLIC_REFRESH *const cr = &cpi->cyclic_refresh; + CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; const int bw = num_8x8_blocks_wide_lookup[bsize]; const int bh = num_8x8_blocks_high_lookup[bsize]; const int xmis = MIN(cm->mi_cols - mi_col, bw); @@ -126,10 +169,10 @@ void vp9_update_segment_aq(VP9_COMP *const cpi, } // Setup cyclic background refresh: set delta q and segmentation map. -void vp9_setup_cyclic_refresh_aq(VP9_COMP *const cpi) { +void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { VP9_COMMON *const cm = &cpi->common; const RATE_CONTROL *const rc = &cpi->rc; - CYCLIC_REFRESH *const cr = &cpi->cyclic_refresh; + CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; struct segmentation *const seg = &cm->seg; unsigned char *const seg_map = cpi->segmentation_map; const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc); @@ -253,3 +296,13 @@ void vp9_setup_cyclic_refresh_aq(VP9_COMP *const cpi) { } } } + +void vp9_cyclic_refresh_set_rate_and_dist_sb(CYCLIC_REFRESH *cr, + int64_t rate_sb, int64_t dist_sb) { + cr->projected_rate_sb = rate_sb; + cr->projected_dist_sb = dist_sb; +} + +int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) { + return cr->rdmult; +} diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.h b/vp9/encoder/vp9_aq_cyclicrefresh.h index 14dc2cd46..f556d658b 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.h +++ b/vp9/encoder/vp9_aq_cyclicrefresh.h @@ -18,47 +18,30 @@ extern "C" { #endif -typedef struct { - // Target percentage of blocks per frame that are cyclicly refreshed. - int max_mbs_perframe; - // Maximum q-delta as percentage of base q. - int max_qdelta_perc; - // Block size below which we don't apply cyclic refresh. - BLOCK_SIZE min_block_size; - // Macroblock starting index (unit of 8x8) for cycling through the frame. - int mb_index; - // Controls how long a block will need to wait to be refreshed again. - int time_for_refresh; - // Actual number of blocks that were applied delta-q (segment 1). - int num_seg_blocks; - // Actual encoding bits for segment 1. - int actual_seg_bits; - // RD mult. parameters for segment 1. - int rdmult; - // Cyclic refresh map. - signed char *map; - // Projected rate and distortion for the current superblock. - int64_t projected_rate_sb; - int64_t projected_dist_sb; - // Thresholds applied to projected rate/distortion of the superblock. - int64_t thresh_rate_sb; - int64_t thresh_dist_sb; -} CYCLIC_REFRESH; - struct VP9_COMP; +struct CYCLIC_REFRESH; +typedef struct CYCLIC_REFRESH CYCLIC_REFRESH; + +CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols); + +void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr); + // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col), // check if we should reset the segment_id, and update the cyclic_refresh map // and segmentation map. -void vp9_update_segment_aq(struct VP9_COMP *const cpi, - MB_MODE_INFO *const mbmi, - int mi_row, - int mi_col, - BLOCK_SIZE bsize, - int use_rd); +void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi, + MB_MODE_INFO *const mbmi, + int mi_row, int mi_col, + BLOCK_SIZE bsize, int use_rd); // Setup cyclic background refresh: set delta q and segmentation map. -void vp9_setup_cyclic_refresh_aq(struct VP9_COMP *const cpi); +void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi); + +void vp9_cyclic_refresh_set_rate_and_dist_sb(CYCLIC_REFRESH *cr, + int64_t rate_sb, int64_t dist_sb); + +int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr); #ifdef __cplusplus } // extern "C" diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index ed9e27cf8..c310354c9 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -902,8 +902,8 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, // the cyclic refresh map. if ((cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) && seg->enabled && output_enabled) { - vp9_update_segment_aq(cpi, &xd->mi_8x8[0]->mbmi, - mi_row, mi_col, bsize, 1); + vp9_cyclic_refresh_update_segment(cpi, &xd->mi_8x8[0]->mbmi, + mi_row, mi_col, bsize, 1); vp9_init_plane_quantizers(cpi, x); } @@ -1102,7 +1102,7 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, : cm->last_frame_seg_map; // If segment 1, use rdmult for that segment. if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) - x->rdmult = cpi->cyclic_refresh.rdmult; + x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); } // Find best coding mode & reconstruct the MB so it is available @@ -1466,7 +1466,8 @@ static void update_state_rt(VP9_COMP *cpi, const PICK_MODE_CONTEXT *ctx, // Check for reseting segment_id and update cyclic map. if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && seg->enabled) { - vp9_update_segment_aq(cpi, &xd->mi_8x8[0]->mbmi, mi_row, mi_col, bsize, 1); + vp9_cyclic_refresh_update_segment(cpi, &xd->mi_8x8[0]->mbmi, + mi_row, mi_col, bsize, 1); vp9_init_plane_quantizers(cpi, x); } @@ -1877,10 +1878,10 @@ static void rd_use_partition(VP9_COMP *cpi, select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, chosen_rate); } - if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - cpi->cyclic_refresh.projected_rate_sb = chosen_rate; - cpi->cyclic_refresh.projected_dist_sb = chosen_dist; - } + + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) + vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, + chosen_rate, chosen_dist); encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize); } @@ -2318,10 +2319,10 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, best_rate); } - if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - cpi->cyclic_refresh.projected_rate_sb = best_rate; - cpi->cyclic_refresh.projected_dist_sb = best_dist; - } + + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) + vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, + best_rate, best_dist); encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize); } @@ -2925,10 +2926,10 @@ static void nonrd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, best_rate); } - if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - cpi->cyclic_refresh.projected_rate_sb = best_rate; - cpi->cyclic_refresh.projected_dist_sb = best_dist; - } + + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) + vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, + best_rate, best_dist); encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize); } @@ -3039,10 +3040,9 @@ static void nonrd_use_partition(VP9_COMP *cpi, } if (bsize == BLOCK_64X64 && output_enabled) { - if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - cpi->cyclic_refresh.projected_rate_sb = *totrate; - cpi->cyclic_refresh.projected_dist_sb = *totdist; - } + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) + vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, + *totrate, *totdist); encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, bsize); } } diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 070cc24e7..f7a6eee42 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -189,11 +189,13 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { cpi->coding_context.last_frame_seg_map_copy = NULL; vpx_free(cpi->complexity_map); - cpi->complexity_map = 0; - vpx_free(cpi->cyclic_refresh.map); - cpi->cyclic_refresh.map = 0; + cpi->complexity_map = NULL; + + vp9_cyclic_refresh_free(cpi->cyclic_refresh); + cpi->cyclic_refresh = NULL; + vpx_free(cpi->active_map); - cpi->active_map = 0; + cpi->active_map = NULL; vp9_free_frame_buffers(cm); @@ -1661,8 +1663,8 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); // Create a map used for cyclic background refresh. - CHECK_MEM_ERROR(cm, cpi->cyclic_refresh.map, - vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); + CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, + vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); // And a place holder structure is the coding context // for use if we want to save and restore it @@ -2679,7 +2681,7 @@ static void encode_without_recode_loop(VP9_COMP *cpi, } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { setup_in_frame_q_adj(cpi); } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - vp9_setup_cyclic_refresh_aq(cpi); + vp9_cyclic_refresh_setup(cpi); } // transform / motion compensation build reconstruction frame vp9_encode_frame(cpi); diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index a2f878aa3..b62fa718a 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -725,7 +725,7 @@ typedef struct VP9_COMP { unsigned char *active_map; unsigned int active_map_enabled; - CYCLIC_REFRESH cyclic_refresh; + CYCLIC_REFRESH *cyclic_refresh; fractional_mv_step_fp *find_fractional_mv_step; fractional_mv_step_comp_fp *find_fractional_mv_step_comp; |