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