aboutsummaryrefslogtreecommitdiff
path: root/libvpx/vp8/encoder/onyx_if.c
diff options
context:
space:
mode:
authorhkuang <hkuang@google.com>2013-06-19 15:33:45 -0700
committerhkuang <hkuang@google.com>2013-06-20 10:24:31 -0700
commitba164dffc5a6795bce97fae02b51ccf3330e15e4 (patch)
tree9b83fdf84e5bd8bb4d47ac37a7ea9ae3eef840b6 /libvpx/vp8/encoder/onyx_if.c
parentca15b5fc158a9df465aaf1acfe38d8cb5042c81b (diff)
downloadlibvpx-ba164dffc5a6795bce97fae02b51ccf3330e15e4.tar.gz
Updates libvpx to enable the VP9 decoder.
This change enables VP9 decoder for all build configurations. Checkout is from master branch(hash:12180c8329d56d72e8d4424b8fd82b1b2f8e846a). Change-Id: Ieaba85d0bc54e1ecdf9596398dafa03c43182f8c
Diffstat (limited to 'libvpx/vp8/encoder/onyx_if.c')
-rw-r--r--libvpx/vp8/encoder/onyx_if.c488
1 files changed, 257 insertions, 231 deletions
diff --git a/libvpx/vp8/encoder/onyx_if.c b/libvpx/vp8/encoder/onyx_if.c
index c7d81b17f..73f658375 100644
--- a/libvpx/vp8/encoder/onyx_if.c
+++ b/libvpx/vp8/encoder/onyx_if.c
@@ -10,6 +10,7 @@
#include "vpx_config.h"
+#include "./vpx_scale_rtcd.h"
#include "vp8/common/onyxc_int.h"
#include "vp8/common/blockd.h"
#include "onyx_int.h"
@@ -19,7 +20,7 @@
#include "mcomp.h"
#include "firstpass.h"
#include "psnr.h"
-#include "vpx_scale/vpxscale.h"
+#include "vpx_scale/vpx_scale.h"
#include "vp8/common/extend.h"
#include "ratectrl.h"
#include "vp8/common/quant_common.h"
@@ -110,7 +111,7 @@ extern int skip_false_count;
#endif
-#ifdef ENTROPY_STATS
+#ifdef VP8_ENTROPY_STATS
extern int intra_mode_stats[10][10][10];
#endif
@@ -238,7 +239,7 @@ static void save_layer_context(VP8_COMP *cpi)
lc->rate_correction_factor = cpi->rate_correction_factor;
lc->key_frame_rate_correction_factor = cpi->key_frame_rate_correction_factor;
lc->gf_rate_correction_factor = cpi->gf_rate_correction_factor;
- lc->zbin_over_quant = cpi->zbin_over_quant;
+ lc->zbin_over_quant = cpi->mb.zbin_over_quant;
lc->inter_frame_target = cpi->inter_frame_target;
lc->total_byte_count = cpi->total_byte_count;
lc->filter_level = cpi->common.filter_level;
@@ -246,8 +247,8 @@ static void save_layer_context(VP8_COMP *cpi)
lc->last_frame_percent_intra = cpi->last_frame_percent_intra;
memcpy (lc->count_mb_ref_frame_usage,
- cpi->count_mb_ref_frame_usage,
- sizeof(cpi->count_mb_ref_frame_usage));
+ cpi->mb.count_mb_ref_frame_usage,
+ sizeof(cpi->mb.count_mb_ref_frame_usage));
}
static void restore_layer_context(VP8_COMP *cpi, const int layer)
@@ -276,16 +277,135 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer)
cpi->rate_correction_factor = lc->rate_correction_factor;
cpi->key_frame_rate_correction_factor = lc->key_frame_rate_correction_factor;
cpi->gf_rate_correction_factor = lc->gf_rate_correction_factor;
- cpi->zbin_over_quant = lc->zbin_over_quant;
+ cpi->mb.zbin_over_quant = lc->zbin_over_quant;
cpi->inter_frame_target = lc->inter_frame_target;
cpi->total_byte_count = lc->total_byte_count;
cpi->common.filter_level = lc->filter_level;
cpi->last_frame_percent_intra = lc->last_frame_percent_intra;
- memcpy (cpi->count_mb_ref_frame_usage,
+ memcpy (cpi->mb.count_mb_ref_frame_usage,
lc->count_mb_ref_frame_usage,
- sizeof(cpi->count_mb_ref_frame_usage));
+ sizeof(cpi->mb.count_mb_ref_frame_usage));
+}
+
+static int rescale(int val, int num, int denom)
+{
+ int64_t llnum = num;
+ int64_t llden = denom;
+ int64_t llval = val;
+
+ return (int)(llval * llnum / llden);
+}
+
+static void init_temporal_layer_context(VP8_COMP *cpi,
+ VP8_CONFIG *oxcf,
+ const int layer,
+ double prev_layer_frame_rate)
+{
+ LAYER_CONTEXT *lc = &cpi->layer_context[layer];
+
+ lc->frame_rate = cpi->output_frame_rate / cpi->oxcf.rate_decimator[layer];
+ lc->target_bandwidth = cpi->oxcf.target_bitrate[layer] * 1000;
+
+ lc->starting_buffer_level_in_ms = oxcf->starting_buffer_level;
+ lc->optimal_buffer_level_in_ms = oxcf->optimal_buffer_level;
+ lc->maximum_buffer_size_in_ms = oxcf->maximum_buffer_size;
+
+ lc->starting_buffer_level =
+ rescale((int)(oxcf->starting_buffer_level),
+ lc->target_bandwidth, 1000);
+
+ if (oxcf->optimal_buffer_level == 0)
+ lc->optimal_buffer_level = lc->target_bandwidth / 8;
+ else
+ lc->optimal_buffer_level =
+ rescale((int)(oxcf->optimal_buffer_level),
+ lc->target_bandwidth, 1000);
+
+ if (oxcf->maximum_buffer_size == 0)
+ lc->maximum_buffer_size = lc->target_bandwidth / 8;
+ else
+ lc->maximum_buffer_size =
+ rescale((int)(oxcf->maximum_buffer_size),
+ lc->target_bandwidth, 1000);
+
+ /* Work out the average size of a frame within this layer */
+ if (layer > 0)
+ lc->avg_frame_size_for_layer =
+ (int)((cpi->oxcf.target_bitrate[layer] -
+ cpi->oxcf.target_bitrate[layer-1]) * 1000 /
+ (lc->frame_rate - prev_layer_frame_rate));
+
+ lc->active_worst_quality = cpi->oxcf.worst_allowed_q;
+ lc->active_best_quality = cpi->oxcf.best_allowed_q;
+ lc->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
+
+ lc->buffer_level = lc->starting_buffer_level;
+ lc->bits_off_target = lc->starting_buffer_level;
+
+ lc->total_actual_bits = 0;
+ lc->ni_av_qi = 0;
+ lc->ni_tot_qi = 0;
+ lc->ni_frames = 0;
+ lc->rate_correction_factor = 1.0;
+ lc->key_frame_rate_correction_factor = 1.0;
+ lc->gf_rate_correction_factor = 1.0;
+ lc->inter_frame_target = 0;
+}
+
+// Upon a run-time change in temporal layers, reset the layer context parameters
+// for any "new" layers. For "existing" layers, let them inherit the parameters
+// from the previous layer state (at the same layer #). In future we may want
+// to better map the previous layer state(s) to the "new" ones.
+static void reset_temporal_layer_change(VP8_COMP *cpi,
+ VP8_CONFIG *oxcf,
+ const int prev_num_layers)
+{
+ int i;
+ double prev_layer_frame_rate = 0;
+ const int curr_num_layers = cpi->oxcf.number_of_layers;
+ // If the previous state was 1 layer, get current layer context from cpi.
+ // We need this to set the layer context for the new layers below.
+ if (prev_num_layers == 1)
+ {
+ cpi->current_layer = 0;
+ save_layer_context(cpi);
+ }
+ for (i = 0; i < curr_num_layers; i++)
+ {
+ LAYER_CONTEXT *lc = &cpi->layer_context[i];
+ if (i >= prev_num_layers)
+ {
+ init_temporal_layer_context(cpi, oxcf, i, prev_layer_frame_rate);
+ }
+ // The initial buffer levels are set based on their starting levels.
+ // We could set the buffer levels based on the previous state (normalized
+ // properly by the layer bandwidths) but we would need to keep track of
+ // the previous set of layer bandwidths (i.e., target_bitrate[i])
+ // before the layer change. For now, reset to the starting levels.
+ lc->buffer_level = cpi->oxcf.starting_buffer_level_in_ms *
+ cpi->oxcf.target_bitrate[i];
+ lc->bits_off_target = lc->buffer_level;
+ // TDOD(marpan): Should we set the rate_correction_factor and
+ // active_worst/best_quality to values derived from the previous layer
+ // state (to smooth-out quality dips/rate fluctuation at transition)?
+
+ // We need to treat the 1 layer case separately: oxcf.target_bitrate[i]
+ // is not set for 1 layer, and the restore_layer_context/save_context()
+ // are not called in the encoding loop, so we need to call it here to
+ // pass the layer context state to |cpi|.
+ if (curr_num_layers == 1)
+ {
+ lc->target_bandwidth = cpi->oxcf.target_bandwidth;
+ lc->buffer_level = cpi->oxcf.starting_buffer_level_in_ms *
+ lc->target_bandwidth / 1000;
+ lc->bits_off_target = lc->buffer_level;
+ restore_layer_context(cpi, 0);
+ }
+ prev_layer_frame_rate = cpi->output_frame_rate /
+ cpi->oxcf.rate_decimator[i];
+ }
}
static void setup_features(VP8_COMP *cpi)
@@ -640,11 +760,9 @@ void vp8_set_speed_features(VP8_COMP *cpi)
for (i = 0; i < MAX_MODES; i ++)
{
cpi->mode_check_freq[i] = 0;
- cpi->mode_test_hit_counts[i] = 0;
- cpi->mode_chosen_counts[i] = 0;
}
- cpi->mbs_tested_so_far = 0;
+ cpi->mb.mbs_tested_so_far = 0;
/* best quality defaults */
sf->RD = 1;
@@ -826,7 +944,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
{
unsigned int sum = 0;
unsigned int total_mbs = cm->MBs;
- int i, thresh;
+ int thresh;
unsigned int total_skip;
int min = 2000;
@@ -838,7 +956,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
for (i = 0; i < min; i++)
{
- sum += cpi->error_bins[i];
+ sum += cpi->mb.error_bins[i];
}
total_skip = sum;
@@ -847,7 +965,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
/* i starts from 2 to make sure thresh started from 2048 */
for (; i < 1024; i++)
{
- sum += cpi->error_bins[i];
+ sum += cpi->mb.error_bins[i];
if (10 * sum >= (unsigned int)(cpi->Speed - 6)*(total_mbs - total_skip))
break;
@@ -902,7 +1020,7 @@ void vp8_set_speed_features(VP8_COMP *cpi)
if (Speed >= 15)
sf->half_pixel_search = 0;
- vpx_memset(cpi->error_bins, 0, sizeof(cpi->error_bins));
+ vpx_memset(cpi->mb.error_bins, 0, sizeof(cpi->mb.error_bins));
}; /* switch */
@@ -1077,10 +1195,7 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
}
/* Data used for real time vc mode to see if gf needs refreshing */
- cpi->inter_zz_count = 0;
cpi->zeromv_count = 0;
- cpi->gf_bad_count = 0;
- cpi->gf_update_recommended = 0;
/* Structures used to monitor GF usage */
@@ -1204,17 +1319,6 @@ void vp8_new_frame_rate(VP8_COMP *cpi, double framerate)
}
-static int
-rescale(int val, int num, int denom)
-{
- int64_t llnum = num;
- int64_t llden = denom;
- int64_t llval = val;
-
- return (int)(llval * llnum / llden);
-}
-
-
static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
{
VP8_COMMON *cm = &cpi->common;
@@ -1269,59 +1373,9 @@ static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
for (i=0; i<cpi->oxcf.number_of_layers; i++)
{
- LAYER_CONTEXT *lc = &cpi->layer_context[i];
-
- /* Layer configuration */
- lc->frame_rate =
- cpi->output_frame_rate / cpi->oxcf.rate_decimator[i];
- lc->target_bandwidth = cpi->oxcf.target_bitrate[i] * 1000;
-
- lc->starting_buffer_level_in_ms = oxcf->starting_buffer_level;
- lc->optimal_buffer_level_in_ms = oxcf->optimal_buffer_level;
- lc->maximum_buffer_size_in_ms = oxcf->maximum_buffer_size;
-
- lc->starting_buffer_level =
- rescale((int)(oxcf->starting_buffer_level),
- lc->target_bandwidth, 1000);
-
- if (oxcf->optimal_buffer_level == 0)
- lc->optimal_buffer_level = lc->target_bandwidth / 8;
- else
- lc->optimal_buffer_level =
- rescale((int)(oxcf->optimal_buffer_level),
- lc->target_bandwidth, 1000);
-
- if (oxcf->maximum_buffer_size == 0)
- lc->maximum_buffer_size = lc->target_bandwidth / 8;
- else
- lc->maximum_buffer_size =
- rescale((int)oxcf->maximum_buffer_size,
- lc->target_bandwidth, 1000);
-
- /* Work out the average size of a frame within this layer */
- if (i > 0)
- lc->avg_frame_size_for_layer =
- (int)((cpi->oxcf.target_bitrate[i] -
- cpi->oxcf.target_bitrate[i-1]) * 1000 /
- (lc->frame_rate - prev_layer_frame_rate));
-
- lc->active_worst_quality = cpi->oxcf.worst_allowed_q;
- lc->active_best_quality = cpi->oxcf.best_allowed_q;
- lc->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
-
- lc->buffer_level = lc->starting_buffer_level;
- lc->bits_off_target = lc->starting_buffer_level;
-
- lc->total_actual_bits = 0;
- lc->ni_av_qi = 0;
- lc->ni_tot_qi = 0;
- lc->ni_frames = 0;
- lc->rate_correction_factor = 1.0;
- lc->key_frame_rate_correction_factor = 1.0;
- lc->gf_rate_correction_factor = 1.0;
- lc->inter_frame_target = 0;
-
- prev_layer_frame_rate = lc->frame_rate;
+ init_temporal_layer_context(cpi, oxcf, i, prev_layer_frame_rate);
+ prev_layer_frame_rate = cpi->output_frame_rate /
+ cpi->oxcf.rate_decimator[i];
}
}
@@ -1388,7 +1442,7 @@ static void update_layer_contexts (VP8_COMP *cpi)
void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
{
VP8_COMMON *cm = &cpi->common;
- int last_w, last_h;
+ int last_w, last_h, prev_number_of_layers;
if (!cpi)
return;
@@ -1413,6 +1467,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
last_w = cpi->oxcf.Width;
last_h = cpi->oxcf.Height;
+ prev_number_of_layers = cpi->oxcf.number_of_layers;
cpi->oxcf = *oxcf;
@@ -1605,6 +1660,16 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
+ // Check if the number of temporal layers has changed, and if so reset the
+ // pattern counter and set/initialize the temporal layer context for the
+ // new layer configuration.
+ if (cpi->oxcf.number_of_layers != prev_number_of_layers)
+ {
+ // If the number of temporal layers are changed we must start at the
+ // base of the pattern cycle, so reset temporal_pattern_counter.
+ cpi->temporal_pattern_counter = 0;
+ reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers);
+ }
cm->Width = cpi->oxcf.Width;
cm->Height = cpi->oxcf.Height;
@@ -1742,6 +1807,7 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
memcpy(cpi->base_skip_false_prob, vp8cx_base_skip_false_prob, sizeof(vp8cx_base_skip_false_prob));
cpi->common.current_video_frame = 0;
+ cpi->temporal_pattern_counter = 0;
cpi->kf_overspend_bits = 0;
cpi->kf_bitrate_adjustment = 0;
cpi->frames_till_gf_update_due = 0;
@@ -1809,7 +1875,7 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
else
cpi->cyclic_refresh_map = (signed char *) NULL;
-#ifdef ENTROPY_STATS
+#ifdef VP8_ENTROPY_STATS
init_context_counters();
#endif
@@ -1924,10 +1990,10 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
/* Set starting values of RD threshold multipliers (128 = *1) */
for (i = 0; i < MAX_MODES; i++)
{
- cpi->rd_thresh_mult[i] = 128;
+ cpi->mb.rd_thresh_mult[i] = 128;
}
-#ifdef ENTROPY_STATS
+#ifdef VP8_ENTROPY_STATS
init_mv_ref_counts();
#endif
@@ -2002,7 +2068,7 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
cpi->refining_search_sad = vp8_refining_search_sad;
/* make sure frame 1 is okay */
- cpi->error_bins[0] = cpi->common.MBs;
+ cpi->mb.error_bins[0] = cpi->common.MBs;
/* vp8cx_init_quantizer() is first called here. Add check in
* vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only
@@ -2064,7 +2130,7 @@ void vp8_remove_compressor(VP8_COMP **ptr)
#endif
-#ifdef ENTROPY_STATS
+#ifdef VP8_ENTROPY_STATS
print_context_counters();
print_tree_update_probs();
print_mode_context();
@@ -2246,7 +2312,7 @@ void vp8_remove_compressor(VP8_COMP **ptr)
}
#endif
-#ifdef ENTROPY_STATS
+#ifdef VP8_ENTROPY_STATS
{
int i, j, k;
FILE *fmode = fopen("modecontext.c", "w");
@@ -2591,7 +2657,7 @@ static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
Scale2Ratio(cm->horiz_scale, &hr, &hs);
Scale2Ratio(cm->vert_scale, &vr, &vs);
- vp8_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer,
+ vpx_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer,
tmp_height, hs, hr, vs, vr, 0);
vp8_yv12_extend_frame_borders(&cpi->scaled_source);
@@ -2689,7 +2755,7 @@ static void update_alt_ref_frame_stats(VP8_COMP *cpi)
/* Clear the alternate reference update pending flag. */
cpi->source_alt_ref_pending = 0;
- /* Set the alternate refernce frame active flag */
+ /* Set the alternate reference frame active flag */
cpi->source_alt_ref_active = 1;
@@ -2775,10 +2841,14 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
if (cpi->common.frames_since_golden > 1)
{
- cpi->recent_ref_frame_usage[INTRA_FRAME] += cpi->count_mb_ref_frame_usage[INTRA_FRAME];
- cpi->recent_ref_frame_usage[LAST_FRAME] += cpi->count_mb_ref_frame_usage[LAST_FRAME];
- cpi->recent_ref_frame_usage[GOLDEN_FRAME] += cpi->count_mb_ref_frame_usage[GOLDEN_FRAME];
- cpi->recent_ref_frame_usage[ALTREF_FRAME] += cpi->count_mb_ref_frame_usage[ALTREF_FRAME];
+ cpi->recent_ref_frame_usage[INTRA_FRAME] +=
+ cpi->mb.count_mb_ref_frame_usage[INTRA_FRAME];
+ cpi->recent_ref_frame_usage[LAST_FRAME] +=
+ cpi->mb.count_mb_ref_frame_usage[LAST_FRAME];
+ cpi->recent_ref_frame_usage[GOLDEN_FRAME] +=
+ cpi->mb.count_mb_ref_frame_usage[GOLDEN_FRAME];
+ cpi->recent_ref_frame_usage[ALTREF_FRAME] +=
+ cpi->mb.count_mb_ref_frame_usage[ALTREF_FRAME];
}
}
}
@@ -2790,7 +2860,7 @@ static void update_rd_ref_frame_probs(VP8_COMP *cpi)
{
VP8_COMMON *cm = &cpi->common;
- const int *const rfct = cpi->count_mb_ref_frame_usage;
+ const int *const rfct = cpi->mb.count_mb_ref_frame_usage;
const int rf_intra = rfct[INTRA_FRAME];
const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];
@@ -2815,6 +2885,8 @@ static void update_rd_ref_frame_probs(VP8_COMP *cpi)
if (cpi->common.refresh_alt_ref_frame)
{
cpi->prob_intra_coded += 40;
+ if (cpi->prob_intra_coded > 255)
+ cpi->prob_intra_coded = 255;
cpi->prob_last_coded = 200;
cpi->prob_gf_coded = 1;
}
@@ -3131,6 +3203,57 @@ static void update_reference_frames(VP8_COMP *cpi)
cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame;
#endif
}
+
+#if CONFIG_TEMPORAL_DENOISING
+ if (cpi->oxcf.noise_sensitivity)
+ {
+ /* we shouldn't have to keep multiple copies as we know in advance which
+ * buffer we should start - for now to get something up and running
+ * I've chosen to copy the buffers
+ */
+ if (cm->frame_type == KEY_FRAME)
+ {
+ int i;
+ vp8_yv12_copy_frame(
+ cpi->Source,
+ &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
+
+ vp8_yv12_extend_frame_borders(
+ &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
+
+ for (i = 2; i < MAX_REF_FRAMES - 1; i++)
+ vp8_yv12_copy_frame(
+ &cpi->denoiser.yv12_running_avg[LAST_FRAME],
+ &cpi->denoiser.yv12_running_avg[i]);
+ }
+ else /* For non key frames */
+ {
+ vp8_yv12_extend_frame_borders(
+ &cpi->denoiser.yv12_running_avg[INTRA_FRAME]);
+
+ if (cm->refresh_alt_ref_frame || cm->copy_buffer_to_arf)
+ {
+ vp8_yv12_copy_frame(
+ &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
+ &cpi->denoiser.yv12_running_avg[ALTREF_FRAME]);
+ }
+ if (cm->refresh_golden_frame || cm->copy_buffer_to_gf)
+ {
+ vp8_yv12_copy_frame(
+ &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
+ &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]);
+ }
+ if(cm->refresh_last_frame)
+ {
+ vp8_yv12_copy_frame(
+ &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
+ &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
+ }
+ }
+
+ }
+#endif
+
}
void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
@@ -3174,51 +3297,6 @@ void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
}
vp8_yv12_extend_frame_borders(cm->frame_to_show);
-#if CONFIG_TEMPORAL_DENOISING
- if (cpi->oxcf.noise_sensitivity)
- {
-
-
- /* we shouldn't have to keep multiple copies as we know in advance which
- * buffer we should start - for now to get something up and running
- * I've chosen to copy the buffers
- */
- if (cm->frame_type == KEY_FRAME)
- {
- int i;
- vp8_yv12_copy_frame(
- cpi->Source,
- &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
-
- vp8_yv12_extend_frame_borders(
- &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
-
- for (i = 2; i < MAX_REF_FRAMES - 1; i++)
- vp8_yv12_copy_frame(
- cpi->Source,
- &cpi->denoiser.yv12_running_avg[i]);
- }
- else /* For non key frames */
- {
- vp8_yv12_extend_frame_borders(
- &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
-
- if (cm->refresh_alt_ref_frame || cm->copy_buffer_to_arf)
- {
- vp8_yv12_copy_frame(
- &cpi->denoiser.yv12_running_avg[LAST_FRAME],
- &cpi->denoiser.yv12_running_avg[ALTREF_FRAME]);
- }
- if (cm->refresh_golden_frame || cm->copy_buffer_to_gf)
- {
- vp8_yv12_copy_frame(
- &cpi->denoiser.yv12_running_avg[LAST_FRAME],
- &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]);
- }
- }
-
- }
-#endif
}
@@ -3302,19 +3380,19 @@ static void encode_frame_to_data_rate
cm->copy_buffer_to_arf = 0;
/* Clear zbin over-quant value and mode boost values. */
- cpi->zbin_over_quant = 0;
- cpi->zbin_mode_boost = 0;
+ cpi->mb.zbin_over_quant = 0;
+ cpi->mb.zbin_mode_boost = 0;
/* Enable or disable mode based tweaking of the zbin
* For 2 Pass Only used where GF/ARF prediction quality
* is above a threshold
*/
- cpi->zbin_mode_boost_enabled = 1;
+ cpi->mb.zbin_mode_boost_enabled = 1;
if (cpi->pass == 2)
{
if ( cpi->gfu_boost <= 400 )
{
- cpi->zbin_mode_boost_enabled = 0;
+ cpi->mb.zbin_mode_boost_enabled = 0;
}
}
@@ -3324,7 +3402,7 @@ static void encode_frame_to_data_rate
else
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0;
- /* Check to see if a key frame is signalled
+ /* Check to see if a key frame is signaled
* For two pass with auto key frame enabled cm->frame_type may already
* be set, but not for one pass.
*/
@@ -3381,7 +3459,7 @@ static void encode_frame_to_data_rate
/* Reset the RD threshold multipliers to default of * 1 (128) */
for (i = 0; i < MAX_MODES; i++)
{
- cpi->rd_thresh_mult[i] = 128;
+ cpi->mb.rd_thresh_mult[i] = 128;
}
}
@@ -3459,7 +3537,7 @@ static void encode_frame_to_data_rate
/* Note that we should not throw out a key frame (especially when
* spatial resampling is enabled).
*/
- if ((cm->frame_type == KEY_FRAME))
+ if (cm->frame_type == KEY_FRAME)
{
cpi->decimation_count = cpi->decimation_factor;
}
@@ -3477,6 +3555,8 @@ static void encode_frame_to_data_rate
cm->current_video_frame++;
cpi->frames_since_key++;
+ // We advance the temporal pattern for dropped frames.
+ cpi->temporal_pattern_counter++;
#if CONFIG_INTERNAL_STATS
cpi->count ++;
@@ -3518,6 +3598,8 @@ static void encode_frame_to_data_rate
#endif
cm->current_video_frame++;
cpi->frames_since_key++;
+ // We advance the temporal pattern for dropped frames.
+ cpi->temporal_pattern_counter++;
return;
}
@@ -4070,8 +4152,9 @@ static void encode_frame_to_data_rate
q_low = (Q < q_high) ? (Q + 1) : q_high;
/* If we are using over quant do the same for zbin_oq_low */
- if (cpi->zbin_over_quant > 0)
- zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
+ if (cpi->mb.zbin_over_quant > 0)
+ zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
+ (cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
if (undershoot_seen)
{
@@ -4087,11 +4170,13 @@ static void encode_frame_to_data_rate
* is max)
*/
if (Q < MAXQ)
- cpi->zbin_over_quant = 0;
+ cpi->mb.zbin_over_quant = 0;
else
{
- zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
- cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
+ zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
+ (cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
+ cpi->mb.zbin_over_quant =
+ (zbin_oq_high + zbin_oq_low) / 2;
}
}
else
@@ -4104,7 +4189,9 @@ static void encode_frame_to_data_rate
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
- while (((Q < q_low) || (cpi->zbin_over_quant < zbin_oq_low)) && (Retries < 10))
+ while (((Q < q_low) ||
+ (cpi->mb.zbin_over_quant < zbin_oq_low)) &&
+ (Retries < 10))
{
vp8_update_rate_correction_factors(cpi, 0);
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
@@ -4117,12 +4204,13 @@ static void encode_frame_to_data_rate
/* Frame is too small */
else
{
- if (cpi->zbin_over_quant == 0)
+ if (cpi->mb.zbin_over_quant == 0)
/* Lower q_high if not using over quant */
q_high = (Q > q_low) ? (Q - 1) : q_low;
else
/* else lower zbin_oq_high */
- zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->zbin_over_quant - 1) : zbin_oq_low;
+ zbin_oq_high = (cpi->mb.zbin_over_quant > zbin_oq_low) ?
+ (cpi->mb.zbin_over_quant - 1) : zbin_oq_low;
if (overshoot_seen)
{
@@ -4138,9 +4226,10 @@ static void encode_frame_to_data_rate
* is max)
*/
if (Q < MAXQ)
- cpi->zbin_over_quant = 0;
+ cpi->mb.zbin_over_quant = 0;
else
- cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
+ cpi->mb.zbin_over_quant =
+ (zbin_oq_high + zbin_oq_low) / 2;
}
else
{
@@ -4163,7 +4252,9 @@ static void encode_frame_to_data_rate
q_low = Q;
}
- while (((Q > q_high) || (cpi->zbin_over_quant > zbin_oq_high)) && (Retries < 10))
+ while (((Q > q_high) ||
+ (cpi->mb.zbin_over_quant > zbin_oq_high)) &&
+ (Retries < 10))
{
vp8_update_rate_correction_factors(cpi, 0);
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
@@ -4181,7 +4272,9 @@ static void encode_frame_to_data_rate
Q = q_low;
/* Clamp cpi->zbin_over_quant */
- cpi->zbin_over_quant = (cpi->zbin_over_quant < zbin_oq_low) ? zbin_oq_low : (cpi->zbin_over_quant > zbin_oq_high) ? zbin_oq_high : cpi->zbin_over_quant;
+ cpi->mb.zbin_over_quant = (cpi->mb.zbin_over_quant < zbin_oq_low) ?
+ zbin_oq_low : (cpi->mb.zbin_over_quant > zbin_oq_high) ?
+ zbin_oq_high : cpi->mb.zbin_over_quant;
Loop = Q != last_q;
}
@@ -4263,7 +4356,6 @@ static void encode_frame_to_data_rate
/* Point to beginning of MODE_INFO arrays. */
MODE_INFO *tmp = cm->mi;
- cpi->inter_zz_count = 0;
cpi->zeromv_count = 0;
if(cm->frame_type != KEY_FRAME)
@@ -4272,8 +4364,6 @@ static void encode_frame_to_data_rate
{
for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
{
- if(tmp->mbmi.mode == ZEROMV && tmp->mbmi.ref_frame == LAST_FRAME)
- cpi->inter_zz_count++;
if(tmp->mbmi.mode == ZEROMV)
cpi->zeromv_count++;
tmp++;
@@ -4583,9 +4673,6 @@ static void encode_frame_to_data_rate
cm->frame_type, cm->refresh_golden_frame,
cm->refresh_alt_ref_frame);
- for (i = 0; i < MAX_MODES; i++)
- fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
-
fprintf(fmodes, "\n");
fclose(fmodes);
@@ -4680,6 +4767,7 @@ static void encode_frame_to_data_rate
{
cm->current_video_frame++;
cpi->frames_since_key++;
+ cpi->temporal_pattern_counter++;
}
/* reset to normal state now that we are done. */
@@ -4703,67 +4791,6 @@ static void encode_frame_to_data_rate
}
-
-
-static void check_gf_quality(VP8_COMP *cpi)
-{
- VP8_COMMON *cm = &cpi->common;
- int gf_active_pct = (100 * cpi->gf_active_count) / (cm->mb_rows * cm->mb_cols);
- int gf_ref_usage_pct = (cpi->count_mb_ref_frame_usage[GOLDEN_FRAME] * 100) / (cm->mb_rows * cm->mb_cols);
- int last_ref_zz_useage = (cpi->inter_zz_count * 100) / (cm->mb_rows * cm->mb_cols);
-
- /* Gf refresh is not currently being signalled */
- if (cpi->gf_update_recommended == 0)
- {
- if (cpi->common.frames_since_golden > 7)
- {
- /* Low use of gf */
- if ((gf_active_pct < 10) || ((gf_active_pct + gf_ref_usage_pct) < 15))
- {
- /* ...but last frame zero zero usage is reasonbable so a
- * new gf might be appropriate
- */
- if (last_ref_zz_useage >= 25)
- {
- cpi->gf_bad_count ++;
-
- /* Check that the condition is stable */
- if (cpi->gf_bad_count >= 8)
- {
- cpi->gf_update_recommended = 1;
- cpi->gf_bad_count = 0;
- }
- }
- else
- /* Restart count as the background is not stable enough */
- cpi->gf_bad_count = 0;
- }
- else
- /* Gf useage has picked up so reset count */
- cpi->gf_bad_count = 0;
- }
- }
- /* If the signal is set but has not been read should we cancel it. */
- else if (last_ref_zz_useage < 15)
- {
- cpi->gf_update_recommended = 0;
- cpi->gf_bad_count = 0;
- }
-
-#if 0
- {
- FILE *f = fopen("gfneeded.stt", "a");
- fprintf(f, "%10d %10d %10d %10d %10ld \n",
- cm->current_video_frame,
- cpi->common.frames_since_golden,
- gf_active_pct, gf_ref_usage_pct,
- cpi->gf_update_recommended);
- fclose(f);
- }
-
-#endif
-}
-
#if !(CONFIG_REALTIME_ONLY)
static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned char * dest_end, unsigned int *frame_flags)
{
@@ -5060,15 +5087,13 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
/* Restore layer specific context & set frame rate */
layer = cpi->oxcf.layer_id[
- cm->current_video_frame % cpi->oxcf.periodicity];
+ cpi->temporal_pattern_counter % cpi->oxcf.periodicity];
restore_layer_context (cpi, layer);
vp8_new_frame_rate (cpi, cpi->layer_context[layer].frame_rate);
}
if (cpi->compressor_speed == 2)
{
- if (cpi->oxcf.number_of_layers == 1)
- check_gf_quality(cpi);
vpx_usec_timer_start(&tsctimer);
vpx_usec_timer_start(&ticktimer);
}
@@ -5229,7 +5254,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
if (cm->show_frame)
{
-
+ cpi->common.show_frame_mi = cpi->common.mi;
cpi->count ++;
if (cpi->b_calculate_psnr)
@@ -5410,6 +5435,7 @@ int vp8_get_preview_raw_frame(VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest, vp8_ppfla
#endif
#if CONFIG_POSTPROC
+ cpi->common.show_frame_mi = cpi->common.mi;
ret = vp8_post_proc_frame(&cpi->common, dest, flags);
#else