Reset Q for key frame when spatial resizing occurs.
authorMarco Paniconi <marpan@google.com>
Wed, 6 Jun 2012 18:38:48 +0000 (11:38 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Wed, 6 Jun 2012 22:18:18 +0000 (15:18 -0700)
The logic for spatial resizing is done after the Q is selected for the
frame. This causes a problem that the Q we select for the (resized)
key frame may be based on a different resolution than the frame we
will encode.

This fix is to ensure that, when resize is on, the selected Q is still
based on the resolution of the frame to be encoded.

Change-Id: Ia49a9eac5f64e48d1c00dfc7ed4ce26fe84d3fa1

vp8/encoder/onyx_if.c

index 878cad4..5b4d08b 100644 (file)
@@ -2612,7 +2612,7 @@ static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
 }
 
 
-static void resize_key_frame(VP8_COMP *cpi)
+static int resize_key_frame(VP8_COMP *cpi)
 {
 #if CONFIG_SPATIAL_RESAMPLING
     VP8_COMMON *cm = &cpi->common;
@@ -2653,10 +2653,12 @@ static void resize_key_frame(VP8_COMP *cpi)
             cm->Height = new_height;
             vp8_alloc_compressor_data(cpi);
             scale_and_extend_source(cpi->un_scaled_source, cpi);
+            return 1;
         }
     }
 
 #endif
+    return 0;
 }
 
 
@@ -3801,7 +3803,17 @@ static void encode_frame_to_data_rate
 
         if (cm->frame_type == KEY_FRAME)
         {
-            resize_key_frame(cpi);
+            if(resize_key_frame(cpi))
+            {
+              /* If the frame size has changed, need to reset Q, quantizer,
+               * and background refresh.
+               */
+              Q = vp8_regulate_q(cpi, cpi->this_frame_target);
+              if (cpi->cyclic_refresh_mode_enabled && (cpi->current_layer==0))
+                cyclic_background_refresh(cpi, Q, 0);
+              vp8_set_quantizer(cpi, Q);
+            }
+
             vp8_setup_key_frame(cpi);
         }