Coverage Report

Created: 2022-08-24 06:15

/src/aom/av1/common/debugmodes.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <stdio.h>
13
14
#include "av1/common/av1_common_int.h"
15
#include "av1/common/blockd.h"
16
#include "av1/common/enums.h"
17
18
0
static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
19
0
  fprintf(f, "%s", str);
20
0
  fprintf(f, "(Frame %u, Show:%d, Q:%d): \n", cm->current_frame.frame_number,
21
0
          cm->show_frame, cm->quant_params.base_qindex);
22
0
}
23
/* This function dereferences a pointer to the mbmi structure
24
 * and uses the passed in member offset to print out the value of an integer
25
 * for each mbmi member value in the mi structure.
26
 */
27
static void print_mi_data(AV1_COMMON *cm, FILE *file, const char *descriptor,
28
0
                          size_t member_offset) {
29
0
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
30
0
  MB_MODE_INFO **mi = mi_params->mi_grid_base;
31
0
  int rows = mi_params->mi_rows;
32
0
  int cols = mi_params->mi_cols;
33
0
  char prefix = descriptor[0];
34
35
0
  log_frame_info(cm, descriptor, file);
36
0
  for (int mi_row = 0; mi_row < rows; mi_row++) {
37
0
    fprintf(file, "%c ", prefix);
38
0
    for (int mi_col = 0; mi_col < cols; mi_col++) {
39
0
      fprintf(file, "%2d ", *((char *)((char *)(mi[0]) + member_offset)));
40
0
      mi++;
41
0
    }
42
0
    fprintf(file, "\n");
43
0
    mi += mi_params->mi_stride - cols;
44
0
  }
45
0
  fprintf(file, "\n");
46
0
}
47
48
0
void av1_print_modes_and_motion_vectors(AV1_COMMON *cm, const char *file) {
49
0
  CommonModeInfoParams *mi_params = &cm->mi_params;
50
0
  FILE *mvs = fopen(file, "a");
51
0
  MB_MODE_INFO **mi = mi_params->mi_grid_base;
52
0
  const int rows = mi_params->mi_rows;
53
0
  const int cols = mi_params->mi_cols;
54
55
0
  print_mi_data(cm, mvs, "Partitions:", offsetof(MB_MODE_INFO, bsize));
56
0
  print_mi_data(cm, mvs, "Modes:", offsetof(MB_MODE_INFO, mode));
57
0
  print_mi_data(cm, mvs, "Ref frame:", offsetof(MB_MODE_INFO, ref_frame[0]));
58
0
  print_mi_data(cm, mvs, "Transform:", offsetof(MB_MODE_INFO, tx_size));
59
0
  print_mi_data(cm, mvs, "UV Modes:", offsetof(MB_MODE_INFO, uv_mode));
60
61
  // output skip infomation.
62
0
  log_frame_info(cm, "Skips:", mvs);
63
0
  for (int mi_row = 0; mi_row < rows; mi_row++) {
64
0
    fprintf(mvs, "S ");
65
0
    for (int mi_col = 0; mi_col < cols; mi_col++) {
66
0
      fprintf(mvs, "%2d ", mi[0]->skip_txfm);
67
0
      mi++;
68
0
    }
69
0
    fprintf(mvs, "\n");
70
0
    mi += mi_params->mi_stride - cols;
71
0
  }
72
0
  fprintf(mvs, "\n");
73
74
  // output motion vectors.
75
0
  log_frame_info(cm, "Vectors ", mvs);
76
0
  mi = mi_params->mi_grid_base;
77
0
  for (int mi_row = 0; mi_row < rows; mi_row++) {
78
0
    fprintf(mvs, "V ");
79
0
    for (int mi_col = 0; mi_col < cols; mi_col++) {
80
0
      fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row, mi[0]->mv[0].as_mv.col);
81
0
      mi++;
82
0
    }
83
0
    fprintf(mvs, "\n");
84
0
    mi += mi_params->mi_stride - cols;
85
0
  }
86
0
  fprintf(mvs, "\n");
87
88
0
  fclose(mvs);
89
0
}
90
91
void av1_print_uncompressed_frame_header(const uint8_t *data, int size,
92
0
                                         const char *filename) {
93
0
  FILE *hdrFile = fopen(filename, "w");
94
0
  fwrite(data, size, sizeof(uint8_t), hdrFile);
95
96
  // Reset order hints(7bit + a previous bit) to 0, so that all camera frame
97
  // headers are identical in large scale coding.
98
0
  uint8_t zero = 0;
99
0
  fseek(hdrFile, 1, SEEK_SET);
100
  // Reset second byte.
101
0
  fwrite(&zero, 1, sizeof(uint8_t), hdrFile);
102
0
  fclose(hdrFile);
103
0
}
104
105
0
void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) {
106
0
  FILE *fcFile = fopen(filename, "w");
107
0
  const uint16_t *fcp = (uint16_t *)fc;
108
0
  const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t);
109
0
  unsigned int i;
110
111
0
  for (i = 0; i < n_contexts; ++i) fprintf(fcFile, "%d ", *fcp++);
112
0
  fclose(fcFile);
113
0
}