Commit 15eaba10 authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Function decomposition inside vp9_decodemv.c file.

Change-Id: Iab96e6a50aec543c63e15cd134f9d5f01ca7ceff
parent 2319b7aa
......@@ -8,20 +8,21 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vp9/decoder/vp9_treereader.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_entropymode.h"
#include "vp9/common/vp9_reconinter.h"
#include "vp9/decoder/vp9_onyxd_int.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_findnearmv.h"
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_seg_common.h"
#include "vp9/common/vp9_mvref_common.h"
#include "vp9/common/vp9_pred_common.h"
#include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_reconinter.h"
#include "vp9/common/vp9_seg_common.h"
#include "vp9/decoder/vp9_decodemv.h"
#include "vp9/decoder/vp9_decodframe.h"
#include "vp9/common/vp9_mvref_common.h"
#include "vp9/decoder/vp9_onyxd_int.h"
#include "vp9/decoder/vp9_treereader.h"
#if CONFIG_DEBUG
#include <assert.h>
#endif
......@@ -37,14 +38,52 @@ extern int dec_debug;
#endif
static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) {
MB_PREDICTION_MODE m = treed_read(r, vp9_intra_mode_tree, p);
return m;
return treed_read(r, vp9_intra_mode_tree, p);
}
static int read_mb_segid(vp9_reader *r, MACROBLOCKD *xd) {
return treed_read(r, vp9_segment_tree, xd->mb_segment_tree_probs);
}
static TX_SIZE select_txfm_size(VP9_COMMON *cm, MACROBLOCKD *xd,
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE);
const vp9_prob *tx_probs = vp9_get_pred_probs(cm, xd, PRED_TX_SIZE);
TX_SIZE txfm_size = vp9_read(r, tx_probs[0]);
if (txfm_size != TX_4X4 && bsize >= BLOCK_SIZE_MB16X16) {
txfm_size += vp9_read(r, tx_probs[1]);
if (txfm_size != TX_8X8 && bsize >= BLOCK_SIZE_SB32X32)
txfm_size += vp9_read(r, tx_probs[2]);
}
if (bsize >= BLOCK_SIZE_SB32X32)
cm->fc.tx_count_32x32p[context][txfm_size]++;
else if (bsize >= BLOCK_SIZE_MB16X16)
cm->fc.tx_count_16x16p[context][txfm_size]++;
else
cm->fc.tx_count_8x8p[context][txfm_size]++;
return txfm_size;
}
static TX_SIZE get_txfm_size(VP9D_COMP *pbi, TXFM_MODE txfm_mode,
BLOCK_SIZE_TYPE bsize, int select_cond,
vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
if (txfm_mode == TX_MODE_SELECT && bsize >= BLOCK_SIZE_SB8X8 && select_cond)
return select_txfm_size(cm, xd, r, bsize);
else if (txfm_mode >= ALLOW_32X32 && bsize >= BLOCK_SIZE_SB32X32)
return TX_32X32;
else if (txfm_mode >= ALLOW_16X16 && bsize >= BLOCK_SIZE_MB16X16)
return TX_16X16;
else if (txfm_mode >= ALLOW_8X8 && bsize >= BLOCK_SIZE_SB8X8)
return TX_8X8;
else
return TX_4X4;
}
static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi,
int mi_row, int mi_col, int segment_id) {
const int mi_index = mi_row * cm->mi_cols + mi_col;
......@@ -63,27 +102,6 @@ static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi,
}
}
static TX_SIZE select_txfm_size(VP9_COMMON *cm, MACROBLOCKD *xd,
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE);
const vp9_prob *tx_probs = vp9_get_pred_probs(cm, xd, PRED_TX_SIZE);
TX_SIZE txfm_size = vp9_read(r, tx_probs[0]);
if (txfm_size != TX_4X4 && bsize >= BLOCK_SIZE_MB16X16) {
txfm_size += vp9_read(r, tx_probs[1]);
if (txfm_size != TX_8X8 && bsize >= BLOCK_SIZE_SB32X32)
txfm_size += vp9_read(r, tx_probs[2]);
}
if (bsize >= BLOCK_SIZE_SB32X32) {
cm->fc.tx_count_32x32p[context][txfm_size]++;
} else if (bsize >= BLOCK_SIZE_MB16X16) {
cm->fc.tx_count_16x16p[context][txfm_size]++;
} else {
cm->fc.tx_count_8x8p[context][txfm_size]++;
}
return txfm_size;
}
static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
int mi_row, int mi_col,
vp9_reader *r) {
......@@ -106,21 +124,8 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
[m->mbmi.mb_skip_coeff]++;
}
if (cm->txfm_mode == TX_MODE_SELECT &&
m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) {
m->mbmi.txfm_size = select_txfm_size(cm, xd, r, m->mbmi.sb_type);
} else if (cm->txfm_mode >= ALLOW_32X32 &&
m->mbmi.sb_type >= BLOCK_SIZE_SB32X32) {
m->mbmi.txfm_size = TX_32X32;
} else if (cm->txfm_mode >= ALLOW_16X16 &&
m->mbmi.sb_type >= BLOCK_SIZE_MB16X16) {
m->mbmi.txfm_size = TX_16X16;
} else if (cm->txfm_mode >= ALLOW_8X8 &&
m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) {
m->mbmi.txfm_size = TX_8X8;
} else {
m->mbmi.txfm_size = TX_4X4;
}
m->mbmi.txfm_size = get_txfm_size(pbi, cm->txfm_mode, m->mbmi.sb_type,
1, r);
// luma mode
m->mbmi.ref_frame[0] = INTRA_FRAME;
......@@ -303,28 +308,22 @@ unsigned int vp9_mv_cont_count[5][4] = {
};
#endif
static void read_switchable_interp_probs(VP9_COMMON* const cm, vp9_reader *r) {
static void read_switchable_interp_probs(FRAME_CONTEXT *fc, vp9_reader *r) {
int i, j;
for (j = 0; j <= VP9_SWITCHABLE_FILTERS; ++j)
for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) {
if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
cm->fc.switchable_interp_prob[j][i] =
// vp9_read_prob(r);
vp9_read_prob_diff_update(r, cm->fc.switchable_interp_prob[j][i]);
}
}
for (j = 0; j < VP9_SWITCHABLE_FILTERS + 1; ++j)
for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i)
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
fc->switchable_interp_prob[j][i] = vp9_read_prob_diff_update(r,
fc->switchable_interp_prob[j][i]);
}
static void read_inter_mode_probs(VP9_COMMON *const cm, vp9_reader *r) {
static void read_inter_mode_probs(FRAME_CONTEXT *fc, vp9_reader *r) {
int i, j;
for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
for (j = 0; j < VP9_INTER_MODES - 1; ++j) {
if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
// cm->fc.inter_mode_probs[i][j] = vp9_read_prob(r);
cm->fc.inter_mode_probs[i][j] =
vp9_read_prob_diff_update(r, cm->fc.inter_mode_probs[i][j]);
}
}
for (j = 0; j < VP9_INTER_MODES - 1; ++j)
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
fc->inter_mode_probs[i][j] = vp9_read_prob_diff_update(r,
fc->inter_mode_probs[i][j]);
}
static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) {
......@@ -337,21 +336,20 @@ static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) {
static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
if ((cm->frame_type != KEY_FRAME) && (!cm->intra_only)) {
if (cm->frame_type != KEY_FRAME && !cm->intra_only) {
nmv_context *const nmvc = &pbi->common.fc.nmvc;
MACROBLOCKD *const xd = &pbi->mb;
int i, j;
read_inter_mode_probs(cm, r);
read_inter_mode_probs(&cm->fc, r);
if (cm->mcomp_filter_type == SWITCHABLE)
read_switchable_interp_probs(cm, r);
read_switchable_interp_probs(&cm->fc, r);
for (i = 0; i < INTRA_INTER_CONTEXTS; i++) {
for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
cm->fc.intra_inter_prob[i] =
vp9_read_prob_diff_update(r, cm->fc.intra_inter_prob[i]);
}
if (cm->allow_comp_inter_inter) {
cm->comp_pred_mode = read_comp_pred_mode(r);
......@@ -476,27 +474,80 @@ static INLINE void decode_mv(vp9_reader *r, MV *mv, const MV *ref,
static INLINE INTERPOLATIONFILTERTYPE read_switchable_filter_type(
VP9D_COMP *pbi, vp9_reader *r) {
const int index = treed_read(r, vp9_switchable_interp_tree,
vp9_get_pred_probs(&pbi->common, &pbi->mb,
PRED_SWITCHABLE_INTERP));
++pbi->common.fc.switchable_interp_count
[vp9_get_pred_context(
&pbi->common, &pbi->mb, PRED_SWITCHABLE_INTERP)][index];
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
const vp9_prob *probs = vp9_get_pred_probs(cm, xd, PRED_SWITCHABLE_INTERP);
const int index = treed_read(r, vp9_switchable_interp_tree, probs);
const int ctx = vp9_get_pred_context(cm, xd, PRED_SWITCHABLE_INTERP);
++cm->fc.switchable_interp_count[ctx][index];
return vp9_switchable_interp[index];
}
static void read_intra_block_modes(VP9D_COMP *pbi, MODE_INFO *mi,
MB_MODE_INFO *mbmi, vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
const int bw = 1 << b_width_log2(bsize);
const int bh = 1 << b_height_log2(bsize);
if (bsize >= BLOCK_SIZE_SB8X8) {
const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type;
const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize);
const int bsl = MIN(bwl, bhl);
mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob[MIN(3, bsl)]);
cm->fc.y_mode_counts[MIN(3, bsl)][mbmi->mode]++;
} else {
int idx, idy;
for (idy = 0; idy < 2; idy += bh) {
for (idx = 0; idx < 2; idx += bw) {
int ib = idy * 2 + idx, k;
int m = read_intra_mode(r, cm->fc.y_mode_prob[0]);
mi->bmi[ib].as_mode.first = m;
cm->fc.y_mode_counts[0][m]++;
for (k = 1; k < bh; ++k)
mi->bmi[ib + k * 2].as_mode.first = m;
for (k = 1; k < bw; ++k)
mi->bmi[ib + k].as_mode.first = m;
}
}
mbmi->mode = mi->bmi[3].as_mode.first;
}
mbmi->uv_mode = read_intra_mode(r, cm->fc.uv_mode_prob[mbmi->mode]);
cm->fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++;
}
static MV_REFERENCE_FRAME read_reference_frame(VP9D_COMP *pbi, int segment_id,
vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
MV_REFERENCE_FRAME ref;
if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME)) {
const int ctx = vp9_get_pred_context(cm, xd, PRED_INTRA_INTER);
ref = (MV_REFERENCE_FRAME)
vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_INTRA_INTER));
cm->fc.intra_inter_count[ctx][ref != INTRA_FRAME]++;
} else {
ref = (MV_REFERENCE_FRAME)
vp9_get_segdata(xd, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
}
return ref;
}
static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
int mi_row, int mi_col,
vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
nmv_context *const nmvc = &cm->fc.nmvc;
MACROBLOCKD *const xd = &pbi->mb;
nmv_context *const nmvc = &cm->fc.nmvc;
int_mv *const mv0 = &mbmi->mv[0];
int_mv *const mv1 = &mbmi->mv[1];
BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
int bw = 1 << b_width_log2(bsize);
int bh = 1 << b_height_log2(bsize);
const BLOCK_SIZE_TYPE bsize = mi->mbmi.sb_type;
const int bw = 1 << b_width_log2(bsize);
const int bh = 1 << b_height_log2(bsize);
int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge;
int j, idx, idy;
......@@ -529,32 +580,9 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
[mbmi->mb_skip_coeff]++;
}
// Read the reference frame
if (!vp9_segfeature_active(xd, mbmi->segment_id, SEG_LVL_REF_FRAME)) {
mbmi->ref_frame[0] =
vp9_read(r, vp9_get_pred_prob(cm, xd, PRED_INTRA_INTER));
cm->fc.intra_inter_count[vp9_get_pred_context(cm, xd, PRED_INTRA_INTER)]
[mbmi->ref_frame[0] != INTRA_FRAME]++;
} else {
mbmi->ref_frame[0] =
vp9_get_segdata(xd, mbmi->segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME;
}
if (cm->txfm_mode == TX_MODE_SELECT &&
(mbmi->mb_skip_coeff == 0 || mbmi->ref_frame[0] == INTRA_FRAME) &&
bsize >= BLOCK_SIZE_SB8X8) {
mbmi->txfm_size = select_txfm_size(cm, xd, r, bsize);
} else if (bsize >= BLOCK_SIZE_SB32X32 &&
cm->txfm_mode >= ALLOW_32X32) {
mbmi->txfm_size = TX_32X32;
} else if (cm->txfm_mode >= ALLOW_16X16 &&
bsize >= BLOCK_SIZE_MB16X16) {
mbmi->txfm_size = TX_16X16;
} else if (cm->txfm_mode >= ALLOW_8X8 && (bsize >= BLOCK_SIZE_SB8X8)) {
mbmi->txfm_size = TX_8X8;
} else {
mbmi->txfm_size = TX_4X4;
}
mbmi->ref_frame[0] = read_reference_frame(pbi, mbmi->segment_id, r);
mbmi->txfm_size = get_txfm_size(pbi, cm->txfm_mode, bsize,
(mbmi->mb_skip_coeff == 0 || mbmi->ref_frame[0] == INTRA_FRAME), r);
// If reference frame is an Inter frame
if (mbmi->ref_frame[0] != INTRA_FRAME) {
......@@ -744,34 +772,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
}
}
} else {
// required for left and above block mv
mv0->as_int = 0;
if (bsize >= BLOCK_SIZE_SB8X8) {
const BLOCK_SIZE_TYPE bsize = xd->mode_info_context->mbmi.sb_type;
const int bwl = b_width_log2(bsize), bhl = b_height_log2(bsize);
const int bsl = MIN(bwl, bhl);
mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob[MIN(3, bsl)]);
cm->fc.y_mode_counts[MIN(3, bsl)][mbmi->mode]++;
} else {
int idx, idy;
for (idy = 0; idy < 2; idy += bh) {
for (idx = 0; idx < 2; idx += bw) {
int ib = idy * 2 + idx, k;
int m = read_intra_mode(r, cm->fc.y_mode_prob[0]);
mi->bmi[ib].as_mode.first = m;
cm->fc.y_mode_counts[0][m]++;
for (k = 1; k < bh; ++k)
mi->bmi[ib + k * 2].as_mode.first = m;
for (k = 1; k < bw; ++k)
mi->bmi[ib + k].as_mode.first = m;
}
}
mbmi->mode = mi->bmi[3].as_mode.first;
}
mbmi->uv_mode = read_intra_mode(r, cm->fc.uv_mode_prob[mbmi->mode]);
cm->fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++;
mv0->as_int = 0; // required for left and above block mv
read_intra_block_modes(pbi, mi, mbmi, r);
}
}
......@@ -781,13 +783,10 @@ void vp9_decode_mode_mvs_init(VP9D_COMP* const pbi, vp9_reader *r) {
// TODO(jkoleszar): does this clear more than MBSKIP_CONTEXTS? Maybe remove.
// vpx_memset(cm->fc.mbskip_probs, 0, sizeof(cm->fc.mbskip_probs));
for (k = 0; k < MBSKIP_CONTEXTS; ++k) {
if (vp9_read(r, VP9_MODE_UPDATE_PROB)) {
for (k = 0; k < MBSKIP_CONTEXTS; ++k)
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
cm->fc.mbskip_probs[k] =
vp9_read_prob_diff_update(r, cm->fc.mbskip_probs[k]);
}
// cm->fc.mbskip_probs[k] = vp9_read_prob(r);
}
mb_mode_mv_init(pbi, r);
}
......@@ -801,7 +800,7 @@ void vp9_decode_mb_mode_mv(VP9D_COMP* const pbi,
MODE_INFO *mi = xd->mode_info_context;
MB_MODE_INFO *const mbmi = &mi->mbmi;
if ((cm->frame_type == KEY_FRAME) || cm->intra_only) {
if (cm->frame_type == KEY_FRAME || cm->intra_only) {
kfread_modes(pbi, mi, mi_row, mi_col, r);
} else {
read_mb_modes_mv(pbi, mi, &mi->mbmi, mi_row, mi_col, r);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment