From: Dmitry Kovalev Date: Fri, 8 Aug 2014 21:27:34 +0000 (-0700) Subject: Moving pass from VP9_COMP to VP9EncoderConfig. X-Git-Tag: v1.4.0~1059^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91c2f1e45a91cbed855c0708d7fde666601772a9;p=platform%2Fupstream%2Flibvpx.git Moving pass from VP9_COMP to VP9EncoderConfig. We had a very complicated way to initialize cpi->pass from cfg->g_pass: switch (cfg->g_pass) { case VPX_RC_ONE_PASS: oxcf->mode = ONE_PASS_GOOD; break; case VPX_RC_FIRST_PASS: oxcf->mode = TWO_PASS_FIRST; break; case VPX_RC_LAST_PASS: oxcf->mode = TWO_PASS_SECOND_BEST; break; } cpi->pass = get_pass(oxcf->mode). Now pass is moved to VP9EncoderConfig and initialization is simple: switch (cfg->g_pass) { case VPX_RC_ONE_PASS: oxcf->pass = 0; break; case VPX_RC_FIRST_PASS: oxcf->pass = 1; break; case VPX_RC_LAST_PASS: oxcf->pass = 2; break; } Change-Id: I8f582203a4575f5e39b071598484a8ad2b72e0d9 --- diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index fb605b4..d638a21 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -902,7 +902,7 @@ static int get_refresh_mask(VP9_COMP *cpi) { (cpi->refresh_golden_frame << cpi->alt_fb_idx); } else { int arf_idx = cpi->alt_fb_idx; - if ((cpi->pass == 2) && cpi->multi_arf_allowed) { + if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; arf_idx = gf_group->arf_update_idx[gf_group->index]; } diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 5e89624..9259a51 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -2476,7 +2476,7 @@ static void encode_rd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, } else { GF_GROUP * gf_grp = &cpi->twopass.gf_group; int last_was_mid_sequence_overlay = 0; - if ((cpi->pass == 2) && (gf_grp->index)) { + if ((cpi->oxcf.pass == 2) && (gf_grp->index)) { if (gf_grp->update_type[gf_grp->index - 1] == OVERLAY_UPDATE) last_was_mid_sequence_overlay = 1; } diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index ddca25e..6557da7 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -553,23 +553,6 @@ static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) { set_tile_limits(cpi); } -static int get_pass(MODE mode) { - switch (mode) { - case REALTIME: - case ONE_PASS_GOOD: - case ONE_PASS_BEST: - return 0; - - case TWO_PASS_FIRST: - return 1; - - case TWO_PASS_SECOND_GOOD: - case TWO_PASS_SECOND_BEST: - return 2; - } - return -1; -} - void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; @@ -584,7 +567,6 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { assert(cm->bit_depth > BITS_8); cpi->oxcf = *oxcf; - cpi->pass = get_pass(cpi->oxcf.mode); rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; @@ -654,7 +636,7 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || - (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { + (cpi->svc.number_spatial_layers > 1 && cpi->oxcf.pass == 2)) { vp9_update_layer_context_change_config(cpi, (int)cpi->oxcf.target_bandwidth); } @@ -748,7 +730,7 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { cpi->use_svc = 0; init_config(cpi, oxcf); - vp9_rc_init(&cpi->oxcf, cpi->pass, &cpi->rc); + vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); cm->current_video_frame = 0; @@ -800,7 +782,7 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { // pending further tuning and testing. The code is left in place here // as a place holder in regard to the required paths. cpi->multi_arf_last_grp_enabled = 0; - if (cpi->pass == 2) { + if (oxcf->pass == 2) { if (cpi->use_svc) { cpi->multi_arf_allowed = 0; cpi->multi_arf_enabled = 0; @@ -888,9 +870,9 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; - if (cpi->pass == 1) { + if (oxcf->pass == 1) { vp9_init_first_pass(cpi); - } else if (cpi->pass == 2) { + } else if (oxcf->pass == 2) { const size_t packet_sz = sizeof(FIRSTPASS_STATS); const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); @@ -1066,7 +1048,7 @@ void vp9_remove_compressor(VP9_COMP *cpi) { vp9_clear_system_state(); // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); - if (cpi->pass != 1) { + if (cpi->oxcf.pass != 1) { FILE *f = fopen("opsnr.stt", "a"); double time_encoded = (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / 10000000.000; @@ -1590,7 +1572,7 @@ void vp9_update_reference_frames(VP9_COMP *cpi) { } else { /* For non key/golden frames */ if (cpi->refresh_alt_ref_frame) { int arf_idx = cpi->alt_fb_idx; - if ((cpi->pass == 2) && cpi->multi_arf_allowed) { + if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; arf_idx = gf_group->arf_update_idx[gf_group->index]; } @@ -2071,7 +2053,7 @@ static void set_arf_sign_bias(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; int arf_sign_bias; - if ((cpi->pass == 2) && cpi->multi_arf_allowed) { + if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; arf_sign_bias = cpi->rc.source_alt_ref_active && (!cpi->refresh_alt_ref_frame || @@ -2173,19 +2155,19 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, // static regions if indicated. // Only allowed in second pass of two pass (as requires lagged coding) // and if the relevant speed feature flag is set. - if (cpi->pass == 2 && cpi->sf.static_segmentation) + if (cpi->oxcf.pass == 2 && cpi->sf.static_segmentation) configure_static_seg_features(cpi); // Check if the current frame is skippable for the partition search in the // second pass according to the first pass stats - if (cpi->pass == 2 && + if (cpi->oxcf.pass == 2 && (!cpi->use_svc || is_spatial_svc(cpi))) { configure_skippable_frame(cpi); } // For 1 pass CBR, check if we are dropping this frame. // Never drop on key frame. - if (cpi->pass == 0 && + if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR && cm->frame_type != KEY_FRAME) { if (vp9_rc_drop_frame(cpi)) { @@ -2517,7 +2499,7 @@ static int get_arf_src_index(VP9_COMP *cpi) { RATE_CONTROL *const rc = &cpi->rc; int arf_src_index = 0; if (is_altref_enabled(cpi)) { - if (cpi->pass == 2) { + if (cpi->oxcf.pass == 2) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { arf_src_index = gf_group->arf_src_offset[gf_group->index]; @@ -2532,7 +2514,7 @@ static int get_arf_src_index(VP9_COMP *cpi) { static void check_src_altref(VP9_COMP *cpi) { RATE_CONTROL *const rc = &cpi->rc; - if (cpi->pass == 2) { + if (cpi->oxcf.pass == 2) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; rc->is_src_frame_alt_ref = (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); @@ -2565,7 +2547,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, if (!cpi) return -1; - if (is_spatial_svc(cpi) && cpi->pass == 2) { + if (is_spatial_svc(cpi) && cpi->oxcf.pass == 2) { #if CONFIG_SPATIAL_SVC vp9_svc_lookahead_peek(cpi, cpi->lookahead, 0, 1); #endif @@ -2679,7 +2661,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } else { *size = 0; - if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) { + if (flush && cpi->oxcf.pass == 1 && !cpi->twopass.first_pass_done) { vp9_end_first_pass(cpi); /* get last stats packet */ cpi->twopass.first_pass_done = 1; } @@ -2717,7 +2699,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, if (!cpi->use_svc && cpi->multi_arf_allowed) { if (cm->frame_type == KEY_FRAME) { init_buffer_indices(cpi); - } else if (cpi->pass == 2) { + } else if (cpi->oxcf.pass == 2) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; } @@ -2725,7 +2707,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, cpi->frame_flags = *frame_flags; - if (cpi->pass == 2 && + if (cpi->oxcf.pass == 2 && cm->current_video_frame == 0 && cpi->oxcf.allow_spatial_resampling && cpi->oxcf.rc_mode == VPX_VBR) { @@ -2763,13 +2745,13 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, vp9_vaq_init(); } - if (cpi->pass == 1 && + if (cpi->oxcf.pass == 1 && (!cpi->use_svc || is_spatial_svc(cpi))) { const int lossless = is_lossless_requested(&cpi->oxcf); cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; vp9_first_pass(cpi); - } else if (cpi->pass == 2 && + } else if (cpi->oxcf.pass == 2 && (!cpi->use_svc || is_spatial_svc(cpi))) { Pass2Encode(cpi, size, dest, frame_flags); } else if (cpi->use_svc) { @@ -2794,19 +2776,19 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, // Save layer specific state. if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || - (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { + (cpi->svc.number_spatial_layers > 1 && cpi->oxcf.pass == 2)) { vp9_save_layer_context(cpi); } vpx_usec_timer_mark(&cmptimer); cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); - if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) + if (cpi->b_calculate_psnr && cpi->oxcf.pass != 1 && cm->show_frame) generate_psnr_packet(cpi); #if CONFIG_INTERNAL_STATS - if (cpi->pass != 1) { + if (cpi->oxcf.pass != 1) { cpi->bytes += (int)(*size); if (cm->show_frame) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index acff173..12ead39 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -143,6 +143,7 @@ typedef struct VP9EncoderConfig { unsigned int rc_max_intra_bitrate_pct; MODE mode; + int pass; // Key Framing Operations int auto_key; // autodetect cut scenes and set the keyframes @@ -313,9 +314,6 @@ typedef struct VP9_COMP { MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; int mbgraph_n_frames; // number of frames filled in the above int static_mb_pct; // % forced skip mbs by segmentation - - int pass; - int ref_frame_flags; SPEED_FEATURES sf; diff --git a/vp9/encoder/vp9_picklpf.c b/vp9/encoder/vp9_picklpf.c index 0f363a7..d365489 100644 --- a/vp9/encoder/vp9_picklpf.c +++ b/vp9/encoder/vp9_picklpf.c @@ -24,7 +24,7 @@ #include "vp9/encoder/vp9_quantize.h" static int get_max_filter_level(const VP9_COMP *cpi) { - if (cpi->pass == 2) { + if (cpi->oxcf.pass == 2) { return cpi->twopass.section_intra_rating > 8 ? MAX_LOOP_FILTER * 3 / 4 : MAX_LOOP_FILTER; } else { @@ -82,7 +82,7 @@ static int search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, // Bias against raising loop filter in favor of lowering it. int bias = (best_err >> (15 - (filt_mid / 8))) * filter_step; - if ((cpi->pass == 2) && (cpi->twopass.section_intra_rating < 20)) + if ((cpi->oxcf.pass == 2) && (cpi->twopass.section_intra_rating < 20)) bias = (bias * cpi->twopass.section_intra_rating) / 20; // yx, bias less for large block size diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 73c6b89..04ab795 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -277,7 +277,7 @@ static double get_rate_correction_factor(const VP9_COMP *cpi) { if (cpi->common.frame_type == KEY_FRAME) { return rc->rate_correction_factors[KF_STD]; - } else if (cpi->pass == 2) { + } else if (cpi->oxcf.pass == 2) { RATE_FACTOR_LEVEL rf_lvl = cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; return rc->rate_correction_factors[rf_lvl]; @@ -296,7 +296,7 @@ static void set_rate_correction_factor(VP9_COMP *cpi, double factor) { if (cpi->common.frame_type == KEY_FRAME) { rc->rate_correction_factors[KF_STD] = factor; - } else if (cpi->pass == 2) { + } else if (cpi->oxcf.pass == 2) { RATE_FACTOR_LEVEL rf_lvl = cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; rc->rate_correction_factors[rf_lvl] = factor; @@ -923,7 +923,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, int *bottom_index, int *top_index) { int q; - if (cpi->pass == 0) { + if (cpi->oxcf.pass == 0) { if (cpi->oxcf.rc_mode == VPX_CBR) q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index); else @@ -991,7 +991,7 @@ static void update_golden_frame_stats(VP9_COMP *cpi) { // this frame refreshes means next frames don't unless specified by user rc->frames_since_golden = 0; - if (cpi->pass == 2) { + if (cpi->oxcf.pass == 2) { if (!rc->source_alt_ref_pending && cpi->twopass.gf_group.rf_level[0] == GF_ARF_STD) rc->source_alt_ref_active = 0; @@ -1242,7 +1242,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG); } - if (cpi->pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) { + if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) { target = calc_iframe_target_size_one_pass_cbr(cpi); } } else { @@ -1260,7 +1260,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { cpi->ref_frame_flags &= (~VP9_ALT_FLAG); } - if (cpi->pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) { + if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) { target = calc_pframe_target_size_one_pass_cbr(cpi); } } diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c index 633ce08..4fc3e9e 100644 --- a/vp9/encoder/vp9_rd.c +++ b/vp9/encoder/vp9_rd.c @@ -121,7 +121,7 @@ int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) { const int q = vp9_dc_quant(qindex, 0); int rdmult = 88 * q * q / 24; - if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { + if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index]; const int boost_index = MIN(15, (cpi->rc.gfu_boost / 100)); diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index e770f33..f2e99cf 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -405,11 +405,11 @@ void vp9_set_speed_features(VP9_COMP *cpi) { // Slow quant, dct and trellis not worthwhile for first pass // so make sure they are always turned off. - if (cpi->pass == 1) + if (oxcf->pass == 1) sf->optimize_coefficients = 0; // No recode for 1 pass. - if (cpi->pass == 0) { + if (oxcf->pass == 0) { sf->recode_loop = DISALLOW_RECODE; sf->optimize_coefficients = 0; } @@ -418,7 +418,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) { cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree; } - cpi->mb.optimize = sf->optimize_coefficients == 1 && cpi->pass != 1; + cpi->mb.optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1; if (sf->disable_split_mask == DISABLE_ALL_SPLIT) sf->adaptive_pred_interp_filter = 0; diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c index 2eca8fc..ce3b311 100644 --- a/vp9/encoder/vp9_temporal_filter.c +++ b/vp9/encoder/vp9_temporal_filter.c @@ -405,7 +405,7 @@ static void adjust_arnr_filter(VP9_COMP *cpi, } // Adjustments for second level arf in multi arf case. - if (cpi->pass == 2 && cpi->multi_arf_allowed) { + if (cpi->oxcf.pass == 2 && cpi->multi_arf_allowed) { const GF_GROUP *const gf_group = &cpi->twopass.gf_group; if (gf_group->rf_level[gf_group->index] != GF_ARF_STD) { cpi->active_arnr_strength >>= 1; diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index 1c6413d..0ba7591 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -337,12 +337,15 @@ static vpx_codec_err_t set_encoder_config( switch (cfg->g_pass) { case VPX_RC_ONE_PASS: oxcf->mode = ONE_PASS_GOOD; + oxcf->pass = 0; break; case VPX_RC_FIRST_PASS: oxcf->mode = TWO_PASS_FIRST; + oxcf->pass = 1; break; case VPX_RC_LAST_PASS: oxcf->mode = TWO_PASS_SECOND_BEST; + oxcf->pass = 2; break; }