2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-11-09 02:09:30 +01:00
|
|
|
#include "./vpx_scale_rtcd.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/onyxc_int.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "onyx_int.h"
|
|
|
|
#include "quantize.h"
|
|
|
|
#include "vpx_mem/vpx_mem.h"
|
2012-12-03 23:19:49 +01:00
|
|
|
#include "vpx_scale/vpx_scale.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/alloccommon.h"
|
2011-07-20 21:53:42 +02:00
|
|
|
#include "vp8/common/loopfilter.h"
|
Add runtime CPU detection support for ARM.
The primary goal is to allow a binary to be built which supports
NEON, but can fall back to non-NEON routines, since some Android
devices do not have NEON, even if they are otherwise ARMv7 (e.g.,
Tegra).
The configure-generated flags HAVE_ARMV7, etc., are used to decide
which versions of each function to build, and when
CONFIG_RUNTIME_CPU_DETECT is enabled, the correct version is chosen
at run time.
In order for this to work, the CFLAGS must be set to something
appropriate (e.g., without -mfpu=neon for ARMv7, and with
appropriate -march and -mcpu for even earlier configurations), or
the native C code will not be able to run.
The ASFLAGS must remain set for the most advanced instruction set
required at build time, since the ARM assembler will refuse to emit
them otherwise.
I have not attempted to make any changes to configure to do this
automatically.
Doing so will probably require the addition of new configure options.
Many of the hooks for RTCD on ARM were already there, but a lot of
the code had bit-rotted, and a good deal of the ARM-specific code
is not integrated into the RTCD structs at all.
I did not try to resolve the latter, merely to add the minimal amount
of protection around them to allow RTCD to work.
Those functions that were called based on an ifdef at the calling
site were expanded to check the RTCD flags at that site, but they
should be added to an RTCD struct somewhere in the future.
The functions invoked with global function pointers still are, but
these should be moved into an RTCD struct for thread safety (I
believe every platform currently supported has atomic pointer
stores, but this is not guaranteed).
The encoder's boolhuff functions did not even have _c and armv7
suffixes, and the correct version was resolved at link time.
The token packing functions did have appropriate suffixes, but the
version was selected with a define, with no associated RTCD struct.
However, for both of these, the only armv7 instruction they actually
used was rbit, and this was completely superfluous, so I reworked
them to avoid it.
The only non-ARMv4 instruction remaining in them is clz, which is
ARMv5 (not even ARMv5TE is required).
Considering that there are no ARM-specific configs which are not at
least ARMv5TE, I did not try to detect these at runtime, and simply
enable them for ARMv5 and above.
Finally, the NEON register saving code was completely non-reentrant,
since it saved the registers to a global, static variable.
I moved the storage for this onto the stack.
A single binary built with this code was tested on an ARM11 (ARMv6)
and a Cortex A8 (ARMv7 w/NEON), for both the encoder and decoder,
and produced identical output, while using the correct accelerated
functions on each.
I did not test on any earlier processors.
Change-Id: I45cbd63a614f4554c3b325c45d46c0806f009eaa
2010-10-21 00:39:11 +02:00
|
|
|
#if ARCH_ARM
|
|
|
|
#include "vpx_ports/arm.h"
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
extern int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
void vp8_yv12_copy_partial_frame_c(YV12_BUFFER_CONFIG *src_ybc,
|
|
|
|
YV12_BUFFER_CONFIG *dst_ybc)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
unsigned char *src_y, *dst_y;
|
|
|
|
int yheight;
|
|
|
|
int ystride;
|
|
|
|
int yoffset;
|
|
|
|
int linestocopy;
|
|
|
|
|
|
|
|
yheight = src_ybc->y_height;
|
|
|
|
ystride = src_ybc->y_stride;
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
/* number of MB rows to use in partial filtering */
|
|
|
|
linestocopy = (yheight >> 4) / PARTIAL_FRAME_FRACTION;
|
|
|
|
linestocopy = linestocopy ? linestocopy << 4 : 16; /* 16 lines per MB */
|
|
|
|
|
|
|
|
/* Copy extra 4 so that full filter context is available if filtering done
|
|
|
|
* on the copied partial frame and not original. Partial filter does mb
|
|
|
|
* filtering for top row also, which can modify3 pixels above.
|
|
|
|
*/
|
|
|
|
linestocopy += 4;
|
|
|
|
/* partial image starts at ~middle of frame (macroblock border)*/
|
|
|
|
yoffset = ystride * (((yheight >> 5) * 16) - 4);
|
2010-05-18 17:58:33 +02:00
|
|
|
src_y = src_ybc->y_buffer + yoffset;
|
|
|
|
dst_y = dst_ybc->y_buffer + yoffset;
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
vpx_memcpy(dst_y, src_y, ystride * linestocopy);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
static int calc_partial_ssl_err(YV12_BUFFER_CONFIG *source,
|
2012-01-13 01:55:44 +01:00
|
|
|
YV12_BUFFER_CONFIG *dest)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int Total = 0;
|
|
|
|
int srcoffset, dstoffset;
|
|
|
|
unsigned char *src = source->y_buffer;
|
|
|
|
unsigned char *dst = dest->y_buffer;
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
int linestocopy;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
/* number of MB rows to use in partial filtering */
|
|
|
|
linestocopy = (source->y_height >> 4) / PARTIAL_FRAME_FRACTION;
|
|
|
|
linestocopy = linestocopy ? linestocopy << 4 : 16; /* 16 lines per MB */
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
/* partial image starts at ~middle of frame (macroblock border)*/
|
|
|
|
srcoffset = source->y_stride * ((dest->y_height >> 5) * 16);
|
|
|
|
dstoffset = dest->y_stride * ((dest->y_height >> 5) * 16);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
src += srcoffset;
|
|
|
|
dst += dstoffset;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Loop through the Y plane raw and reconstruction data summing
|
|
|
|
* (square differences)
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
for (i = 0; i < linestocopy; i += 16)
|
|
|
|
{
|
|
|
|
for (j = 0; j < source->y_width; j += 16)
|
|
|
|
{
|
|
|
|
unsigned int sse;
|
2012-01-13 01:55:44 +01:00
|
|
|
Total += vp8_mse16x16(src + j, source->y_stride,
|
2011-10-18 08:48:50 +02:00
|
|
|
dst + j, dest->y_stride,
|
|
|
|
&sse);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
src += 16 * source->y_stride;
|
|
|
|
dst += 16 * dest->y_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Total;
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Enforce a minimum filter level based upon baseline Q */
|
2010-05-18 17:58:33 +02:00
|
|
|
static int get_min_filter_level(VP8_COMP *cpi, int base_qindex)
|
|
|
|
{
|
|
|
|
int min_filter_level;
|
|
|
|
|
2011-10-18 08:48:50 +02:00
|
|
|
if (cpi->source_alt_ref_active && cpi->common.refresh_golden_frame &&
|
|
|
|
!cpi->common.refresh_alt_ref_frame)
|
2010-05-18 17:58:33 +02:00
|
|
|
min_filter_level = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (base_qindex <= 6)
|
|
|
|
min_filter_level = 0;
|
|
|
|
else if (base_qindex <= 16)
|
|
|
|
min_filter_level = 1;
|
|
|
|
else
|
|
|
|
min_filter_level = (base_qindex / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return min_filter_level;
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Enforce a maximum filter level based upon baseline Q */
|
2010-05-18 17:58:33 +02:00
|
|
|
static int get_max_filter_level(VP8_COMP *cpi, int base_qindex)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* PGW August 2006: Highest filter values almost always a bad idea */
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* jbb chg: 20100118 - not so any more with this overquant stuff allow
|
|
|
|
* high values with lots of intra coming in.
|
|
|
|
*/
|
|
|
|
int max_filter_level = MAX_LOOP_FILTER;
|
2011-06-27 22:31:01 +02:00
|
|
|
(void)base_qindex;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.section_intra_rating > 8)
|
2010-05-18 17:58:33 +02:00
|
|
|
max_filter_level = MAX_LOOP_FILTER * 3 / 4;
|
|
|
|
|
|
|
|
return max_filter_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
int best_err = 0;
|
|
|
|
int filt_err = 0;
|
2011-06-27 22:31:01 +02:00
|
|
|
int min_filter_level = get_min_filter_level(cpi, cm->base_qindex);
|
|
|
|
int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
|
2010-05-18 17:58:33 +02:00
|
|
|
int filt_val;
|
|
|
|
int best_filt_val = cm->filter_level;
|
2011-11-29 12:48:02 +01:00
|
|
|
YV12_BUFFER_CONFIG * saved_frame = cm->frame_to_show;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-29 12:48:02 +01:00
|
|
|
/* Replace unfiltered frame buffer with a new one */
|
|
|
|
cm->frame_to_show = &cpi->pick_lf_lvl_frame;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
cm->sharpness_level = 0;
|
|
|
|
else
|
|
|
|
cm->sharpness_level = cpi->oxcf.Sharpness;
|
|
|
|
|
2011-07-20 21:53:42 +02:00
|
|
|
if (cm->sharpness_level != cm->last_sharpness_level)
|
|
|
|
{
|
|
|
|
vp8_loop_filter_update_sharpness(&cm->lf_info, cm->sharpness_level);
|
2011-07-29 18:26:55 +02:00
|
|
|
cm->last_sharpness_level = cm->sharpness_level;
|
2011-07-20 21:53:42 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Start the search at the previous frame filter level unless it is
|
|
|
|
* now out of range.
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cm->filter_level < min_filter_level)
|
|
|
|
cm->filter_level = min_filter_level;
|
|
|
|
else if (cm->filter_level > max_filter_level)
|
|
|
|
cm->filter_level = max_filter_level;
|
|
|
|
|
|
|
|
filt_val = cm->filter_level;
|
|
|
|
best_filt_val = filt_val;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Get the err using the previous frame's filter value. */
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-29 12:48:02 +01:00
|
|
|
/* Copy the unfiltered / processed recon buffer to the new buffer */
|
2012-01-13 01:55:44 +01:00
|
|
|
vp8_yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
|
2011-11-29 12:48:02 +01:00
|
|
|
vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
best_err = calc_partial_ssl_err(sd, cm->frame_to_show);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-12-22 01:11:31 +01:00
|
|
|
filt_val -= 1 + (filt_val > 10);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Search lower filter levels */
|
2010-05-18 17:58:33 +02:00
|
|
|
while (filt_val >= min_filter_level)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Apply the loop filter */
|
2012-01-13 01:55:44 +01:00
|
|
|
vp8_yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
|
2011-07-20 21:53:42 +02:00
|
|
|
vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Get the err for filtered frame */
|
2012-01-13 01:55:44 +01:00
|
|
|
filt_err = calc_partial_ssl_err(sd, cm->frame_to_show);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Update the best case record or exit loop. */
|
2010-05-18 17:58:33 +02:00
|
|
|
if (filt_err < best_err)
|
|
|
|
{
|
|
|
|
best_err = filt_err;
|
|
|
|
best_filt_val = filt_val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Adjust filter level */
|
2011-12-22 01:11:31 +01:00
|
|
|
filt_val -= 1 + (filt_val > 10);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Search up (note that we have already done filt_val = cm->filter_level) */
|
2011-12-22 01:11:31 +01:00
|
|
|
filt_val = cm->filter_level + 1 + (filt_val > 10);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (best_filt_val == cm->filter_level)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Resist raising filter level for very small gains */
|
2010-05-18 17:58:33 +02:00
|
|
|
best_err -= (best_err >> 10);
|
|
|
|
|
|
|
|
while (filt_val < max_filter_level)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Apply the loop filter */
|
2012-01-13 01:55:44 +01:00
|
|
|
vp8_yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
|
2011-11-29 12:48:02 +01:00
|
|
|
|
2011-07-20 21:53:42 +02:00
|
|
|
vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Get the err for filtered frame */
|
2012-01-13 01:55:44 +01:00
|
|
|
filt_err = calc_partial_ssl_err(sd, cm->frame_to_show);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Update the best case record or exit loop. */
|
2010-05-18 17:58:33 +02:00
|
|
|
if (filt_err < best_err)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Do not raise filter level if improvement is < 1 part
|
|
|
|
* in 4096
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
best_err = filt_err - (filt_err >> 10);
|
|
|
|
|
|
|
|
best_filt_val = filt_val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Adjust filter level */
|
2011-12-22 01:11:31 +01:00
|
|
|
filt_val += 1 + (filt_val > 10);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cm->filter_level = best_filt_val;
|
|
|
|
|
|
|
|
if (cm->filter_level < min_filter_level)
|
|
|
|
cm->filter_level = min_filter_level;
|
|
|
|
|
|
|
|
if (cm->filter_level > max_filter_level)
|
|
|
|
cm->filter_level = max_filter_level;
|
2011-11-29 12:48:02 +01:00
|
|
|
|
|
|
|
/* restore unfiltered frame pointer */
|
|
|
|
cm->frame_to_show = saved_frame;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Stub function for now Alt LF not used */
|
2010-05-18 17:58:33 +02:00
|
|
|
void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val)
|
|
|
|
{
|
|
|
|
MACROBLOCKD *mbd = &cpi->mb.e_mbd;
|
|
|
|
(void) filt_val;
|
|
|
|
|
|
|
|
mbd->segment_feature_data[MB_LVL_ALT_LF][0] = cpi->segment_feature_data[MB_LVL_ALT_LF][0];
|
|
|
|
mbd->segment_feature_data[MB_LVL_ALT_LF][1] = cpi->segment_feature_data[MB_LVL_ALT_LF][1];
|
|
|
|
mbd->segment_feature_data[MB_LVL_ALT_LF][2] = cpi->segment_feature_data[MB_LVL_ALT_LF][2];
|
|
|
|
mbd->segment_feature_data[MB_LVL_ALT_LF][3] = cpi->segment_feature_data[MB_LVL_ALT_LF][3];
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
int best_err = 0;
|
|
|
|
int filt_err = 0;
|
2011-06-27 22:31:01 +02:00
|
|
|
int min_filter_level = get_min_filter_level(cpi, cm->base_qindex);
|
|
|
|
int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
int filter_step;
|
|
|
|
int filt_high = 0;
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Start search at previous frame filter level */
|
|
|
|
int filt_mid = cm->filter_level;
|
2010-05-18 17:58:33 +02:00
|
|
|
int filt_low = 0;
|
|
|
|
int filt_best;
|
|
|
|
int filt_direction = 0;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Bias against raising loop filter and in favor of lowering it */
|
|
|
|
int Bias = 0;
|
2011-11-29 12:48:02 +01:00
|
|
|
|
2011-12-16 23:43:55 +01:00
|
|
|
int ss_err[MAX_LOOP_FILTER + 1];
|
2011-12-09 13:54:41 +01:00
|
|
|
|
2011-11-29 12:48:02 +01:00
|
|
|
YV12_BUFFER_CONFIG * saved_frame = cm->frame_to_show;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-12-09 13:54:41 +01:00
|
|
|
vpx_memset(ss_err, 0, sizeof(ss_err));
|
|
|
|
|
2011-11-29 12:48:02 +01:00
|
|
|
/* Replace unfiltered frame buffer with a new one */
|
|
|
|
cm->frame_to_show = &cpi->pick_lf_lvl_frame;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
cm->sharpness_level = 0;
|
|
|
|
else
|
|
|
|
cm->sharpness_level = cpi->oxcf.Sharpness;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Start the search at the previous frame filter level unless it is
|
|
|
|
* now out of range.
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
filt_mid = cm->filter_level;
|
|
|
|
|
|
|
|
if (filt_mid < min_filter_level)
|
|
|
|
filt_mid = min_filter_level;
|
|
|
|
else if (filt_mid > max_filter_level)
|
|
|
|
filt_mid = max_filter_level;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Define the initial step size */
|
2010-05-18 17:58:33 +02:00
|
|
|
filter_step = (filt_mid < 16) ? 4 : filt_mid / 4;
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Get baseline error score */
|
2011-11-29 12:48:02 +01:00
|
|
|
|
|
|
|
/* Copy the unfiltered / processed recon buffer to the new buffer */
|
2012-04-16 09:23:57 +02:00
|
|
|
vp8_yv12_copy_y(saved_frame, cm->frame_to_show);
|
2011-11-29 12:48:02 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8cx_set_alt_lf_level(cpi, filt_mid);
|
2011-07-20 21:53:42 +02:00
|
|
|
vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_mid);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
best_err = vp8_calc_ss_err(sd, cm->frame_to_show);
|
2011-12-09 13:54:41 +01:00
|
|
|
|
|
|
|
ss_err[filt_mid] = best_err;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
filt_best = filt_mid;
|
|
|
|
|
|
|
|
while (filter_step > 0)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
Bias = (best_err >> (15 - (filt_mid / 8))) * filter_step;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.section_intra_rating < 20)
|
|
|
|
Bias = Bias * cpi->twopass.section_intra_rating / 20;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
filt_high = ((filt_mid + filter_step) > max_filter_level) ? max_filter_level : (filt_mid + filter_step);
|
|
|
|
filt_low = ((filt_mid - filter_step) < min_filter_level) ? min_filter_level : (filt_mid - filter_step);
|
|
|
|
|
|
|
|
if ((filt_direction <= 0) && (filt_low != filt_mid))
|
|
|
|
{
|
2011-12-09 13:54:41 +01:00
|
|
|
if(ss_err[filt_low] == 0)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Get Low filter error score */
|
2012-04-16 09:23:57 +02:00
|
|
|
vp8_yv12_copy_y(saved_frame, cm->frame_to_show);
|
2011-12-09 13:54:41 +01:00
|
|
|
vp8cx_set_alt_lf_level(cpi, filt_low);
|
|
|
|
vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_low);
|
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
filt_err = vp8_calc_ss_err(sd, cm->frame_to_show);
|
2011-12-09 13:54:41 +01:00
|
|
|
ss_err[filt_low] = filt_err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filt_err = ss_err[filt_low];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* If value is close to the best so far then bias towards a
|
|
|
|
* lower loop filter value.
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
if ((filt_err - Bias) < best_err)
|
|
|
|
{
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Was it actually better than the previous best? */
|
2010-05-18 17:58:33 +02:00
|
|
|
if (filt_err < best_err)
|
|
|
|
best_err = filt_err;
|
|
|
|
|
|
|
|
filt_best = filt_low;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Now look at filt_high */
|
2010-05-18 17:58:33 +02:00
|
|
|
if ((filt_direction >= 0) && (filt_high != filt_mid))
|
|
|
|
{
|
2011-12-09 13:54:41 +01:00
|
|
|
if(ss_err[filt_high] == 0)
|
|
|
|
{
|
2012-04-16 09:23:57 +02:00
|
|
|
vp8_yv12_copy_y(saved_frame, cm->frame_to_show);
|
2011-12-09 13:54:41 +01:00
|
|
|
vp8cx_set_alt_lf_level(cpi, filt_high);
|
|
|
|
vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_high);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-13 01:55:44 +01:00
|
|
|
filt_err = vp8_calc_ss_err(sd, cm->frame_to_show);
|
2011-12-09 13:54:41 +01:00
|
|
|
ss_err[filt_high] = filt_err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filt_err = ss_err[filt_high];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Was it better than the previous best? */
|
2010-05-18 17:58:33 +02:00
|
|
|
if (filt_err < (best_err - Bias))
|
|
|
|
{
|
|
|
|
best_err = filt_err;
|
|
|
|
filt_best = filt_high;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:30:56 +02:00
|
|
|
/* Half the step distance if the best filter value was the same
|
|
|
|
* as last time
|
|
|
|
*/
|
2010-05-18 17:58:33 +02:00
|
|
|
if (filt_best == filt_mid)
|
|
|
|
{
|
|
|
|
filter_step = filter_step / 2;
|
|
|
|
filt_direction = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filt_direction = (filt_best < filt_mid) ? -1 : 1;
|
|
|
|
filt_mid = filt_best;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cm->filter_level = filt_best;
|
2011-11-29 12:48:02 +01:00
|
|
|
|
|
|
|
/* restore unfiltered frame pointer */
|
|
|
|
cm->frame_to_show = saved_frame;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|