shithub: libvpx

Download patch

ref: 51acb0116731e80a430512351155b29244cb2305
parent: 45f4b87e8e274256c5f13662f243c27b8eb187d5
author: John Koleszar <jkoleszar@google.com>
date: Tue Feb 7 12:07:49 EST 2012

support changing resolution with vpx_codec_enc_config_set

Allow the application to change the frame size during encoding. This
is only supported when not using lagged compress.

Change-Id: I89b585d703d5fd728a9e3dedf997f1b595d0db0f

--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -323,6 +323,9 @@
 }
 
 
+static void dealloc_raw_frame_buffers(VP8_COMP *cpi);
+
+
 static void dealloc_compressor_data(VP8_COMP *cpi)
 {
     vpx_free(cpi->tplist);
@@ -349,10 +352,7 @@
 
     vp8_yv12_de_alloc_frame_buffer(&cpi->pick_lf_lvl_frame);
     vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
-#if VP8_TEMPORAL_ALT_REF
-    vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
-#endif
-    vp8_lookahead_destroy(cpi->lookahead);
+    dealloc_raw_frame_buffers(cpi);
 
     vpx_free(cpi->tok);
     cpi->tok = 0;
@@ -1044,6 +1044,16 @@
 #endif
 }
 
+
+static void dealloc_raw_frame_buffers(VP8_COMP *cpi)
+{
+#if VP8_TEMPORAL_ALT_REF
+    vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
+#endif
+    vp8_lookahead_destroy(cpi->lookahead);
+}
+
+
 static int vp8_alloc_partition_data(VP8_COMP *cpi)
 {
         vpx_free(cpi->mb.pip);
@@ -1387,6 +1397,7 @@
 void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
 {
     VP8_COMMON *cm = &cpi->common;
+    int last_w, last_h;
 
     if (!cpi)
         return;
@@ -1594,6 +1605,10 @@
 
     cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
 
+
+    last_w = cm->Width;
+    last_h = cm->Height;
+
     cm->Width       = cpi->oxcf.Width;
     cm->Height      = cpi->oxcf.Height;
 
@@ -1619,6 +1634,9 @@
         cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
     }
 
+    if (last_w != cm->Width || last_h != cm->Height)
+        cpi->force_next_frame_intra = 1;
+
     if (((cm->Width + 15) & 0xfffffff0) !=
           cm->yv12_fb[cm->lst_fb_idx].y_width ||
         ((cm->Height + 15) & 0xfffffff0) !=
@@ -3147,15 +3165,9 @@
     // Test code for segmentation of gf/arf (0,0)
     //segmentation_test_function( cpi);
 
-    if (cpi->compressor_speed == 2)
+    if(cpi->force_next_frame_intra)
     {
-        if(cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME)
-        {
-            if(cpi->force_next_frame_intra)
-            {
-                cm->frame_type = KEY_FRAME;  /* delayed intra frame */
-            }
-        }
+        cm->frame_type = KEY_FRAME;  /* delayed intra frame */
         cpi->force_next_frame_intra = 0;
     }
 
@@ -4550,6 +4562,15 @@
 #endif
 
     vpx_usec_timer_start(&timer);
+
+    /* Reinit the lookahead buffer if the frame size changes */
+    if (sd->y_width != cpi->common.Width || sd->y_height != cpi->common.Height)
+    {
+        assert(cpi->oxcf.lag_in_frames < 2);
+        dealloc_raw_frame_buffers(cpi);
+        alloc_raw_frame_buffers(cpi);
+    }
+
     if(vp8_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
                           frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL))
         res = -1;
--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -440,7 +440,8 @@
 {
     vpx_codec_err_t res;
 
-    if ((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h))
+    if (((cfg->g_w != ctx->cfg.g_w) || (cfg->g_h != ctx->cfg.g_h))
+        && cfg->g_lag_in_frames > 1)
         ERROR("Cannot change width or height after initialization");
 
     /* Prevent increasing lag_in_frames. This check is stricter than it needs