| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "vp9/common/vp9_common.h" |
| 12 #include "vp9/common/vp9_entropy.h" |
| 13 #include "vp9/common/vp9_entropymode.h" |
| 14 #include "vp9/common/vp9_entropymv.h" |
| 15 #include "vp9/common/vp9_findnearmv.h" |
| 16 #include "vp9/common/vp9_mvref_common.h" |
| 17 #include "vp9/common/vp9_pred_common.h" |
| 18 #include "vp9/common/vp9_reconinter.h" |
| 19 #include "vp9/common/vp9_seg_common.h" |
| 11 | 20 |
| 12 #include "vp9/decoder/vp9_treereader.h" | |
| 13 #include "vp9/common/vp9_entropymv.h" | |
| 14 #include "vp9/common/vp9_entropymode.h" | |
| 15 #include "vp9/common/vp9_reconinter.h" | |
| 16 #include "vp9/decoder/vp9_onyxd_int.h" | |
| 17 #include "vp9/common/vp9_findnearmv.h" | |
| 18 #include "vp9/common/vp9_common.h" | |
| 19 #include "vp9/common/vp9_seg_common.h" | |
| 20 #include "vp9/common/vp9_pred_common.h" | |
| 21 #include "vp9/common/vp9_entropy.h" | |
| 22 #include "vp9/decoder/vp9_decodemv.h" | 21 #include "vp9/decoder/vp9_decodemv.h" |
| 23 #include "vp9/decoder/vp9_decodframe.h" | 22 #include "vp9/decoder/vp9_decodframe.h" |
| 24 #include "vp9/common/vp9_mvref_common.h" | 23 #include "vp9/decoder/vp9_onyxd_int.h" |
| 24 #include "vp9/decoder/vp9_treereader.h" |
| 25 |
| 25 #if CONFIG_DEBUG | 26 #if CONFIG_DEBUG |
| 26 #include <assert.h> | 27 #include <assert.h> |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 // #define DEBUG_DEC_MV | 30 // #define DEBUG_DEC_MV |
| 30 #ifdef DEBUG_DEC_MV | 31 #ifdef DEBUG_DEC_MV |
| 31 int dec_mvcount = 0; | 32 int dec_mvcount = 0; |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 // #define DEC_DEBUG | 35 // #define DEC_DEBUG |
| 35 #ifdef DEC_DEBUG | 36 #ifdef DEC_DEBUG |
| 36 extern int dec_debug; | 37 extern int dec_debug; |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) { | 40 static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) { |
| 40 MB_PREDICTION_MODE m = treed_read(r, vp9_intra_mode_tree, p); | 41 return treed_read(r, vp9_intra_mode_tree, p); |
| 41 return m; | |
| 42 } | 42 } |
| 43 | 43 |
| 44 static int read_mb_segid(vp9_reader *r, MACROBLOCKD *xd) { | 44 static int read_mb_segid(vp9_reader *r, MACROBLOCKD *xd) { |
| 45 return treed_read(r, vp9_segment_tree, xd->mb_segment_tree_probs); | 45 return treed_read(r, vp9_segment_tree, xd->mb_segment_tree_probs); |
| 46 } | 46 } |
| 47 | 47 |
| 48 static TX_SIZE select_txfm_size(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 49 vp9_reader *r, BLOCK_SIZE_TYPE bsize) { |
| 50 const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE); |
| 51 const vp9_prob *tx_probs = vp9_get_pred_probs(cm, xd, PRED_TX_SIZE); |
| 52 TX_SIZE txfm_size = vp9_read(r, tx_probs[0]); |
| 53 if (txfm_size != TX_4X4 && bsize >= BLOCK_SIZE_MB16X16) { |
| 54 txfm_size += vp9_read(r, tx_probs[1]); |
| 55 if (txfm_size != TX_8X8 && bsize >= BLOCK_SIZE_SB32X32) |
| 56 txfm_size += vp9_read(r, tx_probs[2]); |
| 57 } |
| 58 |
| 59 if (bsize >= BLOCK_SIZE_SB32X32) |
| 60 cm->fc.tx_count_32x32p[context][txfm_size]++; |
| 61 else if (bsize >= BLOCK_SIZE_MB16X16) |
| 62 cm->fc.tx_count_16x16p[context][txfm_size]++; |
| 63 else |
| 64 cm->fc.tx_count_8x8p[context][txfm_size]++; |
| 65 |
| 66 return txfm_size; |
| 67 } |
| 68 |
| 69 static TX_SIZE get_txfm_size(VP9D_COMP *pbi, TXFM_MODE txfm_mode, |
| 70 BLOCK_SIZE_TYPE bsize, int select_cond, |
| 71 vp9_reader *r) { |
| 72 VP9_COMMON *const cm = &pbi->common; |
| 73 MACROBLOCKD *const xd = &pbi->mb; |
| 74 |
| 75 if (txfm_mode == TX_MODE_SELECT && bsize >= BLOCK_SIZE_SB8X8 && select_cond) |
| 76 return select_txfm_size(cm, xd, r, bsize); |
| 77 else if (txfm_mode >= ALLOW_32X32 && bsize >= BLOCK_SIZE_SB32X32) |
| 78 return TX_32X32; |
| 79 else if (txfm_mode >= ALLOW_16X16 && bsize >= BLOCK_SIZE_MB16X16) |
| 80 return TX_16X16; |
| 81 else if (txfm_mode >= ALLOW_8X8 && bsize >= BLOCK_SIZE_SB8X8) |
| 82 return TX_8X8; |
| 83 else |
| 84 return TX_4X4; |
| 85 } |
| 86 |
| 48 static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi, | 87 static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi, |
| 49 int mi_row, int mi_col, int segment_id) { | 88 int mi_row, int mi_col, int segment_id) { |
| 50 const int mi_index = mi_row * cm->mi_cols + mi_col; | 89 const int mi_index = mi_row * cm->mi_cols + mi_col; |
| 51 const BLOCK_SIZE_TYPE sb_type = mbmi->sb_type; | 90 const BLOCK_SIZE_TYPE sb_type = mbmi->sb_type; |
| 52 const int bw = 1 << mi_width_log2(sb_type); | 91 const int bw = 1 << mi_width_log2(sb_type); |
| 53 const int bh = 1 << mi_height_log2(sb_type); | 92 const int bh = 1 << mi_height_log2(sb_type); |
| 54 const int ymis = MIN(cm->mi_rows - mi_row, bh); | 93 const int ymis = MIN(cm->mi_rows - mi_row, bh); |
| 55 const int xmis = MIN(cm->mi_cols - mi_col, bw); | 94 const int xmis = MIN(cm->mi_cols - mi_col, bw); |
| 56 int x, y; | 95 int x, y; |
| 57 | 96 |
| 58 for (y = 0; y < ymis; y++) { | 97 for (y = 0; y < ymis; y++) { |
| 59 for (x = 0; x < xmis; x++) { | 98 for (x = 0; x < xmis; x++) { |
| 60 const int index = mi_index + (y * cm->mi_cols + x); | 99 const int index = mi_index + (y * cm->mi_cols + x); |
| 61 cm->last_frame_seg_map[index] = segment_id; | 100 cm->last_frame_seg_map[index] = segment_id; |
| 62 } | 101 } |
| 63 } | 102 } |
| 64 } | 103 } |
| 65 | 104 |
| 66 static TX_SIZE select_txfm_size(VP9_COMMON *cm, MACROBLOCKD *xd, | |
| 67 vp9_reader *r, BLOCK_SIZE_TYPE bsize) { | |
| 68 const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE); | |
| 69 const vp9_prob *tx_probs = vp9_get_pred_probs(cm, xd, PRED_TX_SIZE); | |
| 70 TX_SIZE txfm_size = vp9_read(r, tx_probs[0]); | |
| 71 if (txfm_size != TX_4X4 && bsize >= BLOCK_SIZE_MB16X16) { | |
| 72 txfm_size += vp9_read(r, tx_probs[1]); | |
| 73 if (txfm_size != TX_8X8 && bsize >= BLOCK_SIZE_SB32X32) | |
| 74 txfm_size += vp9_read(r, tx_probs[2]); | |
| 75 } | |
| 76 if (bsize >= BLOCK_SIZE_SB32X32) { | |
| 77 cm->fc.tx_count_32x32p[context][txfm_size]++; | |
| 78 } else if (bsize >= BLOCK_SIZE_MB16X16) { | |
| 79 cm->fc.tx_count_16x16p[context][txfm_size]++; | |
| 80 } else { | |
| 81 cm->fc.tx_count_8x8p[context][txfm_size]++; | |
| 82 } | |
| 83 return txfm_size; | |
| 84 } | |
| 85 | |
| 86 | |
| 87 static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m, | 105 static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m, |
| 88 int mi_row, int mi_col, | 106 int mi_row, int mi_col, |
| 89 vp9_reader *r) { | 107 vp9_reader *r) { |
| 90 VP9_COMMON *const cm = &pbi->common; | 108 VP9_COMMON *const cm = &pbi->common; |
| 91 MACROBLOCKD *const xd = &pbi->mb; | 109 MACROBLOCKD *const xd = &pbi->mb; |
| 92 const int mis = cm->mode_info_stride; | 110 const int mis = cm->mode_info_stride; |
| 93 | 111 |
| 94 // Read segmentation map if it is being updated explicitly this frame | 112 // Read segmentation map if it is being updated explicitly this frame |
| 95 m->mbmi.segment_id = 0; | 113 m->mbmi.segment_id = 0; |
| 96 if (xd->segmentation_enabled && xd->update_mb_segmentation_map) { | 114 if (xd->segmentation_enabled && xd->update_mb_segmentation_map) { |
| 97 m->mbmi.segment_id = read_mb_segid(r, xd); | 115 m->mbmi.segment_id = read_mb_segid(r, xd); |
| 98 set_segment_id(cm, &m->mbmi, mi_row, mi_col, m->mbmi.segment_id); | 116 set_segment_id(cm, &m->mbmi, mi_row, mi_col, m->mbmi.segment_id); |
| 99 } | 117 } |
| 100 | 118 |
| 101 m->mbmi.mb_skip_coeff = vp9_segfeature_active(xd, m->mbmi.segment_id, | 119 m->mbmi.mb_skip_coeff = vp9_segfeature_active(xd, m->mbmi.segment_id, |
| 102 SEG_LVL_SKIP); | 120 SEG_LVL_SKIP); |
| 103 if (!m->mbmi.mb_skip_coeff) { | 121 if (!m->mbmi.mb_skip_coeff) { |
| 104 m->mbmi.mb_skip_coeff = vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_MBSKIP)); | 122 m->mbmi.mb_skip_coeff = vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_MBSKIP)); |
| 105 cm->fc.mbskip_count[vp9_get_pred_context(cm, xd, PRED_MBSKIP)] | 123 cm->fc.mbskip_count[vp9_get_pred_context(cm, xd, PRED_MBSKIP)] |
| 106 [m->mbmi.mb_skip_coeff]++; | 124 [m->mbmi.mb_skip_coeff]++; |
| 107 } | 125 } |
| 108 | 126 |
| 109 if (cm->txfm_mode == TX_MODE_SELECT && | 127 m->mbmi.txfm_size = get_txfm_size(pbi, cm->txfm_mode, m->mbmi.sb_type, |
| 110 m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { | 128 1, r); |
| 111 m->mbmi.txfm_size = select_txfm_size(cm, xd, r, m->mbmi.sb_type); | |
| 112 } else if (cm->txfm_mode >= ALLOW_32X32 && | |
| 113 m->mbmi.sb_type >= BLOCK_SIZE_SB32X32) { | |
| 114 m->mbmi.txfm_size = TX_32X32; | |
| 115 } else if (cm->txfm_mode >= ALLOW_16X16 && | |
| 116 m->mbmi.sb_type >= BLOCK_SIZE_MB16X16) { | |
| 117 m->mbmi.txfm_size = TX_16X16; | |
| 118 } else if (cm->txfm_mode >= ALLOW_8X8 && | |
| 119 m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { | |
| 120 m->mbmi.txfm_size = TX_8X8; | |
| 121 } else { | |
| 122 m->mbmi.txfm_size = TX_4X4; | |
| 123 } | |
| 124 | 129 |
| 125 // luma mode | 130 // luma mode |
| 126 m->mbmi.ref_frame[0] = INTRA_FRAME; | 131 m->mbmi.ref_frame[0] = INTRA_FRAME; |
| 127 if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { | 132 if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) { |
| 128 const MB_PREDICTION_MODE A = above_block_mode(m, 0, mis); | 133 const MB_PREDICTION_MODE A = above_block_mode(m, 0, mis); |
| 129 const MB_PREDICTION_MODE L = xd->left_available ? | 134 const MB_PREDICTION_MODE L = xd->left_available ? |
| 130 left_block_mode(m, 0) : DC_PRED; | 135 left_block_mode(m, 0) : DC_PRED; |
| 131 m->mbmi.mode = read_intra_mode(r, cm->kf_y_mode_prob[A][L]); | 136 m->mbmi.mode = read_intra_mode(r, cm->kf_y_mode_prob[A][L]); |
| 132 } else { | 137 } else { |
| 133 int idx, idy; | 138 int idx, idy; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 #ifdef VPX_MODE_COUNT | 301 #ifdef VPX_MODE_COUNT |
| 297 unsigned int vp9_mv_cont_count[5][4] = { | 302 unsigned int vp9_mv_cont_count[5][4] = { |
| 298 { 0, 0, 0, 0 }, | 303 { 0, 0, 0, 0 }, |
| 299 { 0, 0, 0, 0 }, | 304 { 0, 0, 0, 0 }, |
| 300 { 0, 0, 0, 0 }, | 305 { 0, 0, 0, 0 }, |
| 301 { 0, 0, 0, 0 }, | 306 { 0, 0, 0, 0 }, |
| 302 { 0, 0, 0, 0 } | 307 { 0, 0, 0, 0 } |
| 303 }; | 308 }; |
| 304 #endif | 309 #endif |
| 305 | 310 |
| 306 static void read_switchable_interp_probs(VP9_COMMON* const cm, vp9_reader *r) { | 311 static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vp9_reader *r) { |
| 307 int i, j; | 312 int i, j; |
| 308 for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j) | 313 for (j = 0; j < VP9_SWITCHABLE_FILTERS + 1; ++j) |
| 309 for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) { | 314 for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) |
| 310 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) { | 315 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) |
| 311 cm->fc.switchable_interp_prob[j][i] = | 316 fc->switchable_interp_prob[j][i] = vp9_read_prob_diff_update(r, |
| 312 // vp9_read_prob(r); | 317 fc->switchable_interp_prob[j][i]); |
| 313 vp9_read_prob_diff_update(r, cm->fc.switchable_interp_prob[j][i]); | |
| 314 } | |
| 315 } | |
| 316 } | 318 } |
| 317 | 319 |
| 318 static void read_inter_mode_probs(VP9_COMMON *const cm, vp9_reader *r) { | 320 static void read_inter_mode_probs(FRAME_CONTEXT *fc, vp9_reader *r) { |
| 319 int i, j; | 321 int i, j; |
| 320 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) | 322 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) |
| 321 for (j = 0; j < VP9_INTER_MODES - 1; ++j) { | 323 for (j = 0; j < VP9_INTER_MODES - 1; ++j) |
| 322 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) { | 324 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) |
| 323 // cm->fc.inter_mode_probs[i][j] = vp9_read_prob(r); | 325 fc->inter_mode_probs[i][j] = vp9_read_prob_diff_update(r, |
| 324 cm->fc.inter_mode_probs[i][j] = | 326 fc->inter_mode_probs[i][j]); |
| 325 vp9_read_prob_diff_update(r, cm->fc.inter_mode_probs[i][j]); | |
| 326 } | |
| 327 } | |
| 328 } | 327 } |
| 329 | 328 |
| 330 static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) { | 329 static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) { |
| 331 COMPPREDMODE_TYPE mode = vp9_read_bit(r); | 330 COMPPREDMODE_TYPE mode = vp9_read_bit(r); |
| 332 if (mode) | 331 if (mode) |
| 333 mode += vp9_read_bit(r); | 332 mode += vp9_read_bit(r); |
| 334 return mode; | 333 return mode; |
| 335 } | 334 } |
| 336 | 335 |
| 337 static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) { | 336 static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) { |
| 338 VP9_COMMON *const cm = &pbi->common; | 337 VP9_COMMON *const cm = &pbi->common; |
| 339 | 338 |
| 340 if ((cm->frame_type != KEY_FRAME) && (!cm->intra_only)) { | 339 if (cm->frame_type != KEY_FRAME && !cm->intra_only) { |
| 341 nmv_context *const nmvc = &pbi->common.fc.nmvc; | 340 nmv_context *const nmvc = &pbi->common.fc.nmvc; |
| 342 MACROBLOCKD *const xd = &pbi->mb; | 341 MACROBLOCKD *const xd = &pbi->mb; |
| 343 int i, j; | 342 int i, j; |
| 344 | 343 |
| 345 read_inter_mode_probs(cm, r); | 344 read_inter_mode_probs(&cm->fc, r); |
| 346 | 345 |
| 347 if (cm->mcomp_filter_type == SWITCHABLE) | 346 if (cm->mcomp_filter_type == SWITCHABLE) |
| 348 read_switchable_interp_probs(cm, r); | 347 read_switchable_interp_probs(&cm->fc, r); |
| 349 | 348 |
| 350 for (i = 0; i < INTRA_INTER_CONTEXTS; i++) { | 349 for (i = 0; i < INTRA_INTER_CONTEXTS; i++) |
| 351 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) | 350 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) |
| 352 cm->fc.intra_inter_prob[i] = | 351 cm->fc.intra_inter_prob[i] = |
| 353 vp9_read_prob_diff_update(r, cm->fc.intra_inter_prob[i]); | 352 vp9_read_prob_diff_update(r, cm->fc.intra_inter_prob[i]); |
| 354 } | |
| 355 | 353 |
| 356 if (cm->allow_comp_inter_inter) { | 354 if (cm->allow_comp_inter_inter) { |
| 357 cm->comp_pred_mode = read_comp_pred_mode(r); | 355 cm->comp_pred_mode = read_comp_pred_mode(r); |
| 358 if (cm->comp_pred_mode == HYBRID_PREDICTION) | 356 if (cm->comp_pred_mode == HYBRID_PREDICTION) |
| 359 for (i = 0; i < COMP_INTER_CONTEXTS; i++) | 357 for (i = 0; i < COMP_INTER_CONTEXTS; i++) |
| 360 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) | 358 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) |
| 361 cm->fc.comp_inter_prob[i] = | 359 cm->fc.comp_inter_prob[i] = |
| 362 vp9_read_prob_diff_update(r, cm->fc.comp_inter_prob[i]); | 360 vp9_read_prob_diff_update(r, cm->fc.comp_inter_prob[i]); |
| 363 } else { | 361 } else { |
| 364 cm->comp_pred_mode = SINGLE_PREDICTION_ONLY; | 362 cm->comp_pred_mode = SINGLE_PREDICTION_ONLY; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 mb_to_bottom_edge); | 452 mb_to_bottom_edge); |
| 455 } | 453 } |
| 456 | 454 |
| 457 static INLINE void decode_mv(vp9_reader *r, MV *mv, const MV *ref, | 455 static INLINE void decode_mv(vp9_reader *r, MV *mv, const MV *ref, |
| 458 const nmv_context *ctx, | 456 const nmv_context *ctx, |
| 459 nmv_context_counts *counts, | 457 nmv_context_counts *counts, |
| 460 int usehp) { | 458 int usehp) { |
| 461 const MV_JOINT_TYPE j = treed_read(r, vp9_mv_joint_tree, ctx->joints); | 459 const MV_JOINT_TYPE j = treed_read(r, vp9_mv_joint_tree, ctx->joints); |
| 462 MV diff = {0, 0}; | 460 MV diff = {0, 0}; |
| 463 | 461 |
| 464 usehp = usehp && vp9_use_nmv_hp(ref); | 462 usehp = usehp && vp9_use_mv_hp(ref); |
| 465 if (mv_joint_vertical(j)) | 463 if (mv_joint_vertical(j)) |
| 466 diff.row = read_mv_component(r, &ctx->comps[0], usehp); | 464 diff.row = read_mv_component(r, &ctx->comps[0], usehp); |
| 467 | 465 |
| 468 if (mv_joint_horizontal(j)) | 466 if (mv_joint_horizontal(j)) |
| 469 diff.col = read_mv_component(r, &ctx->comps[1], usehp); | 467 diff.col = read_mv_component(r, &ctx->comps[1], usehp); |
| 470 | 468 |
| 471 vp9_increment_nmv(&diff, ref, counts, usehp); | 469 vp9_increment_nmv(&diff, ref, counts, usehp); |
| 472 | 470 |
| 473 mv->row = diff.row + ref->row; | 471 mv->row = diff.row + ref->row; |
| 474 mv->col = diff.col + ref->col; | 472 mv->col = diff.col + ref->col; |
| 475 } | 473 } |
| 476 | 474 |
| 477 static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type( | 475 static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type( |
| 478 VP9D_COMP *pbi, vp9_reader *r) { | 476 VP9D_COMP *pbi, vp9_reader *r) { |
| 479 const int index = treed_read(r, vp9_switchable_interp_tree, | 477 VP9_COMMON *const cm = &pbi->common; |
| 480 vp9_get_pred_probs(&pbi->common, &pbi->mb, | 478 MACROBLOCKD *const xd = &pbi->mb; |
| 481 PRED_SWITCHABLE_INTERP)); | 479 const vp9_prob *probs = vp9_get_pred_probs(cm, xd, PRED_SWITCHABLE_INTERP); |
| 482 ++pbi->common.fc.switchable_interp_count | 480 const int index = treed_read(r, vp9_switchable_interp_tree, probs); |
| 483 [vp9_get_pred_context( | 481 const int ctx = vp9_get_pred_context(cm, xd, PRED_SWITCHABLE_INTERP); |
| 484 &pbi->common, &pbi->mb, PRED_SWITCHABLE_INTERP)][index]; | 482 ++cm->fc.switchable_interp_count[ctx][index]; |
| 485 return vp9_switchable_interp[index]; | 483 return vp9_switchable_interp[index]; |
| 486 } | 484 } |
| 487 | 485 |
| 486 static void read_intra_block_modes(VP9D_COMP *pbi, MODE_INFO *mi, |
| 487 MB_MODE_INFO *mbmi, vp9_reader *r) { |
| 488 VP9_COMMON *const cm = &pbi->common; |
| 489 MACROBLOCKD *const xd = &pbi->mb; |
| 490 const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type; |
| 491 const int bw = 1 << b_width_log2(bsize); |
| 492 const int bh = 1 << b_height_log2(bsize); |
| 493 |
| 494 if (bsize >= BLOCK_SIZE_SB8X8) { |
| 495 const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; |
| 496 const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); |
| 497 const int bsl = MIN(bwl, bhl); |
| 498 mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob[MIN(3, bsl)]); |
| 499 cm->fc.y_mode_counts[MIN(3, bsl)][mbmi->mode]++; |
| 500 } else { |
| 501 int idx, idy; |
| 502 for (idy = 0; idy < 2; idy += bh) { |
| 503 for (idx = 0; idx < 2; idx += bw) { |
| 504 int ib = idy * 2 + idx, k; |
| 505 int m = read_intra_mode(r, cm->fc.y_mode_prob[0]); |
| 506 mi->bmi[ib].as_mode.first = m; |
| 507 cm->fc.y_mode_counts[0][m]++; |
| 508 for (k = 1; k < bh; ++k) |
| 509 mi->bmi[ib + k * 2].as_mode.first = m; |
| 510 for (k = 1; k < bw; ++k) |
| 511 mi->bmi[ib + k].as_mode.first = m; |
| 512 } |
| 513 } |
| 514 mbmi->mode = mi->bmi[3].as_mode.first; |
| 515 } |
| 516 |
| 517 mbmi->uv_mode = read_intra_mode(r, cm->fc.uv_mode_prob[mbmi->mode]); |
| 518 cm->fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++; |
| 519 } |
| 520 |
| 521 static MV_REFERENCE_FRAME read_reference_frame(VP9D_COMP *pbi, int segment_id, |
| 522 vp9_reader *r) { |
| 523 VP9_COMMON *const cm = &pbi->common; |
| 524 MACROBLOCKD *const xd = &pbi->mb; |
| 525 |
| 526 MV_REFERENCE_FRAME ref; |
| 527 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME)) { |
| 528 const int ctx = vp9_get_pred_context(cm, xd, PRED_INTRA_INTER); |
| 529 ref = (MV_REFERENCE_FRAME) |
| 530 vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_INTRA_INTER)); |
| 531 cm->fc.intra_inter_count[ctx][ref != INTRA_FRAME]++; |
| 532 } else { |
| 533 ref = (MV_REFERENCE_FRAME) |
| 534 vp9_get_segdata(xd, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME; |
| 535 } |
| 536 return ref; |
| 537 } |
| 538 |
| 488 static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, | 539 static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, |
| 489 int mi_row, int mi_col, | 540 int mi_row, int mi_col, |
| 490 vp9_reader *r) { | 541 vp9_reader *r) { |
| 491 VP9_COMMON *const cm = &pbi->common; | 542 VP9_COMMON *const cm = &pbi->common; |
| 543 MACROBLOCKD *const xd = &pbi->mb; |
| 492 nmv_context *const nmvc = &cm->fc.nmvc; | 544 nmv_context *const nmvc = &cm->fc.nmvc; |
| 493 MACROBLOCKD *const xd = &pbi->mb; | |
| 494 | 545 |
| 495 int_mv *const mv0 = &mbmi->mv[0]; | 546 int_mv *const mv0 = &mbmi->mv[0]; |
| 496 int_mv *const mv1 = &mbmi->mv[1]; | 547 int_mv *const mv1 = &mbmi->mv[1]; |
| 497 BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type; | 548 const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type; |
| 498 int bw = 1 << b_width_log2(bsize); | 549 const int bw = 1 << b_width_log2(bsize); |
| 499 int bh = 1 << b_height_log2(bsize); | 550 const int bh = 1 << b_height_log2(bsize); |
| 500 | 551 |
| 501 int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge; | 552 int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge; |
| 502 int j, idx, idy; | 553 int j, idx, idy; |
| 503 | 554 |
| 504 mbmi->ref_frame[1] = NONE; | 555 mbmi->ref_frame[1] = NONE; |
| 505 | 556 |
| 506 // Make sure the MACROBLOCKD mode info pointer is pointed at the | 557 // Make sure the MACROBLOCKD mode info pointer is pointed at the |
| 507 // correct entry for the current macroblock. | 558 // correct entry for the current macroblock. |
| 508 xd->mode_info_context = mi; | 559 xd->mode_info_context = mi; |
| 509 | 560 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 522 mbmi->segment_id = read_mb_segment_id(pbi, mi_row, mi_col, r); | 573 mbmi->segment_id = read_mb_segment_id(pbi, mi_row, mi_col, r); |
| 523 | 574 |
| 524 mbmi->mb_skip_coeff = vp9_segfeature_active(xd, mbmi->segment_id, | 575 mbmi->mb_skip_coeff = vp9_segfeature_active(xd, mbmi->segment_id, |
| 525 SEG_LVL_SKIP); | 576 SEG_LVL_SKIP); |
| 526 if (!mbmi->mb_skip_coeff) { | 577 if (!mbmi->mb_skip_coeff) { |
| 527 mbmi->mb_skip_coeff = vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_MBSKIP)); | 578 mbmi->mb_skip_coeff = vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_MBSKIP)); |
| 528 cm->fc.mbskip_count[vp9_get_pred_context(cm, xd, PRED_MBSKIP)] | 579 cm->fc.mbskip_count[vp9_get_pred_context(cm, xd, PRED_MBSKIP)] |
| 529 [mbmi->mb_skip_coeff]++; | 580 [mbmi->mb_skip_coeff]++; |
| 530 } | 581 } |
| 531 | 582 |
| 532 // Read the reference frame | 583 mbmi->ref_frame[0] = read_reference_frame(pbi, mbmi->segment_id, r); |
| 533 if (!vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_REF_FRAME)) { | 584 mbmi->txfm_size = get_txfm_size(pbi, cm->txfm_mode, bsize, |
| 534 mbmi->ref_frame[0] = | 585 (mbmi->mb_skip_coeff == 0 || mbmi->ref_frame[0] == INTRA_FRAME), r); |
| 535 vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_INTRA_INTER)); | |
| 536 cm->fc.intra_inter_count[vp9_get_pred_context(cm, xd, PRED_INTRA_INTER)] | |
| 537 [mbmi->ref_frame[0] != INTRA_FRAME]++; | |
| 538 } else { | |
| 539 mbmi->ref_frame[0] = | |
| 540 vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME; | |
| 541 } | |
| 542 | |
| 543 if (cm->txfm_mode == TX_MODE_SELECT && | |
| 544 (mbmi->mb_skip_coeff == 0 || mbmi->ref_frame[0] == INTRA_FRAME) && | |
| 545 bsize >= BLOCK_SIZE_SB8X8) { | |
| 546 mbmi->txfm_size = select_txfm_size(cm, xd, r, bsize); | |
| 547 } else if (bsize >= BLOCK_SIZE_SB32X32 && | |
| 548 cm->txfm_mode >= ALLOW_32X32) { | |
| 549 mbmi->txfm_size = TX_32X32; | |
| 550 } else if (cm->txfm_mode >= ALLOW_16X16 && | |
| 551 bsize >= BLOCK_SIZE_MB16X16) { | |
| 552 mbmi->txfm_size = TX_16X16; | |
| 553 } else if (cm->txfm_mode >= ALLOW_8X8 && (bsize >= BLOCK_SIZE_SB8X8)) { | |
| 554 mbmi->txfm_size = TX_8X8; | |
| 555 } else { | |
| 556 mbmi->txfm_size = TX_4X4; | |
| 557 } | |
| 558 | 586 |
| 559 // If reference frame is an Inter frame | 587 // If reference frame is an Inter frame |
| 560 if (mbmi->ref_frame[0] != INTRA_FRAME) { | 588 if (mbmi->ref_frame[0] != INTRA_FRAME) { |
| 561 int_mv nearest, nearby, best_mv; | 589 int_mv nearest, nearby, best_mv; |
| 562 int_mv nearest_second, nearby_second, best_mv_second; | 590 int_mv nearest_second, nearby_second, best_mv_second; |
| 563 vp9_prob mv_ref_p[VP9_INTER_MODES - 1]; | 591 vp9_prob *mv_ref_p; |
| 564 | 592 |
| 565 read_ref_frame(pbi, r, mbmi->segment_id, mbmi->ref_frame); | 593 read_ref_frame(pbi, r, mbmi->segment_id, mbmi->ref_frame); |
| 566 | 594 |
| 567 { | 595 { |
| 568 #ifdef DEC_DEBUG | 596 #ifdef DEC_DEBUG |
| 569 if (dec_debug) | 597 if (dec_debug) |
| 570 printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row, | 598 printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row, |
| 571 xd->mode_info_context->mbmi.mv[0].as_mv.col); | 599 xd->mode_info_context->mbmi.mv[0].as_mv.col); |
| 572 #endif | 600 #endif |
| 573 vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, | 601 vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, |
| 574 mbmi->ref_frame[0], mbmi->ref_mvs[mbmi->ref_frame[0]], | 602 mbmi->ref_frame[0], mbmi->ref_mvs[mbmi->ref_frame[0]], |
| 575 cm->ref_frame_sign_bias); | 603 cm->ref_frame_sign_bias); |
| 576 | 604 |
| 577 vp9_mv_ref_probs(cm, mv_ref_p, mbmi->mb_mode_context[mbmi->ref_frame[0]]); | 605 mv_ref_p = cm->fc.inter_mode_probs[ |
| 606 mbmi->mb_mode_context[mbmi->ref_frame[0]]]; |
| 578 | 607 |
| 579 // If the segment level skip mode enabled | 608 // If the segment level skip mode enabled |
| 580 if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_SKIP)) { | 609 if (vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 581 mbmi->mode = ZEROMV; | 610 mbmi->mode = ZEROMV; |
| 582 } else if (bsize >= BLOCK_SIZE_SB8X8) { | 611 } else if (bsize >= BLOCK_SIZE_SB8X8) { |
| 583 mbmi->mode = read_sb_mv_ref(r, mv_ref_p); | 612 mbmi->mode = read_sb_mv_ref(r, mv_ref_p); |
| 584 vp9_accum_mv_refs(cm, mbmi->mode, | 613 vp9_accum_mv_refs(cm, mbmi->mode, |
| 585 mbmi->mb_mode_context[mbmi->ref_frame[0]]); | 614 mbmi->mb_mode_context[mbmi->ref_frame[0]]); |
| 586 } | 615 } |
| 587 | 616 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 &cm->fc.NMVcount, xd->allow_high_precision_mv); | 766 &cm->fc.NMVcount, xd->allow_high_precision_mv); |
| 738 break; | 767 break; |
| 739 default: | 768 default: |
| 740 #if CONFIG_DEBUG | 769 #if CONFIG_DEBUG |
| 741 assert(0); | 770 assert(0); |
| 742 #endif | 771 #endif |
| 743 break; | 772 break; |
| 744 } | 773 } |
| 745 } | 774 } |
| 746 } else { | 775 } else { |
| 747 // required for left and above block mv | 776 mv0->as_int = 0; // required for left and above block mv |
| 748 mv0->as_int = 0; | 777 read_intra_block_modes(pbi, mi, mbmi, r); |
| 749 | |
| 750 if (bsize >= BLOCK_SIZE_SB8X8) { | |
| 751 const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type; | |
| 752 const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize); | |
| 753 const int bsl = MIN(bwl, bhl); | |
| 754 mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob[MIN(3, bsl)]); | |
| 755 cm->fc.y_mode_counts[MIN(3, bsl)][mbmi->mode]++; | |
| 756 } else { | |
| 757 int idx, idy; | |
| 758 for (idy = 0; idy < 2; idy += bh) { | |
| 759 for (idx = 0; idx < 2; idx += bw) { | |
| 760 int ib = idy * 2 + idx, k; | |
| 761 int m = read_intra_mode(r, cm->fc.y_mode_prob[0]); | |
| 762 mi->bmi[ib].as_mode.first = m; | |
| 763 cm->fc.y_mode_counts[0][m]++; | |
| 764 for (k = 1; k < bh; ++k) | |
| 765 mi->bmi[ib + k * 2].as_mode.first = m; | |
| 766 for (k = 1; k < bw; ++k) | |
| 767 mi->bmi[ib + k].as_mode.first = m; | |
| 768 } | |
| 769 } | |
| 770 mbmi->mode = mi->bmi[3].as_mode.first; | |
| 771 } | |
| 772 | |
| 773 mbmi->uv_mode = read_intra_mode(r, cm->fc.uv_mode_prob[mbmi->mode]); | |
| 774 cm->fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++; | |
| 775 } | 778 } |
| 776 } | 779 } |
| 777 | 780 |
| 778 void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, vp9_reader *r) { | 781 void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, vp9_reader *r) { |
| 779 VP9_COMMON *cm = &pbi->common; | 782 VP9_COMMON *cm = &pbi->common; |
| 780 int k; | 783 int k; |
| 781 | 784 |
| 782 // TODO(jkoleszar): does this clear more than MBSKIP_CONTEXTS? Maybe remove. | 785 // TODO(jkoleszar): does this clear more than MBSKIP_CONTEXTS? Maybe remove. |
| 783 // vpx_memset(cm->fc.mbskip_probs, 0, sizeof(cm->fc.mbskip_probs)); | 786 // vpx_memset(cm->fc.mbskip_probs, 0, sizeof(cm->fc.mbskip_probs)); |
| 784 for (k = 0; k < MBSKIP_CONTEXTS; ++k) { | 787 for (k = 0; k < MBSKIP_CONTEXTS; ++k) |
| 785 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) { | 788 if (vp9_read(r, VP9_MODE_UPDATE_PROB)) |
| 786 cm->fc.mbskip_probs[k] = | 789 cm->fc.mbskip_probs[k] = |
| 787 vp9_read_prob_diff_update(r, cm->fc.mbskip_probs[k]); | 790 vp9_read_prob_diff_update(r, cm->fc.mbskip_probs[k]); |
| 788 } | |
| 789 // cm->fc.mbskip_probs[k] = vp9_read_prob(r); | |
| 790 } | |
| 791 | 791 |
| 792 mb_mode_mv_init(pbi, r); | 792 mb_mode_mv_init(pbi, r); |
| 793 } | 793 } |
| 794 | 794 |
| 795 void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi, | 795 void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi, |
| 796 MACROBLOCKD* const xd, | 796 MACROBLOCKD* const xd, |
| 797 int mi_row, | 797 int mi_row, |
| 798 int mi_col, | 798 int mi_col, |
| 799 vp9_reader *r) { | 799 vp9_reader *r) { |
| 800 VP9_COMMON *const cm = &pbi->common; | 800 VP9_COMMON *const cm = &pbi->common; |
| 801 MODE_INFO *mi = xd->mode_info_context; | 801 MODE_INFO *mi = xd->mode_info_context; |
| 802 MB_MODE_INFO *const mbmi = &mi->mbmi; | 802 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 803 | 803 |
| 804 if ((cm->frame_type == KEY_FRAME) || cm->intra_only) { | 804 if (cm->frame_type == KEY_FRAME || cm->intra_only) { |
| 805 kfread_modes(pbi, mi, mi_row, mi_col, r); | 805 kfread_modes(pbi, mi, mi_row, mi_col, r); |
| 806 } else { | 806 } else { |
| 807 read_mb_modes_mv(pbi, mi, &mi->mbmi, mi_row, mi_col, r); | 807 read_mb_modes_mv(pbi, mi, &mi->mbmi, mi_row, mi_col, r); |
| 808 } | 808 } |
| 809 | 809 |
| 810 if (1) { | 810 if (1) { |
| 811 const int bw = 1 << mi_width_log2(mbmi->sb_type); | 811 const int bw = 1 << mi_width_log2(mbmi->sb_type); |
| 812 const int bh = 1 << mi_height_log2(mbmi->sb_type); | 812 const int bh = 1 << mi_height_log2(mbmi->sb_type); |
| 813 const int y_mis = MIN(bh, cm->mi_rows - mi_row); | 813 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
| 814 const int x_mis = MIN(bw, cm->mi_cols - mi_col); | 814 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
| 815 const int mis = cm->mode_info_stride; | 815 const int mis = cm->mode_info_stride; |
| 816 int x, y; | 816 int x, y; |
| 817 | 817 |
| 818 for (y = 0; y < y_mis; y++) | 818 for (y = 0; y < y_mis; y++) |
| 819 for (x = !y; x < x_mis; x++) | 819 for (x = !y; x < x_mis; x++) |
| 820 mi[y * mis + x] = *mi; | 820 mi[y * mis + x] = *mi; |
| 821 } | 821 } |
| 822 } | 822 } |
| OLD | NEW |