diff options
Diffstat (limited to 'vp9/encoder/vp9_firstpass.c')
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 81ce5ea46..94bbe9c69 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -432,6 +432,8 @@ void vp9_first_pass(VP9_COMP *cpi) { TWO_PASS *twopass = &cpi->twopass; const MV zero_mv = {0, 0}; const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12; + LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ? + &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0; #if CONFIG_FP_MB_STATS if (cpi->use_fp_mb_stats) { @@ -444,15 +446,14 @@ void vp9_first_pass(VP9_COMP *cpi) { set_first_pass_params(cpi); vp9_set_quantizer(cm, find_fp_qindex()); - if (is_spatial_svc(cpi)) { + if (lc != NULL) { MV_REFERENCE_FRAME ref_frame = LAST_FRAME; const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL; - twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass; + twopass = &lc->twopass; if (cpi->common.current_video_frame == 0) { cpi->ref_frame_flags = 0; } else { - LAYER_CONTEXT *lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id]; if (lc->current_video_frame_in_layer == 0) cpi->ref_frame_flags = VP9_GOLD_FLAG; else @@ -613,7 +614,7 @@ void vp9_first_pass(VP9_COMP *cpi) { &unscaled_last_source_buf_2d); // TODO(pengchong): Replace the hard-coded threshold - if (raw_motion_error > 25 || is_spatial_svc(cpi)) { + if (raw_motion_error > 25 || lc != NULL) { // Test last reference frame using the previous best mv as the // starting point (best reference) for the search. first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv, @@ -895,7 +896,7 @@ void vp9_first_pass(VP9_COMP *cpi) { vp9_extend_frame_borders(new_yv12); - if (is_spatial_svc(cpi)) { + if (lc != NULL) { vp9_update_reference_frames(cpi); } else { // Swap frame pointers so last frame refers to the frame we just compressed. @@ -1081,8 +1082,7 @@ static double get_prediction_decay_rate(const VP9_COMMON *cm, // This function gives an estimate of how badly we believe the prediction // quality is decaying from frame to frame. -static double get_zero_motion_factor(const VP9_COMMON *cm, - const FIRSTPASS_STATS *frame) { +static double get_zero_motion_factor(const FIRSTPASS_STATS *frame) { const double sr_ratio = frame->coded_error / DOUBLE_DIVIDE_CHECK(frame->sr_coded_error); const double zero_motion_pct = frame->pcnt_inter - @@ -1095,12 +1095,10 @@ static double get_zero_motion_factor(const VP9_COMMON *cm, // Function to test for a condition where a complex transition is followed // by a static section. For example in slide shows where there is a fade // between slides. This is to help with more optimal kf and gf positioning. -static int detect_transition_to_still(TWO_PASS *twopass, +static int detect_transition_to_still(const TWO_PASS *twopass, int frame_interval, int still_interval, double loop_decay_rate, double last_decay_rate) { - int trans_to_still = 0; - // Break clause to detect very still sections after motion // For example a static image after a fade or other transition // instead of a clean scene cut. @@ -1108,26 +1106,22 @@ static int detect_transition_to_still(TWO_PASS *twopass, loop_decay_rate >= 0.999 && last_decay_rate < 0.9) { int j; - const FIRSTPASS_STATS *position = twopass->stats_in; - FIRSTPASS_STATS tmp_next_frame; // Look ahead a few frames to see if static condition persists... for (j = 0; j < still_interval; ++j) { - if (EOF == input_stats(twopass, &tmp_next_frame)) + const FIRSTPASS_STATS *stats = &twopass->stats_in[j]; + if (stats >= twopass->stats_in_end) break; - if (tmp_next_frame.pcnt_inter - tmp_next_frame.pcnt_motion < 0.999) + if (stats->pcnt_inter - stats->pcnt_motion < 0.999) break; } - reset_fpf_position(twopass, position); - // Only if it does do we signal a transition to still. - if (j == still_interval) - trans_to_still = 1; + return j == still_interval; } - return trans_to_still; + return 0; } // This function detects a flash through the high relative pcnt_second_ref @@ -1555,8 +1549,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { vp9_clear_system_state(); vp9_zero(next_frame); - gf_group_bits = 0; - // Load stats for the current frame. mod_frame_err = calculate_modified_err(twopass, oxcf, this_frame); @@ -1616,9 +1608,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { decay_accumulator = decay_accumulator * loop_decay_rate; // Monitor for static sections. - zero_motion_accumulator = - MIN(zero_motion_accumulator, - get_zero_motion_factor(&cpi->common, &next_frame)); + zero_motion_accumulator = MIN(zero_motion_accumulator, + get_zero_motion_factor(&next_frame)); // Break clause to detect very still sections after motion. For example, // a static image after a fade or other transition. @@ -1989,9 +1980,8 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { break; // Monitor for static sections. - zero_motion_accumulator = - MIN(zero_motion_accumulator, - get_zero_motion_factor(&cpi->common, &next_frame)); + zero_motion_accumulator =MIN(zero_motion_accumulator, + get_zero_motion_factor(&next_frame)); // For the first few frames collect data to decide kf boost. if (i <= (rc->max_gf_interval * 2)) { @@ -2127,10 +2117,10 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { FIRSTPASS_STATS this_frame_copy; int target_rate; - LAYER_CONTEXT *lc = NULL; + LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ? + &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0; - if (is_spatial_svc(cpi)) { - lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id]; + if (lc != NULL) { frames_left = (int)(twopass->total_stats.count - lc->current_video_frame_in_layer); } else { @@ -2157,7 +2147,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { vp9_rc_set_frame_target(cpi, target_rate); cm->frame_type = INTER_FRAME; - if (is_spatial_svc(cpi)) { + if (lc != NULL) { if (cpi->svc.spatial_layer_id == 0) { lc->is_key_frame = 0; } else { @@ -2173,7 +2163,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { vp9_clear_system_state(); - if (is_spatial_svc(cpi) && twopass->kf_intra_err_min == 0) { + if (lc != NULL && twopass->kf_intra_err_min == 0) { twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs; twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs; } @@ -2181,8 +2171,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { if (cpi->oxcf.rc_mode == VPX_Q) { twopass->active_worst_quality = cpi->oxcf.cq_level; } else if (cm->current_video_frame == 0 || - (is_spatial_svc(cpi) && - lc->current_video_frame_in_layer == 0)) { + (lc != NULL && lc->current_video_frame_in_layer == 0)) { // Special case code for first frame. const int section_target_bandwidth = (int)(twopass->bits_left / frames_left); @@ -2208,7 +2197,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { cm->frame_type = INTER_FRAME; } - if (is_spatial_svc(cpi)) { + if (lc != NULL) { if (cpi->svc.spatial_layer_id == 0) { lc->is_key_frame = (cm->frame_type == KEY_FRAME); if (lc->is_key_frame) @@ -2239,7 +2228,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { } rc->frames_till_gf_update_due = rc->baseline_gf_interval; - if (!is_spatial_svc(cpi)) + if (lc != NULL) cpi->refresh_golden_frame = 1; } |