shithub: libvpx

Download patch

ref: feab7e1146f6b5f55fefc8d17a674c4c48dd3ac5
parent: a84029ad9ca9eb39f1fc66721f10b43600db77e6
parent: b57b82b5d6cfc9e52405bb331afe90283f1ff844
author: Dmitry Kovalev <dkovalev@google.com>
date: Wed Jan 8 09:14:05 EST 2014

Merge "Using struct twopass_rc* instead of VP9_COMP*."

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -92,30 +92,31 @@
 
 // Resets the first pass file to the given position using a relative seek from
 // the current position.
-static void reset_fpf_position(VP9_COMP *cpi, FIRSTPASS_STATS *position) {
-  cpi->twopass.stats_in = position;
+static void reset_fpf_position(struct twopass_rc *p,
+                               FIRSTPASS_STATS *position) {
+  p->stats_in = position;
 }
 
-static int lookup_next_frame_stats(VP9_COMP *cpi, FIRSTPASS_STATS *next_frame) {
-  if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
+static int lookup_next_frame_stats(const struct twopass_rc *p,
+                                   FIRSTPASS_STATS *next_frame) {
+  if (p->stats_in >= p->stats_in_end)
     return EOF;
 
-  *next_frame = *cpi->twopass.stats_in;
+  *next_frame = *p->stats_in;
   return 1;
 }
 
 // Read frame stats at an offset from the current position
-static int read_frame_stats(VP9_COMP *cpi,
-                            FIRSTPASS_STATS *frame_stats,
-                            int offset) {
-  FIRSTPASS_STATS *fps_ptr = cpi->twopass.stats_in;
+static int read_frame_stats(const struct twopass_rc *p,
+                            FIRSTPASS_STATS *frame_stats, int offset) {
+  const FIRSTPASS_STATS *fps_ptr = p->stats_in;
 
   // Check legality of offset
   if (offset >= 0) {
-    if (&fps_ptr[offset] >= cpi->twopass.stats_in_end)
+    if (&fps_ptr[offset] >= p->stats_in_end)
       return EOF;
   } else if (offset < 0) {
-    if (&fps_ptr[offset] < cpi->twopass.stats_in_start)
+    if (&fps_ptr[offset] < p->stats_in_start)
       return EOF;
   }
 
@@ -123,13 +124,12 @@
   return 1;
 }
 
-static int input_stats(VP9_COMP *cpi, FIRSTPASS_STATS *fps) {
-  if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end)
+static int input_stats(struct twopass_rc *p, FIRSTPASS_STATS *fps) {
+  if (p->stats_in >= p->stats_in_end)
     return EOF;
 
-  *fps = *cpi->twopass.stats_in;
-  cpi->twopass.stats_in =
-    (void *)((char *)cpi->twopass.stats_in + sizeof(FIRSTPASS_STATS));
+  *fps = *p->stats_in;
+  ++p->stats_in;
   return 1;
 }
 
@@ -1097,7 +1097,7 @@
 
     start_pos = cpi->twopass.stats_in;  // Note the starting "file" position.
 
-    while (input_stats(cpi, &this_frame) != EOF) {
+    while (input_stats(&cpi->twopass, &this_frame) != EOF) {
       IIRatio = this_frame.intra_error
                 / DOUBLE_DIVIDE_CHECK(this_frame.coded_error);
       IIRatio = (IIRatio < 1.0) ? 1.0 : (IIRatio > 20.0) ? 20.0 : IIRatio;
@@ -1108,7 +1108,7 @@
         DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count);
 
     // Reset file position
-    reset_fpf_position(cpi, start_pos);
+    reset_fpf_position(&cpi->twopass, start_pos);
   }
 
   // Scan the first pass file and calculate a modified total error based upon
@@ -1125,13 +1125,13 @@
     cpi->twopass.modified_error_max =
       (av_error * cpi->oxcf.two_pass_vbrmax_section) / 100;
 
-    while (input_stats(cpi, &this_frame) != EOF) {
+    while (input_stats(&cpi->twopass, &this_frame) != EOF) {
       cpi->twopass.modified_error_total +=
           calculate_modified_err(cpi, &this_frame);
     }
     cpi->twopass.modified_error_left = cpi->twopass.modified_error_total;
 
-    reset_fpf_position(cpi, start_pos);  // Reset file position
+    reset_fpf_position(&cpi->twopass, start_pos);  // Reset file position
   }
 }
 
@@ -1178,7 +1178,7 @@
     // Look ahead a few frames to see if static condition
     // persists...
     for (j = 0; j < still_interval; j++) {
-      if (EOF == input_stats(cpi, &tmp_next_frame))
+      if (EOF == input_stats(&cpi->twopass, &tmp_next_frame))
         break;
 
       zz_inter =
@@ -1187,7 +1187,7 @@
         break;
     }
     // Reset file position
-    reset_fpf_position(cpi, position);
+    reset_fpf_position(&cpi->twopass, position);
 
     // Only if it does do we signal a transition to still
     if (j == still_interval)
@@ -1207,7 +1207,7 @@
 
   // Read the frame data.
   // The return is FALSE (no flash detected) if not a valid frame
-  if (read_frame_stats(cpi, &next_frame, offset) != EOF) {
+  if (read_frame_stats(&cpi->twopass, &next_frame, offset) != EOF) {
     // What we are looking for here is a situation where there is a
     // brief break in prediction (such as a flash) but subsequent frames
     // are reasonably well predicted by an earlier (pre flash) frame.
@@ -1312,7 +1312,7 @@
 
   // Search forward from the proposed arf/next gf position
   for (i = 0; i < f_frames; i++) {
-    if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF)
+    if (read_frame_stats(&cpi->twopass, &this_frame, (i + offset)) == EOF)
       break;
 
     // Update the motion related elements to the boost calculation
@@ -1349,7 +1349,7 @@
 
   // Search backward towards last gf position
   for (i = -1; i >= -b_frames; i--) {
-    if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF)
+    if (read_frame_stats(&cpi->twopass, &this_frame, (i + offset)) == EOF)
       break;
 
     // Update the motion related elements to the boost calculation
@@ -1597,7 +1597,7 @@
     mod_frame_err = calculate_modified_err(cpi, this_frame);
     gf_group_err += mod_frame_err;
 
-    if (EOF == input_stats(cpi, &next_frame))
+    if (EOF == input_stats(&cpi->twopass, &next_frame))
       break;
 
     // Test for the case where there is a brief flash but the prediction
@@ -1666,7 +1666,7 @@
     while (i < (cpi->rc.frames_to_key - 1)) {
       i++;
 
-      if (EOF == input_stats(cpi, this_frame))
+      if (EOF == input_stats(&cpi->twopass, this_frame))
         break;
 
       if (i < cpi->rc.frames_to_key) {
@@ -1797,7 +1797,7 @@
         (int64_t)max_bits * cpi->rc.baseline_gf_interval;
 
   // Reset the file position
-  reset_fpf_position(cpi, start_pos);
+  reset_fpf_position(&cpi->twopass, start_pos);
 
   // Assign  bits to the arf or gf.
   for (i = 0;
@@ -1922,10 +1922,10 @@
     FIRSTPASS_STATS sectionstats;
 
     zero_stats(&sectionstats);
-    reset_fpf_position(cpi, start_pos);
+    reset_fpf_position(&cpi->twopass, start_pos);
 
     for (i = 0; i < cpi->rc.baseline_gf_interval; i++) {
-      input_stats(cpi, &next_frame);
+      input_stats(&cpi->twopass, &next_frame);
       accumulate_stats(&sectionstats, &next_frame);
     }
 
@@ -1935,7 +1935,7 @@
       (sectionstats.intra_error /
       DOUBLE_DIVIDE_CHECK(sectionstats.coded_error));
 
-    reset_fpf_position(cpi, start_pos);
+    reset_fpf_position(&cpi->twopass, start_pos);
   }
 }
 
@@ -2079,7 +2079,7 @@
     // adjust_maxq_qrange(cpi);
   }
   vp9_zero(this_frame);
-  if (EOF == input_stats(cpi, &this_frame))
+  if (EOF == input_stats(&cpi->twopass, &this_frame))
     return;
 
   this_frame_intra_error = this_frame.intra_error;
@@ -2147,7 +2147,7 @@
                               DOUBLE_DIVIDE_CHECK(this_frame_coded_error));
   {
     FIRSTPASS_STATS next_frame;
-    if (lookup_next_frame_stats(cpi, &next_frame) != EOF) {
+    if (lookup_next_frame_stats(&cpi->twopass, &next_frame) != EOF) {
       cpi->twopass.next_iiratio = (int)(next_frame.intra_error /
                                   DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
     }
@@ -2235,7 +2235,7 @@
       old_boost_score = boost_score;
 
       // Get the next frame details
-      if (EOF == input_stats(cpi, &local_next_frame))
+      if (EOF == input_stats(&cpi->twopass, &local_next_frame))
         break;
     }
 
@@ -2245,7 +2245,7 @@
       is_viable_kf = 1;
     } else {
       // Reset the file position
-      reset_fpf_position(cpi, start_pos);
+      reset_fpf_position(&cpi->twopass, start_pos);
 
       is_viable_kf = 0;
     }
@@ -2312,11 +2312,11 @@
 
     // load a the next frame's stats
     last_frame = *this_frame;
-    input_stats(cpi, this_frame);
+    input_stats(&cpi->twopass, this_frame);
 
     // Provided that we are not at the end of the file...
-    if (cpi->oxcf.auto_key
-        && lookup_next_frame_stats(cpi, &next_frame) != EOF) {
+    if (cpi->oxcf.auto_key &&
+        lookup_next_frame_stats(&cpi->twopass, &next_frame) != EOF) {
       // Normal scene cut check
       if (test_candidate_kf(cpi, &last_frame, this_frame, &next_frame))
         break;
@@ -2367,7 +2367,7 @@
     tmp_frame = first_frame;
 
     // Reset to the start of the group
-    reset_fpf_position(cpi, start_position);
+    reset_fpf_position(&cpi->twopass, start_position);
 
     kf_group_err = 0;
     kf_group_intra_err = 0;
@@ -2381,11 +2381,11 @@
       kf_group_coded_err += tmp_frame.coded_error;
 
       // Load a the next frame's stats
-      input_stats(cpi, &tmp_frame);
+      input_stats(&cpi->twopass, &tmp_frame);
     }
 
     // Reset to the start of the group
-    reset_fpf_position(cpi, current_pos);
+    reset_fpf_position(&cpi->twopass, current_pos);
 
     cpi->rc.next_key_frame_forced = 1;
   } else {
@@ -2426,7 +2426,7 @@
     cpi->twopass.kf_group_bits = 0;
   }
   // Reset the first pass file position
-  reset_fpf_position(cpi, start_position);
+  reset_fpf_position(&cpi->twopass, start_position);
 
   // Determine how big to make this keyframe based on how well the subsequent
   // frames use inter blocks.
@@ -2438,7 +2438,7 @@
   for (i = 0; i < cpi->rc.frames_to_key; i++) {
     double r;
 
-    if (EOF == input_stats(cpi, &next_frame))
+    if (EOF == input_stats(&cpi->twopass, &next_frame))
       break;
 
     // Monitor for static sections.
@@ -2476,10 +2476,10 @@
     FIRSTPASS_STATS sectionstats;
 
     zero_stats(&sectionstats);
-    reset_fpf_position(cpi, start_position);
+    reset_fpf_position(&cpi->twopass, start_position);
 
     for (i = 0; i < cpi->rc.frames_to_key; i++) {
-      input_stats(cpi, &next_frame);
+      input_stats(&cpi->twopass, &next_frame);
       accumulate_stats(&sectionstats, &next_frame);
     }
 
@@ -2491,7 +2491,7 @@
   }
 
   // Reset the first pass file position
-  reset_fpf_position(cpi, start_position);
+  reset_fpf_position(&cpi->twopass, start_position);
 
   // Work out how many bits to allocate for the key frame itself
   if (1) {