summaryrefslogtreecommitdiff
path: root/vp8/encoder/onyx_if.c
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/encoder/onyx_if.c')
-rw-r--r--vp8/encoder/onyx_if.c165
1 files changed, 145 insertions, 20 deletions
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index a36c6e757..d7b1bc1c8 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -42,6 +42,11 @@
#include <stdio.h>
#include <limits.h>
+#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
+extern int vp8_update_coef_context(VP8_COMP *cpi);
+extern void vp8_update_coef_probs(VP8_COMP *cpi);
+#endif
+
extern void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
extern void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val);
extern void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
@@ -323,6 +328,9 @@ static void setup_features(VP8_COMP *cpi)
}
+static void dealloc_raw_frame_buffers(VP8_COMP *cpi);
+
+
static void dealloc_compressor_data(VP8_COMP *cpi)
{
vpx_free(cpi->tplist);
@@ -349,10 +357,7 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
vp8_yv12_de_alloc_frame_buffer(&cpi->pick_lf_lvl_frame);
vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
-#if VP8_TEMPORAL_ALT_REF
- vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
-#endif
- vp8_lookahead_destroy(cpi->lookahead);
+ dealloc_raw_frame_buffers(cpi);
vpx_free(cpi->tok);
cpi->tok = 0;
@@ -1044,6 +1049,16 @@ static void alloc_raw_frame_buffers(VP8_COMP *cpi)
#endif
}
+
+static void dealloc_raw_frame_buffers(VP8_COMP *cpi)
+{
+#if VP8_TEMPORAL_ALT_REF
+ vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
+#endif
+ vp8_lookahead_destroy(cpi->lookahead);
+}
+
+
static int vp8_alloc_partition_data(VP8_COMP *cpi)
{
vpx_free(cpi->mb.pip);
@@ -1096,8 +1111,11 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
vpx_free(cpi->tok);
{
+#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
+ unsigned int tokens = 8 * 24 * 16; /* one MB for each thread */
+#else
unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16;
-
+#endif
CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
}
@@ -1387,6 +1405,7 @@ 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;
if (!cpi)
return;
@@ -1503,6 +1522,10 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
cm->refresh_last_frame = 1;
cm->refresh_entropy_probs = 1;
+#if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
+ cpi->oxcf.token_partitions = 3;
+#endif
+
if (cpi->oxcf.token_partitions >= 0 && cpi->oxcf.token_partitions <= 3)
cm->multi_token_partition =
(TOKEN_PARTITION) cpi->oxcf.token_partitions;
@@ -1594,6 +1617,10 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
+
+ last_w = cm->Width;
+ last_h = cm->Height;
+
cm->Width = cpi->oxcf.Width;
cm->Height = cpi->oxcf.Height;
@@ -1619,6 +1646,9 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
}
+ if (last_w != cm->Width || last_h != cm->Height)
+ cpi->force_next_frame_intra = 1;
+
if (((cm->Width + 15) & 0xfffffff0) !=
cm->yv12_fb[cm->lst_fb_idx].y_width ||
((cm->Height + 15) & 0xfffffff0) !=
@@ -1650,6 +1680,17 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf)
cpi->alt_ref_source = NULL;
cpi->is_src_frame_alt_ref = 0;
+#if CONFIG_TEMPORAL_DENOISING
+ if (cpi->oxcf.noise_sensitivity)
+ {
+ if (!cpi->denoiser.yv12_mc_running_avg.buffer_alloc)
+ {
+ int width = (cpi->oxcf.Width + 15) & ~15;
+ int height = (cpi->oxcf.Height + 15) & ~15;
+ vp8_denoiser_allocate(&cpi->denoiser, width, height);
+ }
+ }
+#endif
#if 0
// Experimental RD Code
@@ -2284,6 +2325,9 @@ void vp8_remove_compressor(VP8_COMP **ptr)
vp8cx_remove_encoder_threads(cpi);
#endif
+#if CONFIG_TEMPORAL_DENOISING
+ vp8_denoiser_free(&cpi->denoiser);
+#endif
dealloc_compressor_data(cpi);
vpx_free(cpi->mb.ss);
vpx_free(cpi->tok);
@@ -3068,7 +3112,7 @@ void update_reference_frames(VP8_COMMON *cm)
}
}
-void loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
+void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
{
if (cm->no_lpf)
{
@@ -3103,7 +3147,12 @@ void loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
}
vp8_yv12_extend_frame_borders_ptr(cm->frame_to_show);
-
+#if CONFIG_TEMPORAL_DENOISING
+ if (cpi->oxcf.noise_sensitivity)
+ {
+ vp8_yv12_extend_frame_borders(&cpi->denoiser.yv12_running_avg);
+ }
+#endif
}
static void encode_frame_to_data_rate
@@ -3147,15 +3196,9 @@ static void encode_frame_to_data_rate
// Test code for segmentation of gf/arf (0,0)
//segmentation_test_function( cpi);
- if (cpi->compressor_speed == 2)
+ if(cpi->force_next_frame_intra)
{
- if(cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME)
- {
- if(cpi->force_next_frame_intra)
- {
- cm->frame_type = KEY_FRAME; /* delayed intra frame */
- }
- }
+ cm->frame_type = KEY_FRAME; /* delayed intra frame */
cpi->force_next_frame_intra = 0;
}
@@ -3565,7 +3608,7 @@ static void encode_frame_to_data_rate
scale_and_extend_source(cpi->un_scaled_source, cpi);
-#if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC
+#if !(CONFIG_REALTIME_ONLY) && CONFIG_POSTPROC && !(CONFIG_TEMPORAL_DENOISING)
if (cpi->oxcf.noise_sensitivity > 0)
{
@@ -3704,12 +3747,49 @@ static void encode_frame_to_data_rate
vp8_setup_key_frame(cpi);
}
+#if CONFIG_MULTITHREAD
+ /* wait for the last picture loopfilter thread done */
+ if (cpi->b_lpf_running)
+ {
+ sem_wait(&cpi->h_event_end_lpf);
+ cpi->b_lpf_running = 0;
+ }
+#endif
+
+#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
+ {
+ if(cpi->oxcf.error_resilient_mode)
+ cm->refresh_entropy_probs = 0;
+
+ if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS)
+ {
+ if (cm->frame_type == KEY_FRAME)
+ cm->refresh_entropy_probs = 1;
+ }
+
+ if (cm->refresh_entropy_probs == 0)
+ {
+ // save a copy for later refresh
+ vpx_memcpy(&cm->lfc, &cm->fc, sizeof(cm->fc));
+ }
+
+ vp8_update_coef_context(cpi);
+
+ vp8_update_coef_probs(cpi);
+
+ // transform / motion compensation build reconstruction frame
+ // +pack coef partitions
+ vp8_encode_frame(cpi);
+
+ /* cpi->projected_frame_size is not needed for RT mode */
+ }
+#else
// transform / motion compensation build reconstruction frame
vp8_encode_frame(cpi);
cpi->projected_frame_size -= vp8_estimate_entropy_savings(cpi);
cpi->projected_frame_size = (cpi->projected_frame_size > 0) ? cpi->projected_frame_size : 0;
-
+#endif
vp8_clear_system_state(); //__asm emms;
// Test to see if the stats generated for this frame indicate that we should have coded a key frame
@@ -4062,19 +4142,22 @@ static void encode_frame_to_data_rate
if (cpi->b_multi_threaded)
{
sem_post(&cpi->h_event_start_lpf); /* start loopfilter in separate thread */
+ cpi->b_lpf_running = 1;
}
else
#endif
{
- loopfilter_frame(cpi, cm);
+ vp8_loopfilter_frame(cpi, cm);
}
update_reference_frames(cm);
+#if !(CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING)
if (cpi->oxcf.error_resilient_mode)
{
cm->refresh_entropy_probs = 0;
}
+#endif
#if CONFIG_MULTITHREAD
/* wait that filter_level is picked so that we can continue with stream packing */
@@ -4086,10 +4169,11 @@ static void encode_frame_to_data_rate
vp8_pack_bitstream(cpi, dest, dest_end, size);
#if CONFIG_MULTITHREAD
- /* wait for loopfilter thread done */
- if (cpi->b_multi_threaded)
+ /* if PSNR packets are generated we have to wait for the lpf */
+ if (cpi->b_lpf_running && cpi->b_calculate_psnr)
{
sem_wait(&cpi->h_event_end_lpf);
+ cpi->b_lpf_running = 0;
}
#endif
@@ -4550,6 +4634,15 @@ int vp8_receive_raw_frame(VP8_COMP *cpi, unsigned int frame_flags, YV12_BUFFER_C
#endif
vpx_usec_timer_start(&timer);
+
+ /* Reinit the lookahead buffer if the frame size changes */
+ if (sd->y_width != cpi->oxcf.Width || sd->y_height != cpi->oxcf.Height)
+ {
+ assert(cpi->oxcf.lag_in_frames < 2);
+ dealloc_raw_frame_buffers(cpi);
+ alloc_raw_frame_buffers(cpi);
+ }
+
if(vp8_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL))
res = -1;
@@ -4787,6 +4880,29 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
vpx_usec_timer_start(&ticktimer);
}
+#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
+ {
+ int i;
+ const int num_part = (1 << cm->multi_token_partition);
+ /* the available bytes in dest */
+ const unsigned long dest_size = dest_end - dest;
+ const int tok_part_buff_size = (dest_size * 9) / (10 * num_part);
+
+ unsigned char *dp = dest;
+
+ cpi->partition_d[0] = dp;
+ dp += dest_size/10; /* reserve 1/10 for control partition */
+ cpi->partition_d_end[0] = dp;
+
+ for(i = 0; i < num_part; i++)
+ {
+ cpi->partition_d[i + 1] = dp;
+ dp += tok_part_buff_size;
+ cpi->partition_d_end[i + 1] = dp;
+ }
+ }
+#endif
+
// start with a 0 size frame
*size = 0;
@@ -5086,6 +5202,15 @@ int vp8_get_preview_raw_frame(VP8_COMP *cpi, YV12_BUFFER_CONFIG *dest, vp8_ppfla
else
{
int ret;
+
+#if CONFIG_MULTITHREAD
+ if(cpi->b_lpf_running)
+ {
+ sem_wait(&cpi->h_event_end_lpf);
+ cpi->b_lpf_running = 0;
+ }
+#endif
+
#if CONFIG_POSTPROC
ret = vp8_post_proc_frame(&cpi->common, dest, flags);
#else