Commit f6886c4b authored by Yunqing Wang's avatar Yunqing Wang
Browse files

post-proc: fix 0 or negative threshold handling

If the threshold(limits) <= 0, skipped filtering and copied the
frame directly. Also, fixed memory allocation checking.

Change-Id: If3d79d5b2bcb71b9777e6eb5cba1384585131e22
parent d21070a5
......@@ -28,6 +28,9 @@ void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
if (oci->post_proc_buffer_int_used)
vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
vpx_free(oci->pp_limits_buffer);
oci->pp_limits_buffer = NULL;
#endif
vpx_free(oci->above_context);
......@@ -82,18 +85,6 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
return 1;
}
#if CONFIG_POSTPROC
if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
{
vp8_de_alloc_frame_buffers(oci);
return 1;
}
oci->post_proc_buffer_int_used = 0;
vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
vpx_memset((&oci->post_proc_buffer)->buffer_alloc,128,(&oci->post_proc_buffer)->frame_size);
#endif
oci->mb_rows = height >> 4;
oci->mb_cols = width >> 4;
oci->MBs = oci->mb_rows * oci->mb_cols;
......@@ -119,6 +110,27 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
return 1;
}
#if CONFIG_POSTPROC
if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
{
vp8_de_alloc_frame_buffers(oci);
return 1;
}
oci->post_proc_buffer_int_used = 0;
vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
vpx_memset(oci->post_proc_buffer.buffer_alloc, 128,
oci->post_proc_buffer.frame_size);
/* Allocate buffer to store post-processing filter coefficients. */
oci->pp_limits_buffer = vpx_memalign(16, 24 * oci->mb_cols);
if (!oci->pp_limits_buffer)
{
vp8_de_alloc_frame_buffers(oci);
return 1;
}
#endif
return 0;
}
void vp8_setup_version(VP8_COMMON *cm)
......
......@@ -87,6 +87,7 @@ typedef struct VP8Common
YV12_BUFFER_CONFIG post_proc_buffer;
YV12_BUFFER_CONFIG post_proc_buffer_int;
int post_proc_buffer_int_used;
unsigned char *pp_limits_buffer; /* post-processing filter coefficients */
#endif
FRAME_TYPE last_frame_type; /* Save last frame's frame type for motion search. */
......
......@@ -338,8 +338,8 @@ void vp8_deblock(VP8_COMMON *cm,
/* The pixel thresholds are adjusted according to if or not the macroblock
* is a skipped block. */
unsigned char *ylimits = (unsigned char *)vpx_memalign(16, 16 * cm->mb_cols);
unsigned char *uvlimits = (unsigned char *)vpx_memalign(16, 8 * cm->mb_cols);
unsigned char *ylimits = cm->pp_limits_buffer;
unsigned char *uvlimits = cm->pp_limits_buffer + 16 * cm->mb_cols;
(void) low_var_thresh;
(void) flag;
......@@ -381,13 +381,15 @@ void vp8_deblock(VP8_COMMON *cm,
post->v_buffer + 8 * mbr * post->uv_stride, source->uv_stride,
post->uv_stride, source->uv_width, uvlimits, 8);
}
} else
{
vp8_yv12_copy_frame(source, post);
}
vpx_free(ylimits);
vpx_free(uvlimits);
}
#if !(CONFIG_TEMPORAL_DENOISING)
void vp8_de_noise(YV12_BUFFER_CONFIG *source,
void vp8_de_noise(VP8_COMMON *cm,
YV12_BUFFER_CONFIG *source,
YV12_BUFFER_CONFIG *post,
int q,
int low_var_thresh,
......@@ -397,15 +399,15 @@ void vp8_de_noise(YV12_BUFFER_CONFIG *source,
int ppl = (int)(level + .5);
int mb_rows = source->y_width >> 4;
int mb_cols = source->y_height >> 4;
unsigned char *limits = (unsigned char *)vpx_memalign(16, 16 * mb_cols);
unsigned char *limits = cm->pp_limits_buffer;;
int mbr, mbc;
(void) post;
(void) low_var_thresh;
(void) flag;
/* TODO: The original code don't filter the 2 outer rows and columns. */
vpx_memset(limits, (unsigned char)ppl, 16 * mb_cols);
/* TODO: The original code don't filter the 2 outer rows and columns. */
for (mbr = 0; mbr < mb_rows; mbr++)
{
vp8_post_proc_down_and_across_mb_row(
......@@ -422,8 +424,6 @@ void vp8_de_noise(YV12_BUFFER_CONFIG *source,
source->v_buffer + 8 * mbr * source->uv_stride,
source->uv_stride, source->uv_stride, source->uv_width, limits, 8);
}
vpx_free(limits);
}
#endif
......
......@@ -30,7 +30,8 @@ int vp8_post_proc_frame(struct VP8Common *oci, YV12_BUFFER_CONFIG *dest,
vp8_ppflags_t *flags);
void vp8_de_noise(YV12_BUFFER_CONFIG *source,
void vp8_de_noise(struct VP8Common *oci,
YV12_BUFFER_CONFIG *source,
YV12_BUFFER_CONFIG *post,
int q,
int low_var_thresh,
......
......@@ -3810,11 +3810,11 @@ static void encode_frame_to_data_rate
if (cm->frame_type == KEY_FRAME)
{
vp8_de_noise(cpi->Source, cpi->Source, l , 1, 0);
vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0);
}
else
{
vp8_de_noise(cpi->Source, cpi->Source, l , 1, 0);
vp8_de_noise(cm, cpi->Source, cpi->Source, l , 1, 0);
src = cpi->Source->y_buffer;
......
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