• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017, 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 #include "av1/decoder/decoder.h"
12 #include "av1/decoder/inspection.h"
13 #include "av1/common/enums.h"
14 #include "av1/common/cdef.h"
15 
ifd_init_mi_rc(insp_frame_data * fd,int mi_cols,int mi_rows)16 static void ifd_init_mi_rc(insp_frame_data *fd, int mi_cols, int mi_rows) {
17   fd->mi_cols = mi_cols;
18   fd->mi_rows = mi_rows;
19   fd->mi_grid = (insp_mi_data *)aom_malloc(sizeof(insp_mi_data) * fd->mi_rows *
20                                            fd->mi_cols);
21 }
22 
ifd_init(insp_frame_data * fd,int frame_width,int frame_height)23 void ifd_init(insp_frame_data *fd, int frame_width, int frame_height) {
24   int mi_cols = ALIGN_POWER_OF_TWO(frame_width, 3) >> MI_SIZE_LOG2;
25   int mi_rows = ALIGN_POWER_OF_TWO(frame_height, 3) >> MI_SIZE_LOG2;
26   ifd_init_mi_rc(fd, mi_cols, mi_rows);
27 }
28 
ifd_clear(insp_frame_data * fd)29 void ifd_clear(insp_frame_data *fd) {
30   aom_free(fd->mi_grid);
31   fd->mi_grid = NULL;
32 }
33 
34 /* TODO(negge) This function may be called by more than one thread when using
35                a multi-threaded decoder and this may cause a data race. */
ifd_inspect(insp_frame_data * fd,void * decoder,int skip_not_transform)36 int ifd_inspect(insp_frame_data *fd, void *decoder, int skip_not_transform) {
37   struct AV1Decoder *pbi = (struct AV1Decoder *)decoder;
38   AV1_COMMON *const cm = &pbi->common;
39   const CommonModeInfoParams *const mi_params = &cm->mi_params;
40   const CommonQuantParams *quant_params = &cm->quant_params;
41 
42   if (fd->mi_rows != mi_params->mi_rows || fd->mi_cols != mi_params->mi_cols) {
43     ifd_clear(fd);
44     ifd_init_mi_rc(fd, mi_params->mi_rows, mi_params->mi_cols);
45   }
46   fd->show_existing_frame = cm->show_existing_frame;
47   fd->frame_number = cm->current_frame.frame_number;
48   fd->show_frame = cm->show_frame;
49   fd->frame_type = cm->current_frame.frame_type;
50   fd->base_qindex = quant_params->base_qindex;
51   // Set width and height of the first tile until generic support can be added
52   TileInfo tile_info;
53   av1_tile_set_row(&tile_info, cm, 0);
54   av1_tile_set_col(&tile_info, cm, 0);
55   fd->tile_mi_cols = tile_info.mi_col_end - tile_info.mi_col_start;
56   fd->tile_mi_rows = tile_info.mi_row_end - tile_info.mi_row_start;
57   fd->delta_q_present_flag = cm->delta_q_info.delta_q_present_flag;
58   fd->delta_q_res = cm->delta_q_info.delta_q_res;
59 #if CONFIG_ACCOUNTING
60   fd->accounting = &pbi->accounting;
61 #endif
62   // TODO(negge): copy per frame CDEF data
63   int i, j;
64   for (i = 0; i < MAX_SEGMENTS; i++) {
65     for (j = 0; j < 2; j++) {
66       fd->y_dequant[i][j] = quant_params->y_dequant_QTX[i][j];
67       fd->u_dequant[i][j] = quant_params->u_dequant_QTX[i][j];
68       fd->v_dequant[i][j] = quant_params->v_dequant_QTX[i][j];
69     }
70   }
71   for (j = 0; j < mi_params->mi_rows; j++) {
72     for (i = 0; i < mi_params->mi_cols; i++) {
73       const MB_MODE_INFO *mbmi =
74           mi_params->mi_grid_base[j * mi_params->mi_stride + i];
75       insp_mi_data *mi = &fd->mi_grid[j * mi_params->mi_cols + i];
76       // Segment
77       mi->segment_id = mbmi->segment_id;
78       // Motion Vectors
79       mi->mv[0].row = mbmi->mv[0].as_mv.row;
80       mi->mv[0].col = mbmi->mv[0].as_mv.col;
81       mi->mv[1].row = mbmi->mv[1].as_mv.row;
82       mi->mv[1].col = mbmi->mv[1].as_mv.col;
83       // Reference Frames
84       mi->ref_frame[0] = mbmi->ref_frame[0];
85       mi->ref_frame[1] = mbmi->ref_frame[1];
86       // Prediction Mode
87       mi->mode = mbmi->mode;
88       mi->intrabc = (int16_t)mbmi->use_intrabc;
89       mi->palette = (int16_t)mbmi->palette_mode_info.palette_size[0];
90       mi->uv_palette = (int16_t)mbmi->palette_mode_info.palette_size[1];
91       // Prediction Mode for Chromatic planes
92       if (mi->mode < INTRA_MODES) {
93         mi->uv_mode = mbmi->uv_mode;
94       } else {
95         mi->uv_mode = UV_MODE_INVALID;
96       }
97 
98       mi->motion_mode = mbmi->motion_mode;
99       mi->compound_type = mbmi->interinter_comp.type;
100 
101       // Block Size
102       mi->sb_type = mbmi->sb_type;
103       // Skip Flag
104       mi->skip = mbmi->skip;
105       mi->filter[0] = av1_extract_interp_filter(mbmi->interp_filters, 0);
106       mi->filter[1] = av1_extract_interp_filter(mbmi->interp_filters, 1);
107       mi->dual_filter_type = mi->filter[0] * 3 + mi->filter[1];
108 
109       // Transform
110       // TODO(anyone): extract tx type info from mbmi->txk_type[].
111 
112       const BLOCK_SIZE bsize = mbmi->sb_type;
113       const int c = i % mi_size_wide[bsize];
114       const int r = j % mi_size_high[bsize];
115       if (is_inter_block(mbmi) || is_intrabc_block(mbmi))
116         mi->tx_size = mbmi->inter_tx_size[av1_get_txb_size_index(bsize, r, c)];
117       else
118         mi->tx_size = mbmi->tx_size;
119 
120       if (skip_not_transform && mi->skip) mi->tx_size = -1;
121 
122       if (mi->skip) {
123         const int tx_type_row = j - j % tx_size_high_unit[mi->tx_size];
124         const int tx_type_col = i - i % tx_size_wide_unit[mi->tx_size];
125         const int tx_type_map_idx =
126             tx_type_row * mi_params->mi_stride + tx_type_col;
127         mi->tx_type = mi_params->tx_type_map[tx_type_map_idx];
128       } else {
129         mi->tx_type = 0;
130       }
131 
132       if (skip_not_transform &&
133           (mi->skip || mbmi->tx_skip[av1_get_txk_type_index(bsize, r, c)]))
134         mi->tx_type = -1;
135 
136       mi->cdef_level = cm->cdef_info.cdef_strengths[mbmi->cdef_strength] /
137                        CDEF_SEC_STRENGTHS;
138       mi->cdef_strength = cm->cdef_info.cdef_strengths[mbmi->cdef_strength] %
139                           CDEF_SEC_STRENGTHS;
140 
141       mi->cdef_strength += mi->cdef_strength == 3;
142       if (mbmi->uv_mode == UV_CFL_PRED) {
143         mi->cfl_alpha_idx = mbmi->cfl_alpha_idx;
144         mi->cfl_alpha_sign = mbmi->cfl_alpha_signs;
145       } else {
146         mi->cfl_alpha_idx = 0;
147         mi->cfl_alpha_sign = 0;
148       }
149       // delta_q
150       mi->current_qindex = mbmi->current_qindex;
151     }
152   }
153   return 1;
154 }
155