Lines Matching refs:cm

43 static int is_compound_reference_allowed(const VP9_COMMON *cm) {
46 if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1])
52 static void setup_compound_reference_mode(VP9_COMMON *cm) {
53 if (cm->ref_frame_sign_bias[LAST_FRAME] ==
54 cm->ref_frame_sign_bias[GOLDEN_FRAME]) {
55 cm->comp_fixed_ref = ALTREF_FRAME;
56 cm->comp_var_ref[0] = LAST_FRAME;
57 cm->comp_var_ref[1] = GOLDEN_FRAME;
58 } else if (cm->ref_frame_sign_bias[LAST_FRAME] ==
59 cm->ref_frame_sign_bias[ALTREF_FRAME]) {
60 cm->comp_fixed_ref = GOLDEN_FRAME;
61 cm->comp_var_ref[0] = LAST_FRAME;
62 cm->comp_var_ref[1] = ALTREF_FRAME;
64 cm->comp_fixed_ref = LAST_FRAME;
65 cm->comp_var_ref[0] = GOLDEN_FRAME;
66 cm->comp_var_ref[1] = ALTREF_FRAME;
116 static REFERENCE_MODE read_frame_reference_mode(const VP9_COMMON *cm,
118 if (is_compound_reference_allowed(cm)) {
127 static void read_frame_reference_mode_probs(VP9_COMMON *cm, vp9_reader *r) {
128 FRAME_CONTEXT *const fc = &cm->fc;
131 if (cm->reference_mode == REFERENCE_MODE_SELECT)
135 if (cm->reference_mode != COMPOUND_REFERENCE)
141 if (cm->reference_mode != SINGLE_REFERENCE)
182 static void setup_plane_dequants(VP9_COMMON *cm, MACROBLOCKD *xd, int q_index) {
184 xd->plane[0].dequant = cm->y_dequant[q_index];
187 xd->plane[i].dequant = cm->uv_dequant[q_index];
236 VP9_COMMON *cm;
245 VP9_COMMON *const cm = args->cm;
262 const int eob = vp9_decode_block_tokens(cm, xd, plane, block,
271 VP9_COMMON *cm;
281 VP9_COMMON *const cm = args->cm;
286 eob = vp9_decode_block_tokens(cm, xd, plane, block, plane_bsize, x, y,
294 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd,
299 const int x_mis = MIN(bw, cm->mi_cols - mi_col);
300 const int y_mis = MIN(bh, cm->mi_rows - mi_row);
301 const int offset = mi_row * cm->mi_stride + mi_col;
304 xd->mi = cm->mi_grid_visible + offset;
305 xd->mi[0] = &cm->mi[offset];
309 xd->mi[y * cm->mi_stride + x] = xd->mi[0];
315 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols);
317 vp9_setup_dst_planes(xd, get_frame_new_buffer(cm), mi_row, mi_col);
321 static void set_ref(VP9_COMMON *const cm, MACROBLOCKD *const xd,
324 RefBuffer *ref_buffer = &cm->frame_refs[mbmi->ref_frame[idx] - LAST_FRAME];
327 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
334 static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
339 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col);
340 vp9_read_mode_info(cm, xd, tile, mi_row, mi_col, r);
348 if (cm->seg.enabled)
349 setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id,
350 cm->base_qindex));
354 struct intra_args arg = { cm, xd, r };
359 set_ref(cm, xd, 0, mi_row, mi_col);
361 set_ref(cm, xd, 1, mi_row, mi_col);
369 struct inter_args arg = { cm, xd, r, &eobtotal };
379 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs,
383 const vp9_prob *const probs = get_partition_probs(cm, ctx);
384 const int has_rows = (mi_row + hbs) < cm->mi_rows;
385 const int has_cols = (mi_col + hbs) < cm->mi_cols;
397 if (!cm->frame_parallel_decoding_mode)
398 ++cm->counts.partition[ctx][p];
403 static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd,
411 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
414 partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r);
417 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize);
421 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize);
424 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize);
425 if (mi_row + hbs < cm->mi_rows)
426 decode_block(cm, xd, tile, mi_row + hbs, mi_col, r, subsize);
429 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize);
430 if (mi_col + hbs < cm->mi_cols)
431 decode_block(cm, xd, tile, mi_row, mi_col + hbs, r, subsize);
434 decode_partition(cm, xd, tile, mi_row, mi_col, r, subsize);
435 decode_partition(cm, xd, tile, mi_row, mi_col + hbs, r, subsize);
436 decode_partition(cm, xd, tile, mi_row + hbs, mi_col, r, subsize);
437 decode_partition(cm, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize);
572 static void setup_quantization(VP9_COMMON *const cm, MACROBLOCKD *const xd,
576 cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
577 update |= read_delta_q(rb, &cm->y_dc_delta_q);
578 update |= read_delta_q(rb, &cm->uv_dc_delta_q);
579 update |= read_delta_q(rb, &cm->uv_ac_delta_q);
581 vp9_init_dequantizer(cm);
583 xd->lossless = cm->base_qindex == 0 &&
584 cm->y_dc_delta_q == 0 &&
585 cm->uv_dc_delta_q == 0 &&
586 cm->uv_ac_delta_q == 0;
608 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
609 cm->display_width = cm->width;
610 cm->display_height = cm->height;
612 read_frame_size(rb, &cm->display_width, &cm->display_height);
615 static void apply_frame_size(VP9_COMMON *cm, int width, int height) {
616 if (cm->width != width || cm->height != height) {
619 if (width > cm->width || height > cm->height) {
621 if (vp9_resize_frame_buffers(cm, width, height))
622 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
626 cm->width = width;
627 cm->height = height;
629 vp9_update_frame_size(cm);
633 get_frame_new_buffer(cm), cm->width, cm->height,
634 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS,
635 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
636 cm->cb_priv)) {
637 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
642 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
645 apply_frame_size(cm, width, height);
646 setup_display_size(cm, rb);
649 static void setup_frame_size_with_refs(VP9_COMMON *cm,
655 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf;
667 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
670 apply_frame_size(cm, width, height);
671 setup_display_size(cm, rb);
677 VP9_COMMON *const cm = &pbi->common;
683 lf_data->frame_buffer = get_frame_new_buffer(cm);
684 lf_data->cm = cm;
688 vp9_loop_filter_frame_init(cm, cm->lf.filter_level);
698 decode_partition(cm, xd, tile, mi_row, mi_col, r, BLOCK_64X64);
727 lf_data->stop = cm->mi_rows;
732 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
734 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
738 cm->log2_tile_cols = min_log2_tile_cols;
740 cm->log2_tile_cols++;
743 cm->log2_tile_rows = vp9_rb_read_bit(rb);
744 if (cm->log2_tile_rows)
745 cm->log2_tile_rows += vp9_rb_read_bit(rb);
782 VP9_COMMON *const cm = &pbi->common;
783 const int aligned_cols = mi_cols_aligned_to_sb(cm->mi_cols);
784 const int tile_cols = 1 << cm->log2_tile_cols;
785 const int tile_rows = 1 << cm->log2_tile_rows;
796 vpx_memset(cm->above_context, 0,
797 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols);
799 vpx_memset(cm->above_seg_context, 0,
800 sizeof(*cm->above_seg_context) * aligned_cols);
807 const size_t size = get_tile(data_end, last_tile, &cm->error, &data);
825 vp9_tile_init(&tile, cm, tile_row, col);
826 setup_token_decoder(buf->data, data_end, buf->size, &cm->error, &r);
848 decode_partition(tile_data->cm, &tile_data->xd, tile,
871 VP9_COMMON *const cm = &pbi->common;
873 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
874 const int tile_cols = 1 << cm->log2_tile_cols;
875 const int tile_rows = 1 << cm->log2_tile_rows;
892 CHECK_MEM_ERROR(cm, pbi->tile_workers,
899 CHECK_MEM_ERROR(cm, worker->data1,
901 CHECK_MEM_ERROR(cm, worker->data2, vpx_malloc(sizeof(TileInfo)));
903 vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
916 vpx_memset(cm->above_context, 0,
917 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols);
918 vpx_memset(cm->above_seg_context, 0,
919 sizeof(*cm->above_seg_context) * aligned_mi_cols);
924 get_tile(data_end, n == tile_cols - 1, &cm->error, &data);
960 tile_data->cm = cm;
963 vp9_tile_init(tile, tile_data->cm, 0, buf->col);
964 setup_token_decoder(buf->data, data_end, buf->size, &cm->error,
966 init_macroblockd(cm, &tile_data->xd);
998 static void check_sync_code(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
1002 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1008 VP9_COMMON *const cm = (VP9_COMMON *)data;
1009 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet");
1020 VP9_COMMON *const cm = &pbi->common;
1024 cm->last_frame_type = cm->frame_type;
1027 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1030 cm->profile = read_profile(rb);
1031 if (cm->profile >= MAX_PROFILES)
1032 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1035 cm->show_existing_frame = vp9_rb_read_bit(rb);
1036 if (cm->show_existing_frame) {
1038 const int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)];
1040 if (cm->frame_bufs[frame_to_show].ref_count < 1)
1041 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1045 ref_cnt_fb(cm->frame_bufs, &cm->new_fb_idx, frame_to_show);
1047 cm->lf.filter_level = 0;
1048 cm->show_frame = 1;
1052 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb);
1053 cm->show_frame = vp9_rb_read_bit(rb);
1054 cm->error_resilient_mode = vp9_rb_read_bit(rb);
1056 if (cm->frame_type == KEY_FRAME) {
1057 check_sync_code(cm, rb);
1058 if (cm->profile > PROFILE_1)
1059 cm->bit_depth = vp9_rb_read_bit(rb) ? BITS_12 : BITS_10;
1060 cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3);
1061 if (cm->color_space != SRGB) {
1063 if (cm->profile >= PROFILE_1) {
1064 cm->subsampling_x = vp9_rb_read_bit(rb);
1065 cm->subsampling_y = vp9_rb_read_bit(rb);
1068 cm->subsampling_y = cm->subsampling_x = 1;
1071 if (cm->profile >= PROFILE_1) {
1072 cm->subsampling_y = cm->subsampling_x = 0;
1075 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1083 cm->frame_refs[i].idx = cm->new_fb_idx;
1084 cm->frame_refs[i].buf = get_frame_new_buffer(cm);
1087 setup_frame_size(cm, rb);
1089 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb);
1091 cm->reset_frame_context = cm->error_resilient_mode ?
1094 if (cm->intra_only) {
1095 check_sync_code(cm, rb);
1098 setup_frame_size(cm, rb);
1104 const int idx = cm->ref_frame_map[ref];
1105 cm->frame_refs[i].idx = idx;
1106 cm->frame_refs[i].buf = &cm->frame_bufs[idx].buf;
1107 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb);
1110 setup_frame_size_with_refs(cm, rb);
1112 cm->allow_high_precision_mv = vp9_rb_read_bit(rb);
1113 cm->interp_filter = read_interp_filter(rb);
1116 RefBuffer *const ref_buf = &cm->frame_refs[i];
1120 cm->width, cm->height);
1127 if (!cm->error_resilient_mode) {
1128 cm->coding_use_prev_mi = 1;
1129 cm->refresh_frame_context = vp9_rb_read_bit(rb);
1130 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb);
1132 cm->coding_use_prev_mi = 0;
1133 cm->refresh_frame_context = 0;
1134 cm->frame_parallel_decoding_mode = 1;
1139 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2);
1141 if (frame_is_intra_only(cm) || cm->error_resilient_mode)
1142 vp9_setup_past_independence(cm);
1144 setup_loopfilter(&cm->lf, rb);
1145 setup_quantization(cm, &pbi->mb, rb);
1146 setup_segmentation(&cm->seg, rb);
1148 setup_tile_info(cm, rb);
1152 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1160 VP9_COMMON *const cm = &pbi->common;
1162 FRAME_CONTEXT *const fc = &cm->fc;
1167 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
1170 cm->tx_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r);
1171 if (cm->tx_mode == TX_MODE_SELECT)
1173 read_coef_probs(fc, cm->tx_mode, &r);
1178 if (!frame_is_intra_only(cm)) {
1184 if (cm->interp_filter == SWITCHABLE)
1190 cm->reference_mode = read_frame_reference_mode(cm, &r);
1191 if (cm->reference_mode != SINGLE_REFERENCE)
1192 setup_compound_reference_mode(cm);
1193 read_frame_reference_mode_probs(cm, &r);
1203 read_mv_probs(nmvc, cm->allow_high_precision_mv, &r);
1209 void vp9_init_dequantizer(VP9_COMMON *cm) {
1213 cm->y_dequant[q][0] = vp9_dc_quant(q, cm->y_dc_delta_q);
1214 cm->y_dequant[q][1] = vp9_ac_quant(q, 0);
1216 cm->uv_dequant[q][0] = vp9_dc_quant(q, cm->uv_dc_delta_q);
1217 cm->uv_dequant[q][1] = vp9_ac_quant(q, cm->uv_ac_delta_q);
1222 #define debug_check_frame_counts(cm) (void)0
1226 static void debug_check_frame_counts(const VP9_COMMON *const cm) {
1229 assert(cm->frame_parallel_decoding_mode || cm->error_resilient_mode);
1230 assert(!memcmp(cm->counts.y_mode, zero_counts.y_mode,
1231 sizeof(cm->counts.y_mode)));
1232 assert(!memcmp(cm->counts.uv_mode, zero_counts.uv_mode,
1233 sizeof(cm->counts.uv_mode)));
1234 assert(!memcmp(cm->counts.partition, zero_counts.partition,
1235 sizeof(cm->counts.partition)));
1236 assert(!memcmp(cm->counts.coef, zero_counts.coef,
1237 sizeof(cm->counts.coef)));
1238 assert(!memcmp(cm->counts.eob_branch, zero_counts.eob_branch,
1239 sizeof(cm->counts.eob_branch)));
1240 assert(!memcmp(cm->counts.switchable_interp, zero_counts.switchable_interp,
1241 sizeof(cm->counts.switchable_interp)));
1242 assert(!memcmp(cm->counts.inter_mode, zero_counts.inter_mode,
1243 sizeof(cm->counts.inter_mode)));
1244 assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter,
1245 sizeof(cm->counts.intra_inter)));
1246 assert(!memcmp(cm->counts.comp_inter, zero_counts.comp_inter,
1247 sizeof(cm->counts.comp_inter)));
1248 assert(!memcmp(cm->counts.single_ref, zero_counts.single_ref,
1249 sizeof(cm->counts.single_ref)));
1250 assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref,
1251 sizeof(cm->counts.comp_ref)));
1252 assert(!memcmp(&cm->counts.tx, &zero_counts.tx, sizeof(cm->counts.tx)));
1253 assert(!memcmp(cm->counts.skip, zero_counts.skip, sizeof(cm->counts.skip)));
1254 assert(!memcmp(&cm->counts.mv, &zero_counts.mv, sizeof(cm->counts.mv)));
1261 VP9_COMMON *const cm = &pbi->common;
1264 struct vp9_read_bit_buffer rb = { data, data_end, 0, cm, error_handler };
1266 const int keyframe = cm->frame_type == KEY_FRAME;
1267 const int tile_rows = 1 << cm->log2_tile_rows;
1268 const int tile_cols = 1 << cm->log2_tile_cols;
1269 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm);
1283 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1287 (cm->log2_tile_rows | cm->log2_tile_cols) == 0 && cm->lf.filter_level;
1289 CHECK_MEM_ERROR(cm, pbi->lf_worker.data1,
1293 vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
1298 init_macroblockd(cm, &pbi->mb);
1299 cm->prev_mi = get_prev_mi(cm);
1301 setup_plane_dequants(cm, xd, cm->base_qindex);
1302 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y);
1304 cm->fc = cm->frame_contexts[cm->frame_context_idx];
1305 vp9_zero(cm->counts);
1314 cm->frame_parallel_decoding_mode) {
1326 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1330 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
1331 vp9_adapt_coef_probs(cm);
1333 if (!frame_is_intra_only(cm)) {
1334 vp9_adapt_mode_probs(cm);
1335 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv);
1338 debug_check_frame_counts(cm);
1341 if (cm->refresh_frame_context)
1342 cm->frame_contexts[cm->frame_context_idx] = cm->fc;