NEW_TOKENSET: Make zero block value uncodeable for AC coeffs.

Change-Id: Icd7528d1ec8e117205e5e35ad9a11cfa83b08253
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index c5c656c..12e8a81 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -835,7 +835,7 @@
     const av1_extra_bit *const extra_bits = &extra_bits_table[token];
 
     if (token == BLOCK_Z_TOKEN) {
-      aom_write_symbol(w, 0, *p->head_cdf, 6);
+      aom_write_symbol(w, 0, *p->head_cdf, HEAD_TOKENS + 1);
       p++;
       continue;
     }
@@ -843,12 +843,11 @@
       // Just code a flag indicating whether the value is >1 or 1.
       aom_write_bit(w, token != ONE_TOKEN);
     } else {
-      int comb_symb = 2 * AOMMIN(token, TWO_TOKEN) - p->eob_val + 1;
-      aom_write_symbol(w, comb_symb, *p->head_cdf, 6);
+      int comb_symb = 2 * AOMMIN(token, TWO_TOKEN) - p->eob_val + p->first_val;
+      aom_write_symbol(w, comb_symb, *p->head_cdf, HEAD_TOKENS + p->first_val);
     }
     if (token > ONE_TOKEN) {
-      aom_write_symbol(w, token - TWO_TOKEN, *p->tail_cdf,
-                       CATEGORY6_TOKEN + 1 - 2);
+      aom_write_symbol(w, token - TWO_TOKEN, *p->tail_cdf, TAIL_TOKENS);
     }
 
     if (extra_bits->base_val) {
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c
index d214ad3..f97a78f 100644
--- a/av1/encoder/tokenize.c
+++ b/av1/encoder/tokenize.c
@@ -364,12 +364,14 @@
 static INLINE void add_token(TOKENEXTRA **t,
                              aom_cdf_prob (*tail_cdf)[CDF_SIZE(ENTROPY_TOKENS)],
                              aom_cdf_prob (*head_cdf)[CDF_SIZE(ENTROPY_TOKENS)],
-                             int eob_val, int32_t extra, uint8_t token) {
+                             int eob_val, int first_val, int32_t extra,
+                             uint8_t token) {
   (*t)->token = token;
   (*t)->extra = extra;
   (*t)->tail_cdf = tail_cdf;
   (*t)->head_cdf = head_cdf;
   (*t)->eob_val = eob_val;
+  (*t)->first_val = first_val;
   (*t)++;
 }
 
@@ -547,6 +549,7 @@
   unsigned int(*const blockz_count)[2] =
       td->counts->blockz_count[txsize_sqr_map[tx_size]][type][ref];
   int eob_val;
+  int first_val = 1;
 #else
 #if CONFIG_EC_MULTISYMBOL
   aom_cdf_prob(*const coef_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
@@ -569,17 +572,18 @@
 
 #if CONFIG_NEW_TOKENSET
   if (eob == 0)
-    add_token(&t, &coef_tail_cdfs[band[c]][pt], &coef_head_cdfs[band[c]][pt], 0,
-              0, BLOCK_Z_TOKEN);
+    add_token(&t, &coef_tail_cdfs[band[c]][pt], &coef_head_cdfs[band[c]][pt], 1,
+              1, 0, BLOCK_Z_TOKEN);
 
   ++blockz_count[pt][eob != 0];
 
   while (c < eob) {
     int v = qcoeff[scan[c]];
+    first_val = (c == 0);
 
     if (!v) {
       add_token(&t, &coef_tail_cdfs[band[c]][pt], &coef_head_cdfs[band[c]][pt],
-                0, 0, ZERO_TOKEN);
+                0, first_val, 0, ZERO_TOKEN);
       ++counts[band[c]][pt][ZERO_TOKEN];
       token_cache[scan[c]] = 0;
     } else {
@@ -589,7 +593,7 @@
       av1_get_token_extra(v, &token, &extra);
 
       add_token(&t, &coef_tail_cdfs[band[c]][pt], &coef_head_cdfs[band[c]][pt],
-                eob_val, extra, (uint8_t)token);
+                eob_val, first_val, extra, (uint8_t)token);
 
       if (eob_val != LAST_EOB) {
         ++counts[band[c]][pt][token];
diff --git a/av1/encoder/tokenize.h b/av1/encoder/tokenize.h
index 02aa04f..54b355d 100644
--- a/av1/encoder/tokenize.h
+++ b/av1/encoder/tokenize.h
@@ -39,6 +39,7 @@
   aom_cdf_prob (*tail_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
   aom_cdf_prob (*head_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
   int eob_val;
+  int first_val;
 #elif CONFIG_EC_MULTISYMBOL
   aom_cdf_prob (*token_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
 #endif