summaryrefslogtreecommitdiff
path: root/vp9/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/encoder')
-rw-r--r--vp9/encoder/vp9_bitstream.c31
-rw-r--r--vp9/encoder/vp9_encodeframe.c10
-rw-r--r--vp9/encoder/vp9_onyx_if.c31
-rw-r--r--vp9/encoder/vp9_ratectrl.c69
-rw-r--r--vp9/encoder/vp9_rdopt.c8
5 files changed, 58 insertions, 91 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 1a9d33dae..34d27d1be 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -189,15 +189,7 @@ static void update_refpred_stats(VP9_COMP *cpi) {
int old_cost, new_cost;
// Set the prediction probability structures to defaults
- if (cm->frame_type == KEY_FRAME) {
- // Set the prediction probabilities to defaults
- cm->ref_pred_probs[0] = 120;
- cm->ref_pred_probs[1] = 80;
- cm->ref_pred_probs[2] = 40;
-
- vpx_memset(cpi->ref_pred_probs_update, 0,
- sizeof(cpi->ref_pred_probs_update));
- } else {
+ if (cm->frame_type != KEY_FRAME) {
// From the prediction counts set the probabilities for each context
for (i = 0; i < PREDICTION_PROBS; i++) {
new_pred_probs[i] = get_binary_prob(cpi->ref_pred_count[i][0],
@@ -219,7 +211,6 @@ static void update_refpred_stats(VP9_COMP *cpi) {
cm->ref_pred_probs[i] = new_pred_probs[i];
} else
cpi->ref_pred_probs_update[i] = 0;
-
}
}
}
@@ -508,7 +499,8 @@ static void write_sub_mv_ref
vp9_sub_mv_ref_encoding_array - LEFT4X4 + m);
}
-static void write_nmv(vp9_writer *bc, const MV *mv, const int_mv *ref,
+static void write_nmv(VP9_COMP *cpi, vp9_writer *bc,
+ const MV *mv, const int_mv *ref,
const nmv_context *nmvc, int usehp) {
MV e;
e.row = mv->row - ref->as_mv.row;
@@ -801,7 +793,6 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
vp9_mv_ref_probs(&cpi->common, mv_ref_p, mi->mb_mode_context[rf]);
- // #ifdef ENTROPY_STATS
#ifdef ENTROPY_STATS
accum_mv_refs(mode, ct);
active_section = 3;
@@ -878,12 +869,12 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
#ifdef ENTROPY_STATS
active_section = 5;
#endif
- write_nmv(bc, &mi->mv[0].as_mv, &mi->best_mv,
+ write_nmv(cpi, bc, &mi->mv[0].as_mv, &mi->best_mv,
(const nmv_context*) nmvc,
xd->allow_high_precision_mv);
if (mi->second_ref_frame > 0) {
- write_nmv(bc, &mi->mv[1].as_mv, &mi->best_second_mv,
+ write_nmv(cpi, bc, &mi->mv[1].as_mv, &mi->best_second_mv,
(const nmv_context*) nmvc,
xd->allow_high_precision_mv);
}
@@ -926,12 +917,12 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
#ifdef ENTROPY_STATS
active_section = 11;
#endif
- write_nmv(bc, &blockmv.as_mv, &mi->best_mv,
+ write_nmv(cpi, bc, &blockmv.as_mv, &mi->best_mv,
(const nmv_context*) nmvc,
xd->allow_high_precision_mv);
if (mi->second_ref_frame > 0) {
- write_nmv(bc,
+ write_nmv(cpi, bc,
&cpi->mb.partition_info->bmi[j].second_mv.as_mv,
&mi->best_second_mv,
(const nmv_context*) nmvc,
@@ -1551,6 +1542,9 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
vp9_start_encode(&header_bc, cx_data);
}
+ // error resilient mode
+ vp9_write_bit(&header_bc, pc->error_resilient_mode);
+
// Signal whether or not Segmentation is enabled
vp9_write_bit(&header_bc, (xd->segmentation_enabled) ? 1 : 0);
@@ -1967,7 +1961,7 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
if (pc->mcomp_filter_type == SWITCHABLE)
update_switchable_interp_probs(cpi, &header_bc);
- #if CONFIG_COMP_INTERINTRA_PRED
+#if CONFIG_COMP_INTERINTRA_PRED
if (pc->use_interintra) {
vp9_cond_prob_update(&header_bc,
&pc->fc.interintra_prob,
@@ -2030,7 +2024,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
// if (!cpi->dummy_packing) vp9_zero(cpi->NMVcount);
write_modes(cpi, &residual_bc);
- vp9_update_mode_context(&cpi->common);
+ if (!cpi->common.error_resilient_mode)
+ vp9_adapt_mode_context(&cpi->common);
}
vp9_stop_encode(&residual_bc);
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index e33e20604..a8b93f033 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -646,6 +646,10 @@ static void set_offsets(VP9_COMP *cpi,
const int idx_map = mb_row * cm->mb_cols + mb_col;
const int idx_str = xd->mode_info_stride * mb_row + mb_col;
+#ifdef ENC_DEBUG
+ enc_debug = (cpi->common.current_video_frame == 2 &&
+ mb_row == 4 && mb_col == 5);
+#endif
// entropy context structures
xd->above_context = cm->above_context + mb_col;
xd->left_context = cm->left_context + (mb_row & 3);
@@ -2003,8 +2007,8 @@ static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
assert(!xd->mode_info_context->mbmi.sb_type);
#ifdef ENC_DEBUG
- enc_debug = (cpi->common.current_video_frame == 46 &&
- mb_row == 5 && mb_col == 2);
+ enc_debug = (cpi->common.current_video_frame == 2 &&
+ mb_row == 5 && mb_col == 18);
if (enc_debug)
printf("Encode MB %d %d output %d\n", mb_row, mb_col, output_enabled);
#endif
@@ -2146,7 +2150,7 @@ static void encode_macroblock(VP9_COMP *cpi, TOKENEXTRA **t,
}
if (!x->skip) {
-#ifdef ENC_DEBUG
+#if 0 // def ENC_DEBUG
if (enc_debug) {
int i, j;
printf("\n");
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index c288f93ef..a14165752 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -1355,7 +1355,6 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
if (cpi->oxcf.cpu_used > 5)
cpi->oxcf.cpu_used = 5;
-
break;
case MODE_SECONDPASS_BEST:
@@ -2823,6 +2822,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
for (i = 0; i < MAX_MODES; i++) {
cpi->rd_thresh_mult[i] = 128;
}
+
+ cm->error_resilient_mode = (cpi->oxcf.error_resilient_mode != 0);
}
// Test code for new segment features
@@ -3100,10 +3101,21 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
}
// Set up entropy depending on frame type.
- if (cm->frame_type == KEY_FRAME)
+ if (cm->frame_type == KEY_FRAME) {
+ /* Choose which entropy context to use. When using a forward reference
+ * frame, it immediately follows the keyframe, and thus benefits from
+ * using the same entropy context established by the keyframe. Otherwise,
+ * use the default context 0.
+ */
+ cm->frame_context_idx = cpi->oxcf.play_alternate;
vp9_setup_key_frame(cpi);
- else
+ } else {
+ /* Choose which entropy context to use. Currently there are only two
+ * contexts used, one for normal frames and one for alt ref frames.
+ */
+ cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame;
vp9_setup_inter_frame(cpi);
+ }
}
// transform / motion compensation build reconstruction frame
@@ -3437,7 +3449,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
vp9_copy(cpi->common.fc.hybrid_coef_counts_16x16,
cpi->hybrid_coef_counts_16x16);
vp9_copy(cpi->common.fc.coef_counts_32x32, cpi->coef_counts_32x32);
- vp9_adapt_coef_probs(&cpi->common);
+ if (!cpi->common.error_resilient_mode)
+ vp9_adapt_coef_probs(&cpi->common);
if (cpi->common.frame_type != KEY_FRAME) {
vp9_copy(cpi->common.fc.sb_ymode_counts, cpi->sb_ymode_count);
vp9_copy(cpi->common.fc.ymode_counts, cpi->ymode_count);
@@ -3449,14 +3462,12 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
#if CONFIG_COMP_INTERINTRA_PRED
vp9_copy(cpi->common.fc.interintra_counts, cpi->interintra_count);
#endif
- vp9_adapt_mode_probs(&cpi->common);
+ if (!cpi->common.error_resilient_mode)
+ vp9_adapt_mode_probs(&cpi->common);
cpi->common.fc.NMVcount = cpi->NMVcount;
- /*
- printf("2: %d %d %d %d\n", cpi->NMVcount.joints[0], cpi->NMVcount.joints[1],
- cpi->NMVcount.joints[2], cpi->NMVcount.joints[3]);
- */
- vp9_adapt_nmv_probs(&cpi->common, cpi->mb.e_mbd.allow_high_precision_mv);
+ if (!cpi->common.error_resilient_mode)
+ vp9_adapt_nmv_probs(&cpi->common, cpi->mb.e_mbd.allow_high_precision_mv);
}
#if CONFIG_COMP_INTERINTRA_PRED
if (cm->frame_type != KEY_FRAME)
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index be87326a0..bb608ab37 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -25,6 +25,7 @@
#include "vp9/common/vp9_systemdependent.h"
#include "vp9/encoder/vp9_encodemv.h"
#include "vp9/common/vp9_quant_common.h"
+#include "vp9/common/vp9_seg_common.h"
#define MIN_BPB_FACTOR 0.005
#define MAX_BPB_FACTOR 50
@@ -238,76 +239,30 @@ void vp9_restore_coding_context(VP9_COMP *cpi) {
#endif
}
-
void vp9_setup_key_frame(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
- int i;
-
- // Setup for Key frame:
- vp9_default_coef_probs(& cpi->common);
- vp9_kf_default_bmode_probs(cpi->common.kf_bmode_prob);
- vp9_init_mbmode_probs(& cpi->common);
- vp9_default_bmode_probs(cm->fc.bmode_prob);
-
- if(cm->last_frame_seg_map)
- vpx_memset(cm->last_frame_seg_map, 0, (cm->mb_rows * cm->mb_cols));
-
- vp9_init_mv_probs(& cpi->common);
+ MACROBLOCKD *xd = &cpi->mb.e_mbd;
- // cpi->common.filter_level = 0; // Reset every key frame.
- cpi->common.filter_level = cpi->common.base_qindex * 3 / 8;
+ vp9_setup_past_independence(cm, xd);
// interval before next GF
cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
-
+ /* All buffers are implicitly updated on key frames. */
cpi->refresh_golden_frame = TRUE;
cpi->refresh_alt_ref_frame = TRUE;
-
- vp9_init_mode_contexts(&cpi->common);
-
- for (i = 0; i < NUM_FRAME_CONTEXTS; i++)
- vpx_memcpy(&cpi->common.frame_contexts[i], &cpi->common.fc,
- sizeof(cpi->common.fc));
-
- vpx_memset(cm->prev_mip, 0,
- (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
- vpx_memset(cm->mip, 0,
- (cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
-
- vp9_update_mode_info_border(cm, cm->mip);
- vp9_update_mode_info_in_image(cm, cm->mi);
-
-#if CONFIG_NEW_MVREF
- if (1) {
- MACROBLOCKD *xd = &cpi->mb.e_mbd;
-
- // Defaults probabilities for encoding the MV ref id signal
- vpx_memset(xd->mb_mv_ref_probs, VP9_DEFAULT_MV_REF_PROB,
- sizeof(xd->mb_mv_ref_probs));
- }
-#endif
-
- /* Choose which entropy context to use. When using a forward reference
- * frame, it immediately follows the keyframe, and thus benefits from
- * using the same entropy context established by the keyframe. Otherwise,
- * use the default context 0.
- */
- cm->frame_context_idx = cpi->oxcf.play_alternate;
}
void vp9_setup_inter_frame(VP9_COMP *cpi) {
- /* Choose which entropy context to use. Currently there are only two
- * contexts used, one for normal frames and one for alt ref frames.
- */
- cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame;
-
- assert(cpi->common.frame_context_idx < NUM_FRAME_CONTEXTS);
- vpx_memcpy(&cpi->common.fc,
- &cpi->common.frame_contexts[cpi->common.frame_context_idx],
- sizeof(cpi->common.fc));
+ VP9_COMMON *cm = &cpi->common;
+ MACROBLOCKD *xd = &cpi->mb.e_mbd;
+ if (cm->error_resilient_mode) {
+ vp9_setup_past_independence(cm, xd);
+ }
+ assert(cm->frame_context_idx < NUM_FRAME_CONTEXTS);
+ vpx_memcpy(&cm->fc, &cm->frame_contexts[cm->frame_context_idx],
+ sizeof(cm->fc));
}
-
static int estimate_bits_at_q(int frame_kind, int Q, int MBs,
double correction_factor) {
int Bpm = (int)(.5 + correction_factor * vp9_bits_per_mb(frame_kind, Q));
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 6f7034405..8710475bd 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -3171,19 +3171,21 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
// Gets an initial list of candidate vectors from neighbours and orders them
vp9_find_mv_refs(xd, xd->mode_info_context,
- xd->prev_mode_info_context,
+ cpi->common.error_resilient_mode ?
+ 0 : xd->prev_mode_info_context,
frame_type,
mbmi->ref_mvs[frame_type],
cpi->common.ref_frame_sign_bias);
// Candidate refinement carried out at encoder and decoder
- vp9_find_best_ref_mvs(xd, y_buffer[frame_type],
+ vp9_find_best_ref_mvs(xd,
+ cpi->common.error_resilient_mode ?
+ 0 : y_buffer[frame_type],
yv12->y_stride,
mbmi->ref_mvs[frame_type],
&frame_nearest_mv[frame_type],
&frame_near_mv[frame_type]);
-
// Further refinement that is encode side only to test the top few candidates
// in full and choose the best as the centre point for subsequent searches.
mv_pred(cpi, x, y_buffer[frame_type], yv12->y_stride,