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
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-08-01 22:42:14 +02:00
|
|
|
#include "vpx_config.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"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/systemdependent.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "quantize.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/alloccommon.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "mcomp.h"
|
|
|
|
#include "firstpass.h"
|
|
|
|
#include "psnr.h"
|
|
|
|
#include "vpx_scale/vpxscale.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/extend.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "ratectrl.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/quant_common.h"
|
2010-08-13 20:50:51 +02:00
|
|
|
#include "segmentation.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/g_common.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_scale/yv12extend.h"
|
2011-08-01 22:42:14 +02:00
|
|
|
#if CONFIG_POSTPROC
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/postproc.h"
|
2011-08-01 22:42:14 +02:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/swapyv12buffer.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_ports/vpx_timer.h"
|
2010-10-20 22:27:33 +02:00
|
|
|
#include "temporal_filter.h"
|
2011-10-05 12:26:00 +02:00
|
|
|
|
|
|
|
#include "vp8/common/seg_common.h"
|
|
|
|
#include "mbgraph.h"
|
2012-01-28 13:20:14 +01:00
|
|
|
#include "vp8/common/pred_common.h"
|
2012-04-16 23:53:37 +02:00
|
|
|
#include "vp8/encoder/rdopt.h"
|
2012-06-15 03:14:43 +02:00
|
|
|
#include "bitstream.h"
|
|
|
|
#include "ratectrl.h"
|
2011-10-05 12:26:00 +02:00
|
|
|
|
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-09-02 22:17:52 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#if CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
#define IF_RTCD(x) (x)
|
|
|
|
#define RTCD(x) &cpi->common.rtcd.x
|
|
|
|
#else
|
|
|
|
#define IF_RTCD(x) NULL
|
|
|
|
#define RTCD(x) NULL
|
|
|
|
#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);
|
|
|
|
|
|
|
|
extern void vp8_dmachine_specific_config(VP8_COMP *cpi);
|
|
|
|
extern void vp8_cmachine_specific_config(VP8_COMP *cpi);
|
|
|
|
extern void vp8_deblock_frame(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int filt_lvl, int low_var_thresh, int flag);
|
|
|
|
extern void print_parms(VP8_CONFIG *ocf, char *filenam);
|
|
|
|
extern unsigned int vp8_get_processor_freq();
|
|
|
|
extern void print_tree_update_probs();
|
|
|
|
extern void vp8cx_create_encoder_threads(VP8_COMP *cpi);
|
|
|
|
extern void vp8cx_remove_encoder_threads(VP8_COMP *cpi);
|
|
|
|
#if HAVE_ARMV7
|
|
|
|
extern void vp8_yv12_copy_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
|
|
|
|
extern void vp8_yv12_copy_src_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const vp8_variance_rtcd_vtable_t *rtcd);
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
extern void vp8_temporal_filter_prepare_c(VP8_COMP *cpi, int distance);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-09-29 19:53:08 +02:00
|
|
|
static void set_default_lf_deltas(VP8_COMP *cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
extern const int vp8_gf_interval_table[101];
|
|
|
|
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
2012-04-30 21:24:22 +02:00
|
|
|
#define SEARCH_BEST_FILTER 0 /* to search exhaustively for best filter */
|
2012-04-16 23:53:37 +02:00
|
|
|
#define RESET_FOREACH_FILTER 0 /* whether to reset the encoder state
|
|
|
|
before trying each new filter */
|
|
|
|
#endif
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
#define ALTREF_HIGH_PRECISION_MV 1 /* whether to use high precision mv for altref computation */
|
|
|
|
#define HIGH_PRECISION_MV_QTHRESH 200 /* Q threshold for use of high precision mv */
|
|
|
|
/* Choose a very high value for now so
|
|
|
|
* that HIGH_PRECISION is always chosen
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
extern double vp8_calc_ssim
|
|
|
|
(
|
|
|
|
YV12_BUFFER_CONFIG *source,
|
|
|
|
YV12_BUFFER_CONFIG *dest,
|
|
|
|
int lumamask,
|
2011-03-08 15:05:18 +01:00
|
|
|
double *weight,
|
|
|
|
const vp8_variance_rtcd_vtable_t *rtcd
|
2010-05-18 17:58:33 +02:00
|
|
|
);
|
|
|
|
|
2011-03-08 15:05:18 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
extern double vp8_calc_ssimg
|
|
|
|
(
|
|
|
|
YV12_BUFFER_CONFIG *source,
|
|
|
|
YV12_BUFFER_CONFIG *dest,
|
|
|
|
double *ssim_y,
|
|
|
|
double *ssim_u,
|
2011-05-03 00:27:14 +02:00
|
|
|
double *ssim_v,
|
|
|
|
const vp8_variance_rtcd_vtable_t *rtcd
|
2010-05-18 17:58:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-08-05 01:30:27 +02:00
|
|
|
//#define OUTPUT_YUV_REC
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
FILE *yuv_file;
|
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
|
|
|
FILE *yuv_rec_file;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
FILE *framepsnr;
|
2011-07-20 23:21:24 +02:00
|
|
|
FILE *kf_list;
|
2010-05-18 17:58:33 +02:00
|
|
|
FILE *keyfile;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
extern int skip_true_count;
|
|
|
|
extern int skip_false_count;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
2012-05-15 01:21:01 +02:00
|
|
|
extern int intra_mode_stats[VP8_BINTRAMODES][VP8_BINTRAMODES][VP8_BINTRAMODES];
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SPEEDSTATS
|
|
|
|
unsigned int frames_at_speed[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
unsigned int tot_pm = 0;
|
|
|
|
unsigned int cnt_pm = 0;
|
|
|
|
unsigned int tot_ef = 0;
|
|
|
|
unsigned int cnt_ef = 0;
|
|
|
|
#endif
|
|
|
|
|
2011-02-14 23:18:18 +01:00
|
|
|
#if defined(SECTIONBITS_OUTPUT)
|
|
|
|
extern unsigned __int64 Sectionbits[500];
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef MODE_STATS
|
2011-08-05 01:30:27 +02:00
|
|
|
extern INT64 Sectionbits[500];
|
2012-05-15 01:21:01 +02:00
|
|
|
extern unsigned int y_modes[VP8_YMODES] ;
|
|
|
|
extern unsigned int i8x8_modes[VP8_I8X8_MODES];
|
|
|
|
extern unsigned int uv_modes[VP8_UV_MODES] ;
|
|
|
|
extern unsigned int uv_modes_y[VP8_YMODES][VP8_UV_MODES];
|
|
|
|
extern unsigned int b_modes[B_MODE_COUNT];
|
|
|
|
extern unsigned int inter_y_modes[MB_MODE_COUNT] ;
|
|
|
|
extern unsigned int inter_uv_modes[VP8_UV_MODES] ;
|
2011-12-06 16:37:39 +01:00
|
|
|
extern unsigned int inter_b_modes[B_MODE_COUNT];
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void (*vp8_short_fdct4x4)(short *input, short *output, int pitch);
|
|
|
|
extern void (*vp8_short_fdct8x4)(short *input, short *output, int pitch);
|
|
|
|
|
|
|
|
extern void vp8cx_init_quantizer(VP8_COMP *cpi);
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-03-19 19:02:04 +01:00
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
int vp8cx_base_skip_false_prob[QINDEX_RANGE][3];
|
|
|
|
#else
|
2011-12-12 19:27:25 +01:00
|
|
|
int vp8cx_base_skip_false_prob[QINDEX_RANGE];
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
2011-11-23 12:32:20 +01:00
|
|
|
|
2010-09-29 13:03:19 +02:00
|
|
|
// Tables relating active max Q to active min Q
|
2011-11-23 12:32:20 +01:00
|
|
|
static int kf_low_motion_minq[QINDEX_RANGE];
|
|
|
|
static int kf_high_motion_minq[QINDEX_RANGE];
|
|
|
|
static int gf_low_motion_minq[QINDEX_RANGE];
|
|
|
|
static int gf_high_motion_minq[QINDEX_RANGE];
|
|
|
|
static int inter_minq[QINDEX_RANGE];
|
|
|
|
|
|
|
|
// Functions to compute the active minq lookup table entries based on a
|
|
|
|
// formulaic approach to facilitate easier adjustment of the Q tables.
|
|
|
|
// The formulae were derived from computing a 3rd order polynomial best
|
|
|
|
// fit to the original data (after plotting real maxq vs minq (not q index))
|
|
|
|
int calculate_minq_index( double maxq,
|
|
|
|
double x3, double x2, double x, double c )
|
2010-09-29 13:03:19 +02:00
|
|
|
{
|
2011-11-23 12:32:20 +01:00
|
|
|
int i;
|
|
|
|
double minqtarget;
|
|
|
|
double thisq;
|
|
|
|
|
|
|
|
minqtarget = ( (x3 * maxq * maxq * maxq) +
|
|
|
|
(x2 * maxq * maxq) +
|
|
|
|
(x * maxq) +
|
|
|
|
c );
|
|
|
|
|
|
|
|
if ( minqtarget > maxq )
|
2012-01-31 21:58:34 +01:00
|
|
|
minqtarget = maxq;
|
2011-11-23 12:32:20 +01:00
|
|
|
|
|
|
|
for ( i = 0; i < QINDEX_RANGE; i++ )
|
|
|
|
{
|
|
|
|
thisq = vp8_convert_qindex_to_q(i);
|
|
|
|
if ( minqtarget <= vp8_convert_qindex_to_q(i) )
|
|
|
|
return i;
|
|
|
|
}
|
2012-04-07 01:38:34 +02:00
|
|
|
return QINDEX_RANGE-1;
|
2011-11-23 12:32:20 +01:00
|
|
|
}
|
|
|
|
void init_minq_luts()
|
2010-12-02 00:50:14 +01:00
|
|
|
{
|
2011-11-23 12:32:20 +01:00
|
|
|
int i;
|
|
|
|
double maxq;
|
|
|
|
|
|
|
|
for ( i = 0; i < QINDEX_RANGE; i++ )
|
|
|
|
{
|
|
|
|
maxq = vp8_convert_qindex_to_q(i);
|
|
|
|
|
2011-11-28 12:48:07 +01:00
|
|
|
|
2011-11-23 12:32:20 +01:00
|
|
|
kf_low_motion_minq[i] = calculate_minq_index( maxq,
|
2011-11-28 12:48:07 +01:00
|
|
|
0.0000003,
|
|
|
|
-0.000015,
|
|
|
|
0.074,
|
2011-11-23 12:32:20 +01:00
|
|
|
0.0 );
|
|
|
|
kf_high_motion_minq[i] = calculate_minq_index( maxq,
|
2012-06-07 14:39:20 +02:00
|
|
|
0.0000004,
|
2011-11-28 12:48:07 +01:00
|
|
|
-0.000125,
|
2012-06-07 14:39:20 +02:00
|
|
|
0.14,
|
2011-11-23 12:32:20 +01:00
|
|
|
0.0 );
|
|
|
|
gf_low_motion_minq[i] = calculate_minq_index( maxq,
|
2012-06-07 14:39:20 +02:00
|
|
|
0.0000015,
|
|
|
|
-0.0009,
|
|
|
|
0.33,
|
2011-11-23 12:32:20 +01:00
|
|
|
0.0 );
|
|
|
|
gf_high_motion_minq[i] = calculate_minq_index( maxq,
|
2012-06-07 14:39:20 +02:00
|
|
|
0.0000021,
|
|
|
|
-0.00125,
|
|
|
|
0.45,
|
2011-11-23 12:32:20 +01:00
|
|
|
0.0 );
|
|
|
|
inter_minq[i] = calculate_minq_index( maxq,
|
|
|
|
0.00000271,
|
|
|
|
-0.00113,
|
|
|
|
0.697,
|
|
|
|
0.0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 19:27:25 +01:00
|
|
|
void init_base_skip_probs()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double q;
|
2012-03-19 19:02:04 +01:00
|
|
|
int skip_prob, t;
|
2011-12-12 19:27:25 +01:00
|
|
|
|
|
|
|
for ( i = 0; i < QINDEX_RANGE; i++ )
|
|
|
|
{
|
|
|
|
q = vp8_convert_qindex_to_q(i);
|
|
|
|
|
|
|
|
// Exponential decay caluclation of baseline skip prob with clamping
|
|
|
|
// Based on crude best fit of old table.
|
2012-03-19 19:02:04 +01:00
|
|
|
t = (int)( 564.25 * pow( 2.71828, (-0.012*q) ) );
|
|
|
|
|
|
|
|
skip_prob = t;
|
|
|
|
if ( skip_prob < 1 )
|
|
|
|
skip_prob = 1;
|
|
|
|
else if ( skip_prob > 255 )
|
|
|
|
skip_prob = 255;
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
vp8cx_base_skip_false_prob[i][1] = skip_prob;
|
|
|
|
|
|
|
|
skip_prob = t * 0.75;
|
2011-12-12 19:27:25 +01:00
|
|
|
if ( skip_prob < 1 )
|
|
|
|
skip_prob = 1;
|
|
|
|
else if ( skip_prob > 255 )
|
|
|
|
skip_prob = 255;
|
2012-03-19 19:02:04 +01:00
|
|
|
vp8cx_base_skip_false_prob[i][2] = skip_prob;
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2012-03-19 19:02:04 +01:00
|
|
|
skip_prob = t * 1.25;
|
|
|
|
if ( skip_prob < 1 )
|
|
|
|
skip_prob = 1;
|
|
|
|
else if ( skip_prob > 255 )
|
|
|
|
skip_prob = 255;
|
|
|
|
vp8cx_base_skip_false_prob[i][0] = skip_prob;
|
|
|
|
#else
|
2011-12-12 19:27:25 +01:00
|
|
|
vp8cx_base_skip_false_prob[i] = skip_prob;
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
2011-12-12 19:27:25 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-11 15:37:48 +02:00
|
|
|
void update_base_skip_probs(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
if (cm->frame_type != KEY_FRAME)
|
|
|
|
{
|
|
|
|
update_skip_probs(cpi);
|
|
|
|
|
|
|
|
if (cm->refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[2][k] = cm->mbskip_pred_probs[k];
|
|
|
|
#else
|
|
|
|
cpi->last_skip_false_probs[2] = cpi->prob_skip_false;
|
|
|
|
#endif
|
|
|
|
cpi->last_skip_probs_q[2] = cm->base_qindex;
|
|
|
|
}
|
|
|
|
else if (cpi->common.refresh_golden_frame)
|
|
|
|
{
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[1][k] = cm->mbskip_pred_probs[k];
|
|
|
|
#else
|
|
|
|
cpi->last_skip_false_probs[1] = cpi->prob_skip_false;
|
|
|
|
#endif
|
|
|
|
cpi->last_skip_probs_q[1] = cm->base_qindex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->last_skip_false_probs[0][k] = cm->mbskip_pred_probs[k];
|
|
|
|
#else
|
|
|
|
cpi->last_skip_false_probs[0] = cpi->prob_skip_false;
|
|
|
|
#endif
|
|
|
|
cpi->last_skip_probs_q[0] = cm->base_qindex;
|
|
|
|
|
|
|
|
// update the baseline table for the current q
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; ++k)
|
|
|
|
cpi->base_skip_false_prob[cm->base_qindex][k] =
|
|
|
|
cm->mbskip_pred_probs[k];
|
|
|
|
#else
|
|
|
|
cpi->base_skip_false_prob[cm->base_qindex] = cpi->prob_skip_false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-12-12 19:27:25 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
void vp8_initialize()
|
|
|
|
{
|
|
|
|
static int init_done = 0;
|
|
|
|
|
|
|
|
if (!init_done)
|
|
|
|
{
|
|
|
|
vp8_scale_machine_specific_config();
|
|
|
|
vp8_initialize_common();
|
|
|
|
//vp8_dmachine_specific_config();
|
|
|
|
vp8_tokenize_initialize();
|
2011-12-02 15:57:21 +01:00
|
|
|
vp8_init_quant_tables();
|
2011-11-21 16:45:10 +01:00
|
|
|
vp8_init_me_luts();
|
2011-11-23 12:32:20 +01:00
|
|
|
init_minq_luts();
|
2011-12-12 19:27:25 +01:00
|
|
|
init_base_skip_probs();
|
2010-05-18 17:58:33 +02:00
|
|
|
init_done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef PACKET_TESTING
|
|
|
|
extern FILE *vpxlogc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void setup_features(VP8_COMP *cpi)
|
|
|
|
{
|
2011-09-14 19:20:25 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Set up default state for MB feature flags
|
2011-11-08 16:40:32 +01:00
|
|
|
|
|
|
|
xd->segmentation_enabled = 0; // Default segmentation disabled
|
|
|
|
|
2011-09-14 19:20:25 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
|
|
|
|
|
2011-11-03 17:58:26 +01:00
|
|
|
clearall_segfeatures( xd );
|
2011-09-14 19:20:25 +02:00
|
|
|
|
|
|
|
xd->mode_ref_lf_delta_enabled = 0;
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
|
|
|
vpx_memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
|
|
|
|
vpx_memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
|
|
|
|
vpx_memset(xd->last_ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
|
|
|
|
vpx_memset(xd->last_mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-09-29 19:53:08 +02:00
|
|
|
set_default_lf_deltas(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
static void dealloc_compressor_data(VP8_COMP *cpi)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->tplist);
|
2011-02-05 06:29:25 +01:00
|
|
|
cpi->tplist = NULL;
|
|
|
|
|
2010-12-03 17:26:21 +01:00
|
|
|
// Delete last frame MV storage buffers
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->lfmv);
|
2010-12-03 17:26:21 +01:00
|
|
|
cpi->lfmv = 0;
|
|
|
|
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->lf_ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
cpi->lf_ref_frame_sign_bias = 0;
|
|
|
|
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->lf_ref_frame);
|
2010-12-03 17:26:21 +01:00
|
|
|
cpi->lf_ref_frame = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Delete sementation map
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->segmentation_map);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->segmentation_map = 0;
|
2012-01-27 19:29:07 +01:00
|
|
|
vpx_free(cpi->common.last_frame_seg_map);
|
|
|
|
cpi->common.last_frame_seg_map = 0;
|
2012-04-11 16:44:14 +02:00
|
|
|
vpx_free(cpi->coding_context.last_frame_seg_map_copy);
|
|
|
|
cpi->coding_context.last_frame_seg_map_copy = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->active_map);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->active_map = 0;
|
|
|
|
|
|
|
|
vp8_de_alloc_frame_buffers(&cpi->common);
|
|
|
|
|
|
|
|
vp8_yv12_de_alloc_frame_buffer(&cpi->last_frame_uf);
|
|
|
|
vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
|
|
|
|
#if VP8_TEMPORAL_ALT_REF
|
2011-04-13 20:00:18 +02:00
|
|
|
vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-04-13 20:00:18 +02:00
|
|
|
vp8_lookahead_destroy(cpi->lookahead);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
vpx_free(cpi->tok);
|
|
|
|
cpi->tok = 0;
|
|
|
|
|
2011-01-10 10:14:10 +01:00
|
|
|
// Structure used to monitor GF usage
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->gf_active_flags);
|
2010-08-11 17:02:31 +02:00
|
|
|
cpi->gf_active_flags = 0;
|
|
|
|
|
2011-05-12 18:01:55 +02:00
|
|
|
// Activity mask based per mb zbin adjustments
|
|
|
|
vpx_free(cpi->mb_activity_map);
|
|
|
|
cpi->mb_activity_map = 0;
|
|
|
|
vpx_free(cpi->mb_norm_activity_map);
|
|
|
|
cpi->mb_norm_activity_map = 0;
|
|
|
|
|
2011-02-22 09:29:23 +01:00
|
|
|
vpx_free(cpi->mb.pip);
|
2010-09-02 22:17:52 +02:00
|
|
|
cpi->mb.pip = 0;
|
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
vpx_free(cpi->twopass.total_stats);
|
|
|
|
cpi->twopass.total_stats = 0;
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
vpx_free(cpi->twopass.total_left_stats);
|
|
|
|
cpi->twopass.total_left_stats = 0;
|
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
vpx_free(cpi->twopass.this_frame_stats);
|
|
|
|
cpi->twopass.this_frame_stats = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 15:48:52 +01:00
|
|
|
// Computes a q delta (in "q index" terms) to get from a starting q value
|
|
|
|
// to a target value
|
|
|
|
// target q value
|
|
|
|
static int compute_qdelta( VP8_COMP *cpi, double qstart, double qtarget )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int start_index = cpi->worst_quality;
|
|
|
|
int target_index = cpi->worst_quality;
|
|
|
|
|
|
|
|
// Convert the average q value to an index.
|
|
|
|
for ( i = cpi->best_quality; i < cpi->worst_quality; i++ )
|
|
|
|
{
|
|
|
|
start_index = i;
|
|
|
|
if ( vp8_convert_qindex_to_q(i) >= qstart )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the q target to an index
|
|
|
|
for ( i = cpi->best_quality; i < cpi->worst_quality; i++ )
|
|
|
|
{
|
|
|
|
target_index = i;
|
|
|
|
if ( vp8_convert_qindex_to_q(i) >= qtarget )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target_index - start_index;
|
|
|
|
}
|
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
static void init_seg_features(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
2011-10-05 12:26:00 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2012-01-31 13:45:30 +01:00
|
|
|
int high_q = (int)(cpi->avg_q > 48.0);
|
2011-12-06 15:48:52 +01:00
|
|
|
int qi_delta;
|
2011-10-28 16:27:23 +02:00
|
|
|
|
2011-10-07 17:58:28 +02:00
|
|
|
// Disable and clear down for KF
|
|
|
|
if ( cm->frame_type == KEY_FRAME )
|
2011-09-30 17:45:16 +02:00
|
|
|
{
|
|
|
|
// Clear down the global segmentation map
|
|
|
|
vpx_memset( cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
|
2011-10-05 12:26:00 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
2012-01-11 15:05:57 +01:00
|
|
|
cpi->static_mb_pct = 0;
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
// Disable segmentation
|
|
|
|
vp8_disable_segmentation((VP8_PTR)cpi);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
|
|
|
// Clear down the segment features.
|
|
|
|
clearall_segfeatures(xd);
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2011-09-30 17:45:16 +02:00
|
|
|
|
2011-10-07 17:58:28 +02:00
|
|
|
// If this is an alt ref frame
|
|
|
|
else if ( cm->refresh_alt_ref_frame )
|
2011-10-05 12:26:00 +02:00
|
|
|
{
|
2011-10-07 17:58:28 +02:00
|
|
|
// Clear down the global segmentation map
|
|
|
|
vpx_memset( cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
|
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
2012-01-11 15:05:57 +01:00
|
|
|
cpi->static_mb_pct = 0;
|
2011-10-07 17:58:28 +02:00
|
|
|
|
|
|
|
// Disable segmentation and individual segment features by default
|
|
|
|
vp8_disable_segmentation((VP8_PTR)cpi);
|
|
|
|
clearall_segfeatures(xd);
|
|
|
|
|
|
|
|
// Scan frames from current to arf frame.
|
|
|
|
// This function re-enables segmentation if appropriate.
|
|
|
|
vp8_update_mbgraph_stats(cpi);
|
|
|
|
|
|
|
|
// If segmentation was enabled set those features needed for the
|
|
|
|
// arf itself.
|
|
|
|
if ( xd->segmentation_enabled )
|
2011-10-05 12:26:00 +02:00
|
|
|
{
|
2011-10-07 17:58:28 +02:00
|
|
|
xd->update_mb_segmentation_map = 1;
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
|
|
|
|
2011-12-06 15:48:52 +01:00
|
|
|
qi_delta = compute_qdelta( cpi, cpi->avg_q, (cpi->avg_q * 0.875) );
|
|
|
|
set_segdata( xd, 1, SEG_LVL_ALT_Q, (qi_delta - 2) );
|
2011-11-03 17:58:26 +01:00
|
|
|
set_segdata( xd, 1, SEG_LVL_ALT_LF, -2 );
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
|
|
|
|
enable_segfeature(xd, 1, SEG_LVL_ALT_LF);
|
|
|
|
|
|
|
|
// Where relevant assume segment data is delta data
|
2012-02-27 22:42:36 +01:00
|
|
|
xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
|
2011-11-09 15:05:28 +01:00
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
2011-10-07 17:58:28 +02:00
|
|
|
// All other frames if segmentation has been enabled
|
2011-10-05 12:26:00 +02:00
|
|
|
else if ( xd->segmentation_enabled )
|
2011-09-30 17:45:16 +02:00
|
|
|
{
|
2012-01-31 14:09:49 +01:00
|
|
|
/*
|
2012-01-26 19:04:34 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// clears prior frame seg lev refs
|
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++)
|
|
|
|
{
|
|
|
|
// only do it if the force drop the background stuff is off
|
|
|
|
if(!segfeature_active(xd, i, SEG_LVL_MODE))
|
|
|
|
{
|
|
|
|
disable_segfeature(xd,i,SEG_LVL_REF_FRAME);
|
|
|
|
set_segdata( xd,i, SEG_LVL_REF_FRAME, 0xffffff);
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 14:09:49 +01:00
|
|
|
*/
|
2012-01-26 19:04:34 +01:00
|
|
|
|
2011-10-07 17:58:28 +02:00
|
|
|
// First normal frame in a valid gf or alt ref group
|
|
|
|
if ( cpi->common.frames_since_golden == 0 )
|
2011-09-30 17:45:16 +02:00
|
|
|
{
|
2011-10-07 17:58:28 +02:00
|
|
|
// Set up segment features for normal frames in an af group
|
|
|
|
if ( cpi->source_alt_ref_active )
|
2011-09-30 17:45:16 +02:00
|
|
|
{
|
2011-10-07 17:58:28 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
2011-10-05 12:26:00 +02:00
|
|
|
xd->update_mb_segmentation_data = 1;
|
2012-02-27 22:42:36 +01:00
|
|
|
xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2011-12-06 15:48:52 +01:00
|
|
|
qi_delta = compute_qdelta( cpi, cpi->avg_q,
|
|
|
|
(cpi->avg_q * 1.125) );
|
|
|
|
set_segdata( xd, 1, SEG_LVL_ALT_Q, (qi_delta + 2) );
|
|
|
|
set_segdata( xd, 1, SEG_LVL_ALT_Q, 0 );
|
2011-10-07 17:58:28 +02:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
|
2011-11-03 17:58:26 +01:00
|
|
|
|
|
|
|
set_segdata( xd, 1, SEG_LVL_ALT_LF, -2 );
|
2011-10-07 17:58:28 +02:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_ALT_LF);
|
|
|
|
|
2012-01-28 13:20:14 +01:00
|
|
|
// Segment coding disabled for compred testing
|
|
|
|
if ( high_q || (cpi->static_mb_pct == 100) )
|
2011-10-07 17:58:28 +02:00
|
|
|
{
|
2012-01-31 13:45:30 +01:00
|
|
|
//set_segref(xd, 1, LAST_FRAME);
|
2011-11-02 14:30:10 +01:00
|
|
|
set_segref(xd, 1, ALTREF_FRAME);
|
2011-10-07 17:58:28 +02:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_REF_FRAME);
|
2011-11-03 17:58:26 +01:00
|
|
|
|
|
|
|
set_segdata( xd, 1, SEG_LVL_MODE, ZEROMV );
|
2011-10-07 17:58:28 +02:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_MODE);
|
2011-11-03 17:58:26 +01:00
|
|
|
|
Improved coding using 8x8 transform
In summary, this commit encompasses a series of changes in attempt to
improve the 8x8 transform based coding to help overall compression
quality, please refer to the detailed commit history below for what
are the rationale underly the series of changes:
a. A frame level flag to indicate if 8x8 transform is used at all.
b. 8x8 transform is not used for key frames and small image size.
c. On inter coded frame, macroblocks using modes B_PRED, SPLIT_MV
and I8X8_PRED are forced to using 4x4 transform based coding, the
rest uses 8x8 transform based coding.
d. Encoder and decoder has the same assumption on the relationship
between prediction modes and transform size, therefore no signaling
is encoded in bitstream.
e. Mode decision process now calculate the rate and distortion scores
using their respective transforms.
Overall test results:
1. HD set
http://www.corp.google.com/~yaowu/no_crawl/t8x8/HD_t8x8_20120206.html
(avg psnr: 3.09% glb psnr: 3.22%, ssim: 3.90%)
2. Cif set:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif_t8x8_20120206.html
(avg psnr: -0.03%, glb psnr: -0.02%, ssim: -0.04%)
It should be noted here, as 8x8 transform coding itself is disabled
for cif size clips, the 0.03% loss is purely from the 1 bit/frame
flag overhead on if 8x8 transform is used or not for the frame.
---patch history for future reference---
Patch 1:
this commit tries to select transform size based on macroblock
prediction mode. If the size of a prediction mode is 16x16, then
the macroblock is forced to use 8x8 transform. If the prediction
mode is B_PRED, SPLITMV or I8X8_PRED, then the macroblock is forced
to use 4x4 transform. Tests on the following HD clips showed mixed
results: (all hd clips only used first 100 frames in the test)
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8.html
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8_log.html
while the results are mixed and overall negative, it is interesting to
see 8x8 helped a few of the clips.
Patch 2:
this patch tries to hard-wire selection of transform size based on
prediction modes without using segmentation to signal the transform size.
encoder and decoder both takes the same assumption that all macroblocks
use 8x8 transform except when prediciton mode is B_PRED, I8X8_PRED or
SPLITMV. Test results are as follows:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cifmodebase8x8_0125.html
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8_0125log.html
Interestingly, by removing the overhead or coding the segmentation, the
results on this limited HD set have turn positive on average.
Patch 3:
this patch disabled the usage of 8x8 transform on key frames, and kept the
logic from patch 2 for inter frames only. test results on HD set turned
decidedly positive with 8x8 transform enabled on inter frame with 16x16
prediction modes: (avg psnr: .81% glb psnr: .82 ssim: .55%)
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdintermode8x8_0125.html
results on cif set still negative overall
Patch 4:
continued from last patch, but now in mode decision process, the rate and
distortion estimates are computed based on 8x8 transform results for MBs
with modes associated with 8x8 transform. This patch also fixed a problem
related to segment based eob coding when 8x8 transform is used. The patch
significantly improved the results on HD clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hd8x8RDintermode.html
(avg psnr: 2.70% glb psnr: 2.76% ssim: 3.34%)
results on cif also improved, though they are still negative compared to
baseline that uses 4x4 transform only:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif8x8RDintermode.html
(avg psnr: -.78% glb psnr: -.86% ssim: -.19%)
Patch 5:
This patch does 3 things:
a. a bunch of decoder bug fixes, encodings and decodings were verified
to have matched recon buffer on a number of encodes on cif size mobile and
hd version of _pedestrian.
b. the patch further improved the rate distortion calculation of MBS that
use 8x8 transform. This provided some further gain on compression.
c. the patch also got the experimental work SEG_LVL_EOB to work with 8x8
transformed macroblock, test results indicates it improves the cif set
but hurt the HD set slightly.
Tests results on HD clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/HD_t8x8_20120201.html
(avg psnr: 3.19% glb psnr: 3.30% ssim: 3.93%)
Test results on cif clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif_t8x8_20120201.html
(avg psnr: -.47% glb psnr: -.51% ssim: +.28%)
Patch 6:
Added a frame level flag to indicate if 8x8 transform is allowed at all.
temporarily the decision is based on frame size, can be optimized later
one. This get the cif results to basically unchanged, with one bit per
frame overhead on both cif and hd clips.
Patch 8:
Rebase and Merge to head by PGW.
Fixed some suspect 4s that look like hey should be 64s in regard
to segmented EOB. Perhaps #defines would be bette.
Bulit and tested without T8x8 enabled and produces unchanged
output.
Patch 9:
Corrected misalligned code/decode of "txfm_mode" bit.
Limited testing for correct encode and decode with
T8x8 configured on derf clips.
Change-Id: I156e1405d25f81579d579dff8ab9af53944ec49c
2012-02-10 01:12:23 +01:00
|
|
|
// EOB segment coding not fixed for 8x8 yet
|
|
|
|
set_segdata( xd, 1, SEG_LVL_EOB, 0 );
|
|
|
|
enable_segfeature(xd, 1, SEG_LVL_EOB);
|
2011-10-07 17:58:28 +02:00
|
|
|
}
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
2011-10-07 17:58:28 +02:00
|
|
|
// Disable segmentation and clear down features if alt ref
|
|
|
|
// is not active for this group
|
2011-09-30 17:45:16 +02:00
|
|
|
else
|
|
|
|
{
|
2011-10-07 17:58:28 +02:00
|
|
|
vp8_disable_segmentation((VP8_PTR)cpi);
|
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
vpx_memset( cpi->segmentation_map, 0,
|
|
|
|
(cm->mb_rows * cm->mb_cols));
|
2011-10-07 17:58:28 +02:00
|
|
|
|
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
|
|
|
|
clearall_segfeatures(xd);
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 17:58:28 +02:00
|
|
|
|
|
|
|
// Special case where we are coding over the top of a previous
|
|
|
|
// alt ref frame
|
2012-01-28 13:20:14 +01:00
|
|
|
// Segment coding disabled for compred testing
|
2011-10-07 17:58:28 +02:00
|
|
|
else if ( cpi->is_src_frame_alt_ref )
|
|
|
|
{
|
|
|
|
// Enable mode and ref frame features for segment 0 as well
|
|
|
|
enable_segfeature(xd, 0, SEG_LVL_REF_FRAME);
|
|
|
|
enable_segfeature(xd, 0, SEG_LVL_MODE);
|
2012-01-28 13:20:14 +01:00
|
|
|
enable_segfeature(xd, 1, SEG_LVL_REF_FRAME);
|
|
|
|
enable_segfeature(xd, 1, SEG_LVL_MODE);
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2011-11-02 14:30:10 +01:00
|
|
|
// All mbs should use ALTREF_FRAME, ZEROMV exclusively
|
|
|
|
clear_segref(xd, 0);
|
|
|
|
set_segref(xd, 0, ALTREF_FRAME);
|
|
|
|
clear_segref(xd, 1);
|
|
|
|
set_segref(xd, 1, ALTREF_FRAME);
|
2011-11-03 17:58:26 +01:00
|
|
|
set_segdata( xd, 0, SEG_LVL_MODE, ZEROMV );
|
|
|
|
set_segdata( xd, 1, SEG_LVL_MODE, ZEROMV );
|
2011-10-07 17:58:28 +02:00
|
|
|
|
2011-10-28 16:27:23 +02:00
|
|
|
// Skip all MBs if high Q
|
|
|
|
if ( high_q )
|
|
|
|
{
|
Improved coding using 8x8 transform
In summary, this commit encompasses a series of changes in attempt to
improve the 8x8 transform based coding to help overall compression
quality, please refer to the detailed commit history below for what
are the rationale underly the series of changes:
a. A frame level flag to indicate if 8x8 transform is used at all.
b. 8x8 transform is not used for key frames and small image size.
c. On inter coded frame, macroblocks using modes B_PRED, SPLIT_MV
and I8X8_PRED are forced to using 4x4 transform based coding, the
rest uses 8x8 transform based coding.
d. Encoder and decoder has the same assumption on the relationship
between prediction modes and transform size, therefore no signaling
is encoded in bitstream.
e. Mode decision process now calculate the rate and distortion scores
using their respective transforms.
Overall test results:
1. HD set
http://www.corp.google.com/~yaowu/no_crawl/t8x8/HD_t8x8_20120206.html
(avg psnr: 3.09% glb psnr: 3.22%, ssim: 3.90%)
2. Cif set:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif_t8x8_20120206.html
(avg psnr: -0.03%, glb psnr: -0.02%, ssim: -0.04%)
It should be noted here, as 8x8 transform coding itself is disabled
for cif size clips, the 0.03% loss is purely from the 1 bit/frame
flag overhead on if 8x8 transform is used or not for the frame.
---patch history for future reference---
Patch 1:
this commit tries to select transform size based on macroblock
prediction mode. If the size of a prediction mode is 16x16, then
the macroblock is forced to use 8x8 transform. If the prediction
mode is B_PRED, SPLITMV or I8X8_PRED, then the macroblock is forced
to use 4x4 transform. Tests on the following HD clips showed mixed
results: (all hd clips only used first 100 frames in the test)
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8.html
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8_log.html
while the results are mixed and overall negative, it is interesting to
see 8x8 helped a few of the clips.
Patch 2:
this patch tries to hard-wire selection of transform size based on
prediction modes without using segmentation to signal the transform size.
encoder and decoder both takes the same assumption that all macroblocks
use 8x8 transform except when prediciton mode is B_PRED, I8X8_PRED or
SPLITMV. Test results are as follows:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cifmodebase8x8_0125.html
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdmodebased8x8_0125log.html
Interestingly, by removing the overhead or coding the segmentation, the
results on this limited HD set have turn positive on average.
Patch 3:
this patch disabled the usage of 8x8 transform on key frames, and kept the
logic from patch 2 for inter frames only. test results on HD set turned
decidedly positive with 8x8 transform enabled on inter frame with 16x16
prediction modes: (avg psnr: .81% glb psnr: .82 ssim: .55%)
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hdintermode8x8_0125.html
results on cif set still negative overall
Patch 4:
continued from last patch, but now in mode decision process, the rate and
distortion estimates are computed based on 8x8 transform results for MBs
with modes associated with 8x8 transform. This patch also fixed a problem
related to segment based eob coding when 8x8 transform is used. The patch
significantly improved the results on HD clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/hd8x8RDintermode.html
(avg psnr: 2.70% glb psnr: 2.76% ssim: 3.34%)
results on cif also improved, though they are still negative compared to
baseline that uses 4x4 transform only:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif8x8RDintermode.html
(avg psnr: -.78% glb psnr: -.86% ssim: -.19%)
Patch 5:
This patch does 3 things:
a. a bunch of decoder bug fixes, encodings and decodings were verified
to have matched recon buffer on a number of encodes on cif size mobile and
hd version of _pedestrian.
b. the patch further improved the rate distortion calculation of MBS that
use 8x8 transform. This provided some further gain on compression.
c. the patch also got the experimental work SEG_LVL_EOB to work with 8x8
transformed macroblock, test results indicates it improves the cif set
but hurt the HD set slightly.
Tests results on HD clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/HD_t8x8_20120201.html
(avg psnr: 3.19% glb psnr: 3.30% ssim: 3.93%)
Test results on cif clips:
http://www.corp.google.com/~yaowu/no_crawl/t8x8/cif_t8x8_20120201.html
(avg psnr: -.47% glb psnr: -.51% ssim: +.28%)
Patch 6:
Added a frame level flag to indicate if 8x8 transform is allowed at all.
temporarily the decision is based on frame size, can be optimized later
one. This get the cif results to basically unchanged, with one bit per
frame overhead on both cif and hd clips.
Patch 8:
Rebase and Merge to head by PGW.
Fixed some suspect 4s that look like hey should be 64s in regard
to segmented EOB. Perhaps #defines would be bette.
Bulit and tested without T8x8 enabled and produces unchanged
output.
Patch 9:
Corrected misalligned code/decode of "txfm_mode" bit.
Limited testing for correct encode and decode with
T8x8 configured on derf clips.
Change-Id: I156e1405d25f81579d579dff8ab9af53944ec49c
2012-02-10 01:12:23 +01:00
|
|
|
enable_segfeature(xd, 0, SEG_LVL_EOB);
|
|
|
|
set_segdata( xd, 0, SEG_LVL_EOB, 0 );
|
|
|
|
enable_segfeature(xd, 1, SEG_LVL_EOB);
|
|
|
|
set_segdata( xd, 1, SEG_LVL_EOB, 0 );
|
2011-10-28 16:27:23 +02:00
|
|
|
}
|
2011-10-07 17:58:28 +02:00
|
|
|
// Enable data udpate
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
|
|
|
}
|
|
|
|
// All other frames.
|
2011-09-30 17:45:16 +02:00
|
|
|
else
|
|
|
|
{
|
2012-04-07 01:38:34 +02:00
|
|
|
// No updates.. leave things as they are.
|
2011-10-07 17:58:28 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
2011-10-05 12:26:00 +02:00
|
|
|
xd->update_mb_segmentation_data = 0;
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEBUG: Print out the segment id of each MB in the current frame.
|
|
|
|
static void print_seg_map(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = & cpi->common;
|
|
|
|
int row,col;
|
|
|
|
int map_index = 0;
|
|
|
|
FILE *statsfile;
|
|
|
|
|
|
|
|
statsfile = fopen("segmap.stt", "a");
|
|
|
|
|
|
|
|
fprintf(statsfile, "%10d\n",
|
|
|
|
cm->current_video_frame );
|
|
|
|
|
|
|
|
for ( row = 0; row < cpi->common.mb_rows; row++ )
|
|
|
|
{
|
|
|
|
for ( col = 0; col < cpi->common.mb_cols; col++ )
|
|
|
|
{
|
|
|
|
fprintf(statsfile, "%10d",
|
|
|
|
cpi->segmentation_map[map_index]);
|
|
|
|
map_index++;
|
|
|
|
}
|
|
|
|
fprintf(statsfile, "\n");
|
|
|
|
}
|
|
|
|
fprintf(statsfile, "\n");
|
|
|
|
|
|
|
|
fclose(statsfile);
|
|
|
|
}
|
|
|
|
|
2010-09-29 19:53:08 +02:00
|
|
|
static void set_default_lf_deltas(VP8_COMP *cpi)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 1;
|
|
|
|
cpi->mb.e_mbd.mode_ref_lf_delta_update = 1;
|
|
|
|
|
|
|
|
vpx_memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
|
|
|
|
vpx_memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
|
|
|
|
|
|
|
|
// Test of ref frame deltas
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[INTRA_FRAME] = 2;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[LAST_FRAME] = 0;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[GOLDEN_FRAME] = -2;
|
|
|
|
cpi->mb.e_mbd.ref_lf_deltas[ALTREF_FRAME] = -2;
|
|
|
|
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[0] = 4; // BPRED
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[1] = -2; // Zero
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[2] = 2; // New mv
|
|
|
|
cpi->mb.e_mbd.mode_lf_deltas[3] = 4; // Split mv
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8_set_speed_features(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
SPEED_FEATURES *sf = &cpi->sf;
|
|
|
|
int Mode = cpi->compressor_speed;
|
|
|
|
int Speed = cpi->Speed;
|
|
|
|
int i;
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
2012-02-16 18:02:17 +01:00
|
|
|
// Only modes 0 and 1 supported for now in experimental code basae
|
|
|
|
if ( Mode > 1 )
|
|
|
|
Mode = 1;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Initialise default mode frequency sampling variables
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-06 18:10:07 +01:00
|
|
|
// best quality defaults
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->RD = 1;
|
|
|
|
sf->search_method = NSTEP;
|
|
|
|
sf->improved_dct = 1;
|
|
|
|
sf->auto_filter = 1;
|
|
|
|
sf->recode_loop = 1;
|
|
|
|
sf->quarter_pixel_search = 1;
|
|
|
|
sf->half_pixel_search = 1;
|
|
|
|
sf->iterative_sub_pixel = 1;
|
|
|
|
sf->optimize_coefficients = 1;
|
2011-01-10 23:21:55 +01:00
|
|
|
sf->no_skip_block4x4_search = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
sf->first_step = 0;
|
|
|
|
sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
|
2011-02-11 15:43:37 +01:00
|
|
|
sf->improved_mv_pred = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// default thresholds to 0
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
sf->thresh_mult[i] = 0;
|
|
|
|
|
|
|
|
switch (Mode)
|
|
|
|
{
|
|
|
|
case 0: // best quality mode
|
|
|
|
sf->thresh_mult[THR_ZEROMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_DC ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_V_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_H_PRED ] = 1000;
|
2012-05-15 01:21:01 +02:00
|
|
|
#if CONFIG_NEWINTRAMODES
|
|
|
|
sf->thresh_mult[THR_D45_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_D135_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D117_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D153_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D27_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_D63_PRED ] = 1000;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_B_PRED ] = 2000;
|
2011-12-01 01:25:00 +01:00
|
|
|
sf->thresh_mult[THR_I8X8_PRED] = 2000;
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_TM ] = 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = 2500;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = 5000;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = 5000;
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = 1000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = 1000;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = 2500;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = 5000;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = 5000;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->first_step = 0;
|
|
|
|
sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
|
|
|
sf->search_best_filter = SEARCH_BEST_FILTER;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_DC ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_V_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_H_PRED ] = 1000;
|
2012-05-15 01:21:01 +02:00
|
|
|
#if CONFIG_NEWINTRAMODES
|
|
|
|
sf->thresh_mult[THR_D45_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_D135_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D117_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D153_PRED] = 1000;
|
|
|
|
sf->thresh_mult[THR_D27_PRED ] = 1000;
|
|
|
|
sf->thresh_mult[THR_D63_PRED ] = 1000;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_B_PRED ] = 2500;
|
2011-12-01 01:25:00 +01:00
|
|
|
sf->thresh_mult[THR_I8X8_PRED] = 2500;
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_TM ] = 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 1000;
|
|
|
|
|
2010-12-16 23:01:27 +01:00
|
|
|
sf->thresh_mult[THR_ZEROMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 0;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 0;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 0;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = 1000;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = 1700;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = 4500;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = 4500;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = 0;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = 0;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = 1000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = 1000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = 1000;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = 1700;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = 4500;
|
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = 4500;
|
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
if (Speed > 0)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-02-09 23:18:28 +01:00
|
|
|
/* Disable coefficient optimization above speed 0 */
|
|
|
|
sf->optimize_coefficients = 0;
|
|
|
|
sf->no_skip_block4x4_search = 0;
|
2010-06-21 14:44:42 +02:00
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
sf->first_step = 1;
|
2010-06-21 14:44:42 +02:00
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
cpi->mode_check_freq[THR_SPLITG] = 2;
|
|
|
|
cpi->mode_check_freq[THR_SPLITA] = 2;
|
|
|
|
cpi->mode_check_freq[THR_SPLITMV] = 0;
|
2012-04-18 22:51:58 +02:00
|
|
|
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITGA] = 2;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLG] = 2;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLA] = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
if (Speed > 1)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
cpi->mode_check_freq[THR_SPLITG] = 4;
|
|
|
|
cpi->mode_check_freq[THR_SPLITA] = 4;
|
2010-12-28 20:51:46 +01:00
|
|
|
cpi->mode_check_freq[THR_SPLITMV] = 2;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-18 22:51:58 +02:00
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITGA] = 4;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLG] = 4;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLA] = 2;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_TM ] = 1500;
|
|
|
|
sf->thresh_mult[THR_V_PRED ] = 1500;
|
|
|
|
sf->thresh_mult[THR_H_PRED ] = 1500;
|
2012-05-15 01:21:01 +02:00
|
|
|
#if CONFIG_NEWINTRAMODES
|
|
|
|
sf->thresh_mult[THR_D45_PRED ] = 1500;
|
|
|
|
sf->thresh_mult[THR_D135_PRED] = 1500;
|
|
|
|
sf->thresh_mult[THR_D117_PRED] = 1500;
|
|
|
|
sf->thresh_mult[THR_D153_PRED] = 1500;
|
|
|
|
sf->thresh_mult[THR_D27_PRED ] = 1500;
|
|
|
|
sf->thresh_mult[THR_D63_PRED ] = 1500;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_B_PRED ] = 5000;
|
2011-12-01 01:25:00 +01:00
|
|
|
sf->thresh_mult[THR_I8X8_PRED] = 5000;
|
2011-12-07 22:03:57 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = 2000;
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = 10000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = 20000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 1500;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 1500;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 1500;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = 20000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = 20000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_ALT_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = 20000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = 10000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = 1500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = 1500;
|
|
|
|
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = 2000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
if (Speed > 2)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
cpi->mode_check_freq[THR_SPLITG] = 15;
|
|
|
|
cpi->mode_check_freq[THR_SPLITA] = 15;
|
|
|
|
cpi->mode_check_freq[THR_SPLITMV] = 7;
|
|
|
|
|
2012-04-18 22:51:58 +02:00
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITGA] = 15;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLG] = 15;
|
|
|
|
cpi->mode_check_freq[THR_COMP_SPLITLA] = 7;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_TM ] = 2000;
|
|
|
|
sf->thresh_mult[THR_V_PRED ] = 2000;
|
|
|
|
sf->thresh_mult[THR_H_PRED ] = 2000;
|
2012-05-15 01:21:01 +02:00
|
|
|
#if CONFIG_NEWINTRAMODES
|
|
|
|
sf->thresh_mult[THR_D45_PRED ] = 2000;
|
|
|
|
sf->thresh_mult[THR_D135_PRED] = 2000;
|
|
|
|
sf->thresh_mult[THR_D117_PRED] = 2000;
|
|
|
|
sf->thresh_mult[THR_D153_PRED] = 2000;
|
|
|
|
sf->thresh_mult[THR_D27_PRED ] = 2000;
|
|
|
|
sf->thresh_mult[THR_D63_PRED ] = 2000;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->thresh_mult[THR_B_PRED ] = 7500;
|
2011-12-01 01:25:00 +01:00
|
|
|
sf->thresh_mult[THR_I8X8_PRED] = 7500;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = 2000;
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = 25000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = 50000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = 2500;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = 50000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = 50000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_ALT_FLAG)
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = 2500;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = 50000;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = 25000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = 2000;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = 2000;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = 2500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = 2500;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = 2500;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
|
2010-12-28 20:51:46 +01:00
|
|
|
sf->improved_dct = 0;
|
|
|
|
|
2010-11-17 16:12:04 +01:00
|
|
|
// Only do recode loop on key frames, golden frames and
|
|
|
|
// alt ref frames
|
2010-05-18 17:58:33 +02:00
|
|
|
sf->recode_loop = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-02-09 23:18:28 +01:00
|
|
|
}; /* switch */
|
|
|
|
|
|
|
|
/* disable frame modes if flags not set */
|
|
|
|
if (!(cpi->ref_frame_flags & VP8_LAST_FLAG))
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEWMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARESTMV] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARMV ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITMV ] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cpi->ref_frame_flags & VP8_GOLD_FLAG))
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEWG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITG ] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cpi->ref_frame_flags & VP8_ALT_FLAG))
|
|
|
|
{
|
|
|
|
sf->thresh_mult[THR_NEARESTA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_ZEROA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEARA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_NEWA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_SPLITA ] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
if ((cpi->ref_frame_flags & (VP8_LAST_FLAG | VP8_GOLD_FLAG)) != (VP8_LAST_FLAG | VP8_GOLD_FLAG))
|
|
|
|
{
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLG] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLG ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLG ] = INT_MAX;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLG ] = INT_MAX;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((cpi->ref_frame_flags & (VP8_LAST_FLAG | VP8_ALT_FLAG)) != (VP8_LAST_FLAG | VP8_ALT_FLAG))
|
|
|
|
{
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROLA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARLA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWLA ] = INT_MAX;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITLA ] = INT_MAX;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((cpi->ref_frame_flags & (VP8_GOLD_FLAG | VP8_ALT_FLAG)) != (VP8_GOLD_FLAG | VP8_ALT_FLAG))
|
|
|
|
{
|
2012-02-29 02:25:45 +01:00
|
|
|
sf->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX;
|
|
|
|
sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX;
|
2012-04-18 22:51:58 +02:00
|
|
|
sf->thresh_mult[THR_COMP_SPLITGA ] = INT_MAX;
|
Dual 16x16 inter prediction.
This patch introduces the concept of dual inter16x16 prediction. A
16x16 inter-predicted macroblock can use 2 references instead of 1,
where both references use the same mvmode (new, near/est, zero). In the
case of newmv, this means that two MVs are coded instead of one. The
frame can be encoded in 3 ways: all MBs single-prediction, all MBs dual
prediction, or per-MB single/dual prediction selection ("hybrid"), in
which case a single bit is coded per-MB to indicate whether the MB uses
single or dual inter prediction.
In the future, we can (maybe?) get further gains by mixing this with
Adrian's 32x32 work, per-segment dual prediction settings, or adding
support for dual splitmv/8x8mv inter prediction.
Gain (on derf-set, CQ mode) is ~2.8% (SSIM) or ~3.6% (glb PSNR). Most
gain is at medium/high bitrates, but there's minor gains at low bitrates
also. Output was confirmed to match between encoder and decoder.
Note for optimization people: this patch introduces a 2nd version of
16x16/8x8 sixtap/bilin functions, which does an avg instead of a
store. They may want to look and make sure this is implemented to
their satisfaction so we can optimize it best in the future.
Change-ID: I59dc84b07cbb3ccf073ac0f756d03d294cb19281
2011-12-06 20:53:02 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-06 18:10:07 +01:00
|
|
|
// Slow quant, dct and trellis not worthwhile for first pass
|
|
|
|
// so make sure they are always turned off.
|
|
|
|
if ( cpi->pass == 1 )
|
|
|
|
{
|
|
|
|
sf->optimize_coefficients = 0;
|
|
|
|
sf->improved_dct = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->sf.search_method == NSTEP)
|
|
|
|
{
|
2010-07-22 14:07:32 +02:00
|
|
|
vp8_init3smotion_compensation(&cpi->mb, cm->yv12_fb[cm->lst_fb_idx].y_stride);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else if (cpi->sf.search_method == DIAMOND)
|
|
|
|
{
|
2010-07-22 14:07:32 +02:00
|
|
|
vp8_init_dsmotion_compensation(&cpi->mb, cm->yv12_fb[cm->lst_fb_idx].y_stride);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->sf.improved_dct)
|
|
|
|
{
|
2011-02-14 23:18:18 +01:00
|
|
|
cpi->mb.vp8_short_fdct8x8 = FDCT_INVOKE(&cpi->rtcd.fdct, short8x8);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->mb.vp8_short_fdct8x4 = FDCT_INVOKE(&cpi->rtcd.fdct, short8x4);
|
|
|
|
cpi->mb.vp8_short_fdct4x4 = FDCT_INVOKE(&cpi->rtcd.fdct, short4x4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-14 23:18:18 +01:00
|
|
|
cpi->mb.vp8_short_fdct8x8 = FDCT_INVOKE(&cpi->rtcd.fdct, short8x8);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->mb.vp8_short_fdct8x4 = FDCT_INVOKE(&cpi->rtcd.fdct, fast8x4);
|
|
|
|
cpi->mb.vp8_short_fdct4x4 = FDCT_INVOKE(&cpi->rtcd.fdct, fast4x4);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->mb.short_walsh4x4 = FDCT_INVOKE(&cpi->rtcd.fdct, walsh_short4x4);
|
2011-02-14 23:18:18 +01:00
|
|
|
cpi->mb.short_fhaar2x2 = FDCT_INVOKE(&cpi->rtcd.fdct, haar_short2x2);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-03-21 19:22:33 +01:00
|
|
|
|
|
|
|
cpi->mb.quantize_b = vp8_regular_quantize_b;
|
|
|
|
cpi->mb.quantize_b_pair = vp8_regular_quantize_b_pair;
|
|
|
|
cpi->mb.quantize_b_8x8 = vp8_regular_quantize_b_8x8;
|
|
|
|
cpi->mb.quantize_b_2x2 = vp8_regular_quantize_b_2x2;
|
|
|
|
|
|
|
|
vp8cx_init_quantizer(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
cpi->mb.e_mbd.rtcd = &cpi->common.rtcd;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cpi->sf.iterative_sub_pixel == 1)
|
|
|
|
{
|
|
|
|
cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step_iteratively;
|
|
|
|
}
|
|
|
|
else if (cpi->sf.quarter_pixel_search)
|
|
|
|
{
|
|
|
|
cpi->find_fractional_mv_step = vp8_find_best_sub_pixel_step;
|
|
|
|
}
|
|
|
|
else if (cpi->sf.half_pixel_search)
|
|
|
|
{
|
|
|
|
cpi->find_fractional_mv_step = vp8_find_best_half_pixel_step;
|
|
|
|
}
|
|
|
|
|
2011-05-20 01:00:28 +02:00
|
|
|
if (cpi->sf.optimize_coefficients == 1 && cpi->pass!=1)
|
2011-05-11 04:57:51 +02:00
|
|
|
cpi->mb.optimize = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
cpi->mb.optimize = 0;
|
|
|
|
|
|
|
|
#ifdef SPEEDSTATS
|
|
|
|
frames_at_speed[cpi->Speed]++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
static void alloc_raw_frame_buffers(VP8_COMP *cpi)
|
|
|
|
{
|
2011-02-16 18:00:25 +01:00
|
|
|
int width = (cpi->oxcf.Width + 15) & ~15;
|
2011-04-13 20:00:18 +02:00
|
|
|
int height = (cpi->oxcf.Height + 15) & ~15;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->lookahead = vp8_lookahead_init(cpi->oxcf.Width, cpi->oxcf.Height,
|
|
|
|
cpi->oxcf.lag_in_frames);
|
|
|
|
if(!cpi->lookahead)
|
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate lag buffers");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if VP8_TEMPORAL_ALT_REF
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
if (vp8_yv12_alloc_frame_buffer(&cpi->alt_ref_buffer,
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
width, height, VP8BORDERINPIXELS))
|
2010-05-18 17:58:33 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate altref buffer");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2010-09-02 22:17:52 +02:00
|
|
|
|
|
|
|
static int vp8_alloc_partition_data(VP8_COMP *cpi)
|
|
|
|
{
|
2010-12-06 23:21:37 +01:00
|
|
|
vpx_free(cpi->mb.pip);
|
|
|
|
|
2010-09-02 22:17:52 +02:00
|
|
|
cpi->mb.pip = vpx_calloc((cpi->common.mb_cols + 1) *
|
|
|
|
(cpi->common.mb_rows + 1),
|
|
|
|
sizeof(PARTITION_INFO));
|
|
|
|
if(!cpi->mb.pip)
|
2011-02-17 12:59:48 +01:00
|
|
|
return 1;
|
2010-09-02 22:17:52 +02:00
|
|
|
|
|
|
|
cpi->mb.pi = cpi->mb.pip + cpi->common.mode_info_stride + 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
void vp8_alloc_compressor_data(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = & cpi->common;
|
|
|
|
|
|
|
|
int width = cm->Width;
|
|
|
|
int height = cm->Height;
|
|
|
|
|
|
|
|
if (vp8_alloc_frame_buffers(cm, width, height))
|
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate frame buffers");
|
|
|
|
|
2010-09-02 22:17:52 +02:00
|
|
|
if (vp8_alloc_partition_data(cpi))
|
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate partition data");
|
|
|
|
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if ((width & 0xf) != 0)
|
|
|
|
width += 16 - (width & 0xf);
|
|
|
|
|
|
|
|
if ((height & 0xf) != 0)
|
|
|
|
height += 16 - (height & 0xf);
|
|
|
|
|
|
|
|
|
|
|
|
if (vp8_yv12_alloc_frame_buffer(&cpi->last_frame_uf,
|
|
|
|
width, height, VP8BORDERINPIXELS))
|
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate last frame buffer");
|
|
|
|
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
if (vp8_yv12_alloc_frame_buffer(&cpi->scaled_source,
|
|
|
|
width, height, VP8BORDERINPIXELS))
|
2010-05-18 17:58:33 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate scaled source buffer");
|
|
|
|
|
|
|
|
|
|
|
|
vpx_free(cpi->tok);
|
|
|
|
|
|
|
|
{
|
|
|
|
unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16;
|
|
|
|
|
|
|
|
CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data used for real time vc mode to see if gf needs refreshing
|
|
|
|
cpi->inter_zz_count = 0;
|
|
|
|
cpi->gf_bad_count = 0;
|
|
|
|
cpi->gf_update_recommended = 0;
|
2010-08-11 17:02:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Structures used to minitor GF usage
|
2011-05-12 18:01:55 +02:00
|
|
|
vpx_free(cpi->gf_active_flags);
|
|
|
|
CHECK_MEM_ERROR(cpi->gf_active_flags,
|
|
|
|
vpx_calloc(1, cm->mb_rows * cm->mb_cols));
|
|
|
|
cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
|
2010-08-11 17:02:31 +02:00
|
|
|
|
2011-05-12 18:01:55 +02:00
|
|
|
vpx_free(cpi->mb_activity_map);
|
|
|
|
CHECK_MEM_ERROR(cpi->mb_activity_map,
|
|
|
|
vpx_calloc(sizeof(unsigned int),
|
|
|
|
cm->mb_rows * cm->mb_cols));
|
2010-08-11 17:02:31 +02:00
|
|
|
|
2011-05-12 18:01:55 +02:00
|
|
|
vpx_free(cpi->mb_norm_activity_map);
|
|
|
|
CHECK_MEM_ERROR(cpi->mb_norm_activity_map,
|
|
|
|
vpx_calloc(sizeof(unsigned int),
|
|
|
|
cm->mb_rows * cm->mb_cols));
|
2010-10-14 22:40:12 +02:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
vpx_free(cpi->twopass.total_stats);
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.total_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
vpx_free(cpi->twopass.total_left_stats);
|
|
|
|
cpi->twopass.total_left_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
|
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
vpx_free(cpi->twopass.this_frame_stats);
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.this_frame_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
|
2010-12-06 23:21:37 +01:00
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
if( !cpi->twopass.total_stats ||
|
|
|
|
!cpi->twopass.total_left_stats ||
|
|
|
|
!cpi->twopass.this_frame_stats)
|
2010-10-14 22:40:12 +02:00
|
|
|
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate firstpass stats");
|
2011-01-26 09:29:46 +01:00
|
|
|
|
2011-02-14 20:02:52 +01:00
|
|
|
vpx_free(cpi->tplist);
|
|
|
|
|
2011-02-05 06:29:25 +01:00
|
|
|
CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 19:27:25 +01:00
|
|
|
// TODO perhaps change number of steps expose to outside world when setting
|
|
|
|
// max and min limits. Also this will likely want refining for the extended Q
|
|
|
|
// range.
|
|
|
|
//
|
|
|
|
// Table that converts 0-63 Q range values passed in outside to the Qindex
|
|
|
|
// range used internally.
|
|
|
|
static const int q_trans[] =
|
|
|
|
{
|
|
|
|
0, 4, 8, 12, 16, 20, 24, 28,
|
|
|
|
32, 36, 40, 44, 48, 52, 56, 60,
|
|
|
|
64, 68, 72, 76, 80, 84, 88, 92,
|
|
|
|
96, 100, 104, 108, 112, 116, 120, 124,
|
|
|
|
128, 132, 136, 140, 144, 148, 152, 156,
|
|
|
|
160, 164, 168, 172, 176, 180, 184, 188,
|
|
|
|
192, 196, 200, 204, 208, 212, 216, 220,
|
|
|
|
224, 228, 232, 236, 240, 244, 249, 255,
|
|
|
|
};
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
int vp8_reverse_trans(int x)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
if (q_trans[i] >= x)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return 63;
|
|
|
|
};
|
|
|
|
void vp8_new_frame_rate(VP8_COMP *cpi, double framerate)
|
|
|
|
{
|
2010-10-14 22:19:06 +02:00
|
|
|
if(framerate < .1)
|
|
|
|
framerate = 30;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->oxcf.frame_rate = framerate;
|
|
|
|
cpi->output_frame_rate = cpi->oxcf.frame_rate;
|
|
|
|
cpi->per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth / cpi->output_frame_rate);
|
|
|
|
cpi->av_per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth / cpi->output_frame_rate);
|
|
|
|
cpi->min_frame_bandwidth = (int)(cpi->av_per_frame_bandwidth * cpi->oxcf.two_pass_vbrmin_section / 100);
|
|
|
|
|
2012-03-02 02:24:30 +01:00
|
|
|
if (cpi->min_frame_bandwidth < FRAME_OVERHEAD_BITS )
|
|
|
|
cpi->min_frame_bandwidth = FRAME_OVERHEAD_BITS;
|
|
|
|
|
2011-01-18 16:19:05 +01:00
|
|
|
// Set Maximum gf/arf interval
|
2011-01-18 17:14:17 +01:00
|
|
|
cpi->max_gf_interval = ((int)(cpi->output_frame_rate / 2.0) + 2);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-18 17:14:17 +01:00
|
|
|
if(cpi->max_gf_interval < 12)
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->max_gf_interval = 12;
|
|
|
|
|
2011-01-18 16:19:05 +01:00
|
|
|
// Extended interval for genuinely static scenes
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.static_scene_max_gf_interval = cpi->key_frame_frequency >> 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-18 16:19:05 +01:00
|
|
|
// Special conditions when altr ref frame enabled in lagged compress mode
|
2010-09-09 18:57:23 +02:00
|
|
|
if (cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
if (cpi->max_gf_interval > cpi->oxcf.lag_in_frames - 1)
|
|
|
|
cpi->max_gf_interval = cpi->oxcf.lag_in_frames - 1;
|
2011-01-18 16:19:05 +01:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.static_scene_max_gf_interval > cpi->oxcf.lag_in_frames - 1)
|
|
|
|
cpi->twopass.static_scene_max_gf_interval = cpi->oxcf.lag_in_frames - 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-01-18 16:19:05 +01:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if ( cpi->max_gf_interval > cpi->twopass.static_scene_max_gf_interval )
|
|
|
|
cpi->max_gf_interval = cpi->twopass.static_scene_max_gf_interval;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-08-20 17:04:10 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
rescale(int val, int num, int denom)
|
|
|
|
{
|
|
|
|
int64_t llnum = num;
|
|
|
|
int64_t llden = denom;
|
|
|
|
int64_t llval = val;
|
|
|
|
|
|
|
|
return llval * llnum / llden;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
static void init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
2011-03-11 15:51:40 +01:00
|
|
|
cpi->oxcf = *oxcf;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->goldfreq = 7;
|
|
|
|
|
|
|
|
cm->version = oxcf->Version;
|
|
|
|
vp8_setup_version(cm);
|
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
// change includes all joint functionality
|
|
|
|
vp8_change_config(ptr, oxcf);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
// Initialize active best and worst q and average q values.
|
|
|
|
cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->active_best_quality = cpi->oxcf.best_allowed_q;
|
|
|
|
cpi->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
// Initialise the starting buffer levels
|
2011-03-02 00:07:47 +01:00
|
|
|
cpi->buffer_level = cpi->oxcf.starting_buffer_level;
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
|
|
|
|
|
2010-09-24 18:52:55 +02:00
|
|
|
cpi->rolling_target_bits = cpi->av_per_frame_bandwidth;
|
|
|
|
cpi->rolling_actual_bits = cpi->av_per_frame_bandwidth;
|
2011-03-02 00:07:47 +01:00
|
|
|
cpi->long_rolling_target_bits = cpi->av_per_frame_bandwidth;
|
|
|
|
cpi->long_rolling_actual_bits = cpi->av_per_frame_bandwidth;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->total_actual_bits = 0;
|
2011-03-02 00:07:47 +01:00
|
|
|
cpi->total_target_vs_actual = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
cpi->static_mb_pct = 0;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#if VP8_TEMPORAL_ALT_REF
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cpi->fixed_divide[0] = 0;
|
|
|
|
|
2010-09-28 16:23:41 +02:00
|
|
|
for (i = 1; i < 512; i++)
|
|
|
|
cpi->fixed_divide[i] = 0x80000 / i;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
if (!cpi)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!oxcf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cm->version != oxcf->Version)
|
|
|
|
{
|
|
|
|
cm->version = oxcf->Version;
|
|
|
|
vp8_setup_version(cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->oxcf = *oxcf;
|
|
|
|
|
|
|
|
switch (cpi->oxcf.Mode)
|
|
|
|
{
|
2012-02-16 18:02:17 +01:00
|
|
|
// Real time and one pass deprecated in test code base
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_FIRSTPASS:
|
|
|
|
cpi->pass = 1;
|
|
|
|
cpi->compressor_speed = 1;
|
|
|
|
break;
|
2012-02-16 18:02:17 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_SECONDPASS:
|
|
|
|
cpi->pass = 2;
|
|
|
|
cpi->compressor_speed = 1;
|
|
|
|
|
|
|
|
if (cpi->oxcf.cpu_used < -5)
|
|
|
|
{
|
|
|
|
cpi->oxcf.cpu_used = -5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->oxcf.cpu_used > 5)
|
|
|
|
cpi->oxcf.cpu_used = 5;
|
|
|
|
|
|
|
|
break;
|
2012-02-16 18:02:17 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case MODE_SECONDPASS_BEST:
|
|
|
|
cpi->pass = 2;
|
|
|
|
cpi->compressor_speed = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q];
|
|
|
|
cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q];
|
2011-01-17 18:23:11 +01:00
|
|
|
cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-25 00:27:59 +01:00
|
|
|
cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->ref_frame_flags = VP8_ALT_FLAG | VP8_GOLD_FLAG | VP8_LAST_FLAG;
|
|
|
|
|
|
|
|
//cpi->use_golden_frame_only = 0;
|
|
|
|
//cpi->use_last_frame_only = 0;
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cm->refresh_last_frame = 1;
|
|
|
|
cm->refresh_entropy_probs = 1;
|
|
|
|
|
|
|
|
setup_features(cpi);
|
2012-02-16 18:29:54 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
2012-02-27 19:22:38 +01:00
|
|
|
cpi->mb.e_mbd.allow_high_precision_mv = 0; // Default mv precision adaptation
|
2012-02-16 18:29:54 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++)
|
|
|
|
cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At the moment the first order values may not be > MAXQ
|
|
|
|
if (cpi->oxcf.fixed_q > MAXQ)
|
|
|
|
cpi->oxcf.fixed_q = MAXQ;
|
|
|
|
|
|
|
|
// local file playback mode == really big buffer
|
|
|
|
if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK)
|
|
|
|
{
|
2010-08-20 17:04:10 +02:00
|
|
|
cpi->oxcf.starting_buffer_level = 60000;
|
|
|
|
cpi->oxcf.optimal_buffer_level = 60000;
|
|
|
|
cpi->oxcf.maximum_buffer_size = 240000;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert target bandwidth from Kbit/s to Bit/s
|
|
|
|
cpi->oxcf.target_bandwidth *= 1000;
|
|
|
|
|
2011-04-19 20:05:27 +02:00
|
|
|
cpi->oxcf.starting_buffer_level =
|
|
|
|
rescale(cpi->oxcf.starting_buffer_level,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
// Set or reset optimal and maximum buffer levels.
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->oxcf.optimal_buffer_level == 0)
|
|
|
|
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
|
|
|
|
else
|
2010-08-20 17:04:10 +02:00
|
|
|
cpi->oxcf.optimal_buffer_level =
|
|
|
|
rescale(cpi->oxcf.optimal_buffer_level,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->oxcf.maximum_buffer_size == 0)
|
|
|
|
cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
|
|
|
|
else
|
2010-08-20 17:04:10 +02:00
|
|
|
cpi->oxcf.maximum_buffer_size =
|
|
|
|
rescale(cpi->oxcf.maximum_buffer_size,
|
|
|
|
cpi->oxcf.target_bandwidth, 1000);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
// Set up frame rate and related parameters rate control values.
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_new_frame_rate(cpi, cpi->oxcf.frame_rate);
|
2011-03-10 17:11:39 +01:00
|
|
|
|
|
|
|
// Set absolute upper and lower quality limits
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->worst_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->best_quality = cpi->oxcf.best_allowed_q;
|
|
|
|
|
2011-03-02 00:07:47 +01:00
|
|
|
// active values should only be modified if out of new range
|
|
|
|
if (cpi->active_worst_quality > cpi->oxcf.worst_allowed_q)
|
|
|
|
{
|
|
|
|
cpi->active_worst_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
}
|
|
|
|
// less likely
|
|
|
|
else if (cpi->active_worst_quality < cpi->oxcf.best_allowed_q)
|
|
|
|
{
|
|
|
|
cpi->active_worst_quality = cpi->oxcf.best_allowed_q;
|
|
|
|
}
|
|
|
|
if (cpi->active_best_quality < cpi->oxcf.best_allowed_q)
|
|
|
|
{
|
|
|
|
cpi->active_best_quality = cpi->oxcf.best_allowed_q;
|
|
|
|
}
|
|
|
|
// less likely
|
|
|
|
else if (cpi->active_best_quality > cpi->oxcf.worst_allowed_q)
|
|
|
|
{
|
|
|
|
cpi->active_best_quality = cpi->oxcf.worst_allowed_q;
|
|
|
|
}
|
2011-01-07 19:29:37 +01:00
|
|
|
|
2011-03-02 00:07:47 +01:00
|
|
|
cpi->buffered_mode = (cpi->oxcf.optimal_buffer_level > 0) ? TRUE : FALSE;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-02 00:07:47 +01:00
|
|
|
cpi->cq_target_quality = cpi->oxcf.cq_level;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (!cm->use_bilinear_mc_filter)
|
2012-03-19 15:53:05 +01:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
|
|
|
cm->mcomp_filter_type = EIGHTTAP;
|
|
|
|
#else
|
2010-05-18 17:58:33 +02:00
|
|
|
cm->mcomp_filter_type = SIXTAP;
|
2012-03-19 15:53:05 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
cm->mcomp_filter_type = BILINEAR;
|
|
|
|
|
|
|
|
cpi->target_bandwidth = cpi->oxcf.target_bandwidth;
|
|
|
|
|
|
|
|
cm->Width = cpi->oxcf.Width ;
|
|
|
|
cm->Height = cpi->oxcf.Height ;
|
|
|
|
|
|
|
|
cm->horiz_scale = cpi->horiz_scale;
|
|
|
|
cm->vert_scale = cpi->vert_scale ;
|
|
|
|
|
|
|
|
// VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs)
|
|
|
|
if (cpi->oxcf.Sharpness > 7)
|
|
|
|
cpi->oxcf.Sharpness = 7;
|
|
|
|
|
|
|
|
cm->sharpness_level = cpi->oxcf.Sharpness;
|
|
|
|
|
|
|
|
if (cm->horiz_scale != NORMAL || cm->vert_scale != NORMAL)
|
|
|
|
{
|
|
|
|
int UNINITIALIZED_IS_SAFE(hr), UNINITIALIZED_IS_SAFE(hs);
|
|
|
|
int UNINITIALIZED_IS_SAFE(vr), UNINITIALIZED_IS_SAFE(vs);
|
|
|
|
|
|
|
|
Scale2Ratio(cm->horiz_scale, &hr, &hs);
|
|
|
|
Scale2Ratio(cm->vert_scale, &vr, &vs);
|
|
|
|
|
|
|
|
// always go to the next whole number
|
|
|
|
cm->Width = (hs - 1 + cpi->oxcf.Width * hr) / hs;
|
|
|
|
cm->Height = (vs - 1 + cpi->oxcf.Height * vr) / vs;
|
|
|
|
}
|
|
|
|
|
2011-03-10 17:11:39 +01:00
|
|
|
if (((cm->Width + 15) & 0xfffffff0) !=
|
|
|
|
cm->yv12_fb[cm->lst_fb_idx].y_width ||
|
|
|
|
((cm->Height + 15) & 0xfffffff0) !=
|
|
|
|
cm->yv12_fb[cm->lst_fb_idx].y_height ||
|
2010-07-22 14:07:32 +02:00
|
|
|
cm->yv12_fb[cm->lst_fb_idx].y_width == 0)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
alloc_raw_frame_buffers(cpi);
|
|
|
|
vp8_alloc_compressor_data(cpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->oxcf.fixed_q >= 0)
|
|
|
|
{
|
|
|
|
cpi->last_q[0] = cpi->oxcf.fixed_q;
|
|
|
|
cpi->last_q[1] = cpi->oxcf.fixed_q;
|
2012-01-11 15:05:57 +01:00
|
|
|
cpi->last_boosted_qindex = cpi->oxcf.fixed_q;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cpi->Speed = cpi->oxcf.cpu_used;
|
|
|
|
|
|
|
|
// force to allowlag to 0 if lag_in_frames is 0;
|
|
|
|
if (cpi->oxcf.lag_in_frames == 0)
|
|
|
|
{
|
|
|
|
cpi->oxcf.allow_lag = 0;
|
|
|
|
}
|
|
|
|
// Limit on lag buffers as these are not currently dynamically allocated
|
|
|
|
else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS)
|
|
|
|
cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS;
|
|
|
|
|
|
|
|
// YX Temp
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->alt_ref_source = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->is_src_frame_alt_ref = 0;
|
2011-05-11 04:57:51 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#if 0
|
|
|
|
// Experimental RD Code
|
|
|
|
cpi->frame_distortion = 0;
|
|
|
|
cpi->last_frame_distortion = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define M_LOG2_E 0.693147180559945309417
|
|
|
|
#define log2f(x) (log (x) / (float) M_LOG2_E)
|
|
|
|
static void cal_mvsadcosts(int *mvsadcost[2])
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
mvsadcost [0] [0] = 300;
|
|
|
|
mvsadcost [1] [0] = 300;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2011-04-01 22:41:58 +02:00
|
|
|
double z = 256 * (2 * (log2f(8 * i) + .6));
|
2010-05-18 17:58:33 +02:00
|
|
|
mvsadcost [0][i] = (int) z;
|
|
|
|
mvsadcost [1][i] = (int) z;
|
|
|
|
mvsadcost [0][-i] = (int) z;
|
|
|
|
mvsadcost [1][-i] = (int) z;
|
|
|
|
}
|
2011-04-01 22:41:58 +02:00
|
|
|
while (++i <= mvfp_max);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
static void cal_mvsadcosts_hp(int *mvsadcost[2])
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
mvsadcost [0] [0] = 300;
|
|
|
|
mvsadcost [1] [0] = 300;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
double z = 256 * (2 * (log2f(8 * i) + .6));
|
|
|
|
mvsadcost [0][i] = (int) z;
|
|
|
|
mvsadcost [1][i] = (int) z;
|
|
|
|
mvsadcost [0][-i] = (int) z;
|
|
|
|
mvsadcost [1][-i] = (int) z;
|
|
|
|
}
|
|
|
|
while (++i <= mvfp_max_hp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
volatile union
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi;
|
|
|
|
VP8_PTR ptr;
|
|
|
|
} ctx;
|
2010-09-01 02:43:14 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
VP8_COMP *cpi;
|
|
|
|
VP8_COMMON *cm;
|
|
|
|
|
|
|
|
cpi = ctx.cpi = vpx_memalign(32, sizeof(VP8_COMP));
|
|
|
|
// Check that the CPI instance is valid
|
|
|
|
if (!cpi)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cm = &cpi->common;
|
|
|
|
|
|
|
|
vpx_memset(cpi, 0, sizeof(VP8_COMP));
|
|
|
|
|
|
|
|
if (setjmp(cm->error.jmp))
|
|
|
|
{
|
|
|
|
VP8_PTR ptr = ctx.ptr;
|
|
|
|
|
|
|
|
ctx.cpi->common.error.setjmp = 0;
|
|
|
|
vp8_remove_compressor(&ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->common.error.setjmp = 1;
|
|
|
|
|
|
|
|
CHECK_MEM_ERROR(cpi->mb.ss, vpx_calloc(sizeof(search_site), (MAX_MVSEARCH_STEPS * 8) + 1));
|
|
|
|
|
|
|
|
vp8_create_common(&cpi->common);
|
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
|
|
|
vp8_cmachine_specific_config(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
init_config((VP8_PTR)cpi, oxcf);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
memcpy(cpi->base_skip_false_prob, vp8cx_base_skip_false_prob, sizeof(vp8cx_base_skip_false_prob));
|
|
|
|
cpi->common.current_video_frame = 0;
|
|
|
|
cpi->kf_overspend_bits = 0;
|
|
|
|
cpi->kf_bitrate_adjustment = 0;
|
|
|
|
cpi->frames_till_gf_update_due = 0;
|
|
|
|
cpi->gf_overspend_bits = 0;
|
|
|
|
cpi->non_gf_bitrate_adjustment = 0;
|
2012-01-28 09:50:33 +01:00
|
|
|
cm->prob_last_coded = 128;
|
|
|
|
cm->prob_gf_coded = 128;
|
|
|
|
cm->prob_intra_coded = 63;
|
2012-02-29 02:25:45 +01:00
|
|
|
for ( i = 0; i < COMP_PRED_CONTEXTS; i++ )
|
|
|
|
cm->prob_comppred[i] = 128;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Prime the recent reference frame useage counters.
|
|
|
|
// Hereafter they will be maintained as a sort of moving average
|
|
|
|
cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
|
|
|
|
|
|
|
|
// Set reference frame sign bias for ALTREF frame to 1 (for now)
|
|
|
|
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
|
|
|
|
|
|
|
|
cpi->baseline_gf_interval = DEFAULT_GF_INTERVAL;
|
|
|
|
|
|
|
|
cpi->gold_is_last = 0 ;
|
|
|
|
cpi->alt_is_last = 0 ;
|
|
|
|
cpi->gold_is_alt = 0 ;
|
|
|
|
|
2010-12-03 17:26:21 +01:00
|
|
|
// allocate memory for storing last frame's MVs for MV prediction.
|
2011-01-25 21:54:34 +01:00
|
|
|
CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int_mv)));
|
|
|
|
CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int)));
|
|
|
|
CHECK_MEM_ERROR(cpi->lf_ref_frame, vpx_calloc((cpi->common.mb_rows+2) * (cpi->common.mb_cols+2), sizeof(int)));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Create the encoder segmentation map and set all entries to 0
|
2010-09-01 02:43:14 +02:00
|
|
|
CHECK_MEM_ERROR(cpi->segmentation_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
|
2011-11-11 19:08:06 +01:00
|
|
|
|
2012-01-28 13:20:14 +01:00
|
|
|
// And a copy in common for temporal coding
|
2012-01-27 19:29:07 +01:00
|
|
|
CHECK_MEM_ERROR(cm->last_frame_seg_map,
|
2011-11-11 19:08:06 +01:00
|
|
|
vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// And a place holder structure is the coding context
|
|
|
|
// for use if we want to save and restore it
|
|
|
|
CHECK_MEM_ERROR(cpi->coding_context.last_frame_seg_map_copy,
|
|
|
|
vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
CHECK_MEM_ERROR(cpi->active_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
|
|
|
|
vpx_memset(cpi->active_map , 1, (cpi->common.mb_rows * cpi->common.mb_cols));
|
|
|
|
cpi->active_map_enabled = 0;
|
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
for (i = 0; i < ( sizeof(cpi->mbgraph_stats) /
|
|
|
|
sizeof(cpi->mbgraph_stats[0]) ); i++)
|
|
|
|
{
|
|
|
|
CHECK_MEM_ERROR(cpi->mbgraph_stats[i].mb_stats,
|
|
|
|
vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols *
|
|
|
|
sizeof(*cpi->mbgraph_stats[i].mb_stats),
|
|
|
|
1));
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifdef ENTROPY_STATS
|
2012-05-08 21:38:39 +02:00
|
|
|
if(cpi->pass != 1)
|
|
|
|
init_context_counters();
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2012-05-15 01:21:01 +02:00
|
|
|
#ifdef MODE_STATS
|
|
|
|
vp8_zero(y_modes);
|
|
|
|
vp8_zero(i8x8_modes);
|
|
|
|
vp8_zero(uv_modes);
|
|
|
|
vp8_zero(uv_modes_y);
|
|
|
|
vp8_zero(b_modes);
|
|
|
|
vp8_zero(inter_y_modes);
|
|
|
|
vp8_zero(inter_uv_modes);
|
|
|
|
vp8_zero(inter_b_modes);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-10-11 23:37:27 +02:00
|
|
|
/*Initialize the feed-forward activity masking.*/
|
|
|
|
cpi->activity_avg = 90<<12;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->frames_since_key = 8; // Give a sensible default for the first frame.
|
|
|
|
cpi->key_frame_frequency = cpi->oxcf.key_freq;
|
2011-01-12 18:08:42 +01:00
|
|
|
cpi->this_key_frame_forced = FALSE;
|
|
|
|
cpi->next_key_frame_forced = FALSE;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->source_alt_ref_pending = FALSE;
|
|
|
|
cpi->source_alt_ref_active = FALSE;
|
|
|
|
cpi->common.refresh_alt_ref_frame = 0;
|
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
|
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->b_calculate_ssimg = 0;
|
|
|
|
|
|
|
|
cpi->count = 0;
|
|
|
|
cpi->bytes = 0;
|
|
|
|
|
|
|
|
if (cpi->b_calculate_psnr)
|
|
|
|
{
|
|
|
|
cpi->total_sq_error = 0.0;
|
|
|
|
cpi->total_sq_error2 = 0.0;
|
|
|
|
cpi->total_y = 0.0;
|
|
|
|
cpi->total_u = 0.0;
|
|
|
|
cpi->total_v = 0.0;
|
|
|
|
cpi->total = 0.0;
|
|
|
|
cpi->totalp_y = 0.0;
|
|
|
|
cpi->totalp_u = 0.0;
|
|
|
|
cpi->totalp_v = 0.0;
|
|
|
|
cpi->totalp = 0.0;
|
|
|
|
cpi->tot_recode_hits = 0;
|
|
|
|
cpi->summed_quality = 0;
|
|
|
|
cpi->summed_weights = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->b_calculate_ssimg)
|
|
|
|
{
|
|
|
|
cpi->total_ssimg_y = 0;
|
|
|
|
cpi->total_ssimg_u = 0;
|
|
|
|
cpi->total_ssimg_v = 0;
|
|
|
|
cpi->total_ssimg_all = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:37:45 +02:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#ifndef LLONG_MAX
|
|
|
|
#define LLONG_MAX 9223372036854775807LL
|
|
|
|
#endif
|
|
|
|
cpi->first_time_stamp_ever = LLONG_MAX;
|
|
|
|
|
|
|
|
cpi->frames_till_gf_update_due = 0;
|
|
|
|
cpi->key_frame_count = 1;
|
|
|
|
|
|
|
|
cpi->ni_av_qi = cpi->oxcf.worst_allowed_q;
|
|
|
|
cpi->ni_tot_qi = 0;
|
|
|
|
cpi->ni_frames = 0;
|
2011-12-06 15:48:52 +01:00
|
|
|
cpi->tot_q = 0.0;
|
|
|
|
cpi->avg_q = vp8_convert_qindex_to_q( cpi->oxcf.worst_allowed_q );
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->total_byte_count = 0;
|
|
|
|
|
|
|
|
cpi->rate_correction_factor = 1.0;
|
|
|
|
cpi->key_frame_rate_correction_factor = 1.0;
|
|
|
|
cpi->gf_rate_correction_factor = 1.0;
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.est_max_qcorrection_factor = 1.0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->mb.mvcost[0] = &cpi->mb.mvcosts[0][mv_max+1];
|
|
|
|
cpi->mb.mvcost[1] = &cpi->mb.mvcosts[1][mv_max+1];
|
2011-04-01 22:41:58 +02:00
|
|
|
cpi->mb.mvsadcost[0] = &cpi->mb.mvsadcosts[0][mvfp_max+1];
|
|
|
|
cpi->mb.mvsadcost[1] = &cpi->mb.mvsadcosts[1][mvfp_max+1];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cal_mvsadcosts(cpi->mb.mvsadcost);
|
|
|
|
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
cpi->mb.mvcost_hp[0] = &cpi->mb.mvcosts_hp[0][mv_max_hp+1];
|
|
|
|
cpi->mb.mvcost_hp[1] = &cpi->mb.mvcosts_hp[1][mv_max_hp+1];
|
|
|
|
cpi->mb.mvsadcost_hp[0] = &cpi->mb.mvsadcosts_hp[0][mvfp_max_hp+1];
|
|
|
|
cpi->mb.mvsadcost_hp[1] = &cpi->mb.mvsadcosts_hp[1][mvfp_max_hp+1];
|
|
|
|
|
|
|
|
cal_mvsadcosts_hp(cpi->mb.mvsadcost_hp);
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
for (i = 0; i < KEY_FRAME_CONTEXT; i++)
|
|
|
|
{
|
|
|
|
cpi->prior_key_frame_distance[i] = (int)cpi->output_frame_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
yuv_file = fopen("bd.yuv", "ab");
|
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
|
|
|
yuv_rec_file = fopen("rec.yuv", "wb");
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
framepsnr = fopen("framepsnr.stt", "a");
|
|
|
|
kf_list = fopen("kf_list.stt", "w");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cpi->output_pkt_list = oxcf->output_pkt_list;
|
|
|
|
|
|
|
|
if (cpi->pass == 1)
|
|
|
|
{
|
|
|
|
vp8_init_first_pass(cpi);
|
|
|
|
}
|
|
|
|
else if (cpi->pass == 2)
|
|
|
|
{
|
2011-03-10 20:32:48 +01:00
|
|
|
size_t packet_sz = sizeof(FIRSTPASS_STATS);
|
2010-10-14 22:40:12 +02:00
|
|
|
int packets = oxcf->two_pass_stats_in.sz / packet_sz;
|
|
|
|
|
2011-06-28 18:29:47 +02:00
|
|
|
cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
|
|
|
|
cpi->twopass.stats_in = cpi->twopass.stats_in_start;
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.stats_in_end = (void*)((char *)cpi->twopass.stats_in
|
2010-10-14 22:40:12 +02:00
|
|
|
+ (packets - 1) * packet_sz);
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_init_second_pass(cpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
vp8_set_speed_features(cpi);
|
|
|
|
|
|
|
|
// Set starting values of RD threshold multipliers (128 = *1)
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
{
|
|
|
|
cpi->rd_thresh_mult[i] = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
init_mv_ref_counts();
|
|
|
|
#endif
|
|
|
|
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_16X16].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x16);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].svf = VARIANCE_INVOKE(&cpi->rtcd.variance, subpixvar16x16);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].svf_halfpix_h = VARIANCE_INVOKE(&cpi->rtcd.variance, halfpixvar16x16_h);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].svf_halfpix_v = VARIANCE_INVOKE(&cpi->rtcd.variance, halfpixvar16x16_v);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].svf_halfpix_hv = VARIANCE_INVOKE(&cpi->rtcd.variance, halfpixvar16x16_hv);
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].sdx3f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x16x3);
|
2010-10-27 14:45:24 +02:00
|
|
|
cpi->fn_ptr[BLOCK_16X16].sdx8f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x16x8);
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_16X16].sdx4df = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x16x4d);
|
|
|
|
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x8);
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x8);
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].svf = VARIANCE_INVOKE(&cpi->rtcd.variance, subpixvar16x8);
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].svf_halfpix_h = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].svf_halfpix_v = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].svf_halfpix_hv = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].sdx3f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x8x3);
|
2010-10-27 14:45:24 +02:00
|
|
|
cpi->fn_ptr[BLOCK_16X8].sdx8f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x8x8);
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_16X8].sdx4df = VARIANCE_INVOKE(&cpi->rtcd.variance, sad16x8x4d);
|
|
|
|
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x16);
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var8x16);
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].svf = VARIANCE_INVOKE(&cpi->rtcd.variance, subpixvar8x16);
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].svf_halfpix_h = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].svf_halfpix_v = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].svf_halfpix_hv = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].sdx3f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x16x3);
|
2010-10-27 14:45:24 +02:00
|
|
|
cpi->fn_ptr[BLOCK_8X16].sdx8f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x16x8);
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_8X16].sdx4df = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x16x4d);
|
|
|
|
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x8);
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var8x8);
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].svf = VARIANCE_INVOKE(&cpi->rtcd.variance, subpixvar8x8);
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].svf_halfpix_h = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].svf_halfpix_v = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].svf_halfpix_hv = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].sdx3f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x8x3);
|
2010-10-27 14:45:24 +02:00
|
|
|
cpi->fn_ptr[BLOCK_8X8].sdx8f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x8x8);
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_8X8].sdx4df = VARIANCE_INVOKE(&cpi->rtcd.variance, sad8x8x4d);
|
|
|
|
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].sdf = VARIANCE_INVOKE(&cpi->rtcd.variance, sad4x4);
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].vf = VARIANCE_INVOKE(&cpi->rtcd.variance, var4x4);
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].svf = VARIANCE_INVOKE(&cpi->rtcd.variance, subpixvar4x4);
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].svf_halfpix_h = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].svf_halfpix_v = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].svf_halfpix_hv = NULL;
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].sdx3f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad4x4x3);
|
2010-10-27 14:45:24 +02:00
|
|
|
cpi->fn_ptr[BLOCK_4X4].sdx8f = VARIANCE_INVOKE(&cpi->rtcd.variance, sad4x4x8);
|
2010-10-26 21:34:16 +02:00
|
|
|
cpi->fn_ptr[BLOCK_4X4].sdx4df = VARIANCE_INVOKE(&cpi->rtcd.variance, sad4x4x4d);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-06-28 15:14:13 +02:00
|
|
|
#if ARCH_X86 || ARCH_X86_64
|
|
|
|
cpi->fn_ptr[BLOCK_16X16].copymem = VARIANCE_INVOKE(&cpi->rtcd.variance, copy32xn);
|
|
|
|
cpi->fn_ptr[BLOCK_16X8].copymem = VARIANCE_INVOKE(&cpi->rtcd.variance, copy32xn);
|
|
|
|
cpi->fn_ptr[BLOCK_8X16].copymem = VARIANCE_INVOKE(&cpi->rtcd.variance, copy32xn);
|
|
|
|
cpi->fn_ptr[BLOCK_8X8].copymem = VARIANCE_INVOKE(&cpi->rtcd.variance, copy32xn);
|
|
|
|
cpi->fn_ptr[BLOCK_4X4].copymem = VARIANCE_INVOKE(&cpi->rtcd.variance, copy32xn);
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->full_search_sad = SEARCH_INVOKE(&cpi->rtcd.search, full_search);
|
|
|
|
cpi->diamond_search_sad = SEARCH_INVOKE(&cpi->rtcd.search, diamond_search);
|
2011-05-06 18:51:31 +02:00
|
|
|
cpi->refining_search_sad = SEARCH_INVOKE(&cpi->rtcd.search, refining_search);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// make sure frame 1 is okay
|
|
|
|
cpi->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 called later
|
|
|
|
//when needed. This will avoid unnecessary calls of vp8cx_init_quantizer() for every frame.
|
|
|
|
vp8cx_init_quantizer(cpi);
|
2011-07-20 21:53:42 +02:00
|
|
|
|
|
|
|
vp8_loop_filter_init(cm);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->common.error.setjmp = 0;
|
2011-12-08 20:43:09 +01:00
|
|
|
|
|
|
|
vp8_zero(cpi->y_uv_mode_count)
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
return (VP8_PTR) cpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8_remove_compressor(VP8_PTR *ptr)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(*ptr);
|
2011-10-05 12:26:00 +02:00
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (!cpi)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cpi && (cpi->common.current_video_frame > 0))
|
|
|
|
{
|
|
|
|
if (cpi->pass == 2)
|
|
|
|
{
|
|
|
|
vp8_end_second_pass(cpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
2012-05-08 21:38:39 +02:00
|
|
|
if(cpi->pass != 1)
|
|
|
|
{
|
2010-05-18 17:58:33 +02:00
|
|
|
print_context_counters();
|
|
|
|
print_tree_update_probs();
|
|
|
|
print_mode_context();
|
2012-05-08 21:38:39 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-05 20:22:06 +01:00
|
|
|
vp8_clear_system_state();
|
2012-02-29 02:11:12 +01:00
|
|
|
|
2012-03-19 19:02:04 +01:00
|
|
|
//printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->pass != 1)
|
|
|
|
{
|
|
|
|
FILE *f = fopen("opsnr.stt", "a");
|
2011-04-13 20:00:18 +02:00
|
|
|
double time_encoded = (cpi->last_end_time_stamp_seen
|
|
|
|
- cpi->first_time_stamp_ever) / 10000000.000;
|
2010-05-18 17:58:33 +02:00
|
|
|
double total_encode_time = (cpi->time_receive_data + cpi->time_compress_data) / 1000.000;
|
|
|
|
double dr = (double)cpi->bytes * (double) 8 / (double)1000 / time_encoded;
|
2012-02-03 16:10:44 +01:00
|
|
|
#if defined(MODE_STATS)
|
2011-12-08 20:43:09 +01:00
|
|
|
print_mode_contexts(&cpi->common);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->b_calculate_psnr)
|
|
|
|
{
|
2010-07-22 14:07:32 +02:00
|
|
|
YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
|
|
|
|
double samples = 3.0 / 2 * cpi->count * lst_yv12->y_width * lst_yv12->y_height;
|
2010-05-18 17:58:33 +02:00
|
|
|
double total_psnr = vp8_mse2psnr(samples, 255.0, cpi->total_sq_error);
|
|
|
|
double total_psnr2 = vp8_mse2psnr(samples, 255.0, cpi->total_sq_error2);
|
|
|
|
double total_ssim = 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0);
|
|
|
|
|
2010-05-27 19:32:40 +02:00
|
|
|
fprintf(f, "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\tVPXSSIM\t Time(us)\n");
|
2011-04-14 00:06:17 +02:00
|
|
|
fprintf(f, "%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f\n",
|
2010-05-18 17:58:33 +02:00
|
|
|
dr, cpi->total / cpi->count, total_psnr, cpi->totalp / cpi->count, total_psnr2, total_ssim,
|
|
|
|
total_encode_time);
|
2012-01-11 15:05:57 +01:00
|
|
|
// fprintf(f, "%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f %10ld\n",
|
|
|
|
// dr, cpi->total / cpi->count, total_psnr, cpi->totalp / cpi->count, total_psnr2, total_ssim,
|
|
|
|
// total_encode_time, cpi->tot_recode_hits);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->b_calculate_ssimg)
|
|
|
|
{
|
|
|
|
fprintf(f, "BitRate\tSSIM_Y\tSSIM_U\tSSIM_V\tSSIM_A\t Time(us)\n");
|
|
|
|
fprintf(f, "%7.3f\t%6.4f\t%6.4f\t%6.4f\t%6.4f\t%8.0f\n", dr,
|
|
|
|
cpi->total_ssimg_y / cpi->count, cpi->total_ssimg_u / cpi->count,
|
|
|
|
cpi->total_ssimg_v / cpi->count, cpi->total_ssimg_all / cpi->count, total_encode_time);
|
2012-01-11 15:05:57 +01:00
|
|
|
// fprintf(f, "%7.3f\t%6.4f\t%6.4f\t%6.4f\t%6.4f\t%8.0f %10ld\n", dr,
|
|
|
|
// cpi->total_ssimg_y / cpi->count, cpi->total_ssimg_u / cpi->count,
|
|
|
|
// cpi->total_ssimg_v / cpi->count, cpi->total_ssimg_all / cpi->count, total_encode_time, cpi->tot_recode_hits);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MODE_STATS
|
|
|
|
{
|
|
|
|
extern int count_mb_seg[4];
|
2011-08-05 01:30:27 +02:00
|
|
|
char modes_stats_file[250];
|
2011-11-16 01:16:30 +01:00
|
|
|
FILE *f;
|
2011-02-14 23:18:18 +01:00
|
|
|
double dr = (double)cpi->oxcf.frame_rate * (double)cpi->bytes * (double)8 / (double)cpi->count / (double)1000 ;
|
2011-08-05 01:30:27 +02:00
|
|
|
sprintf(modes_stats_file, "modes_q%03d.stt",cpi->common.base_qindex);
|
|
|
|
f = fopen(modes_stats_file, "w");
|
2010-05-18 17:58:33 +02:00
|
|
|
fprintf(f, "intra_mode in Intra Frames:\n");
|
2011-08-05 01:30:27 +02:00
|
|
|
{
|
|
|
|
int i;
|
2012-05-15 01:21:01 +02:00
|
|
|
fprintf(f, "Y: ");
|
|
|
|
for (i=0;i<VP8_YMODES;i++) fprintf(f, " %8d,", y_modes[i]);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(f, "I8: ");
|
|
|
|
for (i=0;i<VP8_I8X8_MODES;i++) fprintf(f, " %8d,", i8x8_modes[i]);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(f, "UV: ");
|
|
|
|
for (i=0;i<VP8_UV_MODES;i++) fprintf(f, " %8d,", uv_modes[i]);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
fprintf(f, "KeyFrame Y-UV:\n");
|
2011-08-05 01:30:27 +02:00
|
|
|
for(i=0;i<VP8_YMODES;i++)
|
|
|
|
{
|
2012-05-15 01:21:01 +02:00
|
|
|
fprintf(f, "%2d:", i);
|
|
|
|
for (j=0; j<VP8_UV_MODES;j++) fprintf(f, "%8d, ",uv_modes_y[i][j]);
|
|
|
|
fprintf(f, "\n");
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-08 20:43:09 +01:00
|
|
|
{
|
2012-05-15 01:21:01 +02:00
|
|
|
int i, j;
|
|
|
|
fprintf(f, "Inter Y-UV:\n");
|
2011-12-08 20:43:09 +01:00
|
|
|
for(i=0;i<VP8_YMODES;i++)
|
|
|
|
{
|
2012-05-15 01:21:01 +02:00
|
|
|
fprintf(f, "%2d:", i);
|
|
|
|
for (j=0; j<VP8_UV_MODES;j++) fprintf(f, "%8d, ",cpi->y_uv_mode_count[i][j]);
|
|
|
|
fprintf(f, "\n");
|
2011-12-08 20:43:09 +01:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-05-15 01:21:01 +02:00
|
|
|
fprintf(f, "B: ");
|
|
|
|
for (i = 0; i < VP8_BINTRAMODES; i++)
|
2010-05-18 17:58:33 +02:00
|
|
|
fprintf(f, "%8d, ", b_modes[i]);
|
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "Modes in Inter Frames:\n");
|
|
|
|
{
|
|
|
|
int i;
|
2012-05-15 01:21:01 +02:00
|
|
|
fprintf(f, "Y: ");
|
|
|
|
for (i=0;i<MB_MODE_COUNT;i++) fprintf(f, " %8d,", inter_y_modes[i]);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(f, "UV: ");
|
|
|
|
for (i=0;i<VP8_UV_MODES;i++) fprintf(f, " %8d,", inter_uv_modes[i]);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fprintf(f, "B: ");
|
|
|
|
for (i = 0; i < B_MODE_COUNT; i++) fprintf(f, "%8d, ", inter_b_modes[i]);
|
2010-05-18 17:58:33 +02:00
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
fprintf(f, "P:%8d, %8d, %8d, %8d\n", count_mb_seg[0], count_mb_seg[1], count_mb_seg[2], count_mb_seg[3]);
|
|
|
|
fprintf(f, "PB:%8d, %8d, %8d, %8d\n", inter_b_modes[LEFT4X4], inter_b_modes[ABOVE4X4], inter_b_modes[ZERO4X4], inter_b_modes[NEW4X4]);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
FILE *fmode = fopen("modecontext.c", "w");
|
|
|
|
|
|
|
|
fprintf(fmode, "\n#include \"entropymode.h\"\n\n");
|
|
|
|
fprintf(fmode, "const unsigned int vp8_kf_default_bmode_counts ");
|
|
|
|
fprintf(fmode, "[VP8_BINTRAMODES] [VP8_BINTRAMODES] [VP8_BINTRAMODES] =\n{\n");
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(fmode, " { //Above Mode : %d\n", i);
|
|
|
|
|
|
|
|
for (j = 0; j < 10; j++)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(fmode, " {");
|
|
|
|
|
2012-05-15 01:21:01 +02:00
|
|
|
for (k = 0; k < VP8_BINTRAMODES; k++)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
if (!intra_mode_stats[i][j][k])
|
|
|
|
fprintf(fmode, " %5d, ", 1);
|
|
|
|
else
|
|
|
|
fprintf(fmode, " %5d, ", intra_mode_stats[i][j][k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fmode, "}, // left_mode %d\n", j);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fmode, " },\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fmode, "};\n");
|
2010-10-25 19:14:11 +02:00
|
|
|
fclose(fmode);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(SECTIONBITS_OUTPUT)
|
|
|
|
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FILE *f = fopen("tokenbits.stt", "a");
|
|
|
|
|
|
|
|
for (i = 0; i < 28; i++)
|
|
|
|
fprintf(f, "%8d", (int)(Sectionbits[i] / 256));
|
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000);
|
|
|
|
printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
|
|
|
|
printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->time_receive_data / 1000, cpi->time_encode_mb_row / 1000, cpi->time_compress_data / 1000, (cpi->time_receive_data + cpi->time_compress_data) / 1000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
dealloc_compressor_data(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
vpx_free(cpi->mb.ss);
|
|
|
|
vpx_free(cpi->tok);
|
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); i++)
|
|
|
|
{
|
|
|
|
vpx_free(cpi->mbgraph_stats[i].mb_stats);
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_remove_common(&cpi->common);
|
|
|
|
vpx_free(cpi);
|
|
|
|
*ptr = 0;
|
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
fclose(yuv_file);
|
|
|
|
#endif
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
|
|
|
fclose(yuv_rec_file);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
if (keyfile)
|
|
|
|
fclose(keyfile);
|
|
|
|
|
|
|
|
if (framepsnr)
|
|
|
|
fclose(framepsnr);
|
|
|
|
|
|
|
|
if (kf_list)
|
|
|
|
fclose(kf_list);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint64_t calc_plane_error(unsigned char *orig, int orig_stride,
|
|
|
|
unsigned char *recon, int recon_stride,
|
|
|
|
unsigned int cols, unsigned int rows,
|
|
|
|
vp8_variance_rtcd_vtable_t *rtcd)
|
|
|
|
{
|
|
|
|
unsigned int row, col;
|
|
|
|
uint64_t total_sse = 0;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
for (row = 0; row + 16 <= rows; row += 16)
|
|
|
|
{
|
|
|
|
for (col = 0; col + 16 <= cols; col += 16)
|
|
|
|
{
|
|
|
|
unsigned int sse;
|
|
|
|
|
|
|
|
VARIANCE_INVOKE(rtcd, mse16x16)(orig + col, orig_stride,
|
|
|
|
recon + col, recon_stride,
|
|
|
|
&sse);
|
|
|
|
total_sse += sse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle odd-sized width */
|
|
|
|
if (col < cols)
|
|
|
|
{
|
|
|
|
unsigned int border_row, border_col;
|
|
|
|
unsigned char *border_orig = orig;
|
|
|
|
unsigned char *border_recon = recon;
|
|
|
|
|
|
|
|
for (border_row = 0; border_row < 16; border_row++)
|
|
|
|
{
|
|
|
|
for (border_col = col; border_col < cols; border_col++)
|
|
|
|
{
|
|
|
|
diff = border_orig[border_col] - border_recon[border_col];
|
|
|
|
total_sse += diff * diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
border_orig += orig_stride;
|
|
|
|
border_recon += recon_stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
orig += orig_stride * 16;
|
|
|
|
recon += recon_stride * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle odd-sized height */
|
|
|
|
for (; row < rows; row++)
|
|
|
|
{
|
|
|
|
for (col = 0; col < cols; col++)
|
|
|
|
{
|
|
|
|
diff = orig[col] - recon[col];
|
|
|
|
total_sse += diff * diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
orig += orig_stride;
|
|
|
|
recon += recon_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total_sse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void generate_psnr_packet(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *orig = cpi->Source;
|
|
|
|
YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
|
|
|
|
struct vpx_codec_cx_pkt pkt;
|
|
|
|
uint64_t sse;
|
|
|
|
int i;
|
|
|
|
unsigned int width = cpi->common.Width;
|
|
|
|
unsigned int height = cpi->common.Height;
|
|
|
|
|
|
|
|
pkt.kind = VPX_CODEC_PSNR_PKT;
|
|
|
|
sse = calc_plane_error(orig->y_buffer, orig->y_stride,
|
|
|
|
recon->y_buffer, recon->y_stride,
|
|
|
|
width, height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
pkt.data.psnr.sse[0] = sse;
|
|
|
|
pkt.data.psnr.sse[1] = sse;
|
|
|
|
pkt.data.psnr.samples[0] = width * height;
|
|
|
|
pkt.data.psnr.samples[1] = width * height;
|
|
|
|
|
|
|
|
width = (width + 1) / 2;
|
|
|
|
height = (height + 1) / 2;
|
|
|
|
|
|
|
|
sse = calc_plane_error(orig->u_buffer, orig->uv_stride,
|
|
|
|
recon->u_buffer, recon->uv_stride,
|
|
|
|
width, height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
pkt.data.psnr.sse[0] += sse;
|
|
|
|
pkt.data.psnr.sse[2] = sse;
|
|
|
|
pkt.data.psnr.samples[0] += width * height;
|
|
|
|
pkt.data.psnr.samples[2] = width * height;
|
|
|
|
|
|
|
|
sse = calc_plane_error(orig->v_buffer, orig->uv_stride,
|
|
|
|
recon->v_buffer, recon->uv_stride,
|
|
|
|
width, height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
pkt.data.psnr.sse[0] += sse;
|
|
|
|
pkt.data.psnr.sse[3] = sse;
|
|
|
|
pkt.data.psnr.samples[0] += width * height;
|
|
|
|
pkt.data.psnr.samples[3] = width * height;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
pkt.data.psnr.psnr[i] = vp8_mse2psnr(pkt.data.psnr.samples[i], 255.0,
|
|
|
|
pkt.data.psnr.sse[i]);
|
|
|
|
|
|
|
|
vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int vp8_use_as_reference(VP8_PTR ptr, int ref_frame_flags)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
|
|
|
|
if (ref_frame_flags > 7)
|
|
|
|
return -1 ;
|
|
|
|
|
|
|
|
cpi->ref_frame_flags = ref_frame_flags;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int vp8_update_reference(VP8_PTR ptr, int ref_frame_flags)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
|
|
|
|
if (ref_frame_flags > 7)
|
|
|
|
return -1 ;
|
|
|
|
|
|
|
|
cpi->common.refresh_golden_frame = 0;
|
|
|
|
cpi->common.refresh_alt_ref_frame = 0;
|
|
|
|
cpi->common.refresh_last_frame = 0;
|
|
|
|
|
|
|
|
if (ref_frame_flags & VP8_LAST_FLAG)
|
|
|
|
cpi->common.refresh_last_frame = 1;
|
|
|
|
|
|
|
|
if (ref_frame_flags & VP8_GOLD_FLAG)
|
|
|
|
cpi->common.refresh_golden_frame = 1;
|
|
|
|
|
|
|
|
if (ref_frame_flags & VP8_ALT_FLAG)
|
|
|
|
cpi->common.refresh_alt_ref_frame = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_get_reference(VP8_PTR ptr, VP8_REFFRAME ref_frame_flag, YV12_BUFFER_CONFIG *sd)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
2010-07-22 14:07:32 +02:00
|
|
|
int ref_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (ref_frame_flag == VP8_LAST_FLAG)
|
2010-07-22 14:07:32 +02:00
|
|
|
ref_fb_idx = cm->lst_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else if (ref_frame_flag == VP8_GOLD_FLAG)
|
2010-07-22 14:07:32 +02:00
|
|
|
ref_fb_idx = cm->gld_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else if (ref_frame_flag == VP8_ALT_FLAG)
|
2010-07-22 14:07:32 +02:00
|
|
|
ref_fb_idx = cm->alt_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
2010-07-22 14:07:32 +02:00
|
|
|
vp8_yv12_copy_frame_ptr(&cm->yv12_fb[ref_fb_idx], sd);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int vp8_set_reference(VP8_PTR ptr, VP8_REFFRAME ref_frame_flag, YV12_BUFFER_CONFIG *sd)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *)(ptr);
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
2010-07-22 14:07:32 +02:00
|
|
|
int ref_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-07-22 14:07:32 +02:00
|
|
|
if (ref_frame_flag == VP8_LAST_FLAG)
|
|
|
|
ref_fb_idx = cm->lst_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else if (ref_frame_flag == VP8_GOLD_FLAG)
|
2010-07-22 14:07:32 +02:00
|
|
|
ref_fb_idx = cm->gld_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else if (ref_frame_flag == VP8_ALT_FLAG)
|
2010-07-22 14:07:32 +02:00
|
|
|
ref_fb_idx = cm->alt_fb_idx;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
2010-07-22 14:07:32 +02:00
|
|
|
vp8_yv12_copy_frame_ptr(sd, &cm->yv12_fb[ref_fb_idx]);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int vp8_update_entropy(VP8_PTR comp, int update)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) comp;
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
cm->refresh_entropy_probs = update;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-24 17:10:25 +02:00
|
|
|
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
void vp8_write_yuv_frame(YV12_BUFFER_CONFIG *s)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
unsigned char *src = s->y_buffer;
|
|
|
|
int h = s->y_height;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->y_width, 1, yuv_file);
|
|
|
|
src += s->y_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
|
|
|
|
|
|
|
src = s->u_buffer;
|
|
|
|
h = s->uv_height;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
|
|
|
|
|
|
|
src = s->v_buffer;
|
|
|
|
h = s->uv_height;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
2011-02-14 23:18:18 +01:00
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-14 23:18:18 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
|
|
|
void vp8_write_yuv_rec_frame(VP8_COMMON *cm)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *s = cm->frame_to_show;
|
|
|
|
unsigned char *src = s->y_buffer;
|
|
|
|
int h = cm->Height;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->y_width, 1, yuv_rec_file);
|
|
|
|
src += s->y_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
|
|
|
|
|
|
|
src = s->u_buffer;
|
|
|
|
h = (cm->Height+1)/2;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_rec_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
|
|
|
|
|
|
|
src = s->v_buffer;
|
|
|
|
h = (cm->Height+1)/2;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fwrite(src, s->uv_width, 1, yuv_rec_file);
|
|
|
|
src += s->uv_stride;
|
|
|
|
}
|
|
|
|
while (--h);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2010-09-24 17:10:25 +02:00
|
|
|
#endif
|
|
|
|
|
2011-04-20 14:12:23 +02:00
|
|
|
static void update_alt_ref_frame_stats(VP8_COMP *cpi)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
// Update data structure that monitors level of reference to last GF
|
2010-08-11 17:02:31 +02:00
|
|
|
vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
|
|
|
|
cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-10 10:14:10 +01:00
|
|
|
// this frame refreshes means next frames don't unless specified by user
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->common.frames_since_golden = 0;
|
|
|
|
|
|
|
|
// Clear the alternate reference update pending flag.
|
|
|
|
cpi->source_alt_ref_pending = FALSE;
|
|
|
|
|
|
|
|
// Set the alternate refernce frame active flag
|
|
|
|
cpi->source_alt_ref_active = TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
static void update_golden_frame_stats(VP8_COMP *cpi)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
2011-04-20 14:12:23 +02:00
|
|
|
// Update the Golden frame usage counts.
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cm->refresh_golden_frame)
|
|
|
|
{
|
|
|
|
// Update data structure that monitors level of reference to last GF
|
2010-08-11 17:02:31 +02:00
|
|
|
vpx_memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols));
|
|
|
|
cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// this frame refreshes means next frames don't unless specified by user
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cpi->common.frames_since_golden = 0;
|
|
|
|
|
|
|
|
//if ( cm->frame_type == KEY_FRAME )
|
|
|
|
//{
|
|
|
|
cpi->recent_ref_frame_usage[INTRA_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[LAST_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[GOLDEN_FRAME] = 1;
|
|
|
|
cpi->recent_ref_frame_usage[ALTREF_FRAME] = 1;
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// // Carry a potrtion of count over to begining of next gf sequence
|
|
|
|
// cpi->recent_ref_frame_usage[INTRA_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[LAST_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[GOLDEN_FRAME] >>= 5;
|
|
|
|
// cpi->recent_ref_frame_usage[ALTREF_FRAME] >>= 5;
|
|
|
|
//}
|
|
|
|
|
|
|
|
// ******** Fixed Q test code only ************
|
|
|
|
// If we are going to use the ALT reference for the next group of frames set a flag to say so.
|
|
|
|
if (cpi->oxcf.fixed_q >= 0 &&
|
|
|
|
cpi->oxcf.play_alternate && !cpi->common.refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
cpi->source_alt_ref_pending = TRUE;
|
|
|
|
cpi->frames_till_gf_update_due = cpi->baseline_gf_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpi->source_alt_ref_pending)
|
|
|
|
cpi->source_alt_ref_active = FALSE;
|
|
|
|
|
|
|
|
// Decrement count down till next gf
|
|
|
|
if (cpi->frames_till_gf_update_due > 0)
|
|
|
|
cpi->frames_till_gf_update_due--;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (!cpi->common.refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
// Decrement count down till next gf
|
|
|
|
if (cpi->frames_till_gf_update_due > 0)
|
|
|
|
cpi->frames_till_gf_update_due--;
|
|
|
|
|
|
|
|
if (cpi->common.frames_till_alt_ref_frame)
|
|
|
|
cpi->common.frames_till_alt_ref_frame --;
|
|
|
|
|
|
|
|
cpi->common.frames_since_golden ++;
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 15:57:21 +01:00
|
|
|
int find_fp_qindex()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < QINDEX_RANGE; i++ )
|
|
|
|
{
|
|
|
|
if ( vp8_convert_qindex_to_q(i) >= 30.0 )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 00:50:14 +01:00
|
|
|
|
2011-12-02 15:57:21 +01:00
|
|
|
if ( i == QINDEX_RANGE )
|
|
|
|
i--;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags)
|
|
|
|
{
|
|
|
|
(void) size;
|
|
|
|
(void) dest;
|
|
|
|
(void) frame_flags;
|
2011-12-02 15:57:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
vp8_set_quantizer(cpi, find_fp_qindex());
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_first_pass(cpi);
|
|
|
|
}
|
2012-04-07 01:38:34 +02:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
void write_yuv_frame_to_file(YV12_BUFFER_CONFIG *frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
// write the frame
|
|
|
|
int i;
|
|
|
|
FILE *fp = fopen("encode_recon.yuv", "a");
|
|
|
|
|
|
|
|
for (i = 0; i < frame->y_height; i++)
|
|
|
|
fwrite(frame->y_buffer + i * frame->y_stride,
|
|
|
|
frame->y_width, 1, fp);
|
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
|
|
|
fwrite(frame->u_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, fp);
|
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
|
|
|
fwrite(frame->v_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 01:36:46 +01:00
|
|
|
//#define WRITE_RECON_BUFFER 1
|
2011-11-16 01:16:30 +01:00
|
|
|
#if WRITE_RECON_BUFFER
|
2010-05-18 17:58:33 +02:00
|
|
|
void write_cx_frame_to_file(YV12_BUFFER_CONFIG *frame, int this_frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
// write the frame
|
|
|
|
FILE *yframe;
|
|
|
|
int i;
|
|
|
|
char filename[255];
|
|
|
|
|
|
|
|
sprintf(filename, "cx\\y%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
|
|
|
|
|
|
|
for (i = 0; i < frame->y_height; i++)
|
2011-12-01 01:36:46 +01:00
|
|
|
fwrite(frame->y_buffer + i * frame->y_stride,
|
|
|
|
frame->y_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
fclose(yframe);
|
|
|
|
sprintf(filename, "cx\\u%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
|
|
|
|
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
2011-12-01 01:36:46 +01:00
|
|
|
fwrite(frame->u_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
fclose(yframe);
|
|
|
|
sprintf(filename, "cx\\v%04d.raw", this_frame);
|
|
|
|
yframe = fopen(filename, "wb");
|
|
|
|
|
|
|
|
for (i = 0; i < frame->uv_height; i++)
|
2011-12-01 01:36:46 +01:00
|
|
|
fwrite(frame->v_buffer + i * frame->uv_stride,
|
|
|
|
frame->uv_width, 1, yframe);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
fclose(yframe);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-19 15:53:05 +01:00
|
|
|
static double compute_edge_pixel_proportion(YV12_BUFFER_CONFIG *frame)
|
|
|
|
{
|
|
|
|
#define EDGE_THRESH 128
|
|
|
|
int i, j;
|
|
|
|
int num_edge_pels = 0;
|
|
|
|
int num_pels = (frame->y_height - 2) * (frame->y_width - 2);
|
|
|
|
unsigned char *prev = frame->y_buffer + 1;
|
|
|
|
unsigned char *curr = frame->y_buffer + 1 + frame->y_stride;
|
|
|
|
unsigned char *next = frame->y_buffer + 1 + 2*frame->y_stride;
|
|
|
|
for (i = 1; i < frame->y_height - 1; i++)
|
|
|
|
{
|
|
|
|
for (j = 1; j < frame->y_width - 1; j++)
|
|
|
|
{
|
|
|
|
/* Sobel hor and ver gradients */
|
|
|
|
int v = 2*(curr[1] - curr[-1]) + (prev[1] - prev[-1]) + (next[1] - next[-1]);
|
|
|
|
int h = 2*(prev[0] - next[0]) + (prev[1] - next[1]) + (prev[-1] - next[-1]);
|
|
|
|
h = (h < 0 ? -h : h);
|
|
|
|
v = (v < 0 ? -v : v);
|
|
|
|
if (h > EDGE_THRESH || v > EDGE_THRESH) num_edge_pels++;
|
|
|
|
curr++;
|
|
|
|
prev++;
|
|
|
|
next++;
|
|
|
|
}
|
|
|
|
curr += frame->y_stride - frame->y_width + 2;
|
|
|
|
prev += frame->y_stride - frame->y_width + 2;
|
|
|
|
next += frame->y_stride - frame->y_width + 2;
|
|
|
|
}
|
|
|
|
return (double)num_edge_pels/(double)num_pels;
|
|
|
|
}
|
|
|
|
|
2012-04-07 01:38:34 +02:00
|
|
|
// Function to test for conditions that indicate we should loop
|
2010-11-17 16:12:04 +01:00
|
|
|
// back and recode a frame.
|
|
|
|
static BOOL recode_loop_test( VP8_COMP *cpi,
|
|
|
|
int high_limit, int low_limit,
|
|
|
|
int q, int maxq, int minq )
|
|
|
|
{
|
|
|
|
BOOL force_recode = FALSE;
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
|
|
|
|
// Is frame recode allowed at all
|
|
|
|
// Yes if either recode mode 1 is selected or mode two is selcted
|
|
|
|
// and the frame is a key frame. golden frame or alt_ref_frame
|
|
|
|
if ( (cpi->sf.recode_loop == 1) ||
|
|
|
|
( (cpi->sf.recode_loop == 2) &&
|
|
|
|
( (cm->frame_type == KEY_FRAME) ||
|
|
|
|
cm->refresh_golden_frame ||
|
|
|
|
cm->refresh_alt_ref_frame ) ) )
|
|
|
|
{
|
|
|
|
// General over and under shoot tests
|
|
|
|
if ( ((cpi->projected_frame_size > high_limit) && (q < maxq)) ||
|
2011-01-14 12:34:53 +01:00
|
|
|
((cpi->projected_frame_size < low_limit) && (q > minq)) )
|
2010-11-17 16:12:04 +01:00
|
|
|
{
|
|
|
|
force_recode = TRUE;
|
|
|
|
}
|
2011-01-14 12:34:53 +01:00
|
|
|
// Special Constrained quality tests
|
|
|
|
else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY)
|
|
|
|
{
|
|
|
|
// Undershoot and below auto cq level
|
|
|
|
if ( (q > cpi->cq_target_quality) &&
|
|
|
|
(cpi->projected_frame_size <
|
|
|
|
((cpi->this_frame_target * 7) >> 3)))
|
|
|
|
{
|
|
|
|
force_recode = TRUE;
|
|
|
|
}
|
|
|
|
// Severe undershoot and between auto and user cq level
|
|
|
|
else if ( (q > cpi->oxcf.cq_level) &&
|
|
|
|
(cpi->projected_frame_size < cpi->min_frame_bandwidth) &&
|
|
|
|
(cpi->active_best_quality > cpi->oxcf.cq_level))
|
|
|
|
{
|
|
|
|
force_recode = TRUE;
|
|
|
|
cpi->active_best_quality = cpi->oxcf.cq_level;
|
|
|
|
}
|
|
|
|
}
|
2010-11-17 16:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return force_recode;
|
|
|
|
}
|
|
|
|
|
2011-04-20 14:12:23 +02:00
|
|
|
void update_reference_frames(VP8_COMMON *cm)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb;
|
|
|
|
|
|
|
|
// At this point the new frame has been encoded.
|
|
|
|
// If any buffer copy / swapping is signaled it should be done here.
|
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
|
|
|
yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FLAG | VP8_ALT_FLAG ;
|
|
|
|
|
|
|
|
yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FLAG;
|
|
|
|
yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALT_FLAG;
|
|
|
|
|
|
|
|
cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx;
|
|
|
|
}
|
|
|
|
else /* For non key frames */
|
|
|
|
{
|
|
|
|
if (cm->refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
assert(!cm->copy_buffer_to_arf);
|
|
|
|
|
|
|
|
cm->yv12_fb[cm->new_fb_idx].flags |= VP8_ALT_FLAG;
|
|
|
|
cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALT_FLAG;
|
|
|
|
cm->alt_fb_idx = cm->new_fb_idx;
|
|
|
|
}
|
|
|
|
else if (cm->copy_buffer_to_arf)
|
|
|
|
{
|
|
|
|
assert(!(cm->copy_buffer_to_arf & ~0x3));
|
|
|
|
|
|
|
|
if (cm->copy_buffer_to_arf == 1)
|
|
|
|
{
|
2011-05-27 20:57:25 +02:00
|
|
|
if(cm->alt_fb_idx != cm->lst_fb_idx)
|
|
|
|
{
|
|
|
|
yv12_fb[cm->lst_fb_idx].flags |= VP8_ALT_FLAG;
|
|
|
|
yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALT_FLAG;
|
|
|
|
cm->alt_fb_idx = cm->lst_fb_idx;
|
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
|
|
|
else /* if (cm->copy_buffer_to_arf == 2) */
|
|
|
|
{
|
2011-05-27 20:57:25 +02:00
|
|
|
if(cm->alt_fb_idx != cm->gld_fb_idx)
|
|
|
|
{
|
|
|
|
yv12_fb[cm->gld_fb_idx].flags |= VP8_ALT_FLAG;
|
|
|
|
yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALT_FLAG;
|
|
|
|
cm->alt_fb_idx = cm->gld_fb_idx;
|
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->refresh_golden_frame)
|
|
|
|
{
|
|
|
|
assert(!cm->copy_buffer_to_gf);
|
|
|
|
|
|
|
|
cm->yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FLAG;
|
|
|
|
cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FLAG;
|
|
|
|
cm->gld_fb_idx = cm->new_fb_idx;
|
|
|
|
}
|
|
|
|
else if (cm->copy_buffer_to_gf)
|
|
|
|
{
|
|
|
|
assert(!(cm->copy_buffer_to_arf & ~0x3));
|
|
|
|
|
|
|
|
if (cm->copy_buffer_to_gf == 1)
|
|
|
|
{
|
2011-05-27 20:57:25 +02:00
|
|
|
if(cm->gld_fb_idx != cm->lst_fb_idx)
|
|
|
|
{
|
|
|
|
yv12_fb[cm->lst_fb_idx].flags |= VP8_GOLD_FLAG;
|
|
|
|
yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FLAG;
|
|
|
|
cm->gld_fb_idx = cm->lst_fb_idx;
|
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
|
|
|
else /* if (cm->copy_buffer_to_gf == 2) */
|
|
|
|
{
|
2011-05-27 20:57:25 +02:00
|
|
|
if(cm->alt_fb_idx != cm->gld_fb_idx)
|
|
|
|
{
|
|
|
|
yv12_fb[cm->alt_fb_idx].flags |= VP8_GOLD_FLAG;
|
|
|
|
yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FLAG;
|
|
|
|
cm->gld_fb_idx = cm->alt_fb_idx;
|
|
|
|
}
|
2011-04-20 14:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->refresh_last_frame)
|
|
|
|
{
|
|
|
|
cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FLAG;
|
|
|
|
cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FLAG;
|
|
|
|
cm->lst_fb_idx = cm->new_fb_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 12:42:05 +01:00
|
|
|
void loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
|
|
|
|
{
|
|
|
|
if (cm->no_lpf)
|
|
|
|
{
|
|
|
|
cm->filter_level = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct vpx_usec_timer timer;
|
|
|
|
|
|
|
|
vp8_clear_system_state();
|
|
|
|
|
|
|
|
vpx_usec_timer_start(&timer);
|
|
|
|
if (cpi->sf.auto_filter == 0)
|
|
|
|
vp8cx_pick_filter_level_fast(cpi->Source, cpi);
|
|
|
|
|
|
|
|
else
|
|
|
|
vp8cx_pick_filter_level(cpi->Source, cpi);
|
|
|
|
|
|
|
|
vpx_usec_timer_mark(&timer);
|
|
|
|
cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->filter_level > 0)
|
|
|
|
{
|
|
|
|
vp8cx_set_alt_lf_level(cpi, cm->filter_level);
|
2011-07-20 21:53:42 +02:00
|
|
|
vp8_loop_filter_frame(cm, &cpi->mb.e_mbd);
|
2011-02-25 12:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vp8_yv12_extend_frame_borders_ptr(cm->frame_to_show);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-28 16:23:41 +02:00
|
|
|
static void encode_frame_to_data_rate
|
2010-05-18 17:58:33 +02:00
|
|
|
(
|
2010-09-28 16:23:41 +02:00
|
|
|
VP8_COMP *cpi,
|
|
|
|
unsigned long *size,
|
|
|
|
unsigned char *dest,
|
|
|
|
unsigned int *frame_flags
|
2010-05-18 17:58:33 +02:00
|
|
|
)
|
|
|
|
{
|
2011-11-15 17:15:23 +01:00
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
int Q;
|
|
|
|
int frame_over_shoot_limit;
|
|
|
|
int frame_under_shoot_limit;
|
|
|
|
|
|
|
|
int Loop = FALSE;
|
|
|
|
int loop_count;
|
|
|
|
int this_q;
|
|
|
|
int last_zbin_oq;
|
|
|
|
|
|
|
|
int q_low;
|
|
|
|
int q_high;
|
|
|
|
int zbin_oq_high;
|
|
|
|
int zbin_oq_low = 0;
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
int top_index;
|
|
|
|
int bottom_index;
|
|
|
|
int active_worst_qchanged = FALSE;
|
|
|
|
|
|
|
|
int overshoot_seen = FALSE;
|
|
|
|
int undershoot_seen = FALSE;
|
2010-09-24 00:25:33 +02:00
|
|
|
|
2012-03-27 14:01:34 +02:00
|
|
|
int loop_size_estimate = 0;
|
|
|
|
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
|
|
|
SPEED_FEATURES *sf = &cpi->sf;
|
|
|
|
#if RESET_FOREACH_FILTER
|
|
|
|
int q_low0;
|
|
|
|
int q_high0;
|
|
|
|
int zbin_oq_high0;
|
|
|
|
int zbin_oq_low0 = 0;
|
|
|
|
int Q0;
|
|
|
|
int last_zbin_oq0;
|
|
|
|
int active_best_quality0;
|
|
|
|
int active_worst_quality0;
|
|
|
|
double rate_correction_factor0;
|
|
|
|
double gf_rate_correction_factor0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* list of filters to search over */
|
|
|
|
int mcomp_filters_to_search[] = {EIGHTTAP, EIGHTTAP_SHARP, SIXTAP};
|
|
|
|
int mcomp_filters = sizeof(mcomp_filters_to_search)/sizeof(*mcomp_filters_to_search);
|
|
|
|
int mcomp_filter_index = 0;
|
|
|
|
INT64 mcomp_filter_cost[4];
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Clear down mmx registers to allow floating point in what follows
|
|
|
|
vp8_clear_system_state();
|
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
// For an alt ref frame in 2 pass we skip the call to the second
|
|
|
|
// pass function that sets the target bandwidth so must set it here
|
|
|
|
if (cpi->common.refresh_alt_ref_frame)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->per_frame_bandwidth = cpi->twopass.gf_bits; // Per frame bit target for the alt ref frame
|
|
|
|
cpi->target_bandwidth = cpi->twopass.gf_bits * cpi->output_frame_rate; // per second target bitrate
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default turn off buffer to buffer copying
|
|
|
|
cm->copy_buffer_to_gf = 0;
|
|
|
|
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;
|
|
|
|
|
2010-11-08 16:28:54 +01:00
|
|
|
// 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 = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->zbin_mode_boost_enabled = TRUE;
|
2012-02-17 17:29:03 +01:00
|
|
|
if ( cpi->gfu_boost <= 400 )
|
2010-11-08 16:28:54 +01:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->zbin_mode_boost_enabled = FALSE;
|
2010-11-08 16:28:54 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Current default encoder behaviour for the altref sign bias
|
|
|
|
if (cpi->source_alt_ref_active)
|
|
|
|
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1;
|
|
|
|
else
|
|
|
|
cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0;
|
|
|
|
|
|
|
|
// Check to see if a key frame is signalled
|
|
|
|
// For two pass with auto key frame enabled cm->frame_type may already be set, but not for one pass.
|
|
|
|
if ((cm->current_video_frame == 0) ||
|
|
|
|
(cm->frame_flags & FRAMEFLAGS_KEY) ||
|
|
|
|
(cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0)))
|
|
|
|
{
|
|
|
|
// Key frame from VFW/auto-keyframe/first frame
|
|
|
|
cm->frame_type = KEY_FRAME;
|
|
|
|
}
|
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
// Set default state for segment based loop filter update flags
|
2011-11-15 17:15:23 +01:00
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Set various flags etc to special state if it is a key frame
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-09-29 19:04:04 +02:00
|
|
|
// Reset the loop filter deltas and segmentation map
|
|
|
|
setup_features(cpi);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// If segmentation is enabled force a map update for key frames
|
2011-11-15 17:15:23 +01:00
|
|
|
if (xd->segmentation_enabled)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-11-15 17:15:23 +01:00
|
|
|
xd->update_mb_segmentation_map = 1;
|
|
|
|
xd->update_mb_segmentation_data = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The alternate reference frame cannot be active for a key frame
|
|
|
|
cpi->source_alt_ref_active = FALSE;
|
|
|
|
|
|
|
|
// Reset the RD threshold multipliers to default of * 1 (128)
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
{
|
|
|
|
cpi->rd_thresh_mult[i] = 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 17:10:46 +01:00
|
|
|
//#if !CONFIG_COMPRED
|
|
|
|
// This function has been deprecated for now but we may want to do
|
|
|
|
// something here at a late date
|
|
|
|
//update_rd_ref_frame_probs(cpi);
|
|
|
|
//#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-03 13:50:09 +01:00
|
|
|
// Test code for new segment features
|
|
|
|
init_seg_features( cpi );
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Decide how big to make the frame
|
2012-04-11 16:44:14 +02:00
|
|
|
vp8_pick_frame_size(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
vp8_clear_system_state();
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Set an active best quality and if necessary active worst quality
|
2012-02-17 17:29:03 +01:00
|
|
|
Q = cpi->active_worst_quality;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
if ( cm->frame_type == KEY_FRAME )
|
|
|
|
{
|
2012-06-07 14:39:20 +02:00
|
|
|
int high = 2000;
|
|
|
|
int low = 400;
|
|
|
|
|
|
|
|
if ( cpi->kf_boost > high )
|
|
|
|
cpi->active_best_quality = kf_low_motion_minq[Q];
|
|
|
|
else if ( cpi->kf_boost < low )
|
|
|
|
cpi->active_best_quality = kf_high_motion_minq[Q];
|
2012-02-17 17:29:03 +01:00
|
|
|
else
|
2012-06-07 14:39:20 +02:00
|
|
|
{
|
|
|
|
int gap = high - low;
|
|
|
|
int offset = high - cpi->kf_boost;
|
|
|
|
int qdiff = kf_high_motion_minq[Q] - kf_low_motion_minq[Q];
|
|
|
|
int adjustment = ((offset * qdiff) + (gap>>1)) / gap;
|
|
|
|
|
|
|
|
cpi->active_best_quality = kf_low_motion_minq[Q] + adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make an adjustment based on the %s static
|
|
|
|
// The main impact of this is at lower Q to prevent overly large key
|
|
|
|
// frames unless a lot of the image is static.
|
|
|
|
if (cpi->kf_zeromotion_pct < 64 )
|
|
|
|
cpi->active_best_quality += 4 - (cpi->kf_zeromotion_pct >> 4);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
// Special case for key frames forced because we have reached
|
|
|
|
// the maximum key frame interval. Here force the Q to a range
|
|
|
|
// based on the ambient Q to reduce the risk of popping
|
|
|
|
if ( cpi->this_key_frame_forced )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
int delta_qindex;
|
|
|
|
int qindex = cpi->last_boosted_qindex;
|
2011-01-17 18:23:11 +01:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
delta_qindex = compute_qdelta( cpi, qindex,
|
|
|
|
(qindex * 0.75) );
|
2012-01-11 15:05:57 +01:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->active_best_quality = qindex + delta_qindex;
|
|
|
|
if (cpi->active_best_quality < cpi->best_quality)
|
|
|
|
cpi->active_best_quality = cpi->best_quality;
|
2011-01-20 19:01:20 +01:00
|
|
|
}
|
2012-02-17 17:29:03 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
else if (cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame)
|
|
|
|
{
|
2012-06-07 14:39:20 +02:00
|
|
|
int high = 2000;
|
|
|
|
int low = 400;
|
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
// Use the lower of cpi->active_worst_quality and recent
|
|
|
|
// average Q as basis for GF/ARF Q limit unless last frame was
|
|
|
|
// a key frame.
|
|
|
|
if ( (cpi->frames_since_key > 1) &&
|
|
|
|
(cpi->avg_frame_qindex < cpi->active_worst_quality) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
Q = cpi->avg_frame_qindex;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
// For constrained quality dont allow Q less than the cq level
|
|
|
|
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
|
|
|
|
(Q < cpi->cq_target_quality) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
Q = cpi->cq_target_quality;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-06-07 14:39:20 +02:00
|
|
|
if ( cpi->gfu_boost > high )
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->active_best_quality = gf_low_motion_minq[Q];
|
2012-06-07 14:39:20 +02:00
|
|
|
else if ( cpi->gfu_boost < low )
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->active_best_quality = gf_high_motion_minq[Q];
|
|
|
|
else
|
2012-06-07 14:39:20 +02:00
|
|
|
{
|
|
|
|
int gap = high - low;
|
|
|
|
int offset = high - cpi->gfu_boost;
|
|
|
|
int qdiff = gf_high_motion_minq[Q] - gf_low_motion_minq[Q];
|
|
|
|
int adjustment = ((offset * qdiff) + (gap>>1)) / gap;
|
|
|
|
|
|
|
|
cpi->active_best_quality = gf_low_motion_minq[Q] + adjustment;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-17 17:29:03 +01:00
|
|
|
// Constrained quality use slightly lower active best.
|
|
|
|
if ( cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY )
|
|
|
|
{
|
|
|
|
cpi->active_best_quality =
|
|
|
|
cpi->active_best_quality * 15/16;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-17 17:29:03 +01:00
|
|
|
else
|
2011-03-10 17:11:39 +01:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->active_best_quality = inter_minq[Q];
|
|
|
|
|
|
|
|
// For the constant/constrained quality mode we dont want
|
|
|
|
// q to fall below the cq level.
|
|
|
|
if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
|
|
|
|
(cpi->active_best_quality < cpi->cq_target_quality) )
|
2011-03-10 17:11:39 +01:00
|
|
|
{
|
2012-02-17 17:29:03 +01:00
|
|
|
// If we are strongly undershooting the target rate in the last
|
|
|
|
// frames then use the user passed in cq value not the auto
|
|
|
|
// cq value.
|
|
|
|
if ( cpi->rolling_actual_bits < cpi->min_frame_bandwidth )
|
|
|
|
cpi->active_best_quality = cpi->oxcf.cq_level;
|
|
|
|
else
|
|
|
|
cpi->active_best_quality = cpi->cq_target_quality;
|
2011-03-10 17:11:39 +01:00
|
|
|
}
|
2012-02-17 17:29:03 +01:00
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Clip the active best and worst quality values to limits
|
|
|
|
if (cpi->active_worst_quality > cpi->worst_quality)
|
|
|
|
cpi->active_worst_quality = cpi->worst_quality;
|
|
|
|
|
|
|
|
if (cpi->active_best_quality < cpi->best_quality)
|
|
|
|
cpi->active_best_quality = cpi->best_quality;
|
2011-11-23 18:18:31 +01:00
|
|
|
|
2011-12-08 05:08:31 +01:00
|
|
|
if (cpi->active_best_quality > cpi->worst_quality)
|
|
|
|
cpi->active_best_quality = cpi->worst_quality;
|
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
if ( cpi->active_worst_quality < cpi->active_best_quality )
|
|
|
|
cpi->active_worst_quality = cpi->active_best_quality;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
// Specuial case code to try and match quality with forced key frames
|
|
|
|
if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
|
|
|
|
{
|
|
|
|
Q = cpi->last_boosted_qindex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Determine initial Q to try
|
|
|
|
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
last_zbin_oq = cpi->zbin_over_quant;
|
|
|
|
|
|
|
|
// Set highest allowed value for Zbin over quant
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
zbin_oq_high = 0; //ZBIN_OQ_MAX/16
|
|
|
|
else if (cm->refresh_alt_ref_frame || (cm->refresh_golden_frame && !cpi->source_alt_ref_active))
|
|
|
|
zbin_oq_high = 16;
|
|
|
|
else
|
|
|
|
zbin_oq_high = ZBIN_OQ_MAX;
|
|
|
|
|
|
|
|
vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_shoot_limit);
|
|
|
|
|
2010-12-09 16:02:04 +01:00
|
|
|
// Limit Q range for the adaptive loop.
|
2010-05-18 17:58:33 +02:00
|
|
|
bottom_index = cpi->active_best_quality;
|
|
|
|
top_index = cpi->active_worst_quality;
|
2010-12-09 16:02:04 +01:00
|
|
|
q_low = cpi->active_best_quality;
|
|
|
|
q_high = cpi->active_worst_quality;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
loop_count = 0;
|
|
|
|
|
2012-03-19 15:53:05 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV || CONFIG_ENHANCED_INTERP
|
2012-02-27 19:22:38 +01:00
|
|
|
if (cm->frame_type != KEY_FRAME)
|
|
|
|
{
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
2012-03-19 15:53:05 +01:00
|
|
|
/* TODO: Decide this more intelligently */
|
2012-04-16 23:53:37 +02:00
|
|
|
if (sf->search_best_filter)
|
|
|
|
{
|
|
|
|
cm->mcomp_filter_type = mcomp_filters_to_search[0];
|
|
|
|
mcomp_filter_index = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cm->mcomp_filter_type = EIGHTTAP;
|
2012-03-19 15:53:05 +01:00
|
|
|
#endif
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
2012-03-19 15:53:05 +01:00
|
|
|
/* TODO: Decide this more intelligently */
|
2012-04-16 23:53:37 +02:00
|
|
|
xd->allow_high_precision_mv = (Q < HIGH_PRECISION_MV_QTHRESH);
|
2012-03-19 15:53:05 +01:00
|
|
|
#endif
|
2012-02-27 19:22:38 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 18:05:26 +01:00
|
|
|
#if CONFIG_POSTPROC
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->oxcf.noise_sensitivity > 0)
|
|
|
|
{
|
|
|
|
unsigned char *src;
|
|
|
|
int l = 0;
|
|
|
|
|
|
|
|
switch (cpi->oxcf.noise_sensitivity)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
l = 20;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
l = 40;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
l = 60;
|
|
|
|
break;
|
|
|
|
case 4:
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case 5:
|
|
|
|
l = 100;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
l = 150;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
|
|
|
vp8_de_noise(cpi->Source, cpi->Source, l , 1, 0, RTCD(postproc));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vp8_de_noise(cpi->Source, cpi->Source, l , 1, 0, RTCD(postproc));
|
|
|
|
|
|
|
|
src = cpi->Source->y_buffer;
|
|
|
|
|
|
|
|
if (cpi->Source->y_stride < 0)
|
|
|
|
{
|
|
|
|
src += cpi->Source->y_stride * (cpi->Source->y_height - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OUTPUT_YUV_SRC
|
|
|
|
vp8_write_yuv_frame(cpi->Source);
|
|
|
|
#endif
|
|
|
|
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP && RESET_FOREACH_FILTER
|
|
|
|
if (sf->search_best_filter)
|
|
|
|
{
|
|
|
|
q_low0 = q_low;
|
|
|
|
q_high0 = q_high;
|
|
|
|
Q0 = Q;
|
|
|
|
zbin_oq_low0 = zbin_oq_low;
|
|
|
|
zbin_oq_high0 = zbin_oq_high;
|
|
|
|
last_zbin_oq0 = last_zbin_oq;
|
|
|
|
rate_correction_factor0 = cpi->rate_correction_factor;
|
|
|
|
gf_rate_correction_factor0 = cpi->gf_rate_correction_factor;
|
|
|
|
active_best_quality0 = cpi->active_best_quality;
|
|
|
|
active_worst_quality0 = cpi->active_worst_quality;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
vp8_clear_system_state(); //__asm emms;
|
|
|
|
|
2011-05-19 17:04:03 +02:00
|
|
|
vp8_set_quantizer(cpi, Q);
|
2010-05-18 17:58:33 +02:00
|
|
|
this_q = Q;
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
if ( loop_count == 0 )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// setup skip prob for costing in mode/mv decision
|
|
|
|
if (cpi->common.mb_no_coeff_skip)
|
|
|
|
{
|
2012-03-19 19:02:04 +01:00
|
|
|
#if CONFIG_NEWENTROPY
|
2012-04-11 16:44:14 +02:00
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; k++)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->base_skip_false_prob[Q][k];
|
2012-03-19 19:02:04 +01:00
|
|
|
#else
|
2012-04-11 16:44:14 +02:00
|
|
|
cpi->prob_skip_false = cpi->base_skip_false_prob[Q];
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cm->frame_type != KEY_FRAME)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->common.refresh_alt_ref_frame)
|
2012-03-19 19:02:04 +01:00
|
|
|
{
|
2012-04-11 16:44:14 +02:00
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; k++)
|
|
|
|
{
|
|
|
|
if (cpi->last_skip_false_probs[2][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[2][k];
|
|
|
|
}
|
2012-03-19 19:02:04 +01:00
|
|
|
#else
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->last_skip_false_probs[2] != 0)
|
|
|
|
cpi->prob_skip_false = cpi->last_skip_false_probs[2];
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
|
|
|
}
|
2012-04-11 16:44:14 +02:00
|
|
|
else if (cpi->common.refresh_golden_frame)
|
|
|
|
{
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; k++)
|
|
|
|
{
|
|
|
|
if (cpi->last_skip_false_probs[1][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[1][k];
|
|
|
|
}
|
2012-03-19 19:02:04 +01:00
|
|
|
#else
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->last_skip_false_probs[1] != 0)
|
|
|
|
cpi->prob_skip_false = cpi->last_skip_false_probs[1];
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
|
|
|
}
|
2012-04-11 16:44:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; k++)
|
|
|
|
{
|
|
|
|
if (cpi->last_skip_false_probs[0][k] != 0)
|
|
|
|
cm->mbskip_pred_probs[k] = cpi->last_skip_false_probs[0][k];
|
|
|
|
}
|
2012-03-19 19:02:04 +01:00
|
|
|
#else
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->last_skip_false_probs[0] != 0)
|
|
|
|
cpi->prob_skip_false = cpi->last_skip_false_probs[0];
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
2012-04-11 16:44:14 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// as this is for cost estimate, let's make sure it does not
|
|
|
|
// get extreme either way
|
2012-03-19 19:02:04 +01:00
|
|
|
#if CONFIG_NEWENTROPY
|
|
|
|
{
|
2012-04-11 16:44:14 +02:00
|
|
|
int k;
|
|
|
|
for (k=0; k<MBSKIP_CONTEXTS; ++k)
|
|
|
|
{
|
|
|
|
if (cm->mbskip_pred_probs[k] < 5)
|
|
|
|
cm->mbskip_pred_probs[k] = 5;
|
|
|
|
|
|
|
|
if (cm->mbskip_pred_probs[k] > 250)
|
|
|
|
cm->mbskip_pred_probs[k] = 250;
|
|
|
|
|
|
|
|
if (cpi->is_src_frame_alt_ref)
|
|
|
|
cm->mbskip_pred_probs[k] = 1;
|
|
|
|
}
|
2012-03-19 19:02:04 +01:00
|
|
|
}
|
|
|
|
#else
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->prob_skip_false < 5)
|
|
|
|
cpi->prob_skip_false = 5;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->prob_skip_false > 250)
|
|
|
|
cpi->prob_skip_false = 250;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
if (cpi->is_src_frame_alt_ref)
|
|
|
|
cpi->prob_skip_false = 1;
|
2012-03-19 19:02:04 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// Set up entropy depending on frame type.
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
vp8_setup_key_frame(cpi);
|
|
|
|
else
|
|
|
|
vp8_setup_inter_frame(cpi);
|
|
|
|
}
|
2011-12-08 20:43:09 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// transform / motion compensation build reconstruction frame
|
2012-04-16 23:53:37 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_encode_frame(cpi);
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2012-04-11 15:37:48 +02:00
|
|
|
// Update the skip mb flag probabilities based on the distribution
|
|
|
|
// seen in the last encoder iteration.
|
|
|
|
update_base_skip_probs( cpi );
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_clear_system_state(); //__asm emms;
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// Dummy pack of the bitstream using up to date stats to get an
|
|
|
|
// accurate estimate of output frame size to determine if we need
|
|
|
|
// to recode.
|
|
|
|
vp8_save_coding_context(cpi);
|
2012-05-02 22:53:15 +02:00
|
|
|
cpi->dummy_packing = 1;
|
2012-04-11 16:44:14 +02:00
|
|
|
vp8_pack_bitstream(cpi, dest, size);
|
|
|
|
cpi->projected_frame_size = (*size) << 3;
|
|
|
|
vp8_restore_coding_context(cpi);
|
|
|
|
|
2012-04-16 23:53:37 +02:00
|
|
|
if (frame_over_shoot_limit == 0)
|
|
|
|
frame_over_shoot_limit = 1;
|
|
|
|
active_worst_qchanged = FALSE;
|
|
|
|
|
2011-01-17 18:23:11 +01:00
|
|
|
// Special case handling for forced key frames
|
|
|
|
if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
|
|
|
|
{
|
|
|
|
int last_q = Q;
|
|
|
|
int kf_err = vp8_calc_ss_err(cpi->Source,
|
|
|
|
&cm->yv12_fb[cm->new_fb_idx],
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
int high_err_target = cpi->ambient_err;
|
2012-04-11 16:44:14 +02:00
|
|
|
int low_err_target = (cpi->ambient_err >> 1);
|
2012-01-11 15:05:57 +01:00
|
|
|
|
2012-01-18 12:10:51 +01:00
|
|
|
// Prevent possible divide by zero error below for perfect KF
|
|
|
|
kf_err += (!kf_err);
|
|
|
|
|
2012-03-27 14:01:34 +02:00
|
|
|
// The key frame is not good enough or we can afford
|
|
|
|
// to make it better without undue risk of popping.
|
|
|
|
if ( ( (kf_err > high_err_target) &&
|
|
|
|
(cpi->projected_frame_size <= frame_over_shoot_limit) ) ||
|
|
|
|
( (kf_err > low_err_target) &&
|
|
|
|
(cpi->projected_frame_size <= frame_under_shoot_limit) ) )
|
2011-01-17 18:23:11 +01:00
|
|
|
{
|
|
|
|
// Lower q_high
|
|
|
|
q_high = (Q > q_low) ? (Q - 1) : q_low;
|
|
|
|
|
|
|
|
// Adjust Q
|
2012-01-11 15:05:57 +01:00
|
|
|
Q = (Q * high_err_target) / kf_err;
|
|
|
|
if ( Q < ((q_high + q_low) >> 1))
|
|
|
|
Q = (q_high + q_low) >> 1;
|
2011-01-17 18:23:11 +01:00
|
|
|
}
|
|
|
|
// The key frame is much better than the previous frame
|
2012-01-11 15:05:57 +01:00
|
|
|
else if ( (kf_err < low_err_target) &&
|
|
|
|
(cpi->projected_frame_size >= frame_under_shoot_limit) )
|
2011-01-17 18:23:11 +01:00
|
|
|
{
|
|
|
|
// Raise q_low
|
|
|
|
q_low = (Q < q_high) ? (Q + 1) : q_high;
|
|
|
|
|
|
|
|
// Adjust Q
|
2012-01-11 15:05:57 +01:00
|
|
|
Q = (Q * low_err_target) / kf_err;
|
|
|
|
if ( Q > ((q_high + q_low + 1) >> 1))
|
|
|
|
Q = (q_high + q_low + 1) >> 1;
|
2011-01-17 18:23:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp Q to upper and lower limits:
|
|
|
|
if (Q > q_high)
|
|
|
|
Q = q_high;
|
|
|
|
else if (Q < q_low)
|
|
|
|
Q = q_low;
|
|
|
|
|
|
|
|
Loop = ((Q != last_q)) ? TRUE : FALSE;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Is the projected frame size out of range and are we allowed to attempt to recode.
|
2011-01-17 18:23:11 +01:00
|
|
|
else if ( recode_loop_test( cpi,
|
2010-11-17 16:12:04 +01:00
|
|
|
frame_over_shoot_limit, frame_under_shoot_limit,
|
|
|
|
Q, top_index, bottom_index ) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int last_q = Q;
|
|
|
|
int Retries = 0;
|
|
|
|
|
|
|
|
// Frame size out of permitted range:
|
|
|
|
// Update correction factor & compute new Q to try...
|
2010-11-17 16:12:04 +01:00
|
|
|
|
|
|
|
// Frame is too large
|
|
|
|
if (cpi->projected_frame_size > cpi->this_frame_target)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
q_low = (Q < q_high) ? (Q + 1) : q_high; // Raise Qlow as to at least the current value
|
|
|
|
|
2011-01-17 18:23:11 +01:00
|
|
|
if (cpi->zbin_over_quant > 0) // If we are using over quant do the same for zbin_oq_low
|
2010-05-18 17:58:33 +02:00
|
|
|
zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
|
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
if ( undershoot_seen || (loop_count > 1) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
|
|
|
vp8_update_rate_correction_factors(cpi, 1);
|
|
|
|
|
|
|
|
Q = (q_high + q_low + 1) / 2;
|
|
|
|
|
|
|
|
// Adjust cpi->zbin_over_quant (only allowed when Q is max)
|
|
|
|
if (Q < MAXQ)
|
|
|
|
cpi->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
|
|
|
vp8_update_rate_correction_factors(cpi, 0);
|
|
|
|
|
|
|
|
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
|
|
|
|
while (((Q < q_low) || (cpi->zbin_over_quant < zbin_oq_low)) && (Retries < 10))
|
|
|
|
{
|
|
|
|
vp8_update_rate_correction_factors(cpi, 0);
|
|
|
|
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
Retries ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
overshoot_seen = TRUE;
|
|
|
|
}
|
2010-11-17 16:12:04 +01:00
|
|
|
// Frame is too small
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cpi->zbin_over_quant == 0)
|
|
|
|
q_high = (Q > q_low) ? (Q - 1) : q_low; // Lower q_high if not using over quant
|
|
|
|
else // else lower zbin_oq_high
|
|
|
|
zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->zbin_over_quant - 1) : zbin_oq_low;
|
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
if ( overshoot_seen || (loop_count > 1) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
|
|
|
vp8_update_rate_correction_factors(cpi, 1);
|
|
|
|
|
|
|
|
Q = (q_high + q_low) / 2;
|
|
|
|
|
|
|
|
// Adjust cpi->zbin_over_quant (only allowed when Q is max)
|
|
|
|
if (Q < MAXQ)
|
|
|
|
cpi->zbin_over_quant = 0;
|
|
|
|
else
|
|
|
|
cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Update rate_correction_factor unless cpi->active_worst_quality has changed.
|
|
|
|
if (!active_worst_qchanged)
|
|
|
|
vp8_update_rate_correction_factors(cpi, 0);
|
|
|
|
|
|
|
|
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
|
2011-01-14 12:34:53 +01:00
|
|
|
// Special case reset for qlow for constrained quality.
|
|
|
|
// This should only trigger where there is very substantial
|
|
|
|
// undershoot on a frame and the auto cq level is above
|
|
|
|
// the user passsed in value.
|
|
|
|
if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) &&
|
|
|
|
(Q < q_low) )
|
|
|
|
{
|
|
|
|
q_low = Q;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
while (((Q > q_high) || (cpi->zbin_over_quant > zbin_oq_high)) && (Retries < 10))
|
|
|
|
{
|
|
|
|
vp8_update_rate_correction_factors(cpi, 0);
|
|
|
|
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
|
|
|
Retries ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undershoot_seen = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp Q to upper and lower limits:
|
|
|
|
if (Q > q_high)
|
|
|
|
Q = q_high;
|
|
|
|
else if (Q < q_low)
|
|
|
|
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;
|
|
|
|
|
|
|
|
//Loop = ((Q != last_q) || (last_zbin_oq != cpi->zbin_over_quant)) ? TRUE : FALSE;
|
|
|
|
Loop = ((Q != last_q)) ? TRUE : FALSE;
|
|
|
|
last_zbin_oq = cpi->zbin_over_quant;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Loop = FALSE;
|
|
|
|
|
|
|
|
if (cpi->is_src_frame_alt_ref)
|
|
|
|
Loop = FALSE;
|
|
|
|
|
2012-04-16 23:53:37 +02:00
|
|
|
#if CONFIG_ENHANCED_INTERP
|
|
|
|
if (Loop == FALSE && cm->frame_type != KEY_FRAME && sf->search_best_filter)
|
|
|
|
{
|
|
|
|
if (mcomp_filter_index < mcomp_filters)
|
|
|
|
{
|
|
|
|
INT64 err = vp8_calc_ss_err(cpi->Source,
|
|
|
|
&cm->yv12_fb[cm->new_fb_idx],
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
INT64 rate = cpi->projected_frame_size << 8;
|
|
|
|
mcomp_filter_cost[mcomp_filter_index] =
|
|
|
|
(RDCOST(cpi->RDMULT, cpi->RDDIV, rate, err));
|
|
|
|
mcomp_filter_index++;
|
|
|
|
if (mcomp_filter_index < mcomp_filters)
|
|
|
|
{
|
|
|
|
cm->mcomp_filter_type = mcomp_filters_to_search[mcomp_filter_index];
|
|
|
|
loop_count = -1;
|
|
|
|
Loop = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
INT64 best_cost = mcomp_filter_cost[0];
|
|
|
|
int mcomp_best_filter = mcomp_filters_to_search[0];
|
|
|
|
for (f = 1; f < mcomp_filters; f++)
|
|
|
|
{
|
|
|
|
if (mcomp_filter_cost[f] < best_cost)
|
|
|
|
{
|
|
|
|
mcomp_best_filter = mcomp_filters_to_search[f];
|
|
|
|
best_cost = mcomp_filter_cost[f];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mcomp_best_filter != mcomp_filters_to_search[mcomp_filters-1])
|
|
|
|
{
|
|
|
|
loop_count = -1;
|
|
|
|
Loop = TRUE;
|
|
|
|
cm->mcomp_filter_type = mcomp_best_filter;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
printf(" best filter = %d, ( ", mcomp_best_filter);
|
|
|
|
for (f=0;f<mcomp_filters; f++) printf("%d ", mcomp_filter_cost[f]);
|
|
|
|
printf(")\n");
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
#if RESET_FOREACH_FILTER
|
|
|
|
if (Loop == TRUE)
|
|
|
|
{
|
|
|
|
overshoot_seen = FALSE;
|
|
|
|
undershoot_seen = FALSE;
|
|
|
|
zbin_oq_low = zbin_oq_low0;
|
|
|
|
zbin_oq_high = zbin_oq_high0;
|
|
|
|
q_low = q_low0;
|
|
|
|
q_high = q_high0;
|
|
|
|
Q = Q0;
|
|
|
|
cpi->zbin_over_quant = last_zbin_oq = last_zbin_oq0;
|
|
|
|
cpi->rate_correction_factor = rate_correction_factor0;
|
|
|
|
cpi->gf_rate_correction_factor = gf_rate_correction_factor0;
|
|
|
|
cpi->active_best_quality = active_best_quality0;
|
|
|
|
cpi->active_worst_quality = active_worst_quality0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (Loop == TRUE)
|
|
|
|
{
|
|
|
|
loop_count++;
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->tot_recode_hits++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (Loop == TRUE);
|
|
|
|
|
2011-01-17 18:23:11 +01:00
|
|
|
// Special case code to reduce pulsing when key frames are forced at a
|
|
|
|
// fixed interval. Note the reconstruction error if it is the frame before
|
|
|
|
// the force key frame
|
2011-05-19 23:16:39 +02:00
|
|
|
if ( cpi->next_key_frame_forced && (cpi->twopass.frames_to_key == 0) )
|
2011-01-17 18:23:11 +01:00
|
|
|
{
|
|
|
|
cpi->ambient_err = vp8_calc_ss_err(cpi->Source,
|
|
|
|
&cm->yv12_fb[cm->new_fb_idx],
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
}
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// This frame's MVs are saved and will be used in next frame's MV
|
|
|
|
// prediction. Last frame has one more line(add to bottom) and one
|
|
|
|
// more column(add to right) than cm->mip. The edge elements are
|
|
|
|
// initialized to 0.
|
2010-12-03 17:26:21 +01:00
|
|
|
if(cm->show_frame) //do not save for altref frame
|
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
int mb_row;
|
|
|
|
int mb_col;
|
2012-04-11 16:44:14 +02:00
|
|
|
MODE_INFO *tmp = cm->mip;
|
2011-01-25 21:54:34 +01:00
|
|
|
|
|
|
|
if(cm->frame_type != KEY_FRAME)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
for (mb_row = 0; mb_row < cm->mb_rows+1; mb_row ++)
|
|
|
|
{
|
|
|
|
for (mb_col = 0; mb_col < cm->mb_cols+1; mb_col ++)
|
|
|
|
{
|
|
|
|
if(tmp->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
cpi->lfmv[mb_col + mb_row*(cm->mode_info_stride+1)].as_int = tmp->mbmi.mv.as_int;
|
|
|
|
|
|
|
|
cpi->lf_ref_frame_sign_bias[mb_col + mb_row*(cm->mode_info_stride+1)] = cm->ref_frame_sign_bias[tmp->mbmi.ref_frame];
|
|
|
|
cpi->lf_ref_frame[mb_col + mb_row*(cm->mode_info_stride+1)] = tmp->mbmi.ref_frame;
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
}
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 17:10:53 +01:00
|
|
|
// Update the GF useage maps.
|
2012-04-11 16:44:14 +02:00
|
|
|
// This is done after completing the compression of a frame when all modes
|
|
|
|
// etc. are finalized but before loop filter
|
2010-08-11 17:02:31 +02:00
|
|
|
vp8_update_gf_useage_maps(cpi, cm, &cpi->mb);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
cm->refresh_last_frame = 1;
|
|
|
|
|
2010-09-24 17:10:25 +02:00
|
|
|
#if 0
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
FILE *f = fopen("gfactive.stt", "a");
|
2010-08-11 17:02:31 +02:00
|
|
|
fprintf(f, "%8d %8d %8d %8d %8d\n", cm->current_video_frame, (100 * cpi->gf_active_count) / (cpi->common.mb_rows * cpi->common.mb_cols), cpi->this_iiratio, cpi->next_iiratio, cm->refresh_golden_frame);
|
2010-05-18 17:58:33 +02:00
|
|
|
fclose(f);
|
|
|
|
}
|
2010-09-24 17:10:25 +02:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-20 14:12:23 +02:00
|
|
|
cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
|
2011-02-25 12:42:05 +01:00
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
#if WRITE_RECON_BUFFER
|
|
|
|
if(cm->show_frame)
|
2011-12-01 01:36:46 +01:00
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame);
|
|
|
|
else
|
|
|
|
write_cx_frame_to_file(cm->frame_to_show,
|
|
|
|
cm->current_video_frame+1000);
|
2011-11-16 01:16:30 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
// Pick the loop filter level for the frame.
|
|
|
|
loopfilter_frame(cpi, cm);
|
2012-01-28 13:20:14 +01:00
|
|
|
|
2011-02-18 14:46:07 +01:00
|
|
|
// build the bitstream
|
2012-05-02 22:53:15 +02:00
|
|
|
cpi->dummy_packing = 0;
|
2011-02-18 14:46:07 +01:00
|
|
|
vp8_pack_bitstream(cpi, dest, size);
|
|
|
|
|
2012-04-11 16:44:14 +02:00
|
|
|
update_reference_frames(cm);
|
2012-06-06 00:25:07 +02:00
|
|
|
#if CONFIG_ADAPTIVE_ENTROPY
|
|
|
|
vp8_copy(cpi->common.fc.coef_counts, cpi->coef_counts);
|
|
|
|
vp8_copy(cpi->common.fc.coef_counts_8x8, cpi->coef_counts_8x8);
|
|
|
|
vp8_adapt_coef_probs(&cpi->common);
|
|
|
|
if (cpi->common.frame_type != KEY_FRAME)
|
|
|
|
{
|
|
|
|
vp8_copy(cpi->common.fc.ymode_counts, cpi->ymode_count);
|
|
|
|
vp8_copy(cpi->common.fc.uv_mode_counts, cpi->y_uv_mode_count);
|
|
|
|
vp8_copy(cpi->common.fc.bmode_counts, cpi->bmode_count);
|
|
|
|
vp8_copy(cpi->common.fc.i8x8_mode_counts, cpi->i8x8_mode_count);
|
|
|
|
vp8_adapt_mode_probs(&cpi->common);
|
|
|
|
|
|
|
|
vp8_copy(cpi->common.fc.MVcount, cpi->MVcount);
|
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
vp8_copy(cpi->common.fc.MVcount_hp, cpi->MVcount_hp);
|
|
|
|
#endif
|
|
|
|
vp8_adapt_mv_probs(&cpi->common);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADAPTIVE_ENTROPY */
|
2012-02-27 19:22:38 +01:00
|
|
|
|
2011-02-25 12:42:05 +01:00
|
|
|
/* Move storing frame_type out of the above loop since it is also
|
|
|
|
* needed in motion search besides loopfilter */
|
2011-04-20 14:12:23 +02:00
|
|
|
cm->last_frame_type = cm->frame_type;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-03-27 14:01:34 +02:00
|
|
|
// Keep a copy of the size estimate used in the loop
|
|
|
|
loop_size_estimate = cpi->projected_frame_size;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Update rate control heuristics
|
|
|
|
cpi->total_byte_count += (*size);
|
|
|
|
cpi->projected_frame_size = (*size) << 3;
|
|
|
|
|
|
|
|
if (!active_worst_qchanged)
|
|
|
|
vp8_update_rate_correction_factors(cpi, 2);
|
|
|
|
|
|
|
|
cpi->last_q[cm->frame_type] = cm->base_qindex;
|
|
|
|
|
2012-01-11 15:05:57 +01:00
|
|
|
// Keep record of last boosted (KF/KF/ARF) Q value.
|
|
|
|
// If the current frame is coded at a lower Q then we also update it.
|
|
|
|
// If all mbs in this group are skipped only update if the Q value is
|
|
|
|
// better than that already stored.
|
|
|
|
// This is used to help set quality in forced key frames to reduce popping
|
|
|
|
if ( (cm->base_qindex < cpi->last_boosted_qindex) ||
|
|
|
|
( (cpi->static_mb_pct < 100) &&
|
|
|
|
( (cm->frame_type == KEY_FRAME) ||
|
|
|
|
cm->refresh_alt_ref_frame ||
|
|
|
|
(cm->refresh_golden_frame && !cpi->is_src_frame_alt_ref) ) ) )
|
|
|
|
{
|
|
|
|
cpi->last_boosted_qindex = cm->base_qindex;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
|
|
|
vp8_adjust_key_frame_context(cpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep a record of ambient average Q.
|
2011-01-18 16:19:05 +01:00
|
|
|
if (cm->frame_type != KEY_FRAME)
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->avg_frame_qindex = (2 + 3 * cpi->avg_frame_qindex + cm->base_qindex) >> 2;
|
|
|
|
|
|
|
|
// Keep a record from which we can calculate the average Q excluding GF updates and key frames
|
|
|
|
if ((cm->frame_type != KEY_FRAME) && !cm->refresh_golden_frame && !cm->refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
cpi->ni_frames++;
|
2011-12-06 15:48:52 +01:00
|
|
|
cpi->tot_q += vp8_convert_qindex_to_q(Q);
|
|
|
|
cpi->avg_q = cpi->tot_q / (double)cpi->ni_frames;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-10 17:41:53 +01:00
|
|
|
// Calculate the average Q for normal inter frames (not key or GFU
|
|
|
|
// frames).
|
2012-02-17 17:29:03 +01:00
|
|
|
cpi->ni_tot_qi += Q;
|
|
|
|
cpi->ni_av_qi = (cpi->ni_tot_qi / cpi->ni_frames);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the buffer level variable.
|
2011-01-26 13:52:31 +01:00
|
|
|
// Non-viewable frames are a special case and are treated as pure overhead.
|
2011-08-12 20:51:36 +02:00
|
|
|
if ( !cm->show_frame )
|
|
|
|
cpi->bits_off_target -= cpi->projected_frame_size;
|
|
|
|
else
|
|
|
|
cpi->bits_off_target += cpi->av_per_frame_bandwidth - cpi->projected_frame_size;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-18 00:57:37 +01:00
|
|
|
// Clip the buffer level at the maximum buffer size
|
|
|
|
if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size)
|
|
|
|
cpi->bits_off_target = cpi->oxcf.maximum_buffer_size;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Rolling monitors of whether we are over or underspending used to help regulate min and Max Q in two pass.
|
|
|
|
cpi->rolling_target_bits = ((cpi->rolling_target_bits * 3) + cpi->this_frame_target + 2) / 4;
|
|
|
|
cpi->rolling_actual_bits = ((cpi->rolling_actual_bits * 3) + cpi->projected_frame_size + 2) / 4;
|
|
|
|
cpi->long_rolling_target_bits = ((cpi->long_rolling_target_bits * 31) + cpi->this_frame_target + 16) / 32;
|
|
|
|
cpi->long_rolling_actual_bits = ((cpi->long_rolling_actual_bits * 31) + cpi->projected_frame_size + 16) / 32;
|
|
|
|
|
|
|
|
// Actual bits spent
|
|
|
|
cpi->total_actual_bits += cpi->projected_frame_size;
|
|
|
|
|
|
|
|
// Debug stats
|
|
|
|
cpi->total_target_vs_actual += (cpi->this_frame_target - cpi->projected_frame_size);
|
|
|
|
|
2011-08-12 20:51:36 +02:00
|
|
|
cpi->buffer_level = cpi->bits_off_target;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Update bits left to the kf and gf groups to account for overshoot or undershoot on these frames
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.kf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.kf_group_bits < 0)
|
|
|
|
cpi->twopass.kf_group_bits = 0 ;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else if (cm->refresh_golden_frame || cm->refresh_alt_ref_frame)
|
|
|
|
{
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.gf_group_bits += cpi->this_frame_target - cpi->projected_frame_size;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.gf_group_bits < 0)
|
|
|
|
cpi->twopass.gf_group_bits = 0 ;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 15:37:48 +02:00
|
|
|
// Update the skip mb flag probabilities based on the distribution seen
|
|
|
|
// in this frame.
|
|
|
|
update_base_skip_probs( cpi );
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-06-07 14:39:20 +02:00
|
|
|
#if 1 && CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
FILE *f = fopen("tmp.stt", "a");
|
2012-03-27 14:01:34 +02:00
|
|
|
int recon_err;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
vp8_clear_system_state(); //__asm emms;
|
|
|
|
|
2012-03-27 14:01:34 +02:00
|
|
|
recon_err = vp8_calc_ss_err(cpi->Source,
|
|
|
|
&cm->yv12_fb[cm->new_fb_idx],
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
if (cpi->twopass.total_left_stats->coded_error != 0.0)
|
2012-03-27 14:01:34 +02:00
|
|
|
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d"
|
2012-01-11 15:05:57 +01:00
|
|
|
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f"
|
2011-11-24 19:25:03 +01:00
|
|
|
"%6d %5d %5d %5d %8d %8.2f %10d %10.3f"
|
2012-06-07 14:39:20 +02:00
|
|
|
"%10.3f %8d %10d %10d %10d\n",
|
2010-09-29 13:03:19 +02:00
|
|
|
cpi->common.current_video_frame, cpi->this_frame_target,
|
2012-03-27 14:01:34 +02:00
|
|
|
cpi->projected_frame_size, loop_size_estimate,
|
2010-09-29 13:03:19 +02:00
|
|
|
(cpi->projected_frame_size - cpi->this_frame_target),
|
|
|
|
(int)cpi->total_target_vs_actual,
|
|
|
|
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
|
2011-11-24 19:25:03 +01:00
|
|
|
(int)cpi->total_actual_bits,
|
|
|
|
vp8_convert_qindex_to_q(cm->base_qindex),
|
|
|
|
(double)vp8_dc_quant(cm->base_qindex,0)/4.0,
|
|
|
|
vp8_convert_qindex_to_q(cpi->active_best_quality),
|
|
|
|
vp8_convert_qindex_to_q(cpi->active_worst_quality),
|
2011-12-06 15:48:52 +01:00
|
|
|
cpi->avg_q,
|
2011-11-24 19:25:03 +01:00
|
|
|
vp8_convert_qindex_to_q(cpi->ni_av_qi),
|
|
|
|
vp8_convert_qindex_to_q(cpi->cq_target_quality),
|
2011-11-23 18:18:31 +01:00
|
|
|
cpi->zbin_over_quant,
|
2011-01-07 19:29:37 +01:00
|
|
|
//cpi->avg_frame_qindex, cpi->zbin_over_quant,
|
2010-09-29 13:03:19 +02:00
|
|
|
cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
|
|
|
|
cm->frame_type, cpi->gfu_boost,
|
2011-11-23 18:18:31 +01:00
|
|
|
cpi->twopass.est_max_qcorrection_factor,
|
|
|
|
(int)cpi->twopass.bits_left,
|
|
|
|
cpi->twopass.total_left_stats->coded_error,
|
|
|
|
(double)cpi->twopass.bits_left /
|
|
|
|
cpi->twopass.total_left_stats->coded_error,
|
2012-06-07 14:39:20 +02:00
|
|
|
cpi->tot_recode_hits, recon_err, cpi->kf_boost,
|
|
|
|
cpi->kf_zeromotion_pct);
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
2012-03-27 14:01:34 +02:00
|
|
|
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d"
|
2012-01-11 15:05:57 +01:00
|
|
|
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f"
|
2011-11-24 19:25:03 +01:00
|
|
|
"%6d %5d %5d %5d %8d %8.2f %10d %10.3f"
|
2012-06-07 14:39:20 +02:00
|
|
|
"%8d %10d %10d %10d\n",
|
2010-09-29 13:03:19 +02:00
|
|
|
cpi->common.current_video_frame,
|
|
|
|
cpi->this_frame_target, cpi->projected_frame_size,
|
2012-03-27 14:01:34 +02:00
|
|
|
loop_size_estimate,
|
2010-09-29 13:03:19 +02:00
|
|
|
(cpi->projected_frame_size - cpi->this_frame_target),
|
|
|
|
(int)cpi->total_target_vs_actual,
|
|
|
|
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
|
2011-11-24 19:25:03 +01:00
|
|
|
(int)cpi->total_actual_bits,
|
|
|
|
vp8_convert_qindex_to_q(cm->base_qindex),
|
|
|
|
(double)vp8_dc_quant(cm->base_qindex,0)/4.0,
|
|
|
|
vp8_convert_qindex_to_q(cpi->active_best_quality),
|
|
|
|
vp8_convert_qindex_to_q(cpi->active_worst_quality),
|
2011-12-06 15:48:52 +01:00
|
|
|
cpi->avg_q,
|
2011-11-24 19:25:03 +01:00
|
|
|
vp8_convert_qindex_to_q(cpi->ni_av_qi),
|
|
|
|
vp8_convert_qindex_to_q(cpi->cq_target_quality),
|
2011-11-23 18:18:31 +01:00
|
|
|
cpi->zbin_over_quant,
|
2011-01-07 19:29:37 +01:00
|
|
|
//cpi->avg_frame_qindex, cpi->zbin_over_quant,
|
2010-09-29 13:03:19 +02:00
|
|
|
cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
|
|
|
|
cm->frame_type, cpi->gfu_boost,
|
2011-11-23 18:18:31 +01:00
|
|
|
cpi->twopass.est_max_qcorrection_factor,
|
|
|
|
(int)cpi->twopass.bits_left,
|
|
|
|
cpi->twopass.total_left_stats->coded_error,
|
2012-06-07 14:39:20 +02:00
|
|
|
cpi->tot_recode_hits, recon_err, cpi->kf_boost,
|
|
|
|
cpi->kf_zeromotion_pct);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
2011-11-23 18:18:31 +01:00
|
|
|
if ( 0 )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
FILE *fmodes = fopen("Modes.stt", "a");
|
|
|
|
int i;
|
|
|
|
|
2010-09-29 13:03:19 +02:00
|
|
|
fprintf(fmodes, "%6d:%1d:%1d:%1d ",
|
|
|
|
cpi->common.current_video_frame,
|
|
|
|
cm->frame_type, cm->refresh_golden_frame,
|
|
|
|
cm->refresh_alt_ref_frame);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]);
|
|
|
|
|
|
|
|
fprintf(fmodes, "\n");
|
|
|
|
|
|
|
|
fclose(fmodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-30 17:45:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// Debug stats for segment feature experiments.
|
|
|
|
print_seg_map(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// If this was a kf or Gf note the Q
|
|
|
|
if ((cm->frame_type == KEY_FRAME) || cm->refresh_golden_frame || cm->refresh_alt_ref_frame)
|
|
|
|
cm->last_kf_gf_q = cm->base_qindex;
|
|
|
|
|
|
|
|
if (cm->refresh_golden_frame == 1)
|
|
|
|
cm->frame_flags = cm->frame_flags | FRAMEFLAGS_GOLDEN;
|
|
|
|
else
|
|
|
|
cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_GOLDEN;
|
|
|
|
|
|
|
|
if (cm->refresh_alt_ref_frame == 1)
|
|
|
|
cm->frame_flags = cm->frame_flags | FRAMEFLAGS_ALTREF;
|
|
|
|
else
|
|
|
|
cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_ALTREF;
|
|
|
|
|
|
|
|
|
|
|
|
if (cm->refresh_last_frame & cm->refresh_golden_frame) // both refreshed
|
|
|
|
cpi->gold_is_last = 1;
|
|
|
|
else if (cm->refresh_last_frame ^ cm->refresh_golden_frame) // 1 refreshed but not the other
|
|
|
|
cpi->gold_is_last = 0;
|
|
|
|
|
|
|
|
if (cm->refresh_last_frame & cm->refresh_alt_ref_frame) // both refreshed
|
|
|
|
cpi->alt_is_last = 1;
|
|
|
|
else if (cm->refresh_last_frame ^ cm->refresh_alt_ref_frame) // 1 refreshed but not the other
|
|
|
|
cpi->alt_is_last = 0;
|
|
|
|
|
|
|
|
if (cm->refresh_alt_ref_frame & cm->refresh_golden_frame) // both refreshed
|
|
|
|
cpi->gold_is_alt = 1;
|
|
|
|
else if (cm->refresh_alt_ref_frame ^ cm->refresh_golden_frame) // 1 refreshed but not the other
|
|
|
|
cpi->gold_is_alt = 0;
|
|
|
|
|
|
|
|
cpi->ref_frame_flags = VP8_ALT_FLAG | VP8_GOLD_FLAG | VP8_LAST_FLAG;
|
|
|
|
|
|
|
|
if (cpi->gold_is_last)
|
2010-06-18 16:58:18 +02:00
|
|
|
cpi->ref_frame_flags &= ~VP8_GOLD_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->alt_is_last)
|
2010-06-18 16:58:18 +02:00
|
|
|
cpi->ref_frame_flags &= ~VP8_ALT_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->gold_is_alt)
|
2010-06-18 16:58:18 +02:00
|
|
|
cpi->ref_frame_flags &= ~VP8_ALT_FLAG;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-26 02:15:47 +01:00
|
|
|
if (cpi->oxcf.play_alternate && cm->refresh_alt_ref_frame && (cm->frame_type != KEY_FRAME))
|
|
|
|
// Update the alternate reference frame stats as appropriate.
|
|
|
|
update_alt_ref_frame_stats(cpi);
|
|
|
|
else
|
|
|
|
// Update the Golden frame stats as appropriate.
|
|
|
|
update_golden_frame_stats(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME)
|
|
|
|
{
|
|
|
|
// Tell the caller that the frame was coded as a key frame
|
|
|
|
*frame_flags = cm->frame_flags | FRAMEFLAGS_KEY;
|
|
|
|
|
|
|
|
// As this frame is a key frame the next defaults to an inter frame.
|
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*frame_flags = cm->frame_flags&~FRAMEFLAGS_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the one shot update flags for segmentation map and mode/ref loop filter deltas.
|
2011-11-15 17:15:23 +01:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Dont increment frame counters if this was an altref buffer update not a real frame
|
|
|
|
if (cm->show_frame)
|
|
|
|
{
|
|
|
|
cm->current_video_frame++;
|
|
|
|
cpi->frames_since_key++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset to normal state now that we are done.
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-24 17:10:25 +02:00
|
|
|
#if 0
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
char filename[512];
|
|
|
|
FILE *recon_file;
|
|
|
|
sprintf(filename, "enc%04d.yuv", (int) cm->current_video_frame);
|
|
|
|
recon_file = fopen(filename, "wb");
|
2010-07-22 14:07:32 +02:00
|
|
|
fwrite(cm->yv12_fb[cm->lst_fb_idx].buffer_alloc,
|
|
|
|
cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file);
|
2010-05-18 17:58:33 +02:00
|
|
|
fclose(recon_file);
|
|
|
|
}
|
2010-09-24 17:10:25 +02:00
|
|
|
#endif
|
2012-02-27 19:22:38 +01:00
|
|
|
#ifdef OUTPUT_YUV_REC
|
2011-02-14 23:18:18 +01:00
|
|
|
vp8_write_yuv_rec_frame(cm);
|
2010-12-02 00:50:14 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
if(cm->show_frame)
|
|
|
|
{
|
|
|
|
vpx_memcpy(cm->prev_mip, cm->mip,
|
|
|
|
(cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vpx_memset(cm->prev_mip, 0,
|
|
|
|
(cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!cpi->common.refresh_alt_ref_frame)
|
|
|
|
vp8_second_pass(cpi);
|
|
|
|
|
|
|
|
encode_frame_to_data_rate(cpi, size, dest, frame_flags);
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.bits_left -= 8 * *size;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (!cpi->common.refresh_alt_ref_frame)
|
2010-05-20 00:48:00 +02:00
|
|
|
{
|
2012-03-02 02:24:30 +01:00
|
|
|
double lower_bounds_min_rate = FRAME_OVERHEAD_BITS*cpi->oxcf.frame_rate;
|
2010-05-20 00:48:00 +02:00
|
|
|
double two_pass_min_rate = (double)(cpi->oxcf.target_bandwidth
|
|
|
|
*cpi->oxcf.two_pass_vbrmin_section / 100);
|
2012-03-02 02:24:30 +01:00
|
|
|
|
|
|
|
if (two_pass_min_rate < lower_bounds_min_rate)
|
|
|
|
two_pass_min_rate = lower_bounds_min_rate;
|
|
|
|
|
2011-07-26 03:44:59 +02:00
|
|
|
cpi->twopass.bits_left += (int64_t)(two_pass_min_rate / cpi->oxcf.frame_rate);
|
2010-05-20 00:48:00 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//For ARM NEON, d8-d15 are callee-saved registers, and need to be saved by us.
|
|
|
|
#if HAVE_ARMV7
|
2011-07-26 03:44:59 +02:00
|
|
|
extern void vp8_push_neon(int64_t *store);
|
|
|
|
extern void vp8_pop_neon(int64_t *store);
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
2011-04-13 20:00:18 +02:00
|
|
|
|
|
|
|
|
2011-07-26 03:44:59 +02:00
|
|
|
int vp8_receive_raw_frame(VP8_PTR ptr, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-01-11 13:01:24 +01:00
|
|
|
#if HAVE_ARMV7
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t store_reg[8];
|
2011-01-11 13:01:24 +01:00
|
|
|
#endif
|
2011-04-13 20:00:18 +02:00
|
|
|
VP8_COMP *cpi = (VP8_COMP *) ptr;
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
struct vpx_usec_timer timer;
|
2011-04-13 20:00:18 +02:00
|
|
|
int res = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#if HAVE_ARMV7
|
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 CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
if (cm->rtcd.flags & HAS_NEON)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vp8_push_neon(store_reg);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
vpx_usec_timer_start(&timer);
|
2011-04-13 20:00:18 +02:00
|
|
|
if(vp8_lookahead_push(cpi->lookahead, sd, time_stamp, end_time,
|
2011-08-09 21:59:45 +02:00
|
|
|
frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL))
|
2011-04-13 20:00:18 +02:00
|
|
|
res = -1;
|
2010-05-18 17:58:33 +02:00
|
|
|
cm->clr_type = sd->clrtype;
|
|
|
|
vpx_usec_timer_mark(&timer);
|
|
|
|
cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
|
|
|
|
|
|
|
|
#if HAVE_ARMV7
|
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 CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
if (cm->rtcd.flags & HAS_NEON)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vp8_pop_neon(store_reg);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
return res;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-04-13 20:00:18 +02:00
|
|
|
|
|
|
|
|
2011-07-07 16:38:23 +02:00
|
|
|
static int frame_is_reference(const VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
const VP8_COMMON *cm = &cpi->common;
|
|
|
|
const MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
|
|
|
|
return cm->frame_type == KEY_FRAME || cm->refresh_last_frame
|
|
|
|
|| cm->refresh_golden_frame || cm->refresh_alt_ref_frame
|
|
|
|
|| cm->copy_buffer_to_gf || cm->copy_buffer_to_arf
|
|
|
|
|| cm->refresh_entropy_probs
|
|
|
|
|| xd->mode_ref_lf_delta_update
|
|
|
|
|| xd->update_mb_segmentation_map || xd->update_mb_segmentation_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-26 03:44:59 +02:00
|
|
|
int vp8_get_compressed_data(VP8_PTR ptr, unsigned int *frame_flags, unsigned long *size, unsigned char *dest, int64_t *time_stamp, int64_t *time_end, int flush)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-01-11 13:01:24 +01:00
|
|
|
#if HAVE_ARMV7
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t store_reg[8];
|
2011-01-11 13:01:24 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
VP8_COMP *cpi = (VP8_COMP *) ptr;
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
struct vpx_usec_timer cmptimer;
|
2011-04-13 20:00:18 +02:00
|
|
|
YV12_BUFFER_CONFIG *force_src_buffer = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (!cpi)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#if HAVE_ARMV7
|
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 CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
if (cm->rtcd.flags & HAS_NEON)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vp8_push_neon(store_reg);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
vpx_usec_timer_start(&cmptimer);
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->source = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
cpi->mb.e_mbd.allow_high_precision_mv = ALTREF_HIGH_PRECISION_MV;
|
|
|
|
#endif
|
2011-04-13 20:00:18 +02:00
|
|
|
// Should we code an alternate reference frame
|
2012-02-26 02:15:47 +01:00
|
|
|
if (cpi->oxcf.play_alternate &&
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->source_alt_ref_pending)
|
|
|
|
{
|
|
|
|
if ((cpi->source = vp8_lookahead_peek(cpi->lookahead,
|
|
|
|
cpi->frames_till_gf_update_due)))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->alt_ref_source = cpi->source;
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->oxcf.arnr_max_frames > 0)
|
|
|
|
{
|
2011-04-13 20:00:18 +02:00
|
|
|
vp8_temporal_filter_prepare_c(cpi,
|
|
|
|
cpi->frames_till_gf_update_due);
|
|
|
|
force_src_buffer = &cpi->alt_ref_buffer;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
cm->frames_till_alt_ref_frame = cpi->frames_till_gf_update_due;
|
|
|
|
cm->refresh_alt_ref_frame = 1;
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cm->refresh_last_frame = 0;
|
|
|
|
cm->show_frame = 0;
|
|
|
|
cpi->source_alt_ref_pending = FALSE; // Clear Pending altf Ref flag.
|
|
|
|
cpi->is_src_frame_alt_ref = 0;
|
|
|
|
}
|
2011-04-13 20:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpi->source)
|
|
|
|
{
|
|
|
|
if ((cpi->source = vp8_lookahead_pop(cpi->lookahead, flush)))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
cm->show_frame = 1;
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->is_src_frame_alt_ref = cpi->alt_ref_source
|
|
|
|
&& (cpi->source == cpi->alt_ref_source);
|
2010-10-15 03:58:34 +02:00
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
if(cpi->is_src_frame_alt_ref)
|
|
|
|
cpi->alt_ref_source = NULL;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-04-13 20:00:18 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
if (cpi->source)
|
|
|
|
{
|
|
|
|
cpi->un_scaled_source =
|
|
|
|
cpi->Source = force_src_buffer ? force_src_buffer : &cpi->source->img;
|
|
|
|
*time_stamp = cpi->source->ts_start;
|
|
|
|
*time_end = cpi->source->ts_end;
|
|
|
|
*frame_flags = cpi->source->flags;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*size = 0;
|
2011-05-19 23:16:39 +02:00
|
|
|
if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
vp8_end_first_pass(cpi); /* get last stats packet */
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->twopass.first_pass_done = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_ARMV7
|
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 CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
if (cm->rtcd.flags & HAS_NEON)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vp8_pop_neon(store_reg);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
if (cpi->source->ts_start < cpi->first_time_stamp_ever)
|
2010-11-04 20:05:45 +01:00
|
|
|
{
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->first_time_stamp_ever = cpi->source->ts_start;
|
|
|
|
cpi->last_end_time_stamp_seen = cpi->source->ts_start;
|
2010-11-04 20:05:45 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// adjust frame rates based on timestamps given
|
|
|
|
if (!cm->refresh_alt_ref_frame)
|
|
|
|
{
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t this_duration;
|
2011-05-12 21:04:06 +02:00
|
|
|
int step = 0;
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
if (cpi->source->ts_start == cpi->first_time_stamp_ever)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-12 21:04:06 +02:00
|
|
|
this_duration = cpi->source->ts_end - cpi->source->ts_start;
|
|
|
|
step = 1;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t last_duration;
|
2011-05-12 21:04:06 +02:00
|
|
|
|
|
|
|
this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
|
|
|
|
last_duration = cpi->last_end_time_stamp_seen
|
|
|
|
- cpi->last_time_stamp_seen;
|
|
|
|
// do a step update if the duration changes by 10%
|
|
|
|
if (last_duration)
|
|
|
|
step = ((this_duration - last_duration) * 10 / last_duration);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 21:04:06 +02:00
|
|
|
if (this_duration)
|
|
|
|
{
|
|
|
|
if (step)
|
|
|
|
vp8_new_frame_rate(cpi, 10000000.0 / this_duration);
|
|
|
|
else
|
2011-03-01 23:59:22 +01:00
|
|
|
{
|
2011-05-12 21:04:06 +02:00
|
|
|
double avg_duration, interval;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 21:04:06 +02:00
|
|
|
/* Average this frame's rate into the last second's average
|
|
|
|
* frame rate. If we haven't seen 1 second yet, then average
|
|
|
|
* over the whole interval seen.
|
|
|
|
*/
|
|
|
|
interval = cpi->source->ts_end - cpi->first_time_stamp_ever;
|
|
|
|
if(interval > 10000000.0)
|
|
|
|
interval = 10000000;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 21:04:06 +02:00
|
|
|
avg_duration = 10000000.0 / cpi->oxcf.frame_rate;
|
|
|
|
avg_duration *= (interval - avg_duration + this_duration);
|
|
|
|
avg_duration /= interval;
|
|
|
|
|
|
|
|
vp8_new_frame_rate(cpi, 10000000.0 / avg_duration);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-04-13 20:00:18 +02:00
|
|
|
cpi->last_time_stamp_seen = cpi->source->ts_start;
|
|
|
|
cpi->last_end_time_stamp_seen = cpi->source->ts_end;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// start with a 0 size frame
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
// Clear down mmx registers
|
|
|
|
vp8_clear_system_state(); //__asm emms;
|
|
|
|
|
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
cm->frame_flags = *frame_flags;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
if (cm->refresh_alt_ref_frame)
|
|
|
|
{
|
|
|
|
//cm->refresh_golden_frame = 1;
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cm->refresh_last_frame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cm->refresh_last_frame = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2011-04-20 14:12:23 +02:00
|
|
|
/* find a free buffer for the new frame */
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
for(; i < NUM_YV12_BUFFERS; i++)
|
|
|
|
{
|
|
|
|
if(!cm->yv12_fb[i].flags)
|
|
|
|
{
|
|
|
|
cm->new_fb_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-20 14:12:23 +02:00
|
|
|
assert(i < NUM_YV12_BUFFERS );
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->pass == 1)
|
|
|
|
{
|
|
|
|
Pass1Encode(cpi, size, dest, frame_flags);
|
|
|
|
}
|
|
|
|
else if (cpi->pass == 2)
|
|
|
|
{
|
|
|
|
Pass2Encode(cpi, size, dest, frame_flags);
|
|
|
|
}
|
|
|
|
else
|
2012-02-13 18:05:26 +01:00
|
|
|
encode_frame_to_data_rate(cpi, size, dest, frame_flags);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-12-01 01:36:46 +01:00
|
|
|
if(cm->refresh_entropy_probs)
|
|
|
|
{
|
|
|
|
if(cm->refresh_alt_ref_frame)
|
|
|
|
vpx_memcpy(&cm->lfc_a, &cm->fc, sizeof(cm->fc));
|
|
|
|
else
|
|
|
|
vpx_memcpy(&cm->lfc, &cm->fc, sizeof(cm->fc));
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// if its a dropped frame honor the requests on subsequent frames
|
|
|
|
if (*size > 0)
|
|
|
|
{
|
2011-07-07 16:38:23 +02:00
|
|
|
cpi->droppable = !frame_is_reference(cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// return to normal state
|
|
|
|
cm->refresh_entropy_probs = 1;
|
|
|
|
cm->refresh_alt_ref_frame = 0;
|
|
|
|
cm->refresh_golden_frame = 0;
|
|
|
|
cm->refresh_last_frame = 1;
|
|
|
|
cm->frame_type = INTER_FRAME;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vpx_usec_timer_mark(&cmptimer);
|
|
|
|
cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
|
|
|
|
|
|
|
|
if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame)
|
2011-02-25 12:42:05 +01:00
|
|
|
{
|
2010-05-18 17:58:33 +02:00
|
|
|
generate_psnr_packet(cpi);
|
2011-02-25 12:42:05 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-04-29 18:37:59 +02:00
|
|
|
#if CONFIG_INTERNAL_STATS
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->pass != 1)
|
|
|
|
{
|
|
|
|
cpi->bytes += *size;
|
|
|
|
|
|
|
|
if (cm->show_frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
cpi->count ++;
|
|
|
|
|
|
|
|
if (cpi->b_calculate_psnr)
|
|
|
|
{
|
2011-03-08 21:23:40 +01:00
|
|
|
double ye,ue,ve;
|
|
|
|
double frame_psnr;
|
|
|
|
YV12_BUFFER_CONFIG *orig = cpi->Source;
|
|
|
|
YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
|
|
|
|
YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer;
|
|
|
|
int y_samples = orig->y_height * orig->y_width ;
|
|
|
|
int uv_samples = orig->uv_height * orig->uv_width ;
|
|
|
|
int t_samples = y_samples + 2 * uv_samples;
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t sq_error;
|
2011-03-08 21:23:40 +01:00
|
|
|
|
|
|
|
ye = calc_plane_error(orig->y_buffer, orig->y_stride,
|
|
|
|
recon->y_buffer, recon->y_stride, orig->y_width, orig->y_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
|
|
|
ue = calc_plane_error(orig->u_buffer, orig->uv_stride,
|
|
|
|
recon->u_buffer, recon->uv_stride, orig->uv_width, orig->uv_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
|
|
|
ve = calc_plane_error(orig->v_buffer, orig->uv_stride,
|
|
|
|
recon->v_buffer, recon->uv_stride, orig->uv_width, orig->uv_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
|
|
|
sq_error = ye + ue + ve;
|
|
|
|
|
|
|
|
frame_psnr = vp8_mse2psnr(t_samples, 255.0, sq_error);
|
|
|
|
|
|
|
|
cpi->total_y += vp8_mse2psnr(y_samples, 255.0, ye);
|
|
|
|
cpi->total_u += vp8_mse2psnr(uv_samples, 255.0, ue);
|
|
|
|
cpi->total_v += vp8_mse2psnr(uv_samples, 255.0, ve);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->total_sq_error += sq_error;
|
|
|
|
cpi->total += frame_psnr;
|
|
|
|
{
|
2011-04-13 20:00:18 +02:00
|
|
|
double frame_psnr2, frame_ssim2 = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
double weight = 0;
|
|
|
|
|
|
|
|
vp8_deblock(cm->frame_to_show, &cm->post_proc_buffer, cm->filter_level * 10 / 6, 1, 0, IF_RTCD(&cm->rtcd.postproc));
|
|
|
|
vp8_clear_system_state();
|
|
|
|
|
2011-03-08 21:23:40 +01:00
|
|
|
ye = calc_plane_error(orig->y_buffer, orig->y_stride,
|
|
|
|
pp->y_buffer, pp->y_stride, orig->y_width, orig->y_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-03-08 21:23:40 +01:00
|
|
|
ue = calc_plane_error(orig->u_buffer, orig->uv_stride,
|
|
|
|
pp->u_buffer, pp->uv_stride, orig->uv_width, orig->uv_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
|
|
|
ve = calc_plane_error(orig->v_buffer, orig->uv_stride,
|
|
|
|
pp->v_buffer, pp->uv_stride, orig->uv_width, orig->uv_height,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
|
|
|
|
|
|
|
sq_error = ye + ue + ve;
|
|
|
|
|
|
|
|
frame_psnr2 = vp8_mse2psnr(t_samples, 255.0, sq_error);
|
|
|
|
|
|
|
|
cpi->totalp_y += vp8_mse2psnr(y_samples, 255.0, ye);
|
|
|
|
cpi->totalp_u += vp8_mse2psnr(uv_samples, 255.0, ue);
|
|
|
|
cpi->totalp_v += vp8_mse2psnr(uv_samples, 255.0, ve);
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->total_sq_error2 += sq_error;
|
2011-03-08 21:23:40 +01:00
|
|
|
cpi->totalp += frame_psnr2;
|
2011-03-08 15:05:18 +01:00
|
|
|
|
|
|
|
frame_ssim2 = vp8_calc_ssim(cpi->Source,
|
|
|
|
&cm->post_proc_buffer, 1, &weight,
|
|
|
|
IF_RTCD(&cpi->rtcd.variance));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->summed_quality += frame_ssim2 * weight;
|
|
|
|
cpi->summed_weights += weight;
|
2010-12-02 00:50:14 +01:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
FILE *f = fopen("q_used.stt", "a");
|
|
|
|
fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
|
|
|
|
cpi->common.current_video_frame,y2, u2, v2,
|
|
|
|
frame_psnr2, frame_ssim2);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->b_calculate_ssimg)
|
|
|
|
{
|
|
|
|
double y, u, v, frame_all;
|
2011-05-03 00:27:14 +02:00
|
|
|
frame_all = vp8_calc_ssimg(cpi->Source, cm->frame_to_show,
|
|
|
|
&y, &u, &v, IF_RTCD(&cpi->rtcd.variance));
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->total_ssimg_y += y;
|
|
|
|
cpi->total_ssimg_u += u;
|
|
|
|
cpi->total_ssimg_v += v;
|
|
|
|
cpi->total_ssimg_all += frame_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_ARMV7
|
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 CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
if (cm->rtcd.flags & HAS_NEON)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
vp8_pop_neon(store_reg);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-05 00:03:36 +01:00
|
|
|
int vp8_get_preview_raw_frame(VP8_PTR comp, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *flags)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) comp;
|
|
|
|
|
|
|
|
if (cpi->common.refresh_alt_ref_frame)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
#if CONFIG_POSTPROC
|
2010-11-05 00:03:36 +01:00
|
|
|
ret = vp8_post_proc_frame(&cpi->common, dest, flags);
|
2010-05-18 17:58:33 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
if (cpi->common.frame_to_show)
|
|
|
|
{
|
|
|
|
*dest = *cpi->common.frame_to_show;
|
|
|
|
dest->y_width = cpi->common.Width;
|
|
|
|
dest->y_height = cpi->common.Height;
|
|
|
|
dest->uv_height = cpi->common.Height / 2;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //!CONFIG_POSTPROC
|
|
|
|
vp8_clear_system_state();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_set_roimap(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned int cols, int delta_q[4], int delta_lf[4], unsigned int threshold[4])
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) comp;
|
2011-09-13 12:26:39 +02:00
|
|
|
signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
|
2011-10-05 12:26:00 +02:00
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!map)
|
|
|
|
{
|
2011-10-05 12:26:00 +02:00
|
|
|
vp8_disable_segmentation((VP8_PTR)cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the segmentation Map
|
2011-10-05 12:26:00 +02:00
|
|
|
vp8_set_segmentation_map((VP8_PTR)cpi, map);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Activate segmentation.
|
2011-10-05 12:26:00 +02:00
|
|
|
vp8_enable_segmentation((VP8_PTR)cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Set up the quant segment data
|
2011-09-13 12:26:39 +02:00
|
|
|
feature_data[SEG_LVL_ALT_Q][0] = delta_q[0];
|
|
|
|
feature_data[SEG_LVL_ALT_Q][1] = delta_q[1];
|
|
|
|
feature_data[SEG_LVL_ALT_Q][2] = delta_q[2];
|
|
|
|
feature_data[SEG_LVL_ALT_Q][3] = delta_q[3];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Set up the loop segment data s
|
2011-09-13 12:26:39 +02:00
|
|
|
feature_data[SEG_LVL_ALT_LF][0] = delta_lf[0];
|
|
|
|
feature_data[SEG_LVL_ALT_LF][1] = delta_lf[1];
|
|
|
|
feature_data[SEG_LVL_ALT_LF][2] = delta_lf[2];
|
|
|
|
feature_data[SEG_LVL_ALT_LF][3] = delta_lf[3];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cpi->segment_encode_breakout[0] = threshold[0];
|
|
|
|
cpi->segment_encode_breakout[1] = threshold[1];
|
|
|
|
cpi->segment_encode_breakout[2] = threshold[2];
|
|
|
|
cpi->segment_encode_breakout[3] = threshold[3];
|
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
// Enable the loop and quant changes in the feature mask
|
|
|
|
for ( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
if (delta_q[i])
|
|
|
|
enable_segfeature(xd, i, SEG_LVL_ALT_Q);
|
|
|
|
else
|
|
|
|
disable_segfeature(xd, i, SEG_LVL_ALT_Q);
|
|
|
|
|
|
|
|
if (delta_lf[i])
|
|
|
|
enable_segfeature(xd, i, SEG_LVL_ALT_LF);
|
|
|
|
else
|
|
|
|
disable_segfeature(xd, i, SEG_LVL_ALT_LF);
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Initialise the feature data structure
|
|
|
|
// SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1
|
2011-10-05 12:26:00 +02:00
|
|
|
vp8_set_segment_data((VP8_PTR)cpi, &feature_data[0][0], SEGMENT_DELTADATA);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_set_active_map(VP8_PTR comp, unsigned char *map, unsigned int rows, unsigned int cols)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) comp;
|
|
|
|
|
|
|
|
if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols)
|
|
|
|
{
|
|
|
|
if (map)
|
|
|
|
{
|
|
|
|
vpx_memcpy(cpi->active_map, map, rows * cols);
|
|
|
|
cpi->active_map_enabled = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cpi->active_map_enabled = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//cpi->active_map_enabled = 0;
|
|
|
|
return -1 ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_set_internal_size(VP8_PTR comp, VPX_SCALING horiz_mode, VPX_SCALING vert_mode)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) comp;
|
|
|
|
|
2010-11-18 01:50:02 +01:00
|
|
|
if (horiz_mode <= ONETWO)
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->common.horiz_scale = horiz_mode;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
2010-11-18 01:50:02 +01:00
|
|
|
if (vert_mode <= ONETWO)
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->common.vert_scale = vert_mode;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const vp8_variance_rtcd_vtable_t *rtcd)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int Total = 0;
|
|
|
|
|
|
|
|
unsigned char *src = source->y_buffer;
|
|
|
|
unsigned char *dst = dest->y_buffer;
|
|
|
|
(void)rtcd;
|
|
|
|
|
|
|
|
// Loop through the Y plane raw and reconstruction data summing (square differences)
|
|
|
|
for (i = 0; i < source->y_height; i += 16)
|
|
|
|
{
|
|
|
|
for (j = 0; j < source->y_width; j += 16)
|
|
|
|
{
|
|
|
|
unsigned int sse;
|
|
|
|
Total += VARIANCE_INVOKE(rtcd, mse16x16)(src + j, source->y_stride, dst + j, dest->y_stride, &sse);
|
|
|
|
}
|
|
|
|
|
|
|
|
src += 16 * source->y_stride;
|
|
|
|
dst += 16 * dest->y_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Total;
|
|
|
|
}
|
2011-03-17 22:07:59 +01:00
|
|
|
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
int vp8_get_quantizer(VP8_PTR c)
|
|
|
|
{
|
|
|
|
VP8_COMP *cpi = (VP8_COMP *) c;
|
|
|
|
return cpi->common.base_qindex;
|
|
|
|
}
|