• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/blockd.h"
15 #include "av1/common/enums.h"
16 #include "av1/common/onyxc_int.h"
17 
log_frame_info(AV1_COMMON * cm,const char * str,FILE * f)18 static void log_frame_info(AV1_COMMON *cm, const char *str, FILE *f) {
19   fprintf(f, "%s", str);
20   fprintf(f, "(Frame %d, Show:%d, Q:%d): \n", cm->current_frame.frame_number,
21           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  */
print_mi_data(AV1_COMMON * cm,FILE * file,const char * descriptor,size_t member_offset)27 static void print_mi_data(AV1_COMMON *cm, FILE *file, const char *descriptor,
28                           size_t member_offset) {
29   int mi_row, mi_col;
30   MB_MODE_INFO **mi = cm->mi_grid_visible;
31   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++) {
39       fprintf(file, "%2d ", *((char *)((char *)(mi[0]) + member_offset)));
40       mi++;
41     }
42     fprintf(file, "\n");
43     mi += cm->mi_stride - cols;
44   }
45   fprintf(file, "\n");
46 }
47 
av1_print_modes_and_motion_vectors(AV1_COMMON * cm,const char * file)48 void av1_print_modes_and_motion_vectors(AV1_COMMON *cm, const char *file) {
49   int mi_row;
50   int mi_col;
51   FILE *mvs = fopen(file, "a");
52   MB_MODE_INFO **mi = cm->mi_grid_visible;
53   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++) {
67       fprintf(mvs, "%2d ", mi[0]->skip);
68       mi++;
69     }
70     fprintf(mvs, "\n");
71     mi += cm->mi_stride - cols;
72   }
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++) {
81       fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row, mi[0]->mv[0].as_mv.col);
82       mi++;
83     }
84     fprintf(mvs, "\n");
85     mi += cm->mi_stride - cols;
86   }
87   fprintf(mvs, "\n");
88 
89   fclose(mvs);
90 }
91 
av1_print_uncompressed_frame_header(const uint8_t * data,int size,const char * filename)92 void 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 
av1_print_frame_contexts(const FRAME_CONTEXT * fc,const char * filename)99 void 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 }
108