debugmodes.c 3.53 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9
 * 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.
Jingning Han's avatar
Jingning Han committed
10 11 12 13
 */

#include <stdio.h>

14
#include "av1/common/blockd.h"
Yunqing Wang's avatar
Yunqing Wang committed
15
#include "av1/common/enums.h"
16
#include "av1/common/onyxc_int.h"
Jingning Han's avatar
Jingning Han committed
17

Yaowu Xu's avatar
Yaowu Xu committed
18
static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
Jingning Han's avatar
Jingning Han committed
19 20 21 22 23 24 25 26
  fprintf(f, "%s", str);
  fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_video_frame,
          cm->show_frame, cm->base_qindex);
}
/* This function dereferences a pointer to the mbmi structure
 * and uses the passed in member offset to print out the value of an integer
 * for each mbmi member value in the mi structure.
 */
Yaowu Xu's avatar
Yaowu Xu committed
27
static void print_mi_data(AV1_COMMON *cm, FILE *file, const char *descriptor,
Jingning Han's avatar
Jingning Han committed
28 29 30 31 32 33 34 35 36 37 38
                          size_t member_offset) {
  int mi_row, mi_col;
  MODE_INFO **mi = cm->mi_grid_visible;
  int rows = cm->mi_rows;
  int cols = cm->mi_cols;
  char prefix = descriptor[0];

  log_frame_info(cm, descriptor, file);
  for (mi_row = 0; mi_row < rows; mi_row++) {
    fprintf(file, "%c ", prefix);
    for (mi_col = 0; mi_col < cols; mi_col++) {
Yunqing Wang's avatar
Yunqing Wang committed
39 40
      fprintf(file, "%2d ",
              *((char *)((char *)(&mi[0]->mbmi) + member_offset)));
Jingning Han's avatar
Jingning Han committed
41 42 43
      mi++;
    }
    fprintf(file, "\n");
Yunqing Wang's avatar
Yunqing Wang committed
44
    mi += MAX_MIB_SIZE;
Jingning Han's avatar
Jingning Han committed
45 46 47 48
  }
  fprintf(file, "\n");
}

Yaowu Xu's avatar
Yaowu Xu committed
49
void av1_print_modes_and_motion_vectors(AV1_COMMON *cm, const char *file) {
Jingning Han's avatar
Jingning Han committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  int mi_row;
  int mi_col;
  FILE *mvs = fopen(file, "a");
  MODE_INFO **mi = cm->mi_grid_visible;
  int rows = cm->mi_rows;
  int cols = cm->mi_cols;

  print_mi_data(cm, mvs, "Partitions:", offsetof(MB_MODE_INFO, sb_type));
  print_mi_data(cm, mvs, "Modes:", offsetof(MB_MODE_INFO, mode));
  print_mi_data(cm, mvs, "Ref frame:", offsetof(MB_MODE_INFO, ref_frame[0]));
  print_mi_data(cm, mvs, "Transform:", offsetof(MB_MODE_INFO, tx_size));
  print_mi_data(cm, mvs, "UV Modes:", offsetof(MB_MODE_INFO, uv_mode));

  // output skip infomation.
  log_frame_info(cm, "Skips:", mvs);
  for (mi_row = 0; mi_row < rows; mi_row++) {
    fprintf(mvs, "S ");
    for (mi_col = 0; mi_col < cols; mi_col++) {
      fprintf(mvs, "%2d ", mi[0]->mbmi.skip);
      mi++;
    }
    fprintf(mvs, "\n");
Yunqing Wang's avatar
Yunqing Wang committed
72
    mi += MAX_MIB_SIZE;
Jingning Han's avatar
Jingning Han committed
73 74 75 76 77 78 79 80 81 82
  }
  fprintf(mvs, "\n");

  // output motion vectors.
  log_frame_info(cm, "Vectors ", mvs);
  mi = cm->mi_grid_visible;
  for (mi_row = 0; mi_row < rows; mi_row++) {
    fprintf(mvs, "V ");
    for (mi_col = 0; mi_col < cols; mi_col++) {
      fprintf(mvs, "%4d:%4d ", mi[0]->mbmi.mv[0].as_mv.row,
clang-format's avatar
clang-format committed
83
              mi[0]->mbmi.mv[0].as_mv.col);
Jingning Han's avatar
Jingning Han committed
84 85 86
      mi++;
    }
    fprintf(mvs, "\n");
Yunqing Wang's avatar
Yunqing Wang committed
87
    mi += MAX_MIB_SIZE;
Jingning Han's avatar
Jingning Han committed
88 89 90 91 92
  }
  fprintf(mvs, "\n");

  fclose(mvs);
}
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

void av1_print_uncompressed_frame_header(const uint8_t *data, int size,
                                         const char *filename) {
  FILE *hdrFile = fopen(filename, "w");
  fwrite(data, size, sizeof(uint8_t), hdrFile);
  fclose(hdrFile);
}

void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) {
  FILE *fcFile = fopen(filename, "w");
  const uint16_t *fcp = (uint16_t *)fc;
  const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t);
  unsigned int i;

  for (i = 0; i < n_contexts; ++i) fprintf(fcFile, "%d ", *fcp++);
  fclose(fcFile);
}