shithub: libvpx

Download patch

ref: 35358320e33b6602c5dd728367cf3db77f1f9af9
parent: a5d11f298f6a759f5594008e38ecab9acdd9f3ca
author: Paul Wilkins <paulwilkins@google.com>
date: Fri May 11 14:07:33 EDT 2012

First pass overhaul preparatory change.

This is the first patch in a series of changes to the first
pass code. (Broken down for ease of testing/merging/review).

This patch introduces a new stats element "sr_coded_error".
This is the coded error recorded vs the second reference
frame (which is updated such that it lags by at least one frame).
No use is made of the new structure in this change so this patch
should have no material effect.

Removed some ifdefs and deprecated code (#if NEW_BOOST).
Removed twopass.gf_decay_rate (not used any more)

Change-Id: I1be672a73017f7c13fd50fb4f99236aa2ed30916

--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -64,8 +64,6 @@
 #define POW1 (double)cpi->oxcf.two_pass_vbrbias/100.0
 #define POW2 (double)cpi->oxcf.two_pass_vbrbias/100.0
 
-#define NEW_BOOST 1
-
 static int vscale_lookup[7] = {0, 1, 1, 2, 2, 3, 3};
 static int hscale_lookup[7] = {0, 0, 1, 1, 2, 2, 3};
 
@@ -157,12 +155,13 @@
         FILE *fpfile;
         fpfile = fopen("firstpass.stt", "a");
 
-        fprintf(fpfile, "%12.0f %12.0f %12.0f %12.4f %12.4f %12.4f %12.4f"
-                " %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f"
-                " %12.0f %12.0f %12.4f\n",
+        fprintf(fpfile, "%12.0f %12.0f %12.0f %12.0f %12.0f %12.4f %12.4f"
+                        "%12.4f %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f"
+                        "%12.0f %12.0f %12.4f %12.0f %12.0f %12.4f\n",
                 stats->frame,
                 stats->intra_error,
                 stats->coded_error,
+                stats->sr_coded_error,
                 stats->ssim_weighted_pred_err,
                 stats->pcnt_inter,
                 stats->pcnt_motion,
@@ -188,6 +187,7 @@
     section->frame      = 0.0;
     section->intra_error = 0.0;
     section->coded_error = 0.0;
+    section->sr_coded_error = 0.0;
     section->ssim_weighted_pred_err = 0.0;
     section->pcnt_inter  = 0.0;
     section->pcnt_motion  = 0.0;
@@ -210,6 +210,7 @@
     section->frame += frame->frame;
     section->intra_error += frame->intra_error;
     section->coded_error += frame->coded_error;
+    section->sr_coded_error += frame->sr_coded_error;
     section->ssim_weighted_pred_err += frame->ssim_weighted_pred_err;
     section->pcnt_inter  += frame->pcnt_inter;
     section->pcnt_motion += frame->pcnt_motion;
@@ -232,6 +233,7 @@
     section->frame -= frame->frame;
     section->intra_error -= frame->intra_error;
     section->coded_error -= frame->coded_error;
+    section->sr_coded_error -= frame->sr_coded_error;
     section->ssim_weighted_pred_err -= frame->ssim_weighted_pred_err;
     section->pcnt_inter  -= frame->pcnt_inter;
     section->pcnt_motion -= frame->pcnt_motion;
@@ -256,6 +258,7 @@
 
     section->intra_error /= section->count;
     section->coded_error /= section->count;
+    section->sr_coded_error /= section->count;
     section->ssim_weighted_pred_err /= section->count;
     section->pcnt_inter  /= section->count;
     section->pcnt_second_ref /= section->count;
@@ -481,6 +484,7 @@
     int recon_uv_stride = lst_yv12->uv_stride;
     int64_t intra_error = 0;
     int64_t coded_error = 0;
+    int64_t sr_coded_error = 0;
 
     int sum_mvr = 0, sum_mvc = 0;
     int sum_mvr_abs = 0, sum_mvc_abs = 0;
@@ -614,9 +618,12 @@
                 // Experimental search in a second reference frame ((0,0) based only)
                 if (cm->current_video_frame > 1)
                 {
-                    first_pass_motion_search(cpi, x, &zero_ref_mv, &tmp_mv.as_mv, gld_yv12, &gf_motion_error, recon_yoffset);
+                    first_pass_motion_search(cpi, x, &zero_ref_mv,
+                                             &tmp_mv.as_mv, gld_yv12,
+                                             &gf_motion_error, recon_yoffset);
 
-                    if ((gf_motion_error < motion_error) && (gf_motion_error < this_error))
+                    if ( (gf_motion_error < motion_error) &&
+                         (gf_motion_error < this_error))
                     {
                         second_ref_count++;
                     }
@@ -625,7 +632,11 @@
                     xd->pre.y_buffer = lst_yv12->y_buffer + recon_yoffset;
                     xd->pre.u_buffer = lst_yv12->u_buffer + recon_uvoffset;
                     xd->pre.v_buffer = lst_yv12->v_buffer + recon_uvoffset;
+
+                    sr_coded_error += gf_motion_error;
                 }
+                else
+                    sr_coded_error += motion_error;
 
                 /* Intra assumed best */
                 best_ref_mv.as_int = 0;
@@ -702,6 +713,8 @@
                     }
                 }
             }
+            else
+                sr_coded_error += (int64_t)this_error;
 
             coded_error += (int64_t)this_error;
 
@@ -733,6 +746,7 @@
         fps.frame      = cm->current_video_frame ;
         fps.intra_error = intra_error >> 8;
         fps.coded_error = coded_error >> 8;
+        fps.sr_coded_error = sr_coded_error >> 8;
         weight = simple_weight(cpi->Source);
 
 
@@ -1549,7 +1563,6 @@
     return frame_boost;
 }
 
-#if NEW_BOOST
 static int calc_arf_boost(
     VP8_COMP *cpi,
     int offset,
@@ -1664,7 +1677,6 @@
 
     return (*f_boost + *b_boost);
 }
-#endif
 
 // Analyse and define a gf/arf group .
 static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
@@ -1700,7 +1712,6 @@
     BOOL flash_detected;
 
     cpi->twopass.gf_group_bits = 0;
-    cpi->twopass.gf_decay_rate = 0;
 
     vp8_clear_system_state();  //__asm emms;
 
@@ -1802,9 +1813,6 @@
         old_boost_score = boost_score;
     }
 
-    cpi->twopass.gf_decay_rate =
-        (i > 0) ? (int)(100.0 * (1.0 - decay_accumulator)) / i : 0;
-
     // Dont allow conventional gf too near the next kf
     if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL)
     {
@@ -1825,10 +1833,8 @@
 
     cpi->gfu_boost = (int)(boost_score * 100.0) >> 4;
 
-#if NEW_BOOST
     // Alterrnative boost calculation for alt ref
     alt_boost = calc_arf_boost( cpi, 0, (i-1), (i-1), &f_boost, &b_boost );
-#endif
 
     // Should we use the alternate refernce frame
     if (allow_alt_ref &&
@@ -1836,7 +1842,6 @@
         (i >= MIN_GF_INTERVAL) &&
         // dont use ARF very near next kf
         (i <= (cpi->twopass.frames_to_key - MIN_GF_INTERVAL)) &&
-#if NEW_BOOST
         ((next_frame.pcnt_inter > 0.75) ||
          (next_frame.pcnt_second_ref > 0.5)) &&
         ((mv_in_out_accumulator / (double)i > -0.2) ||
@@ -1843,14 +1848,6 @@
          (mv_in_out_accumulator > -2.0)) &&
         (b_boost > 100) &&
         (f_boost > 100) )
-#else
-        (next_frame.pcnt_inter > 0.75) &&
-        ((mv_in_out_accumulator / (double)i > -0.2) ||
-         (mv_in_out_accumulator > -2.0)) &&
-        (cpi->gfu_boost > 100) &&
-        (cpi->twopass.gf_decay_rate <=
-            (ARF_DECAY_THRESH + (cpi->gfu_boost / 200))) )
-#endif
     {
         int Boost;
         int allocation_chunks;
@@ -1860,9 +1857,7 @@
         int arf_frame_bits = 0;
         int group_bits;
 
-#if NEW_BOOST
         cpi->gfu_boost = alt_boost;
-#endif
 
         // Estimate the bits to be allocated to the group as a whole
         if ((cpi->twopass.kf_group_bits > 0) &&
@@ -1875,11 +1870,7 @@
             group_bits = 0;
 
         // Boost for arf frame
-#if NEW_BOOST
         Boost = (alt_boost * vp8_gfboost_qadjust(Q)) / 100;
-#else
-        Boost = (cpi->gfu_boost * 3 * vp8_gfboost_qadjust(Q)) / (2 * 100);
-#endif
         Boost += (i * 50);
 
         // Set max and minimum boost and hence minimum allocation
@@ -2042,11 +2033,7 @@
         // For ARF frames
         if (cpi->source_alt_ref_pending && i == 0)
         {
-#if NEW_BOOST
             Boost = (alt_boost * vp8_gfboost_qadjust(Q)) / 100;
-#else
-            Boost = (cpi->gfu_boost * 3 * vp8_gfboost_qadjust(Q)) / (2 * 100);
-#endif
             Boost += (cpi->baseline_gf_interval * 50);
 
             // Set max and minimum boost and hence minimum allocation
@@ -2165,12 +2152,9 @@
         // calculation of cpi->twopass.alt_extra_bits.
         if ( cpi->baseline_gf_interval >= 3 )
         {
-#if NEW_BOOST
             int boost = (cpi->source_alt_ref_pending)
                         ? b_boost : cpi->gfu_boost;
-#else
-            int boost = cpi->gfu_boost;
-#endif
+
             if ( boost >= 150 )
             {
                 int pct_extra;
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1680,7 +1680,6 @@
     // Set reference frame sign bias for ALTREF frame to 1 (for now)
     cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
 
-    cpi->twopass.gf_decay_rate = 0;
     cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
 
     cpi->gold_is_last = 0 ;
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -105,6 +105,7 @@
     double frame;
     double intra_error;
     double coded_error;
+    double sr_coded_error;
     double ssim_weighted_pred_err;
     double pcnt_inter;
     double pcnt_motion;
@@ -570,7 +571,6 @@
         int frames_to_key;
         int maxq_max_limit;
         int maxq_min_limit;
-        int gf_decay_rate;
         int static_scene_max_gf_interval;
         int kf_bits;
         int gf_group_error_left;           // Remaining error from uncoded frames in a gf group. Two pass use only