Make supertx skip bits observe segment level coding.

Change-Id: Id918d502c8f89e236bcb51949d7ad34efa017321
diff --git a/vp10/decoder/decodeframe.c b/vp10/decoder/decodeframe.c
index 237774f..6a51fbb 100644
--- a/vp10/decoder/decodeframe.c
+++ b/vp10/decoder/decodeframe.c
@@ -1525,14 +1525,18 @@
 }
 
 #if CONFIG_SUPERTX
-static int read_skip_without_seg(VP10_COMMON *cm, const MACROBLOCKD *xd,
-                                 vp10_reader *r) {
-  const int ctx = vp10_get_skip_context(xd);
-  const int skip = vp10_read(r, cm->fc->skip_probs[ctx]);
-  FRAME_COUNTS *counts = xd->counts;
-  if (counts)
-    ++counts->skip[ctx][skip];
-  return skip;
+static int read_skip(VP10_COMMON *cm, const MACROBLOCKD *xd,
+                     int segment_id, vp10_reader *r) {
+  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
+    return 1;
+  } else {
+    const int ctx = vp10_get_skip_context(xd);
+    const int skip = vp10_read(r, cm->fc->skip_probs[ctx]);
+    FRAME_COUNTS *counts = xd->counts;
+    if (counts)
+      ++counts->skip[ctx][skip];
+    return skip;
+  }
 }
 #endif  // CONFIG_SUPERTX
 
@@ -1777,14 +1781,15 @@
     int dst_stride[3], i;
     int offset = mi_row * cm->mi_stride + mi_col;
 
+    set_segment_id_supertx(cm, mi_row, mi_col, bsize);
+
     xd->mi = cm->mi_grid_visible + offset;
     xd->mi[0] = cm->mi + offset;
     set_mi_row_col(xd, tile, mi_row, num_8x8_blocks_high_lookup[bsize],
                    mi_col, num_8x8_blocks_wide_lookup[bsize],
                    cm->mi_rows, cm->mi_cols);
     set_skip_context(xd, mi_row, mi_col);
-    // Here skip is read without using any segment level feature
-    skip = read_skip_without_seg(cm, xd, r);
+    skip = read_skip(cm, xd, xd->mi[0]->mbmi.segment_id_supertx, r);
     if (skip) {
       reset_skip_context(xd, bsize);
     } else {
@@ -1808,7 +1813,6 @@
 #endif  // CONFIG_EXT_TX
     }
 
-    set_segment_id_supertx(cm, mi_row, mi_col, bsize);
 
     vp10_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
     for (i = 0; i < MAX_MB_PLANE; i++) {
diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c
index f5d58e0..97b42d3 100644
--- a/vp10/encoder/bitstream.c
+++ b/vp10/encoder/bitstream.c
@@ -1848,16 +1848,20 @@
   }
 #if CONFIG_SUPERTX
   if (partition != PARTITION_NONE && supertx_enabled && pack_token) {
+    int skip;
     xd->mi = cm->mi_grid_visible + mi_offset;
     supertx_size = mbmi->tx_size;
     set_mi_row_col(xd, tile,
                    mi_row, num_8x8_blocks_high_lookup[bsize],
                    mi_col, num_8x8_blocks_wide_lookup[bsize],
                    cm->mi_rows, cm->mi_cols);
-    vp10_write(w, mbmi->skip, vp10_get_skip_prob(cm, xd));
+
+    assert(IMPLIES(!cm->seg.enabled, mbmi->segment_id_supertx == 0));
+    assert(mbmi->segment_id_supertx < MAX_SEGMENTS);
+
+    skip = write_skip(cm, xd, mbmi->segment_id_supertx, xd->mi[0], w);
 #if CONFIG_EXT_TX
-    if (get_ext_tx_types(supertx_size, bsize, 1) > 1 &&
-        !mbmi->skip) {
+    if (get_ext_tx_types(supertx_size, bsize, 1) > 1 && !skip) {
       int eset = get_ext_tx_set(supertx_size, bsize, 1);
       if (eset > 0) {
         vp10_write_token(
@@ -1867,7 +1871,7 @@
       }
     }
 #else
-    if (supertx_size < TX_32X32 && !mbmi->skip) {
+    if (supertx_size < TX_32X32 && !skip) {
       vp10_write_token(
           w, vp10_ext_tx_tree,
           cm->fc->inter_ext_tx_prob[supertx_size],
@@ -1875,7 +1879,7 @@
     }
 #endif  // CONFIG_EXT_TX
 
-    if (!mbmi->skip) {
+    if (!skip) {
       assert(*tok < tok_end);
       for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
         const int mbmi_txb_size = txsize_to_bsize[mbmi->tx_size];
diff --git a/vp10/encoder/tokenize.c b/vp10/encoder/tokenize.c
index 381063c..c25f8bc 100644
--- a/vp10/encoder/tokenize.c
+++ b/vp10/encoder/tokenize.c
@@ -453,7 +453,11 @@
   int eob = p->eobs[block];
   const PLANE_TYPE type = pd->plane_type;
   const tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block);
+#if CONFIG_SUPERTX
+  const int segment_id = VPXMIN(mbmi->segment_id, mbmi->segment_id_supertx);
+#else
   const int segment_id = mbmi->segment_id;
+#endif  // CONFIG_SUEPRTX
   const int16_t *scan, *nb;
   const TX_TYPE tx_type = get_tx_type(type, xd, block, tx_size);
   const scan_order *const so = get_scan(tx_size, tx_type, is_inter_block(mbmi));
@@ -713,7 +717,7 @@
   MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
   TOKENEXTRA *t_backup = *t;
   const int ctx = vp10_get_skip_context(xd);
-  const int skip_inc = !segfeature_active(&cm->seg, mbmi->segment_id,
+  const int skip_inc = !segfeature_active(&cm->seg, mbmi->segment_id_supertx,
                                           SEG_LVL_SKIP);
   struct tokenize_b_args arg = {cpi, td, t};
   if (mbmi->skip) {