// TBD prediction functions for various bitstream signals
// Returns a context number for the given MB prediction signal
-unsigned char get_pred_context(VP8_COMMON *const cm,
- MACROBLOCKD *const xd,
+unsigned char get_pred_context(const VP8_COMMON *const cm,
+ const MACROBLOCKD *const xd,
PRED_ID pred_id) {
int pred_context;
MODE_INFO *m = xd->mode_info_context;
// This function returns a context probability for coding a given
// prediction signal
-vp8_prob get_pred_prob(VP8_COMMON *const cm,
- MACROBLOCKD *const xd,
+vp8_prob get_pred_prob(const VP8_COMMON *const cm,
+ const MACROBLOCKD *const xd,
PRED_ID pred_id) {
vp8_prob pred_probability;
int pred_context;
// This function returns a context probability ptr for coding a given
// prediction signal
-vp8_prob *get_pred_probs(VP8_COMMON *const cm,
- MACROBLOCKD *const xd,
+const vp8_prob *get_pred_probs(const VP8_COMMON *const cm,
+ const MACROBLOCKD *const xd,
PRED_ID pred_id) {
- vp8_prob *pred_probability;
+ const vp8_prob *pred_probability;
int pred_context;
// Get the appropriate prediction context
// This function returns the status of the given prediction signal.
// I.e. is the predicted value for the given signal correct.
-unsigned char get_pred_flag(MACROBLOCKD *const xd,
+unsigned char get_pred_flag(const MACROBLOCKD *const xd,
PRED_ID pred_id) {
unsigned char pred_flag = 0;
// peredict various bitstream signals.
// Macroblock segment id prediction function
-unsigned char get_pred_mb_segid(VP8_COMMON *const cm, int MbIndex) {
+unsigned char get_pred_mb_segid(const VP8_COMMON *const cm, int MbIndex) {
// Currently the prediction for the macroblock segment ID is
// the value stored for this macroblock in the previous frame.
return cm->last_frame_seg_map[MbIndex];
}
-MV_REFERENCE_FRAME get_pred_ref(VP8_COMMON *const cm,
- MACROBLOCKD *const xd) {
+MV_REFERENCE_FRAME get_pred_ref(const VP8_COMMON *const cm,
+ const MACROBLOCKD *const xd) {
MODE_INFO *m = xd->mode_info_context;
MV_REFERENCE_FRAME left;
static void update_mbintra_mode_probs(VP8_COMP *cpi) {
VP8_COMMON *const cm = & cpi->common;
- vp8_writer *const w = & cpi->bc;
+ vp8_writer *const w = & cpi->bc2;
{
vp8_prob Pnew [VP8_YMODES - 1];
return bestsavings;
}
-static void pack_tokens_c(vp8_writer *w, const TOKENEXTRA *p, int xcount) {
- const TOKENEXTRA *const stop = p + xcount;
+static void pack_mb_tokens(vp8_writer *w,
+ TOKENEXTRA **tp,
+ const TOKENEXTRA *const stop) {
unsigned int split;
unsigned int shift;
int count = w->count;
unsigned int range = w->range;
unsigned int lowvalue = w->lowvalue;
+ TOKENEXTRA *p = *tp;
while (p < stop) {
const int t = p->Token;
int v = a->value;
int n = a->Len;
+ if (t == EOSB_TOKEN)
+ {
+ ++p;
+ break;
+ }
+
/* skip one or two nodes */
if (p->skip_eob_node) {
n -= p->skip_eob_node;
}
}
-
++p;
}
w->count = count;
w->lowvalue = lowvalue;
w->range = range;
-
+ *tp = p;
}
static void write_partition_size(unsigned char *cx_data, int size) {
static void pack_inter_mode_mvs(VP8_COMP *const cpi) {
int i;
VP8_COMMON *const pc = & cpi->common;
- vp8_writer *const w = & cpi->bc;
+ vp8_writer *const w = & cpi->bc2;
#if CONFIG_NEWMVENTROPY
const nmv_context *nmvc = &pc->fc.nmvc;
#else
MACROBLOCKD *xd = &cpi->mb.e_mbd;
MODE_INFO *m;
MODE_INFO *prev_m;
+ TOKENEXTRA *tok = cpi->tok;
+ TOKENEXTRA *tok_end = tok + cpi->tok_count;
const int mis = pc->mode_info_stride;
int mb_row, mb_col;
}
#endif
+#ifdef ENTROPY_STATS
+ active_section = 1;
+#endif
+ assert(tok < tok_end);
+ pack_mb_tokens(w, &tok, tok_end);
+
#if CONFIG_SUPERBLOCKS
if (m->mbmi.encoded_as_sb) {
assert(!i);
}
+static void write_mb_modes_kf(const VP8_COMMON *c,
+ const MACROBLOCKD *xd,
+ const MODE_INFO *m,
+ int mode_info_stride,
+ vp8_writer *const bc) {
+ const int mis = mode_info_stride;
+ int ym;
+ int segment_id;
+
+ ym = m->mbmi.mode;
+ segment_id = m->mbmi.segment_id;
+
+ if (xd->update_mb_segmentation_map) {
+ write_mb_segid(bc, &m->mbmi, xd);
+ }
+
+ if (c->mb_no_coeff_skip &&
+ (!segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
+ (get_segdata(xd, segment_id, SEG_LVL_EOB) != 0))) {
+ int skip_coeff = m->mbmi.mb_skip_coeff;
+#if CONFIG_SUPERBLOCKS
+ if (m->mbmi.encoded_as_sb) {
+ skip_coeff &= m[1].mbmi.mb_skip_coeff;
+ skip_coeff &= m[mis].mbmi.mb_skip_coeff;
+ skip_coeff &= m[mis + 1].mbmi.mb_skip_coeff;
+ }
+#endif
+ vp8_encode_bool(bc, skip_coeff,
+ get_pred_prob(c, xd, PRED_MBSKIP));
+ }
+
+#if CONFIG_SUPERBLOCKS
+ if (m->mbmi.encoded_as_sb) {
+ sb_kfwrite_ymode(bc, ym,
+ c->sb_kf_ymode_prob[c->kf_ymode_probs_index]);
+ } else
+#endif
+ {
+ kfwrite_ymode(bc, ym,
+ c->kf_ymode_prob[c->kf_ymode_probs_index]);
+ }
+
+ if (ym == B_PRED) {
+ const int mis = c->mode_info_stride;
+ int i = 0;
+#if CONFIG_COMP_INTRA_PRED
+ int uses_second =
+ m->bmi[0].as_mode.second !=
+ (B_PREDICTION_MODE)(B_DC_PRED - 1);
+ vp8_write(bc, uses_second, 128);
+#endif
+ do {
+ const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
+ const B_PREDICTION_MODE L = left_block_mode(m, i);
+ const int bm = m->bmi[i].as_mode.first;
+#if CONFIG_COMP_INTRA_PRED
+ const int bm2 = m->bmi[i].as_mode.second;
+#endif
+
+#ifdef ENTROPY_STATS
+ ++intra_mode_stats [A] [L] [bm];
+#endif
+
+ write_bmode(bc, bm, c->kf_bmode_prob [A] [L]);
+ // printf(" mode: %d\n", bm);
+#if CONFIG_COMP_INTRA_PRED
+ if (uses_second) {
+ write_bmode(bc, bm2, c->kf_bmode_prob [A] [L]);
+ }
+#endif
+ } while (++i < 16);
+ }
+ if (ym == I8X8_PRED) {
+ write_i8x8_mode(bc, m->bmi[0].as_mode.first,
+ c->fc.i8x8_mode_prob);
+ // printf(" mode: %d\n", m->bmi[0].as_mode.first); fflush(stdout);
+ write_i8x8_mode(bc, m->bmi[2].as_mode.first,
+ c->fc.i8x8_mode_prob);
+ // printf(" mode: %d\n", m->bmi[2].as_mode.first); fflush(stdout);
+ write_i8x8_mode(bc, m->bmi[8].as_mode.first,
+ c->fc.i8x8_mode_prob);
+ // printf(" mode: %d\n", m->bmi[8].as_mode.first); fflush(stdout);
+ write_i8x8_mode(bc, m->bmi[10].as_mode.first,
+ c->fc.i8x8_mode_prob);
+ // printf(" mode: %d\n", m->bmi[10].as_mode.first); fflush(stdout);
+ } else
+ write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
+
+#if CONFIG_TX_SELECT
+ if (ym <= I8X8_PRED && c->txfm_mode == TX_MODE_SELECT &&
+ !((c->mb_no_coeff_skip && m->mbmi.mb_skip_coeff) ||
+ (segfeature_active(xd, segment_id, SEG_LVL_EOB) &&
+ get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) {
+ TX_SIZE sz = m->mbmi.txfm_size;
+ // FIXME(rbultje) code ternary symbol once all experiments are merged
+ vp8_write(bc, sz != TX_4X4, c->prob_tx[0]);
+ if (sz != TX_4X4 && ym <= TM_PRED)
+ vp8_write(bc, sz != TX_8X8, c->prob_tx[1]);
+ }
+#endif
+}
+
static void write_kfmodes(VP8_COMP *cpi) {
- vp8_writer *const bc = & cpi->bc;
+ vp8_writer *const bc = & cpi->bc2;
VP8_COMMON *const c = & cpi->common;
const int mis = c->mode_info_stride;
MACROBLOCKD *xd = &cpi->mb.e_mbd;
int mb_row, mb_col;
int row_delta[4] = { 0, +1, 0, -1};
int col_delta[4] = { +1, -1, +1, +1};
+ TOKENEXTRA *tok = cpi->tok;
+ TOKENEXTRA *tok_end = tok + cpi->tok_count;
if (c->mb_no_coeff_skip) {
update_skip_probs(cpi);
// Process the 4 MBs in the order:
// top-left, top-right, bottom-left, bottom-right
for (i = 0; i < 4; i++) {
- int ym;
- int segment_id;
int dy = row_delta[i];
int dx = col_delta[i];
int offset_extended = dy * mis + dx;
// Make sure the MacroBlockD mode info pointer is set correctly
xd->mode_info_context = m;
- ym = m->mbmi.mode;
- segment_id = m->mbmi.segment_id;
-
- if (cpi->mb.e_mbd.update_mb_segmentation_map) {
- write_mb_segid(bc, &m->mbmi, &cpi->mb.e_mbd);
- }
-
- if (c->mb_no_coeff_skip &&
- (!segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
- (get_segdata(xd, segment_id, SEG_LVL_EOB) != 0))) {
- int skip_coeff = m->mbmi.mb_skip_coeff;
-#if CONFIG_SUPERBLOCKS
- if (m->mbmi.encoded_as_sb) {
- skip_coeff &= m[1].mbmi.mb_skip_coeff;
- skip_coeff &= m[mis].mbmi.mb_skip_coeff;
- skip_coeff &= m[mis + 1].mbmi.mb_skip_coeff;
- }
-#endif
- vp8_encode_bool(bc, skip_coeff,
- get_pred_prob(c, xd, PRED_MBSKIP));
- }
-
-#if CONFIG_SUPERBLOCKS
- if (m->mbmi.encoded_as_sb) {
- sb_kfwrite_ymode(bc, ym,
- c->sb_kf_ymode_prob[c->kf_ymode_probs_index]);
- } else
-#endif
- {
- kfwrite_ymode(bc, ym,
- c->kf_ymode_prob[c->kf_ymode_probs_index]);
- }
-
- if (ym == B_PRED) {
- const int mis = c->mode_info_stride;
- int i = 0;
-#if CONFIG_COMP_INTRA_PRED
- int uses_second =
- m->bmi[0].as_mode.second !=
- (B_PREDICTION_MODE)(B_DC_PRED - 1);
- vp8_write(bc, uses_second, 128);
-#endif
- do {
- const B_PREDICTION_MODE A = above_block_mode(m, i, mis);
- const B_PREDICTION_MODE L = left_block_mode(m, i);
- const int bm = m->bmi[i].as_mode.first;
-#if CONFIG_COMP_INTRA_PRED
- const int bm2 = m->bmi[i].as_mode.second;
-#endif
-
+ write_mb_modes_kf(c, xd, m, mis, bc);
#ifdef ENTROPY_STATS
- ++intra_mode_stats [A] [L] [bm];
-#endif
-
- write_bmode(bc, bm, c->kf_bmode_prob [A] [L]);
- // printf(" mode: %d\n", bm);
-#if CONFIG_COMP_INTRA_PRED
- if (uses_second) {
- write_bmode(bc, bm2, c->kf_bmode_prob [A] [L]);
- }
-#endif
- } while (++i < 16);
- }
- if (ym == I8X8_PRED) {
- write_i8x8_mode(bc, m->bmi[0].as_mode.first,
- c->fc.i8x8_mode_prob);
- // printf(" mode: %d\n", m->bmi[0].as_mode.first); fflush(stdout);
- write_i8x8_mode(bc, m->bmi[2].as_mode.first,
- c->fc.i8x8_mode_prob);
- // printf(" mode: %d\n", m->bmi[2].as_mode.first); fflush(stdout);
- write_i8x8_mode(bc, m->bmi[8].as_mode.first,
- c->fc.i8x8_mode_prob);
- // printf(" mode: %d\n", m->bmi[8].as_mode.first); fflush(stdout);
- write_i8x8_mode(bc, m->bmi[10].as_mode.first,
- c->fc.i8x8_mode_prob);
- // printf(" mode: %d\n", m->bmi[10].as_mode.first); fflush(stdout);
- } else
- write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
-
-#if CONFIG_TX_SELECT
- if (ym <= I8X8_PRED && c->txfm_mode == TX_MODE_SELECT &&
- !((c->mb_no_coeff_skip && m->mbmi.mb_skip_coeff) ||
- (segfeature_active(xd, segment_id, SEG_LVL_EOB) &&
- get_segdata(xd, segment_id, SEG_LVL_EOB) == 0))) {
- TX_SIZE sz = m->mbmi.txfm_size;
- // FIXME(rbultje) code ternary symbol once all experiments are merged
- vp8_write(bc, sz != TX_4X4, c->prob_tx[0]);
- if (sz != TX_4X4 && ym <= TM_PRED)
- vp8_write(bc, sz != TX_8X8, c->prob_tx[1]);
- }
+ active_section = 8;
#endif
+ assert(tok < tok_end);
+ pack_mb_tokens(bc, &tok, tok_end);
#if CONFIG_SUPERBLOCKS
if (m->mbmi.encoded_as_sb) {
// Write out the mb_no_coeff_skip flag
vp8_write_bit(bc, pc->mb_no_coeff_skip);
- if (pc->frame_type == KEY_FRAME) {
- decide_kf_ymode_entropy(cpi);
- write_kfmodes(cpi);
-
-#ifdef ENTROPY_STATS
- active_section = 8;
-#endif
- } else {
- pack_inter_mode_mvs(cpi);
- vp8_update_mode_context(&cpi->common);
-
-#ifdef ENTROPY_STATS
- active_section = 1;
-#endif
- }
-
vp8_stop_encode(bc);
oh.first_partition_length_in_bytes = cpi->bc.pos;
}
*size = VP8_HEADER_SIZE + extra_bytes_packed + cpi->bc.pos;
-
vp8_start_encode(&cpi->bc2, cx_data + bc->pos);
- pack_tokens(&cpi->bc2, cpi->tok, cpi->tok_count);
+ if (pc->frame_type == KEY_FRAME) {
+ decide_kf_ymode_entropy(cpi);
+ write_kfmodes(cpi);
+ } else {
+ pack_inter_mode_mvs(cpi);
+ vp8_update_mode_context(&cpi->common);
+ }
+
vp8_stop_encode(&cpi->bc2);