shithub: libvpx

Download patch

ref: d03d1c8cd30b3bd711fcb50599adbaf8131f2a42
parent: 57e4cbc632599606ec6cd0d7bc7185c94ed4db7b
author: Vignesh Venkatasubramanian <[email protected]>
date: Mon Oct 10 10:45:39 EDT 2016

vp9_bitstream: Parameterize max_mv_magnitude

Facilitates encoding tiles in parallel.

BUG=webm:1309

Change-Id: I614a5a492c30b6773c30e7294cd6a6f456e02ab4

--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -232,7 +232,8 @@
 
 static void pack_inter_mode_mvs(VP9_COMP *cpi, const MACROBLOCKD *const xd,
                                 const MB_MODE_INFO_EXT *const mbmi_ext,
-                                vpx_writer *w) {
+                                vpx_writer *w,
+                                unsigned int *const max_mv_magnitude) {
   VP9_COMMON *const cm = &cpi->common;
   const nmv_context *nmvc = &cm->fc->nmvc;
   const struct segmentation *const seg = &cm->seg;
@@ -316,7 +317,7 @@
             for (ref = 0; ref < 1 + is_compound; ++ref)
               vp9_encode_mv(cpi, w, &mi->bmi[j].as_mv[ref].as_mv,
                             &mbmi_ext->ref_mvs[mi->ref_frame[ref]][0].as_mv,
-                            nmvc, allow_hp);
+                            nmvc, allow_hp, max_mv_magnitude);
           }
         }
       }
@@ -325,7 +326,7 @@
         for (ref = 0; ref < 1 + is_compound; ++ref)
           vp9_encode_mv(cpi, w, &mi->mv[ref].as_mv,
                         &mbmi_ext->ref_mvs[mi->ref_frame[ref]][0].as_mv, nmvc,
-                        allow_hp);
+                        allow_hp, max_mv_magnitude);
       }
     }
   }
@@ -368,7 +369,8 @@
 static void write_modes_b(VP9_COMP *cpi, MACROBLOCKD *const xd,
                           const TileInfo *const tile, vpx_writer *w,
                           TOKENEXTRA **tok, const TOKENEXTRA *const tok_end,
-                          int mi_row, int mi_col) {
+                          int mi_row, int mi_col,
+                          unsigned int *const max_mv_magnitude) {
   const VP9_COMMON *const cm = &cpi->common;
   const MB_MODE_INFO_EXT *const mbmi_ext =
       cpi->td.mb.mbmi_ext_base + (mi_row * cm->mi_cols + mi_col);
@@ -383,7 +385,7 @@
   if (frame_is_intra_only(cm)) {
     write_mb_modes_kf(cm, xd, w);
   } else {
-    pack_inter_mode_mvs(cpi, xd, mbmi_ext, w);
+    pack_inter_mode_mvs(cpi, xd, mbmi_ext, w, max_mv_magnitude);
   }
 
   assert(*tok < tok_end);
@@ -415,7 +417,8 @@
 static void write_modes_sb(VP9_COMP *cpi, MACROBLOCKD *const xd,
                            const TileInfo *const tile, vpx_writer *w,
                            TOKENEXTRA **tok, const TOKENEXTRA *const tok_end,
-                           int mi_row, int mi_col, BLOCK_SIZE bsize) {
+                           int mi_row, int mi_col, BLOCK_SIZE bsize,
+                           unsigned int *const max_mv_magnitude) {
   const VP9_COMMON *const cm = &cpi->common;
   const int bsl = b_width_log2_lookup[bsize];
   const int bs = (1 << bsl) / 4;
@@ -431,30 +434,37 @@
   write_partition(cm, xd, bs, mi_row, mi_col, partition, bsize, w);
   subsize = get_subsize(bsize, partition);
   if (subsize < BLOCK_8X8) {
-    write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col);
+    write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col,
+                  max_mv_magnitude);
   } else {
     switch (partition) {
       case PARTITION_NONE:
-        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col);
+        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col,
+                      max_mv_magnitude);
         break;
       case PARTITION_HORZ:
-        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col);
+        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col,
+                      max_mv_magnitude);
         if (mi_row + bs < cm->mi_rows)
-          write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row + bs, mi_col);
+          write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row + bs, mi_col,
+                        max_mv_magnitude);
         break;
       case PARTITION_VERT:
-        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col);
+        write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col,
+                      max_mv_magnitude);
         if (mi_col + bs < cm->mi_cols)
-          write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col + bs);
+          write_modes_b(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col + bs,
+                        max_mv_magnitude);
         break;
       case PARTITION_SPLIT:
-        write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col, subsize);
+        write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col, subsize,
+                       max_mv_magnitude);
         write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col + bs,
-                       subsize);
+                       subsize, max_mv_magnitude);
         write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row + bs, mi_col,
-                       subsize);
+                       subsize, max_mv_magnitude);
         write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row + bs, mi_col + bs,
-                       subsize);
+                       subsize, max_mv_magnitude);
         break;
       default: assert(0);
     }
@@ -468,7 +478,8 @@
 
 static void write_modes(VP9_COMP *cpi, MACROBLOCKD *const xd,
                         const TileInfo *const tile, vpx_writer *w,
-                        TOKENEXTRA **tok, const TOKENEXTRA *const tok_end) {
+                        TOKENEXTRA **tok, const TOKENEXTRA *const tok_end,
+                        unsigned int *const max_mv_magnitude) {
   const VP9_COMMON *const cm = &cpi->common;
   int mi_row, mi_col;
 
@@ -480,7 +491,7 @@
     for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end;
          mi_col += MI_BLOCK_SIZE)
       write_modes_sb(cpi, xd, tile, w, tok, tok_end, mi_row, mi_col,
-                     BLOCK_64X64);
+                     BLOCK_64X64, max_mv_magnitude);
   }
 }
 
@@ -922,7 +933,7 @@
         vpx_start_encode(&residual_bc, data_ptr + total_size);
 
       write_modes(cpi, xd, &cpi->tile_data[tile_idx].tile_info, &residual_bc,
-                  &tok, tok_end);
+                  &tok, tok_end, &cpi->max_mv_magnitude);
       assert(tok == tok_end);
       vpx_stop_encode(&residual_bc);
       if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) {
--- a/vp9/encoder/vp9_encodemv.c
+++ b/vp9/encoder/vp9_encodemv.c
@@ -208,7 +208,8 @@
 }
 
 void vp9_encode_mv(VP9_COMP *cpi, vpx_writer *w, const MV *mv, const MV *ref,
-                   const nmv_context *mvctx, int usehp) {
+                   const nmv_context *mvctx, int usehp,
+                   unsigned int *const max_mv_magnitude) {
   const MV diff = { mv->row - ref->row, mv->col - ref->col };
   const MV_JOINT_TYPE j = vp9_get_mv_joint(&diff);
   usehp = usehp && use_mv_hp(ref);
@@ -223,8 +224,8 @@
   // If auto_mv_step_size is enabled then keep track of the largest
   // motion vector component used.
   if (cpi->sf.mv.auto_mv_step_size) {
-    unsigned int maxv = VPXMAX(abs(mv->row), abs(mv->col)) >> 3;
-    cpi->max_mv_magnitude = VPXMAX(maxv, cpi->max_mv_magnitude);
+    const unsigned int maxv = VPXMAX(abs(mv->row), abs(mv->col)) >> 3;
+    *max_mv_magnitude = VPXMAX(maxv, *max_mv_magnitude);
   }
 }
 
--- a/vp9/encoder/vp9_encodemv.h
+++ b/vp9/encoder/vp9_encodemv.h
@@ -23,7 +23,8 @@
                          nmv_context_counts *const counts);
 
 void vp9_encode_mv(VP9_COMP *cpi, vpx_writer *w, const MV *mv, const MV *ref,
-                   const nmv_context *mvctx, int usehp);
+                   const nmv_context *mvctx, int usehp,
+                   unsigned int *const max_mv_magnitude);
 
 void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
                               const nmv_context *mvctx, int usehp);