blob: b26c7ddaa28d21bbc33e7aa4c4e36ed36fcca73b [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <stdio.h>
13
14#include "av1/common/blockd.h"
Yunqing Wangd097ec12017-05-12 09:52:59 -070015#include "av1/common/enums.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016#include "av1/common/onyxc_int.h"
17
Yaowu Xuf883b422016-08-30 14:01:10 -070018static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070019 fprintf(f, "%s", str);
David Turnerd2a592e2018-11-16 14:59:31 +000020 fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_frame.frame_number,
Yaowu Xuc27fc142016-08-22 16:08:15 -070021 cm->show_frame, cm->base_qindex);
22}
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 */
Yaowu Xuf883b422016-08-30 14:01:10 -070027static void print_mi_data(AV1_COMMON *cm, FILE *file, const char *descriptor,
Yaowu Xuc27fc142016-08-22 16:08:15 -070028 size_t member_offset) {
29 int mi_row, mi_col;
Yue Chen53b53f02018-03-29 14:31:23 -070030 MB_MODE_INFO **mi = cm->mi_grid_visible;
Yaowu Xuc27fc142016-08-22 16:08:15 -070031 int rows = cm->mi_rows;
32 int cols = cm->mi_cols;
33 char prefix = descriptor[0];
34
35 log_frame_info(cm, descriptor, file);
36 for (mi_row = 0; mi_row < rows; mi_row++) {
37 fprintf(file, "%c ", prefix);
38 for (mi_col = 0; mi_col < cols; mi_col++) {
Yue Chen53b53f02018-03-29 14:31:23 -070039 fprintf(file, "%2d ", *((char *)((char *)(mi[0]) + member_offset)));
Yaowu Xuc27fc142016-08-22 16:08:15 -070040 mi++;
41 }
42 fprintf(file, "\n");
Yunqing Wang6f557802018-12-21 10:28:33 -080043 mi += cm->mi_stride - cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -070044 }
45 fprintf(file, "\n");
46}
47
Yaowu Xuf883b422016-08-30 14:01:10 -070048void av1_print_modes_and_motion_vectors(AV1_COMMON *cm, const char *file) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070049 int mi_row;
50 int mi_col;
51 FILE *mvs = fopen(file, "a");
Yue Chen53b53f02018-03-29 14:31:23 -070052 MB_MODE_INFO **mi = cm->mi_grid_visible;
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 int rows = cm->mi_rows;
54 int cols = cm->mi_cols;
55
56 print_mi_data(cm, mvs, "Partitions:", offsetof(MB_MODE_INFO, sb_type));
57 print_mi_data(cm, mvs, "Modes:", offsetof(MB_MODE_INFO, mode));
58 print_mi_data(cm, mvs, "Ref frame:", offsetof(MB_MODE_INFO, ref_frame[0]));
59 print_mi_data(cm, mvs, "Transform:", offsetof(MB_MODE_INFO, tx_size));
60 print_mi_data(cm, mvs, "UV Modes:", offsetof(MB_MODE_INFO, uv_mode));
61
62 // output skip infomation.
63 log_frame_info(cm, "Skips:", mvs);
64 for (mi_row = 0; mi_row < rows; mi_row++) {
65 fprintf(mvs, "S ");
66 for (mi_col = 0; mi_col < cols; mi_col++) {
Yue Chen53b53f02018-03-29 14:31:23 -070067 fprintf(mvs, "%2d ", mi[0]->skip);
Yaowu Xuc27fc142016-08-22 16:08:15 -070068 mi++;
69 }
70 fprintf(mvs, "\n");
Yunqing Wang6f557802018-12-21 10:28:33 -080071 mi += cm->mi_stride - cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 }
73 fprintf(mvs, "\n");
74
75 // output motion vectors.
76 log_frame_info(cm, "Vectors ", mvs);
77 mi = cm->mi_grid_visible;
78 for (mi_row = 0; mi_row < rows; mi_row++) {
79 fprintf(mvs, "V ");
80 for (mi_col = 0; mi_col < cols; mi_col++) {
Yue Chen53b53f02018-03-29 14:31:23 -070081 fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row, mi[0]->mv[0].as_mv.col);
Yaowu Xuc27fc142016-08-22 16:08:15 -070082 mi++;
83 }
84 fprintf(mvs, "\n");
Yunqing Wang6f557802018-12-21 10:28:33 -080085 mi += cm->mi_stride - cols;
Yaowu Xuc27fc142016-08-22 16:08:15 -070086 }
87 fprintf(mvs, "\n");
88
89 fclose(mvs);
90}
Yunqing Wangb041d8a2017-11-15 12:31:18 -080091
92void av1_print_uncompressed_frame_header(const uint8_t *data, int size,
93 const char *filename) {
94 FILE *hdrFile = fopen(filename, "w");
95 fwrite(data, size, sizeof(uint8_t), hdrFile);
96 fclose(hdrFile);
97}
98
99void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) {
100 FILE *fcFile = fopen(filename, "w");
101 const uint16_t *fcp = (uint16_t *)fc;
102 const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t);
103 unsigned int i;
104
105 for (i = 0; i < n_contexts; ++i) fprintf(fcFile, "%d ", *fcp++);
106 fclose(fcFile);
107}