aom_entropy_optimizer.c 35.9 KB
Newer Older
Yue Chen's avatar
Yue Chen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

// This tool is a gadget for offline probability training.
// A binary executable aom_entropy_optimizer will be generated in tools/. It
// parses a binary file consisting of counts written in the format of
15 16 17
// FRAME_COUNTS in entropymode.h, and computes optimized probability tables
// and CDF tables, which will be written to a new c file optimized_probs.c
// according to format in the codebase.
Yue Chen's avatar
Yue Chen committed
18 19 20 21 22 23 24 25 26 27 28 29 30
//
// Command line: ./aom_entropy_optimizer [directory of the count file]
//
// The input file can either be generated by encoding a single clip by
// turning on entropy_stats experiment, or be collected at a larger scale at
// which a python script which will be provided soon can be used to aggregate
// multiple stats output.

#include <assert.h>
#include <stdio.h>
#include "./aom_config.h"
#include "av1/common/entropymode.h"

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#if CONFIG_SMOOTH_HV
const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)] = {
  -DC_PRED,
  2, /* 0 = DC_NODE */
  -TM_PRED,
  4, /* 1 = TM_NODE */
  -V_PRED,
  6, /* 2 = V_NODE */
  8,
  12, /* 3 = COM_NODE */
  -H_PRED,
  10, /* 4 = H_NODE */
  -D135_PRED,
  -D117_PRED, /* 5 = D135_NODE */
  -D45_PRED,
  14, /* 6 = D45_NODE */
  -D63_PRED,
  16, /* 7 = D63_NODE */
  -D153_PRED,
  18, /* 8 = D153_NODE */
  -D207_PRED,
  20, /* 9 = D207_NODE */
  -SMOOTH_PRED,
  22, /* 10 = SMOOTH_NODE */
  -SMOOTH_V_PRED,
  -SMOOTH_H_PRED /* 11 = SMOOTH_V_NODE */
};
#else
const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)] = {
  -DC_PRED,   2,            /* 0 = DC_NODE */
  -TM_PRED,   4,            /* 1 = TM_NODE */
  -V_PRED,    6,            /* 2 = V_NODE */
  8,          12,           /* 3 = COM_NODE */
  -H_PRED,    10,           /* 4 = H_NODE */
  -D135_PRED, -D117_PRED,   /* 5 = D135_NODE */
  -D45_PRED,  14,           /* 6 = D45_NODE */
  -D63_PRED,  16,           /* 7 = D63_NODE */
  -D153_PRED, 18,           /* 8 = D153_NODE */
  -D207_PRED, -SMOOTH_PRED, /* 9 = D207_NODE */
};
#endif  // CONFIG_SMOOTH_HV

Yue Chen's avatar
Yue Chen committed
73 74 75 76 77 78
#define SPACES_PER_TAB 2

typedef unsigned int aom_count_type;
// A log file recording parsed counts
static FILE *logfile;  // TODO(yuec): make it a command line option

79 80 81 82 83 84 85
static INLINE aom_prob get_binary_prob_new(unsigned int n0, unsigned int n1) {
  // The "+1" will prevent this function from generating extreme probability
  // when both n0 and n1 are small
  const unsigned int den = n0 + 1 + n1 + 1;
  return get_prob(n0 + 1, den);
}

Yue Chen's avatar
Yue Chen committed
86
// Optimized probabilities will be stored in probs[].
87 88 89 90
static unsigned int optimize_tree_probs(const aom_tree_index *tree,
                                        unsigned int idx,
                                        const unsigned int *counts,
                                        aom_prob *probs) {
Yue Chen's avatar
Yue Chen committed
91 92 93 94 95 96
  const int l = tree[idx];
  const unsigned int left_count =
      (l <= 0) ? counts[-l] : optimize_tree_probs(tree, l, counts, probs);
  const int r = tree[idx + 1];
  const unsigned int right_count =
      (r <= 0) ? counts[-r] : optimize_tree_probs(tree, r, counts, probs);
97
  probs[idx >> 1] = get_binary_prob_new(left_count, right_count);
Yue Chen's avatar
Yue Chen committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  return left_count + right_count;
}

static int parse_stats(aom_count_type **ct_ptr, FILE *const probsfile, int tabs,
                       int dim_of_cts, int *cts_each_dim,
                       const aom_tree_index *tree, int flatten_last_dim) {
  if (dim_of_cts < 1) {
    fprintf(stderr, "The dimension of a counts vector should be at least 1!\n");
    return 1;
  }
  if (dim_of_cts == 1) {
    const int total_modes = cts_each_dim[0];
    aom_count_type *counts1d = *ct_ptr;
    aom_prob *probs = aom_malloc(sizeof(*probs) * (total_modes - 1));

    if (probs == NULL) {
      fprintf(stderr, "Allocating prob array failed!\n");
      return 1;
    }

    (*ct_ptr) += total_modes;
    if (tree != NULL) {
      optimize_tree_probs(tree, 0, counts1d, probs);
    } else {
      assert(total_modes == 2);
123
      probs[0] = get_binary_prob_new(counts1d[0], counts1d[1]);
Yue Chen's avatar
Yue Chen committed
124 125 126
    }
    if (tabs > 0) fprintf(probsfile, "%*c", tabs * SPACES_PER_TAB, ' ');
    for (int k = 0; k < total_modes - 1; ++k) {
127 128 129 130
      if (k == total_modes - 2)
        fprintf(probsfile, " %3d ", probs[k]);
      else
        fprintf(probsfile, " %3d,", probs[k]);
Yue Chen's avatar
Yue Chen committed
131 132 133 134 135 136 137
      fprintf(logfile, "%d ", counts1d[k]);
    }
    fprintf(logfile, "%d\n", counts1d[total_modes - 1]);
  } else if (dim_of_cts == 2 && flatten_last_dim) {
    assert(cts_each_dim[1] == 2);

    for (int k = 0; k < cts_each_dim[0]; ++k) {
138 139
      if (k == cts_each_dim[0] - 1) {
        fprintf(probsfile, " %3d ",
140
                get_binary_prob_new((*ct_ptr)[0], (*ct_ptr)[1]));
141 142
      } else {
        fprintf(probsfile, " %3d,",
143
                get_binary_prob_new((*ct_ptr)[0], (*ct_ptr)[1]));
144
      }
Yue Chen's avatar
Yue Chen committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
      fprintf(logfile, "%d %d\n", (*ct_ptr)[0], (*ct_ptr)[1]);
      (*ct_ptr) += 2;
    }
  } else {
    for (int k = 0; k < cts_each_dim[0]; ++k) {
      int tabs_next_level;
      if (dim_of_cts == 2 || (dim_of_cts == 3 && flatten_last_dim)) {
        fprintf(probsfile, "%*c{", tabs * SPACES_PER_TAB, ' ');
        tabs_next_level = 0;
      } else {
        fprintf(probsfile, "%*c{\n", tabs * SPACES_PER_TAB, ' ');
        tabs_next_level = tabs + 1;
      }
      if (parse_stats(ct_ptr, probsfile, tabs_next_level, dim_of_cts - 1,
                      cts_each_dim + 1, tree, flatten_last_dim)) {
        return 1;
      }
      if (dim_of_cts == 2 || (dim_of_cts == 3 && flatten_last_dim)) {
163 164 165 166
        if (k == cts_each_dim[0] - 1)
          fprintf(probsfile, "}\n");
        else
          fprintf(probsfile, "},\n");
Yue Chen's avatar
Yue Chen committed
167
      } else {
168 169 170 171
        if (k == cts_each_dim[0] - 1)
          fprintf(probsfile, "%*c}\n", tabs * SPACES_PER_TAB, ' ');
        else
          fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
Yue Chen's avatar
Yue Chen committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
      }
    }
  }
  return 0;
}

// This function parses the stats of a syntax, either binary or multi-symbol,
// in different contexts, and writes the optimized probability table to
// probsfile.
//   counts: pointer of the first count element in counts array
//   probsfile: output file
//   dim_of_cts: number of dimensions of counts array
//   cts_each_dim: an array storing size of each dimension of counts array
//   tree: binary tree for a multi-symbol syntax, or NULL for a binary one
//   flatten_last_dim: for a binary syntax, if flatten_last_dim is 0, probs in
//                     different contexts will be written separately, e.g.,
//                     {{p1}, {p2}, ...};
//                     otherwise will be grouped together at the second last
//                     dimension, i.e.,
//                     {p1, p2, ...}.
//   prefix: declaration header for the entropy table
static void optimize_entropy_table(aom_count_type *counts,
                                   FILE *const probsfile, int dim_of_cts,
                                   int *cts_each_dim,
                                   const aom_tree_index *tree,
                                   int flatten_last_dim, char *prefix) {
  aom_count_type *ct_ptr = counts;

  assert(!flatten_last_dim || cts_each_dim[dim_of_cts - 1] == 2);

  fprintf(probsfile, "%s = {\n", prefix);
  if (parse_stats(&ct_ptr, probsfile, 1, dim_of_cts, cts_each_dim, tree,
                  flatten_last_dim)) {
    fprintf(probsfile, "Optimizer failed!\n");
  }
  fprintf(probsfile, "};\n\n");
  fprintf(logfile, "\n");
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
static int counts_to_cdf(const aom_count_type *counts, aom_cdf_prob *cdf,
                         int modes) {
  int64_t *csum = aom_malloc(sizeof(*csum) * modes);

  if (csum == NULL) {
    fprintf(stderr, "Allocating csum array failed!\n");
    return 1;
  }
  csum[0] = counts[0];
  for (int i = 1; i < modes; ++i) csum[i] = counts[i] + csum[i - 1];

  int64_t sum = csum[modes - 1];
  int64_t round_shift = sum >> 1;
  for (int i = 0; i < modes; ++i) {
    if (sum <= 0)
      cdf[i] = CDF_PROB_TOP;
    else
      cdf[i] = (csum[i] * CDF_PROB_TOP + round_shift) / sum;
  }
  return 0;
}

static int parse_counts_for_cdf_opt(aom_count_type **ct_ptr,
                                    FILE *const probsfile, int tabs,
                                    int dim_of_cts, int *cts_each_dim) {
  if (dim_of_cts < 1) {
    fprintf(stderr, "The dimension of a counts vector should be at least 1!\n");
    return 1;
  }
  if (dim_of_cts == 1) {
    const int total_modes = cts_each_dim[0];
    aom_count_type *counts1d = *ct_ptr;
    aom_cdf_prob *cdfs = aom_malloc(sizeof(*cdfs) * total_modes);

    if (cdfs == NULL) {
      fprintf(stderr, "Allocating cdf array failed!\n");
      return 1;
    }

    counts_to_cdf(counts1d, cdfs, total_modes);
    (*ct_ptr) += total_modes;

    if (tabs > 0) fprintf(probsfile, "%*c", tabs * SPACES_PER_TAB, ' ');
    for (int k = 0; k < total_modes; ++k)
      fprintf(probsfile, " AOM_ICDF(%d),", cdfs[k]);
    fprintf(probsfile, " 0 ");
  } else {
    for (int k = 0; k < cts_each_dim[0]; ++k) {
      int tabs_next_level;

      if (dim_of_cts == 2)
        fprintf(probsfile, "%*c{", tabs * SPACES_PER_TAB, ' ');
      else
        fprintf(probsfile, "%*c{\n", tabs * SPACES_PER_TAB, ' ');
      tabs_next_level = dim_of_cts == 2 ? 0 : tabs + 1;

      if (parse_counts_for_cdf_opt(ct_ptr, probsfile, tabs_next_level,
                                   dim_of_cts - 1, cts_each_dim + 1)) {
        return 1;
      }

      if (dim_of_cts == 2) {
        if (k == cts_each_dim[0] - 1)
          fprintf(probsfile, "}\n");
        else
          fprintf(probsfile, "},\n");
      } else {
        if (k == cts_each_dim[0] - 1)
          fprintf(probsfile, "%*c}\n", tabs * SPACES_PER_TAB, ' ');
        else
          fprintf(probsfile, "%*c},\n", tabs * SPACES_PER_TAB, ' ');
      }
    }
  }

  return 0;
}

static void optimize_cdf_table(aom_count_type *counts, FILE *const probsfile,
                               int dim_of_cts, int *cts_each_dim,
                               char *prefix) {
  aom_count_type *ct_ptr = counts;

  fprintf(probsfile, "%s = {\n", prefix);
  if (parse_counts_for_cdf_opt(&ct_ptr, probsfile, 1, dim_of_cts,
                               cts_each_dim)) {
    fprintf(probsfile, "Optimizer failed!\n");
  }
  fprintf(probsfile, "};\n\n");
}

Yue Chen's avatar
Yue Chen committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
int main(int argc, const char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Please specify the input stats file!\n");
    exit(EXIT_FAILURE);
  }

  FILE *const statsfile = fopen(argv[1], "rb");
  if (statsfile == NULL) {
    fprintf(stderr, "Failed to open input file!\n");
    exit(EXIT_FAILURE);
  }

  FRAME_COUNTS fc;
  fread(&fc, sizeof(FRAME_COUNTS), 1, statsfile);

  FILE *const probsfile = fopen("optimized_probs.c", "w");
  if (probsfile == NULL) {
    fprintf(stderr,
            "Failed to create output file for optimized entropy tables!\n");
    exit(EXIT_FAILURE);
  }

  logfile = fopen("aom_entropy_optimizer_parsed_counts.log", "w");
  if (logfile == NULL) {
    fprintf(stderr, "Failed to create log file for parsed counts!\n");
    exit(EXIT_FAILURE);
  }

  int cts_each_dim[10];

  /* Intra mode (keyframe luma) */
  cts_each_dim[0] = INTRA_MODES;
  cts_each_dim[1] = INTRA_MODES;
  cts_each_dim[2] = INTRA_MODES;
  optimize_entropy_table(
337
      &fc.kf_y_mode[0][0][0], probsfile, 3, cts_each_dim, av1_intra_mode_tree,
Yue Chen's avatar
Yue Chen committed
338 339 340
      0,
      "const aom_prob av1_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]"
      "[INTRA_MODES - 1]");
341 342 343 344
  optimize_cdf_table(
      &fc.kf_y_mode[0][0][0], probsfile, 3, cts_each_dim,
      "const aom_cdf_prob\n"
      "av1_kf_y_mode_cdf[INTRA_MODES][INTRA_MODES][CDF_SIZE(INTRA_MODES)]");
Yue Chen's avatar
Yue Chen committed
345 346 347 348 349

  /* Intra mode (non-keyframe luma) */
  cts_each_dim[0] = BLOCK_SIZE_GROUPS;
  cts_each_dim[1] = INTRA_MODES;
  optimize_entropy_table(
350
      &fc.y_mode[0][0], probsfile, 2, cts_each_dim, av1_intra_mode_tree, 0,
Yue Chen's avatar
Yue Chen committed
351 352
      "static const aom_prob default_if_y_probs[BLOCK_SIZE_GROUPS]"
      "[INTRA_MODES - 1]");
353 354 355 356
  optimize_cdf_table(
      &fc.y_mode[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_if_y_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(INTRA_MODES)]");
Yue Chen's avatar
Yue Chen committed
357 358 359

  /* Intra mode (chroma) */
  cts_each_dim[0] = INTRA_MODES;
Luc Trudeau's avatar
Luc Trudeau committed
360
  cts_each_dim[1] = UV_INTRA_MODES;
361
  optimize_entropy_table(&fc.uv_mode[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
362 363
                         av1_intra_mode_tree, 0,
                         "static const aom_prob default_uv_probs[INTRA_MODES]"
Luc Trudeau's avatar
Luc Trudeau committed
364 365 366 367 368
                         "[UV_INTRA_MODES - 1]");
  optimize_cdf_table(
      &fc.uv_mode[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_uv_mode_cdf[INTRA_MODES][CDF_SIZE(UV_INTRA_MODES)]");
Yue Chen's avatar
Yue Chen committed
369 370 371 372 373 374

  /* Partition */
  cts_each_dim[0] = PARTITION_CONTEXTS;
#if CONFIG_EXT_PARTITION_TYPES
  cts_each_dim[1] = EXT_PARTITION_TYPES;
  // TODO(yuec): Wrong prob for context = 0, because the old tree is used
375
  optimize_entropy_table(&fc.partition[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
376 377 378
                         av1_ext_partition_tree, 0,
                         "static const aom_prob default_partition_probs"
                         "[PARTITION_CONTEXTS][EXT_PARTITION_TYPES - 1]");
379 380 381 382
  optimize_cdf_table(&fc.partition[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_partition_cdf[PARTITION_CONTEXTS][CDF_SIZE(EXT_"
                     "PARTITION_TYPES)]");
Yue Chen's avatar
Yue Chen committed
383 384
#else
  cts_each_dim[1] = PARTITION_TYPES;
385
  optimize_entropy_table(&fc.partition[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
386 387 388
                         av1_partition_tree, 0,
                         "static const aom_prob default_partition_probs"
                         "[PARTITION_CONTEXTS][PARTITION_TYPES - 1]");
389 390 391 392
  optimize_cdf_table(
      &fc.partition[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_partition_cdf[PARTITION_CONTEXTS][CDF_SIZE(PARTITION_TYPES)]");
Yue Chen's avatar
Yue Chen committed
393 394 395 396 397
#endif

  /* Interpolation filter */
  cts_each_dim[0] = SWITCHABLE_FILTER_CONTEXTS;
  cts_each_dim[1] = SWITCHABLE_FILTERS;
398 399 400 401
  optimize_cdf_table(&fc.switchable_interp[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_switchable_interp_cdf[SWITCHABLE_FILTER_CONTEXTS]"
                     "[CDF_SIZE(SWITCHABLE_FILTERS)]");
Yue Chen's avatar
Yue Chen committed
402 403 404 405 406

  /* Motion vector referencing */
  cts_each_dim[0] = NEWMV_MODE_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
407
      &fc.newmv_mode[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
408
      "static const aom_prob default_newmv_prob[NEWMV_MODE_CONTEXTS]");
409 410 411
  optimize_cdf_table(&fc.newmv_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_newmv_cdf[NEWMV_MODE_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
412 413 414 415

  cts_each_dim[0] = ZEROMV_MODE_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
416
      &fc.zeromv_mode[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
417
      "static const aom_prob default_zeromv_prob[ZEROMV_MODE_CONTEXTS]");
418 419 420
  optimize_cdf_table(&fc.zeromv_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_zeromv_cdf[ZEROMV_MODE_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
421 422 423 424

  cts_each_dim[0] = REFMV_MODE_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
425
      &fc.refmv_mode[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
426
      "static const aom_prob default_refmv_prob[REFMV_MODE_CONTEXTS]");
427 428 429
  optimize_cdf_table(&fc.refmv_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_refmv_cdf[REFMV_MODE_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
430 431 432 433

  cts_each_dim[0] = DRL_MODE_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
434
      &fc.drl_mode[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
435
      "static const aom_prob default_drl_prob[DRL_MODE_CONTEXTS]");
436 437 438
  optimize_cdf_table(&fc.drl_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_drl_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
439

440
  /* ext_inter experiment */
Yue Chen's avatar
Yue Chen committed
441 442 443 444
  /* New compound mode */
  cts_each_dim[0] = INTER_MODE_CONTEXTS;
  cts_each_dim[1] = INTER_COMPOUND_MODES;
  optimize_entropy_table(
445
      &fc.inter_compound_mode[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
446 447 448
      av1_inter_compound_mode_tree, 0,
      "static const aom_prob default_inter_compound_mode_probs\n"
      "[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES - 1]");
449 450 451 452
  optimize_cdf_table(&fc.inter_compound_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_inter_compound_mode_cdf[INTER_MODE_CONTEXTS][CDF_"
                     "SIZE(INTER_COMPOUND_MODES)]");
Yue Chen's avatar
Yue Chen committed
453 454 455 456 457
#if CONFIG_COMPOUND_SINGLEREF
  /* Compound singleref mode */
  cts_each_dim[0] = INTER_MODE_CONTEXTS;
  cts_each_dim[1] = INTER_SINGLEREF_COMP_MODES;
  optimize_entropy_table(
458
      &fc.inter_singleref_comp_mode[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
459 460 461
      av1_inter_singleref_comp_mode_tree, 0,
      "static const aom_prob default_inter_singleref_comp_mode_probs\n"
      "[INTER_MODE_CONTEXTS][INTER_SINGLEREF_COMP_MODES - 1]");
462 463 464 465 466
  optimize_cdf_table(&fc.inter_singleref_comp_mode[0][0], probsfile, 2,
                     cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_inter_singleref_comp_mode_cdf[INTER_MODE_"
                     "CONTEXTS][CDF_SIZE(INTER_SINGLEREF_COMP_MODES)]");
Yue Chen's avatar
Yue Chen committed
467 468 469 470 471 472
#endif
#if CONFIG_INTERINTRA
  /* Interintra */
  cts_each_dim[0] = BLOCK_SIZE_GROUPS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
473
      &fc.interintra[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
474
      "static const aom_prob default_interintra_prob[BLOCK_SIZE_GROUPS]");
475 476 477
  optimize_cdf_table(&fc.interintra[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_interintra_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
478 479 480 481

  cts_each_dim[0] = BLOCK_SIZE_GROUPS;
  cts_each_dim[1] = INTERINTRA_MODES;
  optimize_entropy_table(
482
      &fc.interintra_mode[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
483 484 485
      av1_interintra_mode_tree, 0,
      "static const aom_prob "
      "default_interintra_mode_prob[BLOCK_SIZE_GROUPS][INTERINTRA_MODES - 1]");
486 487 488 489
  optimize_cdf_table(&fc.interintra_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_interintra_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE("
                     "INTERINTRA_MODES)]");
Yue Chen's avatar
Yue Chen committed
490

491
  cts_each_dim[0] = BLOCK_SIZES_ALL;
Yue Chen's avatar
Yue Chen committed
492 493
  cts_each_dim[1] = 2;
  optimize_entropy_table(
494 495 496 497 498 499
      &fc.wedge_interintra[0][0], probsfile, 2, cts_each_dim, NULL, 1,
      "static const aom_prob default_wedge_interintra_prob[BLOCK_SIZES_ALL]");
  optimize_cdf_table(
      &fc.wedge_interintra[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_wedge_interintra_cdf[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
500 501
#endif
  /* Compound type */
502
  cts_each_dim[0] = BLOCK_SIZES_ALL;
Yue Chen's avatar
Yue Chen committed
503
  cts_each_dim[1] = COMPOUND_TYPES;
504
  optimize_entropy_table(&fc.compound_interinter[0][0], probsfile, 2,
Yue Chen's avatar
Yue Chen committed
505 506
                         cts_each_dim, av1_compound_type_tree, 0,
                         "static const aom_prob default_compound_type_probs"
507 508 509 510 511
                         "[BLOCK_SIZES_ALL][COMPOUND_TYPES - 1]");
  optimize_cdf_table(
      &fc.compound_interinter[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_compound_type_cdf[BLOCK_SIZES_ALL][CDF_SIZE(COMPOUND_TYPES)]");
Yue Chen's avatar
Yue Chen committed
512 513 514

/* motion_var and warped_motion experiments */
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
515
  cts_each_dim[0] = BLOCK_SIZES_ALL;
Yue Chen's avatar
Yue Chen committed
516 517
  cts_each_dim[1] = MOTION_MODES;
  optimize_entropy_table(
518
      &fc.motion_mode[0][0], probsfile, 2, cts_each_dim, av1_motion_mode_tree,
Yue Chen's avatar
Yue Chen committed
519 520 521
      0,
      "static const aom_prob default_motion_mode_prob[BLOCK_SIZES]"
      "[MOTION_MODES - 1]");
522 523 524 525
  optimize_cdf_table(
      &fc.motion_mode[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_motion_mode_cdf[BLOCK_SIZES_ALL][CDF_SIZE(MOTION_MODES)]");
Yue Chen's avatar
Yue Chen committed
526
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
527
  cts_each_dim[0] = BLOCK_SIZES_ALL;
Yue Chen's avatar
Yue Chen committed
528 529
  cts_each_dim[1] = 2;
  optimize_entropy_table(
530 531 532 533 534
      &fc.obmc[0][0], probsfile, 2, cts_each_dim, NULL, 1,
      "static const aom_prob default_obmc_prob[BLOCK_SIZES_ALL]");
  optimize_cdf_table(&fc.obmc[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_obmc_cdf[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
535
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
536 537 538 539 540 541 542 543 544 545 546 547
#if CONFIG_NCOBMC_ADAPT_WEIGHT
  cts_each_dim[0] = ADAPT_OVERLAP_BLOCKS;
  cts_each_dim[1] = MAX_NCOBMC_MODES;
  optimize_entropy_table(
      &fc.ncobmc_mode[0][0], probsfile, 2, cts_each_dim, av1_ncobmc_mode_tree,
      0,
      "static const aom_prob default_ncobmc_mode_prob[ADAPT_OVERLAP_BLOCKS]"
      "[MAX_NCOBMC_MODES - 1]");
  optimize_cdf_table(&fc.ncobmc_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_ncobmc_mode_cdf[ADAPT_OVERLAP_BLOCKS]"
                     "[CDF_SIZE(MAX_NCOBMC_MODES)]");
548 549 550 551 552 553 554 555 556 557 558
#if CONFIG_WARPED_MOTION
  cts_each_dim[0] = BLOCK_SIZES_ALL;
  cts_each_dim[1] = OBMC_FAMILY_MODES;
  optimize_entropy_table(
      &fc.ncobmc[0][0], probsfile, 2, cts_each_dim, av1_ncobmc_tree, 0,
      "static const aom_prob default_ncobmc_prob[BLOCK_SIZES_ALL]"
      "[OBMC_FAMILY_MODES - 1]");
  optimize_cdf_table(&fc.ncobmc[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_ncobmc_cdf[BLOCK_SIZES_ALL]"
                     "[CDF_SIZE(OBMC_FAMILY_MODES)]");
559
#endif
560
#endif  // CONFIG_NCOBMC_ADAPT_WEIGHT
Yue Chen's avatar
Yue Chen committed
561 562 563 564 565
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION

  /* Intra/inter flag */
  cts_each_dim[0] = INTRA_INTER_CONTEXTS;
  cts_each_dim[1] = 2;
566
  optimize_entropy_table(&fc.intra_inter[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
567 568 569
                         NULL, 1,
                         "static const aom_prob default_intra_inter_p"
                         "[INTRA_INTER_CONTEXTS]");
570 571 572 573
  optimize_cdf_table(
      &fc.intra_inter[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_intra_inter_cdf[INTRA_INTER_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
574 575 576 577

  /* Single/comp ref flag */
  cts_each_dim[0] = COMP_INTER_CONTEXTS;
  cts_each_dim[1] = 2;
578 579
  optimize_entropy_table(&fc.comp_inter[0][0], probsfile, 2, cts_each_dim, NULL,
                         1,
Yue Chen's avatar
Yue Chen committed
580 581
                         "static const aom_prob default_comp_inter_p"
                         "[COMP_INTER_CONTEXTS]");
582 583 584 585
  optimize_cdf_table(
      &fc.comp_inter[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
586 587 588 589 590 591

/* ext_comp_refs experiment */
#if CONFIG_EXT_COMP_REFS
  cts_each_dim[0] = COMP_REF_TYPE_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
592
      &fc.comp_ref_type[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
593
      "static const aom_prob default_comp_ref_type_p[COMP_REF_TYPE_CONTEXTS]");
594 595 596 597
  optimize_cdf_table(
      &fc.comp_ref_type[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
598 599 600 601 602

  cts_each_dim[0] = UNI_COMP_REF_CONTEXTS;
  cts_each_dim[1] = UNIDIR_COMP_REFS - 1;
  cts_each_dim[2] = 2;
  optimize_entropy_table(
603
      &fc.uni_comp_ref[0][0][0], probsfile, 3, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
604 605
      "static const aom_prob\n"
      "default_uni_comp_ref_p[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]");
606 607 608 609
  optimize_cdf_table(&fc.uni_comp_ref[0][0][0], probsfile, 3, cts_each_dim,
                     "static const aom_cdf_prob\n"
                     "default_uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_"
                     "COMP_REFS - 1][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
610 611 612 613 614 615 616
#endif

  /* Reference frame (single ref) */
  cts_each_dim[0] = REF_CONTEXTS;
  cts_each_dim[1] = SINGLE_REFS - 1;
  cts_each_dim[2] = 2;
  optimize_entropy_table(
617
      &fc.single_ref[0][0][0], probsfile, 3, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
618 619
      "static const aom_prob default_single_ref_p[REF_CONTEXTS]"
      "[SINGLE_REFS - 1]");
620 621 622 623
  optimize_cdf_table(
      &fc.single_ref[0][0][0], probsfile, 3, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
624 625 626 627 628 629 630

#if CONFIG_EXT_REFS
  /* ext_refs experiment */
  cts_each_dim[0] = REF_CONTEXTS;
  cts_each_dim[1] = FWD_REFS - 1;
  cts_each_dim[2] = 2;
  optimize_entropy_table(
631
      &fc.comp_ref[0][0][0], probsfile, 3, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
632
      "static const aom_prob default_comp_ref_p[REF_CONTEXTS][FWD_REFS - 1]");
633 634 635 636
  optimize_cdf_table(
      &fc.comp_ref[0][0][0], probsfile, 3, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_comp_ref_cdf[REF_CONTEXTS][FWD_REFS - 1][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
637 638 639 640

  cts_each_dim[0] = REF_CONTEXTS;
  cts_each_dim[1] = BWD_REFS - 1;
  cts_each_dim[2] = 2;
641
  optimize_entropy_table(&fc.comp_bwdref[0][0][0], probsfile, 3, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
642 643 644
                         NULL, 1,
                         "static const aom_prob "
                         "default_comp_bwdref_p[REF_CONTEXTS][BWD_REFS - 1]");
645 646 647 648
  optimize_cdf_table(
      &fc.comp_bwdref[0][0][0], probsfile, 3, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_comp_bwdref_cdf[REF_CONTEXTS][BWD_REFS - 1][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
649 650 651 652 653 654
#else
  /* Reference frame (compound refs) */
  cts_each_dim[0] = REF_CONTEXTS;
  cts_each_dim[1] = COMP_REFS - 1;
  cts_each_dim[2] = 2;
  optimize_entropy_table(
655
      &fc.comp_ref[0][0][0], probsfile, 3, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
656 657
      "static const aom_prob default_comp_ref_p[REF_CONTEXTS]"
      "[COMP_REFS - 1]");
658 659 660 661
  optimize_cdf_table(
      &fc.comp_ref[0][0][0], probsfile, 3, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_comp_ref_cdf[REF_CONTEXTS][COMP_REFS - 1][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
662 663 664
#endif  // CONFIG_EXT_REFS

/* Compound single ref inter mode */
665
#if CONFIG_COMPOUND_SINGLEREF
Yue Chen's avatar
Yue Chen committed
666 667
  cts_each_dim[0] = COMP_INTER_MODE_CONTEXTS;
  cts_each_dim[1] = 2;
668 669
  optimize_entropy_table(&fc.comp_inter_mode[0][0], probsfile, 2, cts_each_dim,
                         NULL, 1,
Yue Chen's avatar
Yue Chen committed
670 671
                         "static const aom_prob "
                         "default_comp_inter_mode_p[COMP_INTER_MODE_CONTEXTS]");
672 673 674 675
  optimize_cdf_table(&fc.comp_inter_mode[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_comp_inter_mode_cdf[COMP_INTER_MODE_CONTEXTS]["
                     "CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
676 677 678
#endif

/* Transform size */
Yue Chen's avatar
Yue Chen committed
679
#if CONFIG_RECT_TX_EXT && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yue Chen's avatar
Yue Chen committed
680
  cts_each_dim[0] = 2;
681
  optimize_entropy_table(&fc.quarter_tx_size[0], probsfile, 1, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
682 683
                         NULL, 1,
                         "static const aom_prob default_quarter_tx_size_prob");
684 685 686
  optimize_cdf_table(
      &fc.quarter_tx_size[0], probsfile, 1, cts_each_dim,
      "static const aom_cdf_prob default_quarter_tx_size_cdf[CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
687 688 689 690 691
#endif
#if CONFIG_VAR_TX
  cts_each_dim[0] = TXFM_PARTITION_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
692
      &fc.txfm_partition[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
693 694
      "static const aom_prob "
      "default_txfm_partition_probs[TXFM_PARTITION_CONTEXTS]");
695 696 697 698
  optimize_cdf_table(
      &fc.txfm_partition[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob\n"
      "default_txfm_partition_cdf[TXFM_PARTITION_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
699 700 701 702 703 704
#endif

  /* Skip flag */
  cts_each_dim[0] = SKIP_CONTEXTS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
705
      &fc.skip[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
706
      "static const aom_prob default_skip_probs[SKIP_CONTEXTS]");
707 708 709
  optimize_cdf_table(&fc.skip[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_skip_cdfs[SKIP_CONTEXTS][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
710 711 712 713

/* intrabc experiment */
#if CONFIG_INTRABC
  cts_each_dim[0] = 2;
714
  optimize_entropy_table(&fc.intrabc[0], probsfile, 1, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
715
                         "INTRABC_PROB_DEFAULT");
716 717 718
  optimize_cdf_table(
      &fc.intrabc[0], probsfile, 1, cts_each_dim,
      "static const aom_cdf_prob default_intrabc_cdf[CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
719 720
#endif

721
  /* delta_q */
Yue Chen's avatar
Yue Chen committed
722 723 724
  cts_each_dim[0] = DELTA_Q_PROBS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
725
      &fc.delta_q[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
726 727 728 729 730
      "static const aom_prob default_delta_q_probs[DELTA_Q_PROBS]");
#if CONFIG_EXT_DELTA_Q
  cts_each_dim[0] = DELTA_LF_PROBS;
  cts_each_dim[1] = 2;
  optimize_entropy_table(
731
      &fc.delta_lf[0][0], probsfile, 2, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
732 733 734 735 736 737 738 739 740 741
      "static const aom_prob default_delta_lf_probs[DELTA_LF_PROBS]");
#endif

/* Transform type */
#if CONFIG_EXT_TX
// TODO(yuec): different trees are used depending on selected ext tx set
#else
  // TODO(yuec): intra_ext_tx use different trees depending on the context
  cts_each_dim[0] = EXT_TX_SIZES;
  cts_each_dim[1] = TX_TYPES;
742
  optimize_entropy_table(&fc.inter_ext_tx[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
743 744 745
                         av1_ext_tx_tree, 0,
                         "static const aom_prob default_inter_ext_tx_prob"
                         "[EXT_TX_SIZES][TX_TYPES - 1]");
746 747 748 749
  optimize_cdf_table(&fc.inter_ext_tx[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_inter_ext_tx_prob[EXT_TX_SIZES][CDF_SIZE(TX_"
                     "TYPES)]");
Yue Chen's avatar
Yue Chen committed
750 751 752 753 754 755 756 757
#endif

/* supertx experiment */
#if CONFIG_SUPERTX
  cts_each_dim[0] = PARTITION_SUPERTX_CONTEXTS;
  cts_each_dim[1] = TX_SIZES;
  cts_each_dim[2] = 2;
  optimize_entropy_table(
758
      &fc.supertx[0][0][0], probsfile, 3, cts_each_dim, NULL, 1,
Yue Chen's avatar
Yue Chen committed
759 760
      "static const aom_prob\n"
      "default_supertx_prob[PARTITION_SUPERTX_CONTEXTS][TX_SIZES]");
761 762 763 764
  optimize_cdf_table(&fc.supertx[0][0][0], probsfile, 3, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_supertx_cdf[PARTITION_SUPERTX_CONTEXTS][TX_SIZES]"
                     "[CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
765 766 767 768 769 770 771 772
#endif

/* ext_intra experiment */
#if CONFIG_EXT_INTRA
#if CONFIG_INTRA_INTERP
  cts_each_dim[0] = INTRA_FILTERS + 1;
  cts_each_dim[1] = INTRA_FILTERS;
  optimize_entropy_table(
773 774
      &fc.intra_filter[0][0], probsfile, 2, cts_each_dim, av1_intra_filter_tree,
      0,
Yue Chen's avatar
Yue Chen committed
775 776
      "static const aom_prob\n"
      "default_intra_filter_probs[INTRA_FILTERS + 1][INTRA_FILTERS - 1]");
777 778 779 780
  optimize_cdf_table(&fc.intra_filter[0][0], probsfile, 2, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_intra_filter_cdf[INTRA_FILTERS + "
                     "1][CDF_SIZE(INTRA_FILTERS)]");
Yue Chen's avatar
Yue Chen committed
781 782 783 784 785 786 787
#endif
#endif

/* filter_intra experiment */
#if CONFIG_FILTER_INTRA
  cts_each_dim[0] = PLANE_TYPES;
  cts_each_dim[1] = 2;
788
  optimize_entropy_table(&fc.filter_intra[0][0], probsfile, 2, cts_each_dim,
Yue Chen's avatar
Yue Chen committed
789 790
                         NULL, 1,
                         "static const aom_prob default_filter_intra_probs[2]");
791 792 793
  optimize_cdf_table(
      &fc.filter_intra[0][0], probsfile, 2, cts_each_dim,
      "static const aom_cdf_prob default_filter_intra_cdf[2][CDF_SIZE(2)]");
Yue Chen's avatar
Yue Chen committed
794 795
#endif

796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
#if CONFIG_LV_MAP
  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = NUM_BASE_LEVELS;
  cts_each_dim[3] = COEFF_BASE_CONTEXTS;
  cts_each_dim[4] = 2;
  optimize_entropy_table(&fc.coeff_base[0][0][0][0][0], probsfile, 5,
                         cts_each_dim, NULL, 1,
                         "static const aom_prob "
                         "default_coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_"
                         "LEVELS][COEFF_BASE_CONTEXTS]");
  optimize_cdf_table(&fc.coeff_base[0][0][0][0][0], probsfile, 5, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_coeff_base_cdf[TX_SIZES][PLANE_TYPES][NUM_BASE_"
                     "LEVELS][COEFF_BASE_CONTEXTS][CDF_SIZE(2)]");

  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = SIG_COEF_CONTEXTS;
  cts_each_dim[3] = 2;
  optimize_entropy_table(
      &fc.nz_map[0][0][0][0], probsfile, 4, cts_each_dim, NULL, 1,
      "static const aom_prob "
      "default_nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS]");
  optimize_cdf_table(&fc.nz_map[0][0][0][0], probsfile, 4, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_nz_map_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_"
                     "CONTEXTS][CDF_SIZE(2)]");

  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = EOB_COEF_CONTEXTS;
  cts_each_dim[3] = 2;
  optimize_entropy_table(
      &fc.eob_flag[0][0][0][0], probsfile, 4, cts_each_dim, NULL, 1,
      "static const aom_prob "
      "default_eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS]");
  optimize_cdf_table(&fc.eob_flag[0][0][0][0], probsfile, 4, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_eob_flag_cdf[TX_SIZES][PLANE_TYPES][EOB_COEF_"
                     "CONTEXTS][CDF_SIZE(2)]");

  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = LEVEL_CONTEXTS;
  cts_each_dim[3] = 2;
  optimize_entropy_table(
      &fc.coeff_lps[0][0][0][0], probsfile, 4, cts_each_dim, NULL, 1,
      "static const aom_prob "
      "default_coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS]");
  optimize_cdf_table(&fc.coeff_lps[0][0][0][0], probsfile, 4, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_coeff_lps_cdf[TX_SIZES][PLANE_TYPES][LEVEL_"
                     "CONTEXTS][CDF_SIZE(2)]");
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866

#if BR_NODE
  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = BASE_RANGE_SETS;
  cts_each_dim[3] = LEVEL_CONTEXTS;
  cts_each_dim[4] = 2;
  optimize_entropy_table(&fc.coeff_br[0][0][0][0][0], probsfile, 5,
                         cts_each_dim, NULL, 1,
                         "static const aom_prob "
                         "default_coeff_br[TX_SIZES][PLANE_TYPES][BASE_RANGE_"
                         "SETS][LEVEL_CONTEXTS]");
  optimize_cdf_table(&fc.coeff_br[0][0][0][0][0], probsfile, 5, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_coeff_br_cdf[TX_SIZES][PLANE_TYPES][BASE_RANGE_"
                     "SETS][LEVEL_CONTEXTS][CDF_SIZE(2)]");
#endif  // BR_NODE
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910

#if CONFIG_CTX1D
  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = TX_CLASSES;
  cts_each_dim[3] = 2;
  optimize_entropy_table(&fc.eob_mode[0][0][0][0], probsfile, 4, cts_each_dim,
                         NULL, 1,
                         "static const aom_prob "
                         "default_eob_mode[TX_SIZES][PLANE_TYPES][TX_CLASSES]");
  optimize_cdf_table(&fc.eob_mode[0][0][0][0], probsfile, 4, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_eob_mode_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES]["
                     "CDF_SIZE(2)]");

  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = TX_CLASSES;
  cts_each_dim[3] = EMPTY_LINE_CONTEXTS;
  cts_each_dim[4] = 2;
  optimize_entropy_table(&fc.empty_line[0][0][0][0][0], probsfile, 5,
                         cts_each_dim, NULL, 1,
                         "static const aom_prob "
                         "default_empty_line[TX_SIZES][PLANE_TYPES][TX_CLASSES]"
                         "[EMPTY_LINE_CONTEXTS]");
  optimize_cdf_table(&fc.empty_line[0][0][0][0][0], probsfile, 5, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_empty_line_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES]"
                     "[EMPTY_LINE_CONTEXTS][CDF_SIZE(2)]");

  cts_each_dim[0] = TX_SIZES;
  cts_each_dim[1] = PLANE_TYPES;
  cts_each_dim[2] = TX_CLASSES;
  cts_each_dim[3] = HV_EOB_CONTEXTS;
  cts_each_dim[4] = 2;
  optimize_entropy_table(
      &fc.hv_eob[0][0][0][0][0], probsfile, 5, cts_each_dim, NULL, 1,
      "static const aom_prob "
      "default_hv_eob[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_EOB_CONTEXTS]");
  optimize_cdf_table(&fc.hv_eob[0][0][0][0][0], probsfile, 5, cts_each_dim,
                     "static const aom_cdf_prob "
                     "default_hv_eob_cdf[TX_SIZES][PLANE_TYPES][TX_CLASSES][HV_"
                     "EOB_CONTEXTS][CDF_SIZE(2)]");
#endif  // CONFIG_CTX1D
911
#endif  // CONFIG_LV_MAP
912

Yue Chen's avatar
Yue Chen committed
913 914 915 916 917 918
  fclose(statsfile);
  fclose(logfile);
  fclose(probsfile);

  return 0;
}