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