]> granicus.if.org Git - libvpx/commitdiff
Interleave modes/residual per macroblock
authorJohn Koleszar <jkoleszar@google.com>
Tue, 16 Oct 2012 20:52:39 +0000 (13:52 -0700)
committerJohn Koleszar <jkoleszar@google.com>
Wed, 17 Oct 2012 20:19:41 +0000 (13:19 -0700)
Packs the bitstream with each mb's residual following its mode/mv
information.

TODO: There are still a few fields that should be packed into partition
0 but are included in partition 1, due to them being serialized from
write_kfmodes/pack_inter_mode_mvs, which execute after the first
partition is finalized. These need to be separated out into a separate
function, similar to mb_mode_mv_init() in decodemv.c.

Change-Id: I43a46c363601ab36954d07ebe498760e1e2e3af4

vp8/common/entropy.h
vp8/common/pred_common.c
vp8/common/pred_common.h
vp8/common/seg_common.c
vp8/common/seg_common.h
vp8/decoder/decodemv.c
vp8/decoder/decodframe.c
vp8/encoder/bitstream.c
vp8/encoder/encodeframe.c
vp8/encoder/encodemv.c

index 4af3ecf15e972fcdef446313a90a7c0f2d131cc4..b9dfb344f9da0fb71af665fc82d97732fd0b7a20 100644 (file)
@@ -37,9 +37,9 @@ extern const int vp8_i8x8_block[4];
 #define DCT_VAL_CATEGORY5       9       /* 35-66     Extra Bits 5+1 */
 #define DCT_VAL_CATEGORY6       10      /* 67+       Extra Bits 13+1 */
 #define DCT_EOB_TOKEN           11      /* EOB       Extra Bits 0+0 */
-
 #define MAX_ENTROPY_TOKENS 12
 #define ENTROPY_NODES 11
+#define EOSB_TOKEN              127     /* Not signalled, encoder only */
 
 extern const vp8_tree_index vp8_coef_tree[];
 
index cb80a0f7e92e438d823456989181c268abfb2e1e..a32389433882bc25f258efb73459c51dcffbcbb9 100644 (file)
@@ -15,8 +15,8 @@
 // TBD prediction functions for various bitstream signals
 
 // Returns a context number for the given MB prediction signal
-unsigned char get_pred_context(VP8_COMMON *const cm,
-                               MACROBLOCKD *const xd,
+unsigned char get_pred_context(const VP8_COMMON *const cm,
+                               const MACROBLOCKD *const xd,
                                PRED_ID pred_id) {
   int pred_context;
   MODE_INFO *m = xd->mode_info_context;
@@ -106,8 +106,8 @@ unsigned char get_pred_context(VP8_COMMON *const cm,
 
 // This function returns a context probability for coding a given
 // prediction signal
-vp8_prob get_pred_prob(VP8_COMMON *const cm,
-                       MACROBLOCKD *const xd,
+vp8_prob get_pred_prob(const VP8_COMMON *const cm,
+                       const MACROBLOCKD *const xd,
                        PRED_ID pred_id) {
   vp8_prob pred_probability;
   int pred_context;
@@ -146,10 +146,10 @@ vp8_prob get_pred_prob(VP8_COMMON *const cm,
 
 // This function returns a context probability ptr for coding a given
 // prediction signal
-vp8_prob *get_pred_probs(VP8_COMMON *const cm,
-                         MACROBLOCKD *const xd,
+const vp8_prob *get_pred_probs(const VP8_COMMON *const cm,
+                         const MACROBLOCKD *const xd,
                          PRED_ID pred_id) {
-  vp8_prob *pred_probability;
+  const vp8_prob *pred_probability;
   int pred_context;
 
   // Get the appropriate prediction context
@@ -191,7 +191,7 @@ vp8_prob *get_pred_probs(VP8_COMMON *const cm,
 
 // This function returns the status of the given prediction signal.
 // I.e. is the predicted value for the given signal correct.
-unsigned char get_pred_flag(MACROBLOCKD *const xd,
+unsigned char get_pred_flag(const MACROBLOCKD *const xd,
                             PRED_ID pred_id) {
   unsigned char pred_flag = 0;
 
@@ -260,14 +260,14 @@ void set_pred_flag(MACROBLOCKD *const xd,
 // peredict various bitstream signals.
 
 // Macroblock segment id prediction function
-unsigned char get_pred_mb_segid(VP8_COMMON *const cm, int MbIndex) {
+unsigned char get_pred_mb_segid(const VP8_COMMON *const cm, int MbIndex) {
   // Currently the prediction for the macroblock segment ID is
   // the value stored for this macroblock in the previous frame.
   return cm->last_frame_seg_map[MbIndex];
 }
 
-MV_REFERENCE_FRAME get_pred_ref(VP8_COMMON *const cm,
-                                MACROBLOCKD *const xd) {
+MV_REFERENCE_FRAME get_pred_ref(const VP8_COMMON *const cm,
+                                const MACROBLOCKD *const xd) {
   MODE_INFO *m = xd->mode_info_context;
 
   MV_REFERENCE_FRAME left;
index f4992f55546f866894081aba476aafcf8278d3d3..402e0235f13b7a77b87ecb11312dfbc4c5b7dd0d 100644 (file)
@@ -28,19 +28,19 @@ typedef enum {
 } PRED_ID;
 
 
-extern unsigned char get_pred_context(VP8_COMMON *const cm,
-                                      MACROBLOCKD *const xd,
+extern unsigned char get_pred_context(const VP8_COMMON *const cm,
+                                      const MACROBLOCKD *const xd,
                                       PRED_ID pred_id);
 
-extern vp8_prob get_pred_prob(VP8_COMMON *const cm,
-                              MACROBLOCKD *const xd,
+extern vp8_prob get_pred_prob(const VP8_COMMON *const cm,
+                              const MACROBLOCKD *const xd,
                               PRED_ID pred_id);
 
-extern vp8_prob *get_pred_probs(VP8_COMMON *const cm,
-                                MACROBLOCKD *const xd,
+extern const vp8_prob *get_pred_probs(const VP8_COMMON *const cm,
+                                const MACROBLOCKD *const xd,
                                 PRED_ID pred_id);
 
-extern unsigned char get_pred_flag(MACROBLOCKD *const xd,
+extern unsigned char get_pred_flag(const MACROBLOCKD *const xd,
                                    PRED_ID pred_id);
 
 extern void set_pred_flag(MACROBLOCKD *const xd,
@@ -48,10 +48,10 @@ extern void set_pred_flag(MACROBLOCKD *const xd,
                           unsigned char pred_flag);
 
 
-extern unsigned char get_pred_mb_segid(VP8_COMMON *const cm, int MbIndex);
+extern unsigned char get_pred_mb_segid(const VP8_COMMON *const cm, int MbIndex);
 
-extern MV_REFERENCE_FRAME get_pred_ref(VP8_COMMON *const cm,
-                                       MACROBLOCKD *const xd);
+extern MV_REFERENCE_FRAME get_pred_ref(const VP8_COMMON *const cm,
+                                       const MACROBLOCKD *const xd);
 extern void compute_mod_refprobs(VP8_COMMON *const cm);
 
 #endif /* __INC_PRED_COMMON_H__ */
index b616391ba1191be5c99b77a053617724ed81a4a9..a11fe87e9020cd9ee15afc309df5ac989668d6c4 100644 (file)
@@ -19,7 +19,7 @@ const int vp8_seg_feature_data_bits[SEG_LVL_MAX] =
 // the coding mechanism is still subject to change so these provide a
 // convenient single point of change.
 
-int segfeature_active(MACROBLOCKD *xd,
+int segfeature_active(const MACROBLOCKD *xd,
                       int segment_id,
                       SEG_LVL_FEATURES feature_id) {
   // Return true if mask bit set and segmentation enabled.
@@ -66,7 +66,7 @@ void set_segdata(MACROBLOCKD *xd,
   xd->segment_feature_data[segment_id][feature_id] = seg_data;
 }
 
-int get_segdata(MACROBLOCKD *xd,
+int get_segdata(const MACROBLOCKD *xd,
                 int segment_id,
                 SEG_LVL_FEATURES feature_id) {
   return xd->segment_feature_data[segment_id][feature_id];
@@ -126,7 +126,7 @@ void set_segref(MACROBLOCKD *xd,
     (1 << ref_frame);
 }
 
-int check_segref(MACROBLOCKD *xd,
+int check_segref(const MACROBLOCKD *xd,
                  int segment_id,
                  MV_REFERENCE_FRAME ref_frame) {
   return (xd->segment_feature_data[segment_id][SEG_LVL_REF_FRAME] &
index 74131926f8e82efe7371d2d07e5f393fcf5b32b6..59f40d112cc66bf957b0b16297ea2ce8c69fe180 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef __INC_SEG_COMMON_H__
 #define __INC_SEG_COMMON_H__ 1
 
-int segfeature_active(MACROBLOCKD *xd,
+int segfeature_active(const MACROBLOCKD *xd,
                       int segment_id,
                       SEG_LVL_FEATURES feature_id);
 
@@ -42,7 +42,7 @@ void set_segdata(MACROBLOCKD *xd,
                  SEG_LVL_FEATURES feature_id,
                  int seg_data);
 
-int get_segdata(MACROBLOCKD *xd,
+int get_segdata(const MACROBLOCKD *xd,
                 int segment_id,
                 SEG_LVL_FEATURES feature_id);
 
@@ -73,7 +73,7 @@ void set_segref(MACROBLOCKD *xd,
                 int segment_id,
                 MV_REFERENCE_FRAME ref_frame);
 
-int check_segref(MACROBLOCKD *xd,
+int check_segref(const MACROBLOCKD *xd,
                  int segment_id,
                  MV_REFERENCE_FRAME ref_frame);
 
index 4408ae7f91fcab21701d03eacf799427b3f7d983..c5fc6d58d47587f85efb537eb83d67eb3c4d997c 100644 (file)
@@ -78,7 +78,7 @@ static void vp8_kfread_modes(VP8D_COMP *pbi,
                              int mb_row,
                              int mb_col) {
   VP8_COMMON *const cm = & pbi->common;
-  vp8_reader *const bc = & pbi->bc;
+  vp8_reader *const bc = pbi->mb.current_bc;
   const int mis = pbi->common.mode_info_stride;
   int map_index = mb_row * pbi->common.mb_cols + mb_col;
   MB_PREDICTION_MODE y_mode;
@@ -612,9 +612,8 @@ static void read_switchable_interp_probs(VP8D_COMP *pbi) {
 }
 #endif
 
-static void mb_mode_mv_init(VP8D_COMP *pbi) {
+static void mb_mode_mv_init(VP8D_COMP *pbi, vp8_reader *bc) {
   VP8_COMMON *const cm = & pbi->common;
-  vp8_reader *const bc = & pbi->bc;
 #if CONFIG_NEWMVENTROPY
   nmv_context *const nmvc = &pbi->common.fc.nmvc;
 #else
@@ -682,9 +681,9 @@ static void mb_mode_mv_init(VP8D_COMP *pbi) {
 // value
 static void read_mb_segment_id(VP8D_COMP *pbi,
                                int mb_row, int mb_col) {
-  vp8_reader *const bc = & pbi->bc;
   VP8_COMMON *const cm = & pbi->common;
   MACROBLOCKD *const xd  = & pbi->mb;
+  vp8_reader *const bc = xd->current_bc;
   MODE_INFO *mi = xd->mode_info_context;
   MB_MODE_INFO *mbmi = &mi->mbmi;
   int index = mb_row * pbi->common.mb_cols + mb_col;
@@ -755,7 +754,6 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
                              MODE_INFO *prev_mi,
                              int mb_row, int mb_col) {
   VP8_COMMON *const cm = & pbi->common;
-  vp8_reader *const bc = & pbi->bc;
 #if CONFIG_NEWMVENTROPY
   nmv_context *const nmvc = &pbi->common.fc.nmvc;
 #else
@@ -764,6 +762,7 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
 #endif
   const int mis = pbi->common.mode_info_stride;
   MACROBLOCKD *const xd  = & pbi->mb;
+  vp8_reader *const bc = xd->current_bc;
 
   int_mv *const mv = & mbmi->mv;
   int mb_to_left_edge;
@@ -1304,9 +1303,10 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
 
 void vpx_decode_mode_mvs_init(VP8D_COMP *pbi){
   VP8_COMMON *cm = &pbi->common;
-  mb_mode_mv_init(pbi);
+
+  mb_mode_mv_init(pbi, pbi->mb.current_bc);
   if (cm->frame_type == KEY_FRAME && !cm->kf_ymode_probs_update)
-    cm->kf_ymode_probs_index = vp8_read_literal(&pbi->bc, 3);
+    cm->kf_ymode_probs_index = vp8_read_literal(pbi->mb.current_bc, 3);
 }
 void vpx_decode_mb_mode_mv(VP8D_COMP *pbi,
                            MACROBLOCKD *xd,
index bcf6ea3d4f029703d4ac4b2a004c74050e36f414..4d12d7a3e4e7c647ca01104882c5fe85c85c1a73 100644 (file)
@@ -1149,7 +1149,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) {
 
   init_frame(pbi);
 
-  if (vp8dx_start_decode(bc, data, data_end - data))
+  if (vp8dx_start_decode(bc, data, first_partition_length_in_bytes))
     vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
                        "Failed to allocate bool decoder 0");
   if (pc->frame_type == KEY_FRAME) {
index 812565915f28153f6cbe900f7a47391e1c6c2416..db585646a00716e688db01e0a8fc3ec933686504 100644 (file)
@@ -226,7 +226,7 @@ static void update_mode(
 static void update_mbintra_mode_probs(VP8_COMP *cpi) {
   VP8_COMMON *const cm = & cpi->common;
 
-  vp8_writer *const w = & cpi->bc;
+  vp8_writer *const w = & cpi->bc2;
 
   {
     vp8_prob Pnew   [VP8_YMODES - 1];
@@ -454,13 +454,15 @@ static int prob_diff_update_savings_search(const unsigned int *ct,
   return bestsavings;
 }
 
-static void pack_tokens_c(vp8_writer *w, const TOKENEXTRA *p, int xcount) {
-  const TOKENEXTRA *const stop = p + xcount;
+static void pack_mb_tokens(vp8_writer *w,
+                           TOKENEXTRA **tp,
+                           const TOKENEXTRA *const stop) {
   unsigned int split;
   unsigned int shift;
   int count = w->count;
   unsigned int range = w->range;
   unsigned int lowvalue = w->lowvalue;
+  TOKENEXTRA *p = *tp;
 
   while (p < stop) {
     const int t = p->Token;
@@ -471,6 +473,12 @@ static void pack_tokens_c(vp8_writer *w, const TOKENEXTRA *p, int xcount) {
     int v = a->value;
     int n = a->Len;
 
+    if (t == EOSB_TOKEN)
+    {
+      ++p;
+      break;
+    }
+
     /* skip one or two nodes */
     if (p->skip_eob_node) {
       n -= p->skip_eob_node;
@@ -604,14 +612,13 @@ static void pack_tokens_c(vp8_writer *w, const TOKENEXTRA *p, int xcount) {
       }
 
     }
-
     ++p;
   }
 
   w->count = count;
   w->lowvalue = lowvalue;
   w->range = range;
-
+  *tp = p;
 }
 
 static void write_partition_size(unsigned char *cx_data, int size) {
@@ -844,7 +851,7 @@ static void update_ref_probs(VP8_COMP *const cpi) {
 static void pack_inter_mode_mvs(VP8_COMP *const cpi) {
   int i;
   VP8_COMMON *const pc = & cpi->common;
-  vp8_writer *const w = & cpi->bc;
+  vp8_writer *const w = & cpi->bc2;
 #if CONFIG_NEWMVENTROPY
   const nmv_context *nmvc = &pc->fc.nmvc;
 #else
@@ -855,6 +862,8 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi) {
   MACROBLOCKD *xd = &cpi->mb.e_mbd;
   MODE_INFO *m;
   MODE_INFO *prev_m;
+  TOKENEXTRA *tok = cpi->tok;
+  TOKENEXTRA *tok_end = tok + cpi->tok_count;
 
   const int mis = pc->mode_info_stride;
   int mb_row, mb_col;
@@ -1315,6 +1324,12 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi) {
         }
 #endif
 
+#ifdef ENTROPY_STATS
+        active_section = 1;
+#endif
+        assert(tok < tok_end);
+        pack_mb_tokens(w, &tok, tok_end);
+
 #if CONFIG_SUPERBLOCKS
         if (m->mbmi.encoded_as_sb) {
           assert(!i);
@@ -1348,8 +1363,110 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi) {
 }
 
 
+static void write_mb_modes_kf(const VP8_COMMON  *c,
+                              const MACROBLOCKD *xd,
+                              const MODE_INFO   *m,
+                              int                mode_info_stride,
+                              vp8_writer *const  bc) {
+  const int mis = mode_info_stride;
+  int ym;
+  int segment_id;
+
+  ym = m->mbmi.mode;
+  segment_id = m->mbmi.segment_id;
+
+  if (xd->update_mb_segmentation_map) {
+    write_mb_segid(bc, &m->mbmi, xd);
+  }
+
+  if (c->mb_no_coeff_skip &&
+      (!segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
+       (get_segdata(xd, segment_id, SEG_LVL_EOB) != 0))) {
+        int skip_coeff = m->mbmi.mb_skip_coeff;
+#if CONFIG_SUPERBLOCKS
+        if (m->mbmi.encoded_as_sb) {
+          skip_coeff &= m[1].mbmi.mb_skip_coeff;
+          skip_coeff &= m[mis].mbmi.mb_skip_coeff;
+          skip_coeff &= m[mis + 1].mbmi.mb_skip_coeff;
+        }
+#endif
+        vp8_encode_bool(bc, skip_coeff,
+                    get_pred_prob(c, xd, PRED_MBSKIP));
+  }
+
+#if CONFIG_SUPERBLOCKS
+  if (m->mbmi.encoded_as_sb) {
+    sb_kfwrite_ymode(bc, ym,
+                     c->sb_kf_ymode_prob[c->kf_ymode_probs_index]);
+  } else
+#endif
+  {
+    kfwrite_ymode(bc, ym,
+                  c->kf_ymode_prob[c->kf_ymode_probs_index]);
+  }
+
+  if (ym == B_PRED) {
+    const int mis = c->mode_info_stride;
+    int i = 0;
+#if CONFIG_COMP_INTRA_PRED
+    int uses_second =
+      m->bmi[0].as_mode.second !=
+      (B_PREDICTION_MODE)(B_DC_PRED - 1);
+    vp8_write(bc, uses_second, 128);
+#endif
+    do {
+      const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
+      const B_PREDICTION_MODE L = left_block_mode(m, i);
+      const int bm = m->bmi[i].as_mode.first;
+#if CONFIG_COMP_INTRA_PRED
+      const int bm2 = m->bmi[i].as_mode.second;
+#endif
+
+#ifdef ENTROPY_STATS
+      ++intra_mode_stats [A] [L] [bm];
+#endif
+
+      write_bmode(bc, bm, c->kf_bmode_prob [A] [L]);
+      // printf("    mode: %d\n", bm);
+#if CONFIG_COMP_INTRA_PRED
+      if (uses_second) {
+        write_bmode(bc, bm2, c->kf_bmode_prob [A] [L]);
+      }
+#endif
+    } while (++i < 16);
+  }
+  if (ym == I8X8_PRED) {
+    write_i8x8_mode(bc, m->bmi[0].as_mode.first,
+                    c->fc.i8x8_mode_prob);
+    // printf("    mode: %d\n", m->bmi[0].as_mode.first); fflush(stdout);
+    write_i8x8_mode(bc, m->bmi[2].as_mode.first,
+                    c->fc.i8x8_mode_prob);
+    // printf("    mode: %d\n", m->bmi[2].as_mode.first); fflush(stdout);
+    write_i8x8_mode(bc, m->bmi[8].as_mode.first,
+                    c->fc.i8x8_mode_prob);
+    // printf("    mode: %d\n", m->bmi[8].as_mode.first); fflush(stdout);
+    write_i8x8_mode(bc, m->bmi[10].as_mode.first,
+                    c->fc.i8x8_mode_prob);
+    // printf("    mode: %d\n", m->bmi[10].as_mode.first); fflush(stdout);
+  } else
+    write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
+
+#if CONFIG_TX_SELECT
+  if (ym <= I8X8_PRED && c->txfm_mode == TX_MODE_SELECT &&
+      !((c->mb_no_coeff_skip && m->mbmi.mb_skip_coeff) ||
+        (segfeature_active(xd, segment_id, SEG_LVL_EOB) &&
+         get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) {
+    TX_SIZE sz = m->mbmi.txfm_size;
+    // FIXME(rbultje) code ternary symbol once all experiments are merged
+    vp8_write(bc, sz != TX_4X4, c->prob_tx[0]);
+    if (sz != TX_4X4 && ym <= TM_PRED)
+      vp8_write(bc, sz != TX_8X8, c->prob_tx[1]);
+  }
+#endif
+}
+
 static void write_kfmodes(VP8_COMP *cpi) {
-  vp8_writer *const bc = & cpi->bc;
+  vp8_writer *const bc = & cpi->bc2;
   VP8_COMMON *const c = & cpi->common;
   const int mis = c->mode_info_stride;
   MACROBLOCKD *xd = &cpi->mb.e_mbd;
@@ -1359,6 +1476,8 @@ static void write_kfmodes(VP8_COMP *cpi) {
   int mb_row, mb_col;
   int row_delta[4] = { 0, +1,  0, -1};
   int col_delta[4] = { +1, -1, +1, +1};
+  TOKENEXTRA *tok = cpi->tok;
+  TOKENEXTRA *tok_end = tok + cpi->tok_count;
 
   if (c->mb_no_coeff_skip) {
     update_skip_probs(cpi);
@@ -1382,8 +1501,6 @@ static void write_kfmodes(VP8_COMP *cpi) {
       // Process the 4 MBs in the order:
       // top-left, top-right, bottom-left, bottom-right
       for (i = 0; i < 4; i++) {
-        int ym;
-        int segment_id;
         int dy = row_delta[i];
         int dx = col_delta[i];
         int offset_extended = dy * mis + dx;
@@ -1399,97 +1516,12 @@ static void write_kfmodes(VP8_COMP *cpi) {
         // Make sure the MacroBlockD mode info pointer is set correctly
         xd->mode_info_context = m;
 
-        ym = m->mbmi.mode;
-        segment_id = m->mbmi.segment_id;
-
-        if (cpi->mb.e_mbd.update_mb_segmentation_map) {
-          write_mb_segid(bc, &m->mbmi, &cpi->mb.e_mbd);
-        }
-
-        if (c->mb_no_coeff_skip &&
-            (!segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
-             (get_segdata(xd, segment_id, SEG_LVL_EOB) != 0))) {
-              int skip_coeff = m->mbmi.mb_skip_coeff;
-#if CONFIG_SUPERBLOCKS
-              if (m->mbmi.encoded_as_sb) {
-                skip_coeff &= m[1].mbmi.mb_skip_coeff;
-                skip_coeff &= m[mis].mbmi.mb_skip_coeff;
-                skip_coeff &= m[mis + 1].mbmi.mb_skip_coeff;
-              }
-#endif
-              vp8_encode_bool(bc, skip_coeff,
-                          get_pred_prob(c, xd, PRED_MBSKIP));
-        }
-
-#if CONFIG_SUPERBLOCKS
-        if (m->mbmi.encoded_as_sb) {
-          sb_kfwrite_ymode(bc, ym,
-                           c->sb_kf_ymode_prob[c->kf_ymode_probs_index]);
-        } else
-#endif
-        {
-          kfwrite_ymode(bc, ym,
-                        c->kf_ymode_prob[c->kf_ymode_probs_index]);
-        }
-
-        if (ym == B_PRED) {
-          const int mis = c->mode_info_stride;
-          int i = 0;
-#if CONFIG_COMP_INTRA_PRED
-          int uses_second =
-            m->bmi[0].as_mode.second !=
-            (B_PREDICTION_MODE)(B_DC_PRED - 1);
-          vp8_write(bc, uses_second, 128);
-#endif
-          do {
-            const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
-            const B_PREDICTION_MODE L = left_block_mode(m, i);
-            const int bm = m->bmi[i].as_mode.first;
-#if CONFIG_COMP_INTRA_PRED
-            const int bm2 = m->bmi[i].as_mode.second;
-#endif
-
+        write_mb_modes_kf(c, xd, m, mis, bc);
 #ifdef ENTROPY_STATS
-            ++intra_mode_stats [A] [L] [bm];
-#endif
-
-            write_bmode(bc, bm, c->kf_bmode_prob [A] [L]);
-            // printf("    mode: %d\n", bm);
-#if CONFIG_COMP_INTRA_PRED
-            if (uses_second) {
-              write_bmode(bc, bm2, c->kf_bmode_prob [A] [L]);
-            }
-#endif
-          } while (++i < 16);
-        }
-        if (ym == I8X8_PRED) {
-          write_i8x8_mode(bc, m->bmi[0].as_mode.first,
-                          c->fc.i8x8_mode_prob);
-          // printf("    mode: %d\n", m->bmi[0].as_mode.first); fflush(stdout);
-          write_i8x8_mode(bc, m->bmi[2].as_mode.first,
-                          c->fc.i8x8_mode_prob);
-          // printf("    mode: %d\n", m->bmi[2].as_mode.first); fflush(stdout);
-          write_i8x8_mode(bc, m->bmi[8].as_mode.first,
-                          c->fc.i8x8_mode_prob);
-          // printf("    mode: %d\n", m->bmi[8].as_mode.first); fflush(stdout);
-          write_i8x8_mode(bc, m->bmi[10].as_mode.first,
-                          c->fc.i8x8_mode_prob);
-          // printf("    mode: %d\n", m->bmi[10].as_mode.first); fflush(stdout);
-        } else
-          write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
-
-#if CONFIG_TX_SELECT
-        if (ym <= I8X8_PRED && c->txfm_mode == TX_MODE_SELECT &&
-            !((c->mb_no_coeff_skip && m->mbmi.mb_skip_coeff) ||
-              (segfeature_active(xd, segment_id, SEG_LVL_EOB) &&
-               get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) {
-          TX_SIZE sz = m->mbmi.txfm_size;
-          // FIXME(rbultje) code ternary symbol once all experiments are merged
-          vp8_write(bc, sz != TX_4X4, c->prob_tx[0]);
-          if (sz != TX_4X4 && ym <= TM_PRED)
-            vp8_write(bc, sz != TX_8X8, c->prob_tx[1]);
-        }
+        active_section = 8;
 #endif
+        assert(tok < tok_end);
+        pack_mb_tokens(bc, &tok, tok_end);
 
 #if CONFIG_SUPERBLOCKS
         if (m->mbmi.encoded_as_sb) {
@@ -2836,22 +2868,6 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
   // Write out the mb_no_coeff_skip flag
   vp8_write_bit(bc, pc->mb_no_coeff_skip);
 
-  if (pc->frame_type == KEY_FRAME) {
-    decide_kf_ymode_entropy(cpi);
-    write_kfmodes(cpi);
-
-#ifdef ENTROPY_STATS
-    active_section = 8;
-#endif
-  } else {
-    pack_inter_mode_mvs(cpi);
-    vp8_update_mode_context(&cpi->common);
-
-#ifdef ENTROPY_STATS
-    active_section = 1;
-#endif
-  }
-
   vp8_stop_encode(bc);
 
   oh.first_partition_length_in_bytes = cpi->bc.pos;
@@ -2869,10 +2885,16 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
   }
 
   *size = VP8_HEADER_SIZE + extra_bytes_packed + cpi->bc.pos;
-
   vp8_start_encode(&cpi->bc2, cx_data + bc->pos);
 
-  pack_tokens(&cpi->bc2, cpi->tok, cpi->tok_count);
+  if (pc->frame_type == KEY_FRAME) {
+    decide_kf_ymode_entropy(cpi);
+    write_kfmodes(cpi);
+  } else {
+    pack_inter_mode_mvs(cpi);
+    vp8_update_mode_context(&cpi->common);
+  }
+
 
   vp8_stop_encode(&cpi->bc2);
 
index ac22456d17dec75f885df0f8ed56b69a2e1ea682..44e1f9a657e76d5ab25eea956c9aff4fee74d9ce 100644 (file)
@@ -1050,9 +1050,6 @@ static void encode_sb(VP8_COMP *cpi,
         cpi->inter_zz_count++;
     }
 
-    // TODO Partitioning is broken!
-    cpi->tplist[mb_row].stop = *tp;
-
 #if CONFIG_SUPERBLOCKS
     if (xd->mode_info_context->mbmi.encoded_as_sb) {
       x->src.y_buffer += 32;
@@ -1064,6 +1061,9 @@ static void encode_sb(VP8_COMP *cpi,
       xd->mode_info_context += 2;
       xd->prev_mode_info_context += 2;
       
+      (*tp)->Token = EOSB_TOKEN;
+      (*tp)++;
+      cpi->tplist[mb_row].stop = *tp;
       break;
     }
 #endif
@@ -1085,6 +1085,9 @@ static void encode_sb(VP8_COMP *cpi,
     assert((xd->prev_mode_info_context - cpi->common.prev_mip) ==
            (xd->mode_info_context - cpi->common.mip));
 #endif
+    (*tp)->Token = EOSB_TOKEN;
+    (*tp)++;
+    cpi->tplist[mb_row].stop = *tp;
   }
 
   // debug output
index 1289d89bb7dd6825c2c0bdea2cee898222a62d1e..fdb3e4f745e7cf3b96c385226fa18ea1e5df7398 100644 (file)
@@ -832,7 +832,7 @@ static void write_component_probs(
 }
 
 void vp8_write_mvprobs(VP8_COMP *cpi) {
-  vp8_writer *const w  = & cpi->bc;
+  vp8_writer *const w  = & cpi->bc2;
   MV_CONTEXT *mvc = cpi->common.fc.mvc;
   int flags[2] = {0, 0};
 #ifdef ENTROPY_STATS
@@ -1108,7 +1108,7 @@ static void write_component_probs_hp(
 }
 
 void vp8_write_mvprobs_hp(VP8_COMP *cpi) {
-  vp8_writer *const w  = & cpi->bc;
+  vp8_writer *const w  = & cpi->bc2;
   MV_CONTEXT_HP *mvc = cpi->common.fc.mvc_hp;
   int flags[2] = {0, 0};
 #ifdef ENTROPY_STATS