• 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 
40   if (fd->mi_rows != cm->mi_rows || fd->mi_cols != cm->mi_cols) {
41     ifd_clear(fd);
42     ifd_init_mi_rc(fd, cm->mi_rows, cm->mi_cols);
43   }
44   fd->show_existing_frame = cm->show_existing_frame;
45   fd->frame_number = cm->current_frame.frame_number;
46   fd->show_frame = cm->show_frame;
47   fd->frame_type = cm->current_frame.frame_type;
48   fd->base_qindex = cm->base_qindex;
49   // Set width and height of the first tile until generic support can be added
50   TileInfo tile_info;
51   av1_tile_set_row(&tile_info, cm, 0);
52   av1_tile_set_col(&tile_info, cm, 0);
53   fd->tile_mi_cols = tile_info.mi_col_end - tile_info.mi_col_start;
54   fd->tile_mi_rows = tile_info.mi_row_end - tile_info.mi_row_start;
55   fd->delta_q_present_flag = cm->delta_q_info.delta_q_present_flag;
56   fd->delta_q_res = cm->delta_q_info.delta_q_res;
57 #if CONFIG_ACCOUNTING
58   fd->accounting = &pbi->accounting;
59 #endif
60   // TODO(negge): copy per frame CDEF data
61   int i, j;
62   for (i = 0; i < MAX_SEGMENTS; i++) {
63     for (j = 0; j < 2; j++) {
64       fd->y_dequant[i][j] = cm->y_dequant_QTX[i][j];
65       fd->u_dequant[i][j] = cm->u_dequant_QTX[i][j];
66       fd->v_dequant[i][j] = cm->v_dequant_QTX[i][j];
67     }
68   }
69   for (j = 0; j < cm->mi_rows; j++) {
70     for (i = 0; i < cm->mi_cols; i++) {
71       const MB_MODE_INFO *mbmi = cm->mi_grid_visible[j * cm->mi_stride + i];
72       insp_mi_data *mi = &fd->mi_grid[j * cm->mi_cols + i];
73       // Segment
74       mi->segment_id = mbmi->segment_id;
75       // Motion Vectors
76       mi->mv[0].row = mbmi->mv[0].as_mv.row;
77       mi->mv[0].col = mbmi->mv[0].as_mv.col;
78       mi->mv[1].row = mbmi->mv[1].as_mv.row;
79       mi->mv[1].col = mbmi->mv[1].as_mv.col;
80       // Reference Frames
81       mi->ref_frame[0] = mbmi->ref_frame[0];
82       mi->ref_frame[1] = mbmi->ref_frame[1];
83       // Prediction Mode
84       mi->mode = mbmi->mode;
85       mi->intrabc = (int16_t)mbmi->use_intrabc;
86       mi->palette = (int16_t)mbmi->palette_mode_info.palette_size[0];
87       mi->uv_palette = (int16_t)mbmi->palette_mode_info.palette_size[1];
88       // Prediction Mode for Chromatic planes
89       if (mi->mode < INTRA_MODES) {
90         mi->uv_mode = mbmi->uv_mode;
91       } else {
92         mi->uv_mode = UV_MODE_INVALID;
93       }
94 
95       mi->motion_mode = mbmi->motion_mode;
96       mi->compound_type = mbmi->interinter_comp.type;
97 
98       // Block Size
99       mi->sb_type = mbmi->sb_type;
100       // Skip Flag
101       mi->skip = mbmi->skip;
102       mi->filter[0] = av1_extract_interp_filter(mbmi->interp_filters, 0);
103       mi->filter[1] = av1_extract_interp_filter(mbmi->interp_filters, 1);
104       mi->dual_filter_type = mi->filter[0] * 3 + mi->filter[1];
105 
106       // Transform
107       // TODO(anyone): extract tx type info from mbmi->txk_type[].
108 
109       const BLOCK_SIZE bsize = mbmi->sb_type;
110       const int c = i % mi_size_wide[bsize];
111       const int r = j % mi_size_high[bsize];
112       if (is_inter_block(mbmi) || is_intrabc_block(mbmi))
113         mi->tx_size = mbmi->inter_tx_size[av1_get_txb_size_index(bsize, r, c)];
114       else
115         mi->tx_size = mbmi->tx_size;
116 
117       if (skip_not_transform && mi->skip) mi->tx_size = -1;
118 
119       mi->tx_type =
120           (mi->skip ? 0 : mbmi->txk_type[av1_get_txk_type_index(bsize, r, c)]);
121       if (skip_not_transform &&
122           (mi->skip || mbmi->tx_skip[av1_get_txk_type_index(bsize, r, c)]))
123         mi->tx_type = -1;
124 
125       mi->cdef_level = cm->cdef_info.cdef_strengths[mbmi->cdef_strength] /
126                        CDEF_SEC_STRENGTHS;
127       mi->cdef_strength = cm->cdef_info.cdef_strengths[mbmi->cdef_strength] %
128                           CDEF_SEC_STRENGTHS;
129 
130       mi->cdef_strength += mi->cdef_strength == 3;
131       if (mbmi->uv_mode == UV_CFL_PRED) {
132         mi->cfl_alpha_idx = mbmi->cfl_alpha_idx;
133         mi->cfl_alpha_sign = mbmi->cfl_alpha_signs;
134       } else {
135         mi->cfl_alpha_idx = 0;
136         mi->cfl_alpha_sign = 0;
137       }
138       // delta_q
139       mi->current_qindex = mbmi->current_qindex;
140     }
141   }
142   return 1;
143 }
144