Align EXT_TX with EC_MULTISYMBOL and EC_ADAPT.

Do multisymbol coding for transform type.
Load default cdf probabilities directly.
Use CDF frame update mechanism when EC_ADAPT is
enabled.

Change-Id: Id23c927e81587b560e9df8b9bc56c0e2e3bb6f03
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 9daaa8d..41d53d5 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -728,6 +728,9 @@
   { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
 };
 
+// Numbers of transform types used in each intra set
+static const int ext_tx_cnt_intra[EXT_TX_SETS_INTRA] = { 1, 7, 5 };
+
 // Transform types used in each inter set
 static const int ext_tx_used_inter[EXT_TX_SETS_INTER][TX_TYPES] = {
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -736,6 +739,9 @@
   { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
 };
 
+// Numbers of transform types used in each inter set
+static const int ext_tx_cnt_inter[EXT_TX_SETS_INTER] = { 1, 16, 12, 2 };
+
 // 1D Transforms used in inter set, this needs to be changed if
 // ext_tx_used_inter is changed
 static const int ext_tx_used_inter_1D[EXT_TX_SETS_INTER][TX_TYPES_1D] = {
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index d6294bd..6ccc560 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -5681,16 +5681,12 @@
 #if CONFIG_VAR_TX
 // FIXME: txfm_partition probs
 #endif
-// FIXME: skip probs
 
-#if CONFIG_EXT_TX
-// FIXME: ext_tx CDFs
-#else
+  // FIXME: skip probs
+
   AVERAGE_TILE_CDFS(intra_ext_tx_cdf)
   AVERAGE_TILE_CDFS(inter_ext_tx_cdf);
 
-#endif  // CONFIG_EXT_TX
-
   AVERAGE_TILE_CDFS(seg.tree_cdf)
   AVERAGE_TILE_CDFS(uv_mode_cdf)
 
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index 7541a4c..44fecf3 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -638,6 +638,12 @@
 int av1_intra_mode_inv[INTRA_MODES];
 int av1_inter_mode_ind[INTER_MODES];
 int av1_inter_mode_inv[INTER_MODES];
+#if CONFIG_EXT_TX
+int av1_ext_tx_intra_ind[EXT_TX_SETS_INTRA][TX_TYPES];
+int av1_ext_tx_intra_inv[EXT_TX_SETS_INTRA][TX_TYPES];
+int av1_ext_tx_inter_ind[EXT_TX_SETS_INTER][TX_TYPES];
+int av1_ext_tx_inter_inv[EXT_TX_SETS_INTER][TX_TYPES];
+#endif
 #endif
 
 /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
@@ -1721,13 +1727,248 @@
       { 3200, 6550, 9622, 32768, 0 },
     };
 
-#if !CONFIG_EXT_TX
+#if CONFIG_EXT_TX
+static const aom_cdf_prob default_intra_ext_tx_cdf
+    [EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES][CDF_SIZE(TX_TYPES)] = {
+      {
+// FIXME: unused zero positions, from uncoded trivial transform set
+#if CONFIG_CB4X4
+          {
+              { 0 },
+          },
+#endif
+          { { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+#if CONFIG_ALT_INTRA
+            { 0 }
+#endif
+          },
+          { { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+#if CONFIG_ALT_INTRA
+            { 0 }
+#endif
+          },
+          { { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+#if CONFIG_ALT_INTRA
+            { 0 }
+#endif
+          },
+          { { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+            { 0 },
+#if CONFIG_ALT_INTRA
+            { 0 }
+#endif
+          },
+      },
+      {
+          { { 1024, 28800, 29048, 29296, 30164, 31466, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1152, 25852, 26284, 26717, 28230, 30499, 32768, 0 },
+            { 1024, 2016, 3938, 5860, 29404, 31086, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29048, 29296, 30164, 31466, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1152, 25852, 26284, 26717, 28230, 30499, 32768, 0 },
+            { 1024, 2016, 3938, 5860, 29404, 31086, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29048, 29296, 30164, 31466, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1152, 25852, 26284, 26717, 28230, 30499, 32768, 0 },
+            { 1024, 2016, 3938, 5860, 29404, 31086, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29048, 29296, 30164, 31466, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1152, 25852, 26284, 26717, 28230, 30499, 32768, 0 },
+            { 1024, 2016, 3938, 5860, 29404, 31086, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 27118, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 4109, 5900, 7691, 15528, 27380, 32768, 0 },
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 8660, 10167, 15817, 32768, 0 }
+#endif
+          },
+      },
+      {
+          { { 1024, 28800, 29792, 31280, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1152, 25852, 27581, 30174, 32768, 0 },
+            { 1024, 2016, 28924, 30846, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 13396, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29792, 31280, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1152, 25852, 27581, 30174, 32768, 0 },
+            { 1024, 2016, 28924, 30846, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 13396, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29792, 31280, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1152, 25852, 27581, 30174, 32768, 0 },
+            { 1024, 2016, 28924, 30846, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 13396, 32768, 0 }
+#endif
+          },
+          { { 1024, 28800, 29792, 31280, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1152, 25852, 27581, 30174, 32768, 0 },
+            { 1024, 2016, 28924, 30846, 32768, 0 },
+            { 1280, 5216, 6938, 26310, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 4109, 13065, 26611, 32768, 0 },
+            { 1280, 5216, 6938, 13396, 32768, 0 },
+#if CONFIG_ALT_INTRA
+            { 1280, 5216, 6938, 13396, 32768, 0 }
+#endif
+          },
+      }
+    };
+static const aom_cdf_prob
+    default_inter_ext_tx_cdf[EXT_TX_SETS_INTER][EXT_TX_SIZES][CDF_SIZE(
+        TX_TYPES)] = {
+      {
+#if CONFIG_CB4X4
+          { 0 },
+#endif
+          { 0 },
+          { 0 },
+          { 0 },
+          { 0 } },
+      {
+#if CONFIG_CB4X4
+          { 0 },
+#endif
+          { 1280, 1453, 1626, 2277, 2929, 3580, 4232, 16717, 19225, 21733,
+            24241, 26749, 28253, 29758, 31263, 32768, 0 },
+          { 1280, 1453, 1626, 2277, 2929, 3580, 4232, 16717, 19225, 21733,
+            24241, 26749, 28253, 29758, 31263, 32768, 0 },
+          { 1280, 1453, 1626, 2277, 2929, 3580, 4232, 16717, 19225, 21733,
+            24241, 26749, 28253, 29758, 31263, 32768, 0 },
+          { 1280, 1453, 1626, 2277, 2929, 3580, 4232, 16717, 19225, 21733,
+            24241, 26749, 28253, 29758, 31263, 32768, 0 } },
+      {
+#if CONFIG_CB4X4
+          { 0 },
+#endif
+          { 1280, 3125, 4970, 17132, 19575, 22018, 24461, 26904, 28370, 29836,
+            31302, 32768, 0 },
+          { 1280, 3125, 4970, 17132, 19575, 22018, 24461, 26904, 28370, 29836,
+            31302, 32768, 0 },
+          { 1280, 3125, 4970, 17132, 19575, 22018, 24461, 26904, 28370, 29836,
+            31302, 32768, 0 },
+          { 1280, 3125, 4970, 17132, 19575, 22018, 24461, 26904, 28370, 29836,
+            31302, 32768, 0 } },
+      {
+#if CONFIG_CB4X4
+          { 0 },
+#endif
+          { 1536, 32768, 0 },
+          { 1536, 32768, 0 },
+          { 1536, 32768, 0 },
+          { 1536, 32768, 0 } }
+    };
+#else
 static const aom_cdf_prob
     default_intra_ext_tx_cdf[EXT_TX_SIZES][TX_TYPES][CDF_SIZE(TX_TYPES)] = {
+#if CONFIG_CB4X4
       { { 30720, 31400, 32084, 32768, 0 },
         { 512, 638, 31764, 32768, 0 },
         { 512, 638, 1642, 32768, 0 },
         { 512, 31760, 32264, 32768, 0 } },
+#endif
+      { { 30720, 31400, 32084, 32768, 0 },
+        { 512, 638, 31764, 32768, 0 },
+        { 512, 638, 1642, 32768, 0 },
+        { 512, 31760, 32264, 32768, 0 } },
+
       { { 31232, 31742, 32255, 32768, 0 },
         { 1024, 1272, 31784, 32768, 0 },
         { 1024, 1272, 2256, 32768, 0 },
@@ -1740,6 +1981,9 @@
 
 static const aom_cdf_prob
     default_inter_ext_tx_cdf[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)] = {
+#if CONFIG_CB4X4
+      { 20480, 24560, 28664, 32768, 0 },
+#endif
       { 20480, 24560, 28664, 32768, 0 },
       { 22528, 25928, 29348, 32768, 0 },
       { 24576, 27296, 30032, 32768, 0 },
@@ -2292,10 +2536,8 @@
   av1_copy(fc->switchable_interp_cdf, default_switchable_interp_cdf);
   av1_copy(fc->partition_cdf, default_partition_cdf);
   av1_copy(fc->inter_mode_cdf, default_inter_mode_cdf);
-#if !CONFIG_EXT_TX
   av1_copy(fc->intra_ext_tx_cdf, default_intra_ext_tx_cdf);
   av1_copy(fc->inter_ext_tx_cdf, default_inter_ext_tx_cdf);
-#endif  // !CONFIG_EXT_TX
 #if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
   av1_copy(fc->intra_filter_cdf, default_intra_filter_cdf);
 #endif  // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
@@ -2372,7 +2614,20 @@
   for (i = 0; i < BLOCK_SIZE_GROUPS; ++i)
     av1_tree_to_cdf(av1_intra_mode_tree, fc->y_mode_prob[i], fc->y_mode_cdf[i]);
 
-#if !CONFIG_EXT_TX
+#if CONFIG_EXT_TX
+  int s;
+  for (s = 0; s < EXT_TX_SETS_INTRA; ++s)
+    for (i = TX_4X4; i < EXT_TX_SIZES; ++i)
+      for (j = 0; j < INTRA_MODES; ++j)
+        av1_tree_to_cdf(av1_ext_tx_intra_tree[s],
+                        fc->intra_ext_tx_prob[s][i][j],
+                        fc->intra_ext_tx_cdf[s][i][j]);
+
+  for (s = 0; s < EXT_TX_SETS_INTER; ++s)
+    for (i = TX_4X4; i < EXT_TX_SIZES; ++i)
+      av1_tree_to_cdf(av1_ext_tx_inter_tree[s], fc->inter_ext_tx_prob[s][i],
+                      fc->inter_ext_tx_cdf[s][i]);
+#else
   for (i = TX_4X4; i < EXT_TX_SIZES; ++i)
     for (j = 0; j < TX_TYPES; ++j)
       av1_tree_to_cdf(av1_ext_tx_tree, fc->intra_ext_tx_prob[i][j],
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index a91d8ce..adf6b74 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -261,10 +261,15 @@
 #if CONFIG_DELTA_Q
   aom_cdf_prob delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)];
 #endif  // CONFIG_DELTA_Q
-#if !CONFIG_EXT_TX
+#if CONFIG_EXT_TX
+  aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
+                               [CDF_SIZE(TX_TYPES)];
+  aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SETS_INTER][EXT_TX_SIZES]
+                               [CDF_SIZE(TX_TYPES)];
+#else
   aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SIZES][TX_TYPES][CDF_SIZE(TX_TYPES)];
   aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)];
-#endif  // !CONFIG_EXT_TX
+#endif  // CONFIG_EXT_TX
 #if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
   aom_cdf_prob intra_filter_cdf[INTRA_FILTERS + 1][CDF_SIZE(INTRA_FILTERS)];
 #endif  // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
@@ -432,7 +437,14 @@
 extern int av1_intra_mode_inv[INTRA_MODES];
 extern int av1_inter_mode_ind[INTER_MODES];
 extern int av1_inter_mode_inv[INTER_MODES];
+#if CONFIG_EXT_TX
+extern int av1_ext_tx_intra_ind[EXT_TX_SETS_INTRA][TX_TYPES];
+extern int av1_ext_tx_intra_inv[EXT_TX_SETS_INTRA][TX_TYPES];
+extern int av1_ext_tx_inter_ind[EXT_TX_SETS_INTER][TX_TYPES];
+extern int av1_ext_tx_inter_inv[EXT_TX_SETS_INTER][TX_TYPES];
 #endif
+#endif
+
 #if CONFIG_EXT_INTER
 extern const aom_tree_index
     av1_interintra_mode_tree[TREE_SIZE(INTERINTRA_MODES)];
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 2f3c3a3..e12f2a4 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -787,18 +787,30 @@
 
       if (inter_block) {
         if (eset > 0) {
+#if CONFIG_EC_MULTISYMBOL
+          mbmi->tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol(
+              r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
+              ext_tx_cnt_inter[eset], ACCT_STR)];
+#else
           mbmi->tx_type = aom_read_tree(
               r, av1_ext_tx_inter_tree[eset],
               ec_ctx->inter_ext_tx_prob[eset][square_tx_size], ACCT_STR);
+#endif
           if (counts)
             ++counts->inter_ext_tx[eset][square_tx_size][mbmi->tx_type];
         }
       } else if (ALLOW_INTRA_EXT_TX) {
         if (eset > 0) {
+#if CONFIG_EC_MULTISYMBOL
+          mbmi->tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol(
+              r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
+              ext_tx_cnt_intra[eset], ACCT_STR)];
+#else
           mbmi->tx_type = aom_read_tree(
               r, av1_ext_tx_intra_tree[eset],
               ec_ctx->intra_ext_tx_prob[eset][square_tx_size][mbmi->mode],
               ACCT_STR);
+#endif
           if (counts)
             ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode]
                                   [mbmi->tx_type];
diff --git a/av1/decoder/decoder.c b/av1/decoder/decoder.c
index a3550dc..5a74a3b 100644
--- a/av1/decoder/decoder.c
+++ b/av1/decoder/decoder.c
@@ -55,7 +55,15 @@
                           av1_intra_mode_tree);
     av1_indices_from_tree(av1_switchable_interp_ind, av1_switchable_interp_inv,
                           SWITCHABLE_FILTERS, av1_switchable_interp_tree);
-#if !CONFIG_EXT_TX
+#if CONFIG_EXT_TX
+    int s;
+    for (s = 1; s < EXT_TX_SETS_INTRA; ++s)
+      av1_indices_from_tree(av1_ext_tx_intra_ind[s], av1_ext_tx_intra_inv[s],
+                            ext_tx_cnt_intra[s], av1_ext_tx_intra_tree[s]);
+    for (s = 1; s < EXT_TX_SETS_INTER; ++s)
+      av1_indices_from_tree(av1_ext_tx_inter_ind[s], av1_ext_tx_inter_inv[s],
+                            ext_tx_cnt_inter[s], av1_ext_tx_inter_tree[s]);
+#else
     av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, TX_TYPES,
                           av1_ext_tx_tree);
 #endif
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index af94487..80cd4a6 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -196,7 +196,14 @@
 /* This hack is necessary because the four TX_TYPES are not consecutive,
     e.g., 0, 1, 2, 3, when doing an in-order traversal of the av1_ext_tx_tree
     structure. */
-#if !CONFIG_EXT_TX
+#if CONFIG_EXT_TX
+  for (s = 1; s < EXT_TX_SETS_INTRA; ++s)
+    av1_indices_from_tree(av1_ext_tx_intra_ind[s], av1_ext_tx_intra_inv[s],
+                          ext_tx_cnt_intra[s], av1_ext_tx_intra_tree[s]);
+  for (s = 1; s < EXT_TX_SETS_INTER; ++s)
+    av1_indices_from_tree(av1_ext_tx_inter_ind[s], av1_ext_tx_inter_inv[s],
+                          ext_tx_cnt_inter[s], av1_ext_tx_inter_tree[s]);
+#else
   av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, TX_TYPES,
                         av1_ext_tx_tree);
 #endif
@@ -1441,17 +1448,30 @@
       if (is_inter) {
         assert(ext_tx_used_inter[eset][mbmi->tx_type]);
         if (eset > 0) {
+#if CONFIG_EC_MULTISYMBOL
+          aom_write_symbol(w, av1_ext_tx_inter_ind[eset][mbmi->tx_type],
+                           ec_ctx->inter_ext_tx_cdf[eset][square_tx_size],
+                           ext_tx_cnt_inter[eset]);
+#else
           av1_write_token(w, av1_ext_tx_inter_tree[eset],
                           ec_ctx->inter_ext_tx_prob[eset][square_tx_size],
                           &ext_tx_inter_encodings[eset][mbmi->tx_type]);
+#endif
         }
       } else if (ALLOW_INTRA_EXT_TX) {
         assert(ext_tx_used_intra[eset][mbmi->tx_type]);
         if (eset > 0) {
+#if CONFIG_EC_MULTISYMBOL
+          aom_write_symbol(
+              w, av1_ext_tx_intra_ind[eset][mbmi->tx_type],
+              ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode],
+              ext_tx_cnt_intra[eset]);
+#else
           av1_write_token(
               w, av1_ext_tx_intra_tree[eset],
               ec_ctx->intra_ext_tx_prob[eset][square_tx_size][mbmi->mode],
               &ext_tx_intra_encodings[eset][mbmi->tx_type]);
+#endif
         }
       }
     }
@@ -2684,9 +2704,15 @@
       const int eset =
           get_ext_tx_set(supertx_size, bsize, 1, cm->reduced_tx_set_used);
       if (eset > 0) {
+#if CONFIG_EC_MULTISYMBOL
+        aom_write_symbol(w, av1_ext_tx_inter_ind[eset][mbmi->tx_type],
+                         ec_ctx->inter_ext_tx_cdf[eset][supertx_size],
+                         ext_tx_cnt_inter[eset]);
+#else
         av1_write_token(w, av1_ext_tx_inter_tree[eset],
                         cm->fc->inter_ext_tx_prob[eset][supertx_size],
                         &ext_tx_inter_encodings[eset][mbmi->tx_type]);
+#endif
       }
     }
 #else