shithub: libvpx

Download patch

ref: 6b22c999ca9192cee05c28dd9dabb8977226d37b
parent: 3ff77503c935c105f5cab28bd7c508ba0a66080e
author: Jingning Han <jingning@google.com>
date: Fri Jul 27 11:08:39 EDT 2018

Add frame pointer to support recon frames in tpl model

Add frame pointer to re-use spare frames to store the reconstructed
frames.

Change-Id: I870aa048fc9b7d8b356aa73df3a92b4670425f95

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -5496,12 +5496,40 @@
 
 void init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture,
                      const GF_GROUP *gf_group, int *tpl_group_frames) {
-  int frame_idx, i;
+  VP9_COMMON *cm = &cpi->common;
+  int frame_idx = 0;
+  int i;
   int gld_index = -1;
   int alt_index = -1;
   int lst_index = -1;
   int extend_frame_count = 0;
   int pframe_qindex = cpi->tpl_stats[2].base_qindex;
+
+  RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs;
+  int recon_frame_index[REFS_PER_FRAME + 1] = { -1, -1, -1, -1 };
+
+  for (i = 0; i < FRAME_BUFFERS && frame_idx < REFS_PER_FRAME + 1; ++i) {
+    if (frame_bufs[i].ref_count == 0) {
+      alloc_frame_mvs(cm, i);
+      if (vpx_realloc_frame_buffer(&frame_bufs[i].buf, cm->width, cm->height,
+                                   cm->subsampling_x, cm->subsampling_y,
+#if CONFIG_VP9_HIGHBITDEPTH
+                                   cm->use_highbitdepth,
+#endif
+                                   VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
+                                   NULL, NULL, NULL))
+        vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
+                           "Failed to allocate frame buffer");
+
+      recon_frame_index[frame_idx] = i;
+      ++frame_idx;
+    }
+  }
+
+  for (i = 0; i < REFS_PER_FRAME + 1; ++i) {
+    assert(recon_frame_index[i] >= 0);
+    cpi->tpl_recon_frames[i] = &frame_bufs[recon_frame_index[i]].buf;
+  }
 
   *tpl_group_frames = 0;
 
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -501,6 +501,7 @@
   YV12_BUFFER_CONFIG *raw_source_frame;
 
   TplDepFrame tpl_stats[MAX_LAG_BUFFERS];
+  YV12_BUFFER_CONFIG *tpl_recon_frames[REFS_PER_FRAME + 1];
 
   TileDataEnc *tile_data;
   int allocated_tiles;  // Keep track of memory allocated for tiles.