• 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/av1_common_int.h"
15 #include "av1/common/blockd.h"
16 #include "av1/common/enums.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->quant_params.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   const CommonModeInfoParams *const mi_params = &cm->mi_params;
30   MB_MODE_INFO **mi = mi_params->mi_grid_base;
31   int rows = mi_params->mi_rows;
32   int cols = mi_params->mi_cols;
33   char prefix = descriptor[0];
34 
35   log_frame_info(cm, descriptor, file);
36   for (int mi_row = 0; mi_row < rows; mi_row++) {
37     fprintf(file, "%c ", prefix);
38     for (int 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 += mi_params->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   CommonModeInfoParams *mi_params = &cm->mi_params;
50   FILE *mvs = fopen(file, "a");
51   MB_MODE_INFO **mi = mi_params->mi_grid_base;
52   const int rows = mi_params->mi_rows;
53   const int cols = mi_params->mi_cols;
54 
55   print_mi_data(cm, mvs, "Partitions:", offsetof(MB_MODE_INFO, sb_type));
56   print_mi_data(cm, mvs, "Modes:", offsetof(MB_MODE_INFO, mode));
57   print_mi_data(cm, mvs, "Ref frame:", offsetof(MB_MODE_INFO, ref_frame[0]));
58   print_mi_data(cm, mvs, "Transform:", offsetof(MB_MODE_INFO, tx_size));
59   print_mi_data(cm, mvs, "UV Modes:", offsetof(MB_MODE_INFO, uv_mode));
60 
61   // output skip infomation.
62   log_frame_info(cm, "Skips:", mvs);
63   for (int mi_row = 0; mi_row < rows; mi_row++) {
64     fprintf(mvs, "S ");
65     for (int mi_col = 0; mi_col < cols; mi_col++) {
66       fprintf(mvs, "%2d ", mi[0]->skip);
67       mi++;
68     }
69     fprintf(mvs, "\n");
70     mi += mi_params->mi_stride - cols;
71   }
72   fprintf(mvs, "\n");
73 
74   // output motion vectors.
75   log_frame_info(cm, "Vectors ", mvs);
76   mi = mi_params->mi_grid_base;
77   for (int mi_row = 0; mi_row < rows; mi_row++) {
78     fprintf(mvs, "V ");
79     for (int mi_col = 0; mi_col < cols; mi_col++) {
80       fprintf(mvs, "%4d:%4d ", mi[0]->mv[0].as_mv.row, mi[0]->mv[0].as_mv.col);
81       mi++;
82     }
83     fprintf(mvs, "\n");
84     mi += mi_params->mi_stride - cols;
85   }
86   fprintf(mvs, "\n");
87 
88   fclose(mvs);
89 }
90 
av1_print_uncompressed_frame_header(const uint8_t * data,int size,const char * filename)91 void av1_print_uncompressed_frame_header(const uint8_t *data, int size,
92                                          const char *filename) {
93   FILE *hdrFile = fopen(filename, "w");
94   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   uint8_t zero = 0;
99   fseek(hdrFile, 1, SEEK_SET);
100   // Reset second byte.
101   fwrite(&zero, 1, sizeof(uint8_t), hdrFile);
102   fclose(hdrFile);
103 }
104 
av1_print_frame_contexts(const FRAME_CONTEXT * fc,const char * filename)105 void av1_print_frame_contexts(const FRAME_CONTEXT *fc, const char *filename) {
106   FILE *fcFile = fopen(filename, "w");
107   const uint16_t *fcp = (uint16_t *)fc;
108   const unsigned int n_contexts = sizeof(FRAME_CONTEXT) / sizeof(uint16_t);
109   unsigned int i;
110 
111   for (i = 0; i < n_contexts; ++i) fprintf(fcFile, "%d ", *fcp++);
112   fclose(fcFile);
113 }
114