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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/pragmas.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#include "tokenize.h"
|
|
|
|
#include "treewriter.h"
|
|
|
|
#include "onyx_int.h"
|
|
|
|
#include "modecosts.h"
|
|
|
|
#include "encodeintra.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/entropymode.h"
|
|
|
|
#include "vp8/common/reconinter.h"
|
|
|
|
#include "vp8/common/reconintra.h"
|
|
|
|
#include "vp8/common/reconintra4x4.h"
|
|
|
|
#include "vp8/common/findnearmv.h"
|
2011-12-22 01:19:09 +01:00
|
|
|
#include "vp8/common/quant_common.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "encodemb.h"
|
|
|
|
#include "quantize.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/idct.h"
|
|
|
|
#include "vp8/common/g_common.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "variance.h"
|
|
|
|
#include "mcomp.h"
|
2011-04-07 22:57:25 +02:00
|
|
|
#include "rdopt.h"
|
2011-11-21 16:45:10 +01:00
|
|
|
#include "ratectrl.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
#include "dct.h"
|
2011-02-10 20:41:38 +01:00
|
|
|
#include "vp8/common/systemdependent.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
#include "vp8/common/seg_common.h"
|
2012-01-28 13:20:14 +01:00
|
|
|
#include "vp8/common/pred_common.h"
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#if CONFIG_RUNTIME_CPU_DETECT
|
|
|
|
#define IF_RTCD(x) (x)
|
|
|
|
#else
|
|
|
|
#define IF_RTCD(x) NULL
|
|
|
|
#endif
|
|
|
|
|
2010-12-29 20:30:57 +01:00
|
|
|
extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x);
|
|
|
|
extern void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x);
|
|
|
|
|
2012-03-01 12:10:21 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
#define XMVCOST (x->e_mbd.allow_high_precision_mv?x->mvcost_hp:x->mvcost)
|
|
|
|
#else
|
|
|
|
#define XMVCOST (x->mvcost)
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
#define MAXF(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
static const int auto_speed_thresh[17] =
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
1000,
|
|
|
|
200,
|
|
|
|
150,
|
|
|
|
130,
|
|
|
|
150,
|
|
|
|
125,
|
|
|
|
120,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
115,
|
|
|
|
105
|
|
|
|
};
|
|
|
|
|
|
|
|
const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES] =
|
|
|
|
{
|
|
|
|
ZEROMV,
|
|
|
|
DC_PRED,
|
|
|
|
|
|
|
|
NEARESTMV,
|
|
|
|
NEARMV,
|
|
|
|
|
|
|
|
ZEROMV,
|
|
|
|
NEARESTMV,
|
|
|
|
|
|
|
|
ZEROMV,
|
|
|
|
NEARESTMV,
|
|
|
|
|
|
|
|
NEARMV,
|
|
|
|
NEARMV,
|
|
|
|
|
|
|
|
V_PRED,
|
|
|
|
H_PRED,
|
|
|
|
TM_PRED,
|
|
|
|
|
|
|
|
NEWMV,
|
|
|
|
NEWMV,
|
|
|
|
NEWMV,
|
|
|
|
|
|
|
|
SPLITMV,
|
|
|
|
SPLITMV,
|
|
|
|
SPLITMV,
|
|
|
|
|
|
|
|
B_PRED,
|
2011-12-01 01:25:00 +01:00
|
|
|
I8X8_PRED,
|
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
|
|
|
/* compound prediction modes */
|
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
|
|
|
ZEROMV,
|
|
|
|
NEARESTMV,
|
|
|
|
NEARMV,
|
|
|
|
|
|
|
|
ZEROMV,
|
|
|
|
NEARESTMV,
|
|
|
|
NEARMV,
|
|
|
|
|
|
|
|
ZEROMV,
|
|
|
|
NEARESTMV,
|
|
|
|
NEARMV,
|
|
|
|
|
|
|
|
NEWMV,
|
|
|
|
NEWMV,
|
|
|
|
NEWMV,
|
2010-05-18 17:58:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES] =
|
|
|
|
{
|
|
|
|
LAST_FRAME,
|
|
|
|
INTRA_FRAME,
|
|
|
|
|
|
|
|
LAST_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
|
|
|
|
ALTREF_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
INTRA_FRAME,
|
|
|
|
INTRA_FRAME,
|
|
|
|
INTRA_FRAME,
|
|
|
|
|
|
|
|
LAST_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
LAST_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
INTRA_FRAME,
|
2011-12-01 01:25:00 +01:00
|
|
|
INTRA_FRAME,
|
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
|
|
|
/* compound prediction modes */
|
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
|
|
|
LAST_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
|
|
|
|
ALTREF_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
|
|
|
|
LAST_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
};
|
|
|
|
|
|
|
|
const MV_REFERENCE_FRAME vp8_second_ref_frame_order[MAX_MODES] =
|
|
|
|
{
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0,
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
/* compound prediction modes */
|
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
|
|
|
GOLDEN_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
|
|
|
|
LAST_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
|
|
|
|
ALTREF_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
ALTREF_FRAME,
|
|
|
|
|
|
|
|
GOLDEN_FRAME,
|
|
|
|
LAST_FRAME,
|
|
|
|
ALTREF_FRAME,
|
2010-05-18 17:58:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void fill_token_costs(
|
2011-06-28 23:03:47 +02:00
|
|
|
unsigned int c [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS],
|
|
|
|
const vp8_prob p [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES]
|
2010-05-18 17:58:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < BLOCK_TYPES; i++)
|
|
|
|
for (j = 0; j < COEF_BANDS; j++)
|
|
|
|
for (k = 0; k < PREV_COEF_CONTEXTS; k++)
|
|
|
|
vp8_cost_tokens((int *)(c [i][j][k]), p [i][j][k], vp8_coef_tree);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-07 18:34:46 +02:00
|
|
|
static int rd_iifactor [ 32 ] = { 4, 4, 3, 2, 1, 0, 0, 0,
|
2010-05-18 17:58:33 +02:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
|
2010-12-02 00:50:14 +01:00
|
|
|
// 3* dc_qlookup[Q]*dc_qlookup[Q];
|
2011-11-23 12:32:20 +01:00
|
|
|
|
2010-12-24 04:59:12 +01:00
|
|
|
/* values are now correlated to quantizer */
|
2011-11-21 16:45:10 +01:00
|
|
|
static int sad_per_bit16lut[QINDEX_RANGE];
|
|
|
|
static int sad_per_bit4lut[QINDEX_RANGE];
|
|
|
|
|
|
|
|
void vp8_init_me_luts()
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-11-21 16:45:10 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// Initialize the sad lut tables using a formulaic calculation for now
|
|
|
|
// This is to make it easier to resolve the impact of experimental changes
|
|
|
|
// to the quantizer tables.
|
|
|
|
for ( i = 0; i < QINDEX_RANGE; i++ )
|
|
|
|
{
|
|
|
|
sad_per_bit16lut[i] =
|
|
|
|
(int)((0.0418*vp8_convert_qindex_to_q(i)) + 2.4107);
|
|
|
|
sad_per_bit4lut[i] = (int)((0.063*vp8_convert_qindex_to_q(i)) + 2.742);
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-23 12:32:20 +01:00
|
|
|
int compute_rd_mult( int qindex )
|
|
|
|
{
|
|
|
|
int q;
|
|
|
|
|
|
|
|
q = vp8_dc_quant(qindex,0);
|
|
|
|
return (3 * q * q) >> 4;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex)
|
|
|
|
{
|
2011-05-20 08:12:40 +02:00
|
|
|
cpi->mb.sadperbit16 = sad_per_bit16lut[QIndex];
|
|
|
|
cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-12-02 00:50:14 +01:00
|
|
|
|
|
|
|
void vp8_initialize_rd_consts(VP8_COMP *cpi, int QIndex)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int q;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vp8_clear_system_state(); //__asm emms;
|
|
|
|
|
2010-06-29 13:15:54 +02:00
|
|
|
// Further tests required to see if optimum is different
|
|
|
|
// for key frames, golden frames and arf frames.
|
|
|
|
// if (cpi->common.refresh_golden_frame ||
|
|
|
|
// cpi->common.refresh_alt_ref_frame)
|
2011-12-12 19:27:25 +01:00
|
|
|
QIndex=(QIndex<0)? 0 : ((QIndex>MAXQ)?MAXQ : QIndex);
|
2011-11-23 12:32:20 +01:00
|
|
|
|
|
|
|
cpi->RDMULT = compute_rd_mult(QIndex);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-06-29 13:15:54 +02:00
|
|
|
// Extend rate multiplier along side quantizer zbin increases
|
|
|
|
if (cpi->zbin_over_quant > 0)
|
|
|
|
{
|
|
|
|
double oq_factor;
|
|
|
|
|
|
|
|
// Experimental code using the same basic equation as used for Q above
|
|
|
|
// The units of cpi->zbin_over_quant are 1/128 of Q bin size
|
|
|
|
oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant);
|
2010-12-02 00:50:14 +01:00
|
|
|
cpi->RDMULT = (int)((double)cpi->RDMULT * oq_factor * oq_factor);
|
2010-06-29 13:15:54 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-06-07 18:34:46 +02:00
|
|
|
if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-19 23:16:39 +02:00
|
|
|
if (cpi->twopass.next_iiratio > 31)
|
2010-06-07 18:34:46 +02:00
|
|
|
cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
2011-05-19 23:16:39 +02:00
|
|
|
cpi->RDMULT +=
|
|
|
|
(cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-12-02 00:50:14 +01:00
|
|
|
if (cpi->RDMULT < 7)
|
|
|
|
cpi->RDMULT = 7;
|
2011-12-02 15:57:21 +01:00
|
|
|
|
2011-06-21 01:30:26 +02:00
|
|
|
cpi->mb.errorperbit = (cpi->RDMULT / 110);
|
2011-01-26 07:24:22 +01:00
|
|
|
cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_set_speed_features(cpi);
|
|
|
|
|
2011-12-02 15:57:21 +01:00
|
|
|
q = (int)pow(vp8_dc_quant(QIndex,0)>>2, 1.25);
|
|
|
|
q = q << 2;
|
2011-12-06 15:48:52 +01:00
|
|
|
cpi->RDMULT = cpi->RDMULT << 4;
|
2012-02-09 17:44:46 +01:00
|
|
|
|
2011-12-02 15:57:21 +01:00
|
|
|
if (q < 8)
|
|
|
|
q = 8;
|
2010-12-02 00:50:14 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->RDMULT > 1000)
|
|
|
|
{
|
|
|
|
cpi->RDDIV = 1;
|
|
|
|
cpi->RDMULT /= 100;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
{
|
|
|
|
if (cpi->sf.thresh_mult[i] < INT_MAX)
|
|
|
|
{
|
|
|
|
cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpi->rd_threshes[i] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpi->RDDIV = 100;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODES; i++)
|
|
|
|
{
|
|
|
|
if (cpi->sf.thresh_mult[i] < (INT_MAX / q))
|
|
|
|
{
|
|
|
|
cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpi->rd_threshes[i] = INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fill_token_costs(
|
|
|
|
cpi->mb.token_costs,
|
|
|
|
(const vp8_prob( *)[8][3][11]) cpi->common.fc.coef_probs
|
|
|
|
);
|
|
|
|
|
2012-01-26 23:36:20 +01:00
|
|
|
fill_token_costs(
|
|
|
|
cpi->mb.token_costs_8x8,
|
|
|
|
(const vp8_prob( *)[8][3][11]) cpi->common.fc.coef_probs_8x8
|
|
|
|
);
|
2011-08-31 21:01:58 +02:00
|
|
|
#if CONFIG_QIMODE
|
|
|
|
//rough estimate for costing
|
|
|
|
cpi->common.kf_ymode_probs_index = cpi->common.base_qindex>>4;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_init_mode_costs(cpi);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void vp8_auto_select_speed(VP8_COMP *cpi)
|
|
|
|
{
|
|
|
|
int milliseconds_for_compress = (int)(1000000 / cpi->oxcf.frame_rate);
|
|
|
|
|
|
|
|
milliseconds_for_compress = milliseconds_for_compress * (16 - cpi->oxcf.cpu_used) / 16;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
f = fopen("speed.stt", "a");
|
|
|
|
fprintf(f, " %8ld %10ld %10ld %10ld\n",
|
|
|
|
cpi->common.current_video_frame, cpi->Speed, milliseconds_for_compress, cpi->avg_pick_mode_time);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
// this is done during parameter valid check
|
2011-05-09 17:16:31 +02:00
|
|
|
if( cpi->oxcf.cpu_used > 16)
|
|
|
|
cpi->oxcf.cpu_used = 16;
|
|
|
|
if( cpi->oxcf.cpu_used < -16)
|
|
|
|
cpi->oxcf.cpu_used = -16;
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (cpi->avg_pick_mode_time < milliseconds_for_compress && (cpi->avg_encode_time - cpi->avg_pick_mode_time) < milliseconds_for_compress)
|
|
|
|
{
|
|
|
|
if (cpi->avg_pick_mode_time == 0)
|
|
|
|
{
|
|
|
|
cpi->Speed = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (milliseconds_for_compress * 100 < cpi->avg_encode_time * 95)
|
|
|
|
{
|
|
|
|
cpi->Speed += 2;
|
|
|
|
cpi->avg_pick_mode_time = 0;
|
|
|
|
cpi->avg_encode_time = 0;
|
|
|
|
|
|
|
|
if (cpi->Speed > 16)
|
|
|
|
{
|
|
|
|
cpi->Speed = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
if (milliseconds_for_compress * 100 > cpi->avg_encode_time * auto_speed_thresh[cpi->Speed])
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
cpi->Speed -= 1;
|
|
|
|
cpi->avg_pick_mode_time = 0;
|
|
|
|
cpi->avg_encode_time = 0;
|
|
|
|
|
|
|
|
// In real-time mode, cpi->speed is in [4, 16].
|
|
|
|
if (cpi->Speed < 4) //if ( cpi->Speed < 0 )
|
|
|
|
{
|
|
|
|
cpi->Speed = 4; //cpi->Speed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpi->Speed += 4;
|
|
|
|
|
|
|
|
if (cpi->Speed > 16)
|
|
|
|
cpi->Speed = 16;
|
|
|
|
|
|
|
|
|
|
|
|
cpi->avg_pick_mode_time = 0;
|
|
|
|
cpi->avg_encode_time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_block_error_c(short *coeff, short *dqcoeff)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
int this_diff = coeff[i] - dqcoeff[i];
|
|
|
|
error += this_diff * this_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_mbblock_error_c(MACROBLOCK *mb, int dc)
|
|
|
|
{
|
|
|
|
BLOCK *be;
|
|
|
|
BLOCKD *bd;
|
|
|
|
int i, j;
|
|
|
|
int berror, error = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
be = &mb->block[i];
|
|
|
|
bd = &mb->e_mbd.block[i];
|
|
|
|
|
|
|
|
berror = 0;
|
|
|
|
|
|
|
|
for (j = dc; j < 16; j++)
|
|
|
|
{
|
|
|
|
int this_diff = be->coeff[j] - bd->dqcoeff[j];
|
|
|
|
berror += this_diff * this_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
error += berror;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vp8_mbuverror_c(MACROBLOCK *mb)
|
|
|
|
{
|
|
|
|
|
|
|
|
BLOCK *be;
|
|
|
|
BLOCKD *bd;
|
|
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
for (i = 16; i < 24; i++)
|
|
|
|
{
|
|
|
|
be = &mb->block[i];
|
|
|
|
bd = &mb->e_mbd.block[i];
|
|
|
|
|
|
|
|
error += vp8_block_error_c(be->coeff, bd->dqcoeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VP8_UVSSE(MACROBLOCK *x, const vp8_variance_rtcd_vtable_t *rtcd)
|
|
|
|
{
|
|
|
|
unsigned char *uptr, *vptr;
|
|
|
|
unsigned char *upred_ptr = (*(x->block[16].base_src) + x->block[16].src);
|
|
|
|
unsigned char *vpred_ptr = (*(x->block[20].base_src) + x->block[20].src);
|
|
|
|
int uv_stride = x->block[16].src_stride;
|
|
|
|
|
|
|
|
unsigned int sse1 = 0;
|
|
|
|
unsigned int sse2 = 0;
|
2011-08-24 20:42:26 +02:00
|
|
|
int mv_row = x->e_mbd.mode_info_context->mbmi.mv.as_mv.row;
|
|
|
|
int mv_col = x->e_mbd.mode_info_context->mbmi.mv.as_mv.col;
|
2010-05-18 17:58:33 +02:00
|
|
|
int offset;
|
|
|
|
int pre_stride = x->e_mbd.block[16].pre_stride;
|
|
|
|
|
2011-08-24 20:42:26 +02:00
|
|
|
if (mv_row < 0)
|
|
|
|
mv_row -= 1;
|
|
|
|
else
|
|
|
|
mv_row += 1;
|
|
|
|
|
|
|
|
if (mv_col < 0)
|
|
|
|
mv_col -= 1;
|
|
|
|
else
|
|
|
|
mv_col += 1;
|
|
|
|
|
|
|
|
mv_row /= 2;
|
|
|
|
mv_col /= 2;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
offset = (mv_row >> 3) * pre_stride + (mv_col >> 3);
|
|
|
|
uptr = x->e_mbd.pre.u_buffer + offset;
|
|
|
|
vptr = x->e_mbd.pre.v_buffer + offset;
|
|
|
|
|
|
|
|
if ((mv_row | mv_col) & 7)
|
|
|
|
{
|
2012-02-16 18:29:54 +01:00
|
|
|
#if CONFIG_SIXTEENTH_SUBPEL_UV
|
|
|
|
VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride,
|
|
|
|
(mv_col & 7)<<1, (mv_row & 7)<<1, upred_ptr, uv_stride, &sse2);
|
|
|
|
VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride,
|
|
|
|
(mv_col & 7)<<1, (mv_row & 7)<<1, vpred_ptr, uv_stride, &sse1);
|
|
|
|
#else
|
2011-05-22 06:51:21 +02:00
|
|
|
VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride,
|
|
|
|
mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
|
|
|
|
VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride,
|
|
|
|
mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
|
2012-02-16 18:29:54 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
sse2 += sse1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-25 11:54:34 +02:00
|
|
|
VARIANCE_INVOKE(rtcd, var8x8)(uptr, pre_stride,
|
|
|
|
upred_ptr, uv_stride, &sse2);
|
|
|
|
VARIANCE_INVOKE(rtcd, var8x8)(vptr, pre_stride,
|
|
|
|
vpred_ptr, uv_stride, &sse1);
|
2010-05-18 17:58:33 +02:00
|
|
|
sse2 += sse1;
|
|
|
|
}
|
|
|
|
return sse2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, int type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
|
|
|
|
{
|
|
|
|
int c = !type; /* start at coef 0, unless Y with Y2 */
|
|
|
|
int eob = b->eob;
|
|
|
|
int pt ; /* surrounding block/prev coef predictor */
|
|
|
|
int cost = 0;
|
|
|
|
short *qcoeff_ptr = b->qcoeff;
|
|
|
|
|
|
|
|
VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
|
|
|
|
|
|
|
|
# define QC( I) ( qcoeff_ptr [vp8_default_zig_zag1d[I]] )
|
|
|
|
|
|
|
|
for (; c < eob; c++)
|
|
|
|
{
|
|
|
|
int v = QC(c);
|
|
|
|
int t = vp8_dct_value_tokens_ptr[v].Token;
|
|
|
|
cost += mb->token_costs [type] [vp8_coef_bands[c]] [pt] [t];
|
|
|
|
cost += vp8_dct_value_cost_ptr[v];
|
|
|
|
pt = vp8_prev_token_class[t];
|
|
|
|
}
|
|
|
|
|
|
|
|
# undef QC
|
|
|
|
|
|
|
|
if (c < 16)
|
|
|
|
cost += mb->token_costs [type] [vp8_coef_bands[c]] [pt] [DCT_EOB_TOKEN];
|
|
|
|
|
|
|
|
pt = (c != !type); // is eob first coefficient;
|
|
|
|
*a = *l = pt;
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2010-11-17 19:15:13 +01:00
|
|
|
static int vp8_rdcost_mby(MACROBLOCK *mb)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int cost = 0;
|
|
|
|
int b;
|
|
|
|
MACROBLOCKD *x = &mb->e_mbd;
|
2010-08-31 16:49:57 +02:00
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-08-31 16:49:57 +02:00
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
for (b = 0; b < 16; b++)
|
2011-02-23 22:37:08 +01:00
|
|
|
cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_Y_NO_DC,
|
2010-08-31 16:49:57 +02:00
|
|
|
ta + vp8_block2above[b], tl + vp8_block2left[b]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-23 22:37:08 +01:00
|
|
|
cost += cost_coeffs(mb, x->block + 24, PLANE_TYPE_Y2,
|
2010-11-17 19:15:13 +01:00
|
|
|
ta + vp8_block2above[24], tl + vp8_block2left[24]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2011-01-26 19:46:34 +01:00
|
|
|
static void macro_block_yrd( MACROBLOCK *mb,
|
|
|
|
int *Rate,
|
|
|
|
int *Distortion,
|
|
|
|
const vp8_encodemb_rtcd_vtable_t *rtcd)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
MACROBLOCKD *const x = &mb->e_mbd;
|
|
|
|
BLOCK *const mb_y2 = mb->block + 24;
|
|
|
|
BLOCKD *const x_y2 = x->block + 24;
|
|
|
|
short *Y2DCPtr = mb_y2->src_diff;
|
|
|
|
BLOCK *beptr;
|
|
|
|
int d;
|
|
|
|
|
2011-06-23 19:54:02 +02:00
|
|
|
ENCODEMB_INVOKE(rtcd, submby)( mb->src_diff, *(mb->block[0].base_src),
|
|
|
|
mb->e_mbd.predictor, mb->block[0].src_stride );
|
2011-01-26 19:46:34 +01:00
|
|
|
|
|
|
|
// Fdct and building the 2nd order block
|
|
|
|
for (beptr = mb->block; beptr < mb->block + 16; beptr += 2)
|
|
|
|
{
|
|
|
|
mb->vp8_short_fdct8x4(beptr->src_diff, beptr->coeff, 32);
|
|
|
|
*Y2DCPtr++ = beptr->coeff[0];
|
|
|
|
*Y2DCPtr++ = beptr->coeff[16];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2nd order fdct
|
|
|
|
mb->short_walsh4x4(mb_y2->src_diff, mb_y2->coeff, 8);
|
|
|
|
|
|
|
|
// Quantization
|
|
|
|
for (b = 0; b < 16; b++)
|
|
|
|
{
|
|
|
|
mb->quantize_b(&mb->block[b], &mb->e_mbd.block[b]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// DC predication and Quantization of 2nd Order block
|
|
|
|
mb->quantize_b(mb_y2, x_y2);
|
|
|
|
|
|
|
|
// Distortion
|
|
|
|
d = ENCODEMB_INVOKE(rtcd, mberr)(mb, 1) << 2;
|
2011-06-23 00:07:04 +02:00
|
|
|
|
|
|
|
d += ENCODEMB_INVOKE(rtcd, berr)(mb_y2->coeff, x_y2->dqcoeff)<<2;
|
2011-01-26 19:46:34 +01:00
|
|
|
|
|
|
|
*Distortion = (d >> 4);
|
|
|
|
// rate
|
|
|
|
*Rate = vp8_rdcost_mby(mb);
|
|
|
|
}
|
2010-05-18 17:58:33 +02: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
|
|
|
|
|
|
|
static int cost_coeffs_2x2(MACROBLOCK *mb,
|
|
|
|
BLOCKD *b, int type,
|
|
|
|
ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
|
|
|
|
{
|
|
|
|
int c = !type; /* start at coef 0, unless Y with Y2 */
|
|
|
|
int eob = b->eob;
|
|
|
|
int pt ; /* surrounding block/prev coef predictor */
|
|
|
|
int cost = 0;
|
|
|
|
short *qcoeff_ptr = b->qcoeff;
|
|
|
|
|
|
|
|
VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
|
|
|
|
assert(eob<=4);
|
|
|
|
|
|
|
|
# define QC2X2( I) ( qcoeff_ptr [vp8_default_zig_zag1d[I]] )
|
|
|
|
|
|
|
|
for (; c < eob; c++)
|
|
|
|
{
|
|
|
|
int v = QC2X2(c);
|
|
|
|
int t = vp8_dct_value_tokens_ptr[v].Token;
|
|
|
|
cost += mb->token_costs_8x8[type] [vp8_coef_bands[c]] [pt] [t];
|
|
|
|
cost += vp8_dct_value_cost_ptr[v];
|
|
|
|
pt = vp8_prev_token_class[t];
|
|
|
|
}
|
|
|
|
|
|
|
|
# undef QC2X2
|
|
|
|
if (c < 4)
|
|
|
|
cost += mb->token_costs_8x8 [type][vp8_coef_bands[c]]
|
|
|
|
[pt] [DCT_EOB_TOKEN];
|
|
|
|
|
|
|
|
pt = (c != !type); // is eob first coefficient;
|
|
|
|
*a = *l = pt;
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int cost_coeffs_8x8(MACROBLOCK *mb,
|
|
|
|
BLOCKD *b, int type,
|
2012-01-21 00:30:31 +01:00
|
|
|
ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
|
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
|
|
|
{
|
|
|
|
int c = !type; /* start at coef 0, unless Y with Y2 */
|
|
|
|
int eob = b->eob;
|
|
|
|
int pt ; /* surrounding block/prev coef predictor */
|
|
|
|
int cost = 0;
|
|
|
|
short *qcoeff_ptr = b->qcoeff;
|
|
|
|
|
2012-01-21 00:30:31 +01:00
|
|
|
VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l);
|
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
|
|
|
|
|
|
|
# define QC8X8( I) ( qcoeff_ptr [vp8_default_zig_zag1d_8x8[I]] )
|
|
|
|
|
|
|
|
for (; c < eob; c++)
|
|
|
|
{
|
|
|
|
int v = QC8X8(c);
|
|
|
|
int t = vp8_dct_value_tokens_ptr[v].Token;
|
|
|
|
cost += mb->token_costs_8x8[type] [vp8_coef_bands_8x8[c]] [pt] [t];
|
|
|
|
cost += vp8_dct_value_cost_ptr[v];
|
|
|
|
pt = vp8_prev_token_class[t];
|
|
|
|
}
|
|
|
|
|
|
|
|
# undef QC8X8
|
|
|
|
if (c < 64)
|
|
|
|
cost += mb->token_costs_8x8 [type][vp8_coef_bands_8x8[c]]
|
|
|
|
[pt] [DCT_EOB_TOKEN];
|
|
|
|
|
|
|
|
pt = (c != !type); // is eob first coefficient;
|
|
|
|
*a = *l = pt;
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
static int vp8_rdcost_mby_8x8(MACROBLOCK *mb)
|
|
|
|
{
|
|
|
|
int cost = 0;
|
|
|
|
int b;
|
|
|
|
MACROBLOCKD *x = &mb->e_mbd;
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
|
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
|
|
|
|
|
|
|
for (b = 0; b < 16; b+=4)
|
|
|
|
cost += cost_coeffs_8x8(mb, x->block + b, PLANE_TYPE_Y_NO_DC,
|
2012-01-21 00:30:31 +01:00
|
|
|
ta + vp8_block2above_8x8[b], tl + vp8_block2left_8x8[b]);
|
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
|
|
|
|
|
|
|
cost += cost_coeffs_2x2(mb, x->block + 24, PLANE_TYPE_Y2,
|
|
|
|
ta + vp8_block2above[24], tl + vp8_block2left[24]);
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void macro_block_yrd_8x8( MACROBLOCK *mb,
|
|
|
|
int *Rate,
|
|
|
|
int *Distortion,
|
|
|
|
const VP8_ENCODER_RTCD *rtcd)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
MACROBLOCKD *const x = &mb->e_mbd;
|
|
|
|
BLOCK *const mb_y2 = mb->block + 24;
|
|
|
|
BLOCKD *const x_y2 = x->block + 24;
|
|
|
|
short *Y2DCPtr = mb_y2->src_diff;
|
|
|
|
BLOCK *beptr;
|
|
|
|
int d;
|
|
|
|
|
|
|
|
ENCODEMB_INVOKE(&rtcd->encodemb, submby)
|
|
|
|
( mb->src_diff, *(mb->block[0].base_src),
|
|
|
|
mb->e_mbd.predictor, mb->block[0].src_stride );
|
|
|
|
|
|
|
|
vp8_transform_mby_8x8(mb);
|
|
|
|
vp8_quantize_mby_8x8(mb);
|
|
|
|
|
|
|
|
/* remove 1st order dc to properly combine 1st/2nd order distortion */
|
|
|
|
mb->coeff[0] = 0;
|
|
|
|
mb->coeff[64] = 0;
|
|
|
|
mb->coeff[128] = 0;
|
|
|
|
mb->coeff[192] = 0;
|
|
|
|
mb->e_mbd.dqcoeff[0] = 0;
|
|
|
|
mb->e_mbd.dqcoeff[64] = 0;
|
|
|
|
mb->e_mbd.dqcoeff[128] = 0;
|
|
|
|
mb->e_mbd.dqcoeff[192] = 0;
|
|
|
|
d = ENCODEMB_INVOKE(&rtcd->encodemb, mberr)(mb, 0) << 2;
|
|
|
|
|
2012-02-14 16:40:26 +01:00
|
|
|
d += ENCODEMB_INVOKE(&rtcd->encodemb, berr)(mb_y2->coeff, x_y2->dqcoeff)<<2;
|
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
|
|
|
|
|
|
|
*Distortion = (d >> 4);
|
|
|
|
// rate
|
|
|
|
*Rate = vp8_rdcost_mby_8x8(mb);
|
|
|
|
}
|
2012-01-26 23:36:20 +01:00
|
|
|
|
2011-02-24 19:31:47 +01:00
|
|
|
static void copy_predictor(unsigned char *dst, const unsigned char *predictor)
|
2011-02-14 19:32:58 +01:00
|
|
|
{
|
2011-02-24 19:31:47 +01:00
|
|
|
const unsigned int *p = (const unsigned int *)predictor;
|
|
|
|
unsigned int *d = (unsigned int *)dst;
|
|
|
|
d[0] = p[0];
|
|
|
|
d[4] = p[4];
|
|
|
|
d[8] = p[8];
|
|
|
|
d[12] = p[12];
|
2011-02-14 19:32:58 +01:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
|
|
|
|
static void copy_predictor_8x8(unsigned char *dst, const unsigned char *predictor)
|
|
|
|
{
|
|
|
|
const unsigned int *p = (const unsigned int *)predictor;
|
|
|
|
unsigned int *d = (unsigned int *)dst;
|
|
|
|
d[0] = p[0];
|
|
|
|
d[1] = p[1];
|
|
|
|
d[4] = p[4];
|
|
|
|
d[5] = p[5];
|
|
|
|
d[8] = p[8];
|
|
|
|
d[9] = p[9];
|
|
|
|
d[12] = p[12];
|
|
|
|
d[13] = p[13];
|
|
|
|
d[16] = p[16];
|
|
|
|
d[17] = p[17];
|
|
|
|
d[20] = p[20];
|
|
|
|
d[21] = p[21];
|
|
|
|
d[24] = p[24];
|
|
|
|
d[25] = p[25];
|
|
|
|
d[28] = p[28];
|
|
|
|
d[29] = p[29];
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:50:43 +01:00
|
|
|
static int rd_pick_intra4x4block(
|
2010-05-18 17:58:33 +02:00
|
|
|
VP8_COMP *cpi,
|
|
|
|
MACROBLOCK *x,
|
|
|
|
BLOCK *be,
|
|
|
|
BLOCKD *b,
|
|
|
|
B_PREDICTION_MODE *best_mode,
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
B_PREDICTION_MODE *best_second_mode,
|
|
|
|
#endif
|
2011-02-14 19:32:58 +01:00
|
|
|
unsigned int *bmode_costs,
|
2010-05-18 17:58:33 +02:00
|
|
|
ENTROPY_CONTEXT *a,
|
|
|
|
ENTROPY_CONTEXT *l,
|
|
|
|
|
|
|
|
int *bestrate,
|
|
|
|
int *bestratey,
|
|
|
|
int *bestdistortion)
|
|
|
|
{
|
|
|
|
B_PREDICTION_MODE mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
B_PREDICTION_MODE mode2;
|
|
|
|
#endif
|
2011-02-14 19:32:58 +01:00
|
|
|
int best_rd = INT_MAX;
|
2010-05-18 17:58:33 +02:00
|
|
|
int rate = 0;
|
|
|
|
int distortion;
|
|
|
|
|
|
|
|
ENTROPY_CONTEXT ta = *a, tempa = *a;
|
|
|
|
ENTROPY_CONTEXT tl = *l, templ = *l;
|
2011-02-24 19:31:47 +01:00
|
|
|
/*
|
|
|
|
* The predictor buffer is a 2d buffer with a stride of 16. Create
|
|
|
|
* a temp buffer that meets the stride requirements, but we are only
|
|
|
|
* interested in the left 4x4 block
|
|
|
|
* */
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16*4);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
for (mode = B_DC_PRED; mode <= B_HU_PRED; mode++)
|
|
|
|
{
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
for (mode2 = B_DC_PRED - 1; mode2 != B_HU_PRED + 1; mode2++)
|
|
|
|
{
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
int this_rd;
|
|
|
|
int ratey;
|
|
|
|
|
2012-02-02 18:04:40 +01:00
|
|
|
#if CONFIG_SUPERBLOCKS
|
|
|
|
// Ignore modes thact need the above-right data
|
|
|
|
if (mode==B_LD_PRED || mode==B_VL_PRED)
|
|
|
|
continue;
|
|
|
|
#endif
|
2011-02-14 19:32:58 +01:00
|
|
|
rate = bmode_costs[mode];
|
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
if (mode2 == (B_PREDICTION_MODE) (B_DC_PRED - 1))
|
|
|
|
{
|
|
|
|
#endif
|
2011-04-27 19:05:10 +02:00
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, intra4x4_predict)
|
|
|
|
(b, mode, b->predictor);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
rate += vp8_cost_bit(128, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, comp_intra4x4_predict)
|
|
|
|
(b, mode, mode2, b->predictor);
|
|
|
|
rate += vp8_cost_bit(128, 1);
|
|
|
|
rate += bmode_costs[mode2];
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-14 19:32:58 +01:00
|
|
|
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), subb)(be, b, 16);
|
|
|
|
x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
|
|
|
|
x->quantize_b(be, b);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
tempa = ta;
|
|
|
|
templ = tl;
|
|
|
|
|
2011-02-23 22:37:08 +01:00
|
|
|
ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ);
|
2010-05-18 17:58:33 +02:00
|
|
|
rate += ratey;
|
|
|
|
distortion = ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)(be->coeff, b->dqcoeff) >> 2;
|
|
|
|
|
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
|
|
|
|
|
|
|
|
if (this_rd < best_rd)
|
|
|
|
{
|
|
|
|
*bestrate = rate;
|
|
|
|
*bestratey = ratey;
|
|
|
|
*bestdistortion = distortion;
|
|
|
|
best_rd = this_rd;
|
|
|
|
*best_mode = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
*best_second_mode = mode2;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
*a = tempa;
|
|
|
|
*l = templ;
|
2011-02-24 19:31:47 +01:00
|
|
|
copy_predictor(best_predictor, b->predictor);
|
|
|
|
vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 02:12:08 +01:00
|
|
|
b->bmi.as_mode.first = (B_PREDICTION_MODE)(*best_mode);
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
b->bmi.as_mode.second = (B_PREDICTION_MODE)(*best_second_mode);
|
|
|
|
#endif
|
2011-02-14 19:32:58 +01:00
|
|
|
|
2011-02-24 19:31:47 +01:00
|
|
|
IDCT_INVOKE(IF_RTCD(&cpi->rtcd.common->idct), idct16)(best_dqcoeff, b->diff, 32);
|
|
|
|
RECON_INVOKE(IF_RTCD(&cpi->rtcd.common->recon), recon)(best_predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-08 22:50:43 +01:00
|
|
|
return best_rd;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 18:05:05 +02:00
|
|
|
static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
|
|
|
|
int *rate_y, int *Distortion, int best_rd)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
MACROBLOCKD *const xd = &mb->e_mbd;
|
|
|
|
int i;
|
|
|
|
int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
|
|
|
|
int distortion = 0;
|
|
|
|
int tot_rate_y = 0;
|
2011-07-26 03:44:59 +02:00
|
|
|
int64_t total_rd = 0;
|
2010-08-31 16:49:57 +02:00
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
2011-02-14 19:32:58 +01:00
|
|
|
unsigned int *bmode_costs;
|
2010-08-31 16:49:57 +02:00
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
|
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-02 18:04:40 +01:00
|
|
|
#if !CONFIG_SUPERBLOCKS
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_intra_prediction_down_copy(xd);
|
2012-02-02 18:04:40 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-14 19:32:58 +01:00
|
|
|
bmode_costs = mb->inter_bmode_costs;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
MODE_INFO *const mic = xd->mode_info_context;
|
|
|
|
const int mis = xd->mode_info_stride;
|
|
|
|
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_second_mode);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SAFE(d);
|
|
|
|
|
2011-02-14 19:32:58 +01:00
|
|
|
if (mb->e_mbd.frame_type == KEY_FRAME)
|
|
|
|
{
|
2011-05-24 19:24:52 +02:00
|
|
|
const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
|
|
|
|
const B_PREDICTION_MODE L = left_block_mode(mic, i);
|
2011-02-14 19:32:58 +01:00
|
|
|
|
|
|
|
bmode_costs = mb->bmode_costs[A][L];
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:50:43 +01:00
|
|
|
total_rd += rd_pick_intra4x4block(
|
2012-02-29 02:12:08 +01:00
|
|
|
cpi, mb, mb->block + i, xd->block + i, &best_mode,
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
&best_second_mode,
|
|
|
|
#endif
|
|
|
|
bmode_costs, ta + vp8_block2above[i],
|
2010-08-31 16:49:57 +02:00
|
|
|
tl + vp8_block2left[i], &r, &ry, &d);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
cost += r;
|
|
|
|
distortion += d;
|
|
|
|
tot_rate_y += ry;
|
2011-05-24 19:24:52 +02:00
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
mic->bmi[i].as_mode.first = best_mode;
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mic->bmi[i].as_mode.second = best_second_mode;
|
|
|
|
#endif
|
2011-02-08 22:50:43 +01:00
|
|
|
|
2011-07-26 03:44:59 +02:00
|
|
|
if(total_rd >= (int64_t)best_rd)
|
2011-02-24 19:31:47 +01:00
|
|
|
break;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 03:44:59 +02:00
|
|
|
if(total_rd >= (int64_t)best_rd)
|
2011-02-24 19:31:47 +01:00
|
|
|
return INT_MAX;
|
2011-02-08 22:50:43 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
*Rate = cost;
|
|
|
|
*rate_y += tot_rate_y;
|
|
|
|
*Distortion = distortion;
|
|
|
|
|
|
|
|
return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
|
|
|
|
}
|
2011-06-08 18:05:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
static int rd_pick_intra16x16mby_mode(VP8_COMP *cpi,
|
|
|
|
MACROBLOCK *x,
|
|
|
|
int *Rate,
|
|
|
|
int *rate_y,
|
|
|
|
int *Distortion)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
MB_PREDICTION_MODE mode;
|
|
|
|
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
MB_PREDICTION_MODE mode2;
|
|
|
|
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode2_selected);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
int rate, ratey;
|
2011-01-27 17:50:29 +01:00
|
|
|
int distortion;
|
2010-05-18 17:58:33 +02:00
|
|
|
int best_rd = INT_MAX;
|
2011-01-26 19:46:34 +01:00
|
|
|
int this_rd;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
//Y Search for 16x16 intra prediction mode
|
|
|
|
for (mode = DC_PRED; mode <= TM_PRED; mode++)
|
|
|
|
{
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++)
|
|
|
|
{
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mode = mode2;
|
|
|
|
if (mode2 == (MB_PREDICTION_MODE) (DC_PRED - 1))
|
|
|
|
{
|
|
|
|
#endif
|
2011-03-11 17:35:38 +01:00
|
|
|
RECON_INVOKE(&cpi->common.rtcd.recon, build_intra_predictors_mby)
|
|
|
|
(&x->e_mbd);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue; // i.e. disable for now
|
|
|
|
RECON_INVOKE(&cpi->common.rtcd.recon, build_comp_intra_predictors_mby)(&x->e_mbd);
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-26 19:46:34 +01:00
|
|
|
macro_block_yrd(x, &ratey, &distortion, IF_RTCD(&cpi->rtcd.encodemb));
|
2012-02-29 02:12:08 +01:00
|
|
|
// FIXME add compoundmode cost
|
|
|
|
// FIXME add rate for mode2
|
2011-01-26 19:46:34 +01:00
|
|
|
rate = ratey + x->mbmode_cost[x->e_mbd.frame_type]
|
|
|
|
[x->e_mbd.mode_info_context->mbmi.mode];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
|
|
|
|
|
|
|
|
if (this_rd < best_rd)
|
|
|
|
{
|
|
|
|
mode_selected = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mode2_selected = mode2;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
best_rd = this_rd;
|
|
|
|
*Rate = rate;
|
|
|
|
*rate_y = ratey;
|
2011-01-27 17:50:29 +01:00
|
|
|
*Distortion = distortion;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = mode_selected;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mode = mode2_selected;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
return best_rd;
|
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
static int rd_pick_intra8x8block(
|
|
|
|
VP8_COMP *cpi,
|
|
|
|
MACROBLOCK *x,
|
|
|
|
int ib,
|
|
|
|
B_PREDICTION_MODE *best_mode,
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
B_PREDICTION_MODE *best_second_mode,
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
unsigned int *mode_costs,
|
|
|
|
ENTROPY_CONTEXT *a,
|
|
|
|
ENTROPY_CONTEXT *l,
|
|
|
|
int *bestrate,
|
|
|
|
int *bestratey,
|
|
|
|
int *bestdistortion)
|
|
|
|
{
|
|
|
|
MB_PREDICTION_MODE mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
MB_PREDICTION_MODE mode2;
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
int best_rd = INT_MAX;
|
|
|
|
int rate = 0;
|
|
|
|
int distortion;
|
|
|
|
BLOCK *be=x->block + ib;
|
|
|
|
BLOCKD *b=x->e_mbd.block + ib;
|
|
|
|
ENTROPY_CONTEXT ta0, ta1, besta0, besta1;
|
|
|
|
ENTROPY_CONTEXT tl0, tl1, bestl0, bestl1;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The predictor buffer is a 2d buffer with a stride of 16. Create
|
|
|
|
* a temp buffer that meets the stride requirements, but we are only
|
|
|
|
* interested in the left 8x8 block
|
|
|
|
* */
|
|
|
|
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16*8);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16*4);
|
|
|
|
|
|
|
|
for (mode = DC_PRED; mode <= TM_PRED; mode++)
|
|
|
|
{
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++)
|
|
|
|
{
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
int this_rd;
|
|
|
|
int rate_t;
|
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
// FIXME rate for compound mode and second intrapred mode
|
2011-08-05 01:30:27 +02:00
|
|
|
rate = mode_costs[mode];
|
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
if (mode2 == (MB_PREDICTION_MODE) (DC_PRED - 1))
|
|
|
|
{
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, intra8x8_predict)
|
|
|
|
(b, mode, b->predictor);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue; // i.e. disable for now
|
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, comp_intra8x8_predict)
|
|
|
|
(b, mode, mode2, b->predictor);
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
|
|
|
|
vp8_subtract_4b_c(be, b, 16);
|
|
|
|
|
|
|
|
x->vp8_short_fdct8x4(be->src_diff, be->coeff, 32);
|
|
|
|
x->vp8_short_fdct8x4(be->src_diff + 64, be->coeff + 64, 32);
|
|
|
|
|
|
|
|
x->quantize_b_pair(x->block+ib, x->block+ib+1,
|
|
|
|
xd->block+ib, xd->block+ib+1);
|
|
|
|
x->quantize_b_pair(x->block+ib+4, x->block+ib+5,
|
|
|
|
xd->block+ib+4, xd->block+ib+5);
|
|
|
|
|
|
|
|
distortion = ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)
|
|
|
|
((x->block+ib)->coeff,(xd->block+ib)->dqcoeff)>>2;
|
|
|
|
distortion += ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)
|
|
|
|
((x->block+ib+1)->coeff,(xd->block+ib+1)->dqcoeff)>>2;
|
|
|
|
distortion += ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)
|
|
|
|
((x->block+ib+4)->coeff,(xd->block+ib+4)->dqcoeff)>>2;
|
|
|
|
distortion += ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), berr)
|
|
|
|
((x->block+ib+5)->coeff,(xd->block+ib+5)->dqcoeff)>>2;
|
|
|
|
|
|
|
|
ta0 = *(a + vp8_block2above[ib]);
|
|
|
|
ta1 = *(a + vp8_block2above[ib+1]);
|
|
|
|
tl0 = *(l + vp8_block2above[ib]);
|
|
|
|
tl1 = *(l + vp8_block2above[ib+4]);
|
|
|
|
rate_t = cost_coeffs(x, xd->block+ib, PLANE_TYPE_Y_WITH_DC,
|
|
|
|
&ta0, &tl0);
|
|
|
|
rate_t += cost_coeffs(x, xd->block+ib+1, PLANE_TYPE_Y_WITH_DC,
|
|
|
|
&ta1, &tl0);
|
|
|
|
rate_t += cost_coeffs(x, xd->block+ib+4, PLANE_TYPE_Y_WITH_DC,
|
|
|
|
&ta0, &tl1);
|
|
|
|
rate_t += cost_coeffs(x, xd->block+ib+5, PLANE_TYPE_Y_WITH_DC,
|
|
|
|
&ta1, &tl1);
|
|
|
|
rate += rate_t;
|
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
|
|
|
|
if (this_rd < best_rd)
|
|
|
|
{
|
|
|
|
*bestrate = rate;
|
|
|
|
*bestratey = rate_t;
|
|
|
|
*bestdistortion = distortion;
|
|
|
|
besta0 = ta0;
|
|
|
|
besta1 = ta1;
|
|
|
|
bestl0 = tl0;
|
|
|
|
bestl1 = tl1;
|
|
|
|
best_rd = this_rd;
|
|
|
|
*best_mode = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
*best_second_mode = mode2;
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
copy_predictor_8x8(best_predictor, b->predictor);
|
|
|
|
vpx_memcpy(best_dqcoeff, b->dqcoeff, 64);
|
|
|
|
vpx_memcpy(best_dqcoeff+32, b->dqcoeff+64, 64);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 02:12:08 +01:00
|
|
|
b->bmi.as_mode.first = (*best_mode);
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
b->bmi.as_mode.second = (*best_second_mode);
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
vp8_encode_intra8x8 (IF_RTCD(&cpi->rtcd), x, ib);
|
|
|
|
*(a + vp8_block2above[ib]) = besta0;
|
|
|
|
*(a + vp8_block2above[ib+1]) = besta1;
|
|
|
|
*(l + vp8_block2above[ib]) = bestl0;
|
|
|
|
*(l + vp8_block2above[ib+4]) = bestl1;
|
|
|
|
return best_rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int vp8_i8x8_block[4]={0, 2, 8, 10};
|
|
|
|
int rd_pick_intra8x8mby_modes(VP8_COMP *cpi,
|
|
|
|
MACROBLOCK *mb,
|
|
|
|
int *Rate,
|
|
|
|
int *rate_y,
|
|
|
|
int *Distortion,
|
|
|
|
int best_rd)
|
|
|
|
{
|
|
|
|
MACROBLOCKD *const xd = &mb->e_mbd;
|
|
|
|
int i,ib;
|
|
|
|
int cost = mb->mbmode_cost [xd->frame_type] [I8X8_PRED];
|
|
|
|
int distortion = 0;
|
|
|
|
int tot_rate_y = 0;
|
|
|
|
long long total_rd = 0;
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
unsigned int *i8x8mode_costs;
|
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
|
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
|
|
|
|
|
|
|
i8x8mode_costs = mb->i8x8_mode_costs;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
MODE_INFO *const mic = xd->mode_info_context;
|
|
|
|
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_second_mode);
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SAFE(d);
|
|
|
|
|
|
|
|
ib = vp8_i8x8_block[i];
|
|
|
|
total_rd += rd_pick_intra8x8block(
|
2012-02-29 02:12:08 +01:00
|
|
|
cpi, mb, ib, &best_mode,
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
&best_second_mode,
|
|
|
|
#endif
|
|
|
|
i8x8mode_costs, ta, tl, &r, &ry, &d);
|
2011-08-05 01:30:27 +02:00
|
|
|
cost += r;
|
|
|
|
distortion += d;
|
|
|
|
tot_rate_y += ry;
|
2012-02-29 02:12:08 +01:00
|
|
|
mic->bmi[ib].as_mode.first = best_mode;
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mic->bmi[ib].as_mode.second = best_second_mode;
|
|
|
|
#endif
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
*Rate = cost;
|
|
|
|
*rate_y += tot_rate_y;
|
|
|
|
*Distortion = distortion;
|
|
|
|
return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
static int rd_cost_mbuv(MACROBLOCK *mb)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
int cost = 0;
|
|
|
|
MACROBLOCKD *x = &mb->e_mbd;
|
2010-08-31 16:49:57 +02:00
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-08-31 16:49:57 +02:00
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-02-23 22:37:08 +01:00
|
|
|
for (b = 16; b < 24; b++)
|
|
|
|
cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_UV,
|
2010-08-31 16:49:57 +02:00
|
|
|
ta + vp8_block2above[b], tl + vp8_block2left[b]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 20:42:26 +02:00
|
|
|
static int rd_inter16x16_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
|
|
|
|
int *distortion, int fullpixel)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-08-24 20:42:26 +02:00
|
|
|
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
|
|
|
|
x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-08-24 20:42:26 +02:00
|
|
|
vp8_transform_mbuv(x);
|
|
|
|
vp8_quantize_mbuv(x);
|
|
|
|
|
|
|
|
*rate = rd_cost_mbuv(x);
|
|
|
|
*distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
|
|
|
|
|
|
|
|
return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
|
|
|
|
}
|
2012-02-29 02:11:12 +01:00
|
|
|
|
2012-01-21 00:30:31 +01:00
|
|
|
static int rd_cost_mbuv_8x8(MACROBLOCK *mb)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
int cost = 0;
|
|
|
|
MACROBLOCKD *x = &mb->e_mbd;
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
|
|
|
|
vpx_memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
|
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
|
|
|
|
|
|
|
for (b = 16; b < 24; b+=4)
|
|
|
|
cost += cost_coeffs_8x8(mb, x->block + b, PLANE_TYPE_UV,
|
2012-01-21 00:30:31 +01:00
|
|
|
ta + vp8_block2above_8x8[b],
|
|
|
|
tl + vp8_block2left_8x8[b]);
|
2012-01-21 00:30:31 +01:00
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int rd_inter16x16_uv_8x8(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
|
|
|
|
int *distortion, int fullpixel)
|
|
|
|
{
|
|
|
|
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
|
|
|
|
x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
|
|
|
|
|
|
|
|
vp8_transform_mbuv_8x8(x);
|
|
|
|
|
|
|
|
vp8_quantize_mbuv_8x8(x);
|
|
|
|
|
|
|
|
*rate = rd_cost_mbuv_8x8(x);
|
|
|
|
*distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
|
|
|
|
|
|
|
|
return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
|
|
|
|
}
|
2012-02-29 02:11:12 +01:00
|
|
|
|
2011-08-24 20:42:26 +02:00
|
|
|
|
|
|
|
static int rd_inter4x4_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate,
|
|
|
|
int *distortion, int fullpixel)
|
|
|
|
{
|
|
|
|
vp8_build_inter4x4_predictors_mbuv(&x->e_mbd);
|
|
|
|
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
|
|
|
|
x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
|
|
|
|
|
|
|
|
vp8_transform_mbuv(x);
|
|
|
|
vp8_quantize_mbuv(x);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
*rate = rd_cost_mbuv(x);
|
|
|
|
*distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
|
|
|
|
|
2011-01-07 15:41:13 +01:00
|
|
|
return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 18:05:05 +02:00
|
|
|
static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_tokenonly, int *distortion)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
MB_PREDICTION_MODE mode;
|
|
|
|
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
MB_PREDICTION_MODE mode2;
|
|
|
|
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode2_selected);
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
int best_rd = INT_MAX;
|
|
|
|
int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
|
|
|
|
int rate_to;
|
|
|
|
|
|
|
|
for (mode = DC_PRED; mode <= TM_PRED; mode++)
|
|
|
|
{
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++)
|
|
|
|
{
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
int rate;
|
|
|
|
int distortion;
|
|
|
|
int this_rd;
|
|
|
|
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.uv_mode = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_uv_mode = mode2;
|
|
|
|
if (mode2 == (MB_PREDICTION_MODE) (DC_PRED - 1))
|
|
|
|
{
|
|
|
|
#endif
|
2011-04-27 19:05:10 +02:00
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, build_intra_predictors_mbuv)
|
|
|
|
(&x->e_mbd);
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
RECON_INVOKE(&cpi->rtcd.common->recon, build_comp_intra_predictors_mbuv)
|
|
|
|
(&x->e_mbd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-14 22:34:33 +01:00
|
|
|
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
|
|
|
|
x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor,
|
|
|
|
x->src.uv_stride);
|
|
|
|
vp8_transform_mbuv(x);
|
|
|
|
vp8_quantize_mbuv(x);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
rate_to = rd_cost_mbuv(x);
|
2010-08-12 22:25:43 +02:00
|
|
|
rate = rate_to + x->intra_uv_mode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_context->mbmi.uv_mode];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-28 14:13:30 +01:00
|
|
|
distortion = ENCODEMB_INVOKE(&cpi->rtcd.encodemb, mbuverr)(x) / 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-07 15:41:13 +01:00
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (this_rd < best_rd)
|
|
|
|
{
|
|
|
|
best_rd = this_rd;
|
|
|
|
d = distortion;
|
|
|
|
r = rate;
|
|
|
|
*rate_tokenonly = rate_to;
|
|
|
|
mode_selected = mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mode2_selected = mode2;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*rate = r;
|
|
|
|
*distortion = d;
|
|
|
|
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_uv_mode = mode2_selected;
|
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 21:03:42 +01:00
|
|
|
int vp8_cost_mv_ref(VP8_COMMON *pc,
|
|
|
|
MB_PREDICTION_MODE m,
|
|
|
|
const int near_mv_ref_ct[4])
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
vp8_prob p [VP8_MVREFS-1];
|
|
|
|
assert(NEARESTMV <= m && m <= SPLITMV);
|
2011-12-06 21:03:42 +01:00
|
|
|
vp8_mv_ref_probs(pc, p, near_mv_ref_ct);
|
2010-08-09 19:27:26 +02:00
|
|
|
return vp8_cost_token(vp8_mv_ref_tree, p,
|
|
|
|
vp8_mv_ref_encoding_array - NEARESTMV + m);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = mb;
|
2011-05-12 16:50:16 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = mv->as_int;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int labels2mode(
|
|
|
|
MACROBLOCK *x,
|
|
|
|
int const *labelings, int which_label,
|
|
|
|
B_PREDICTION_MODE this_mode,
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv *this_mv, int_mv *best_ref_mv,
|
2010-05-18 17:58:33 +02:00
|
|
|
int *mvcost[2]
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MACROBLOCKD *const xd = & x->e_mbd;
|
|
|
|
MODE_INFO *const mic = xd->mode_info_context;
|
|
|
|
const int mis = xd->mode_info_stride;
|
|
|
|
|
|
|
|
int cost = 0;
|
|
|
|
int thismvcost = 0;
|
|
|
|
|
|
|
|
/* We have to be careful retrieving previously-encoded motion vectors.
|
|
|
|
Ones from this macroblock have to be pulled from the BLOCKD array
|
|
|
|
as they have not yet made it to the bmi array in our MB_MODE_INFO. */
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
BLOCKD *const d = xd->block + i;
|
|
|
|
const int row = i >> 2, col = i & 3;
|
|
|
|
|
|
|
|
B_PREDICTION_MODE m;
|
|
|
|
|
|
|
|
if (labelings[i] != which_label)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (col && labelings[i] == labelings[i-1])
|
|
|
|
m = LEFT4X4;
|
|
|
|
else if (row && labelings[i] == labelings[i-4])
|
|
|
|
m = ABOVE4X4;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// the only time we should do costing for new motion vector or mode
|
|
|
|
// is when we are on a new label (jbb May 08, 2007)
|
|
|
|
switch (m = this_mode)
|
|
|
|
{
|
|
|
|
case NEW4X4 :
|
2012-03-01 12:10:21 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost,
|
|
|
|
102, xd->allow_high_precision_mv);
|
|
|
|
#else
|
2010-05-18 17:58:33 +02:00
|
|
|
thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102);
|
2012-03-01 12:10:21 +01:00
|
|
|
#endif
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
case LEFT4X4:
|
2011-05-24 19:24:52 +02:00
|
|
|
this_mv->as_int = col ? d[-1].bmi.mv.as_int : left_block_mv(mic, i);
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
case ABOVE4X4:
|
2011-05-24 19:24:52 +02:00
|
|
|
this_mv->as_int = row ? d[-4].bmi.mv.as_int : above_block_mv(mic, i, mis);
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
case ZERO4X4:
|
2011-05-12 16:50:16 +02:00
|
|
|
this_mv->as_int = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m == ABOVE4X4) // replace above with left if same
|
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv left_mv;
|
2011-05-24 19:24:52 +02:00
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
left_mv.as_int = col ? d[-1].bmi.mv.as_int :
|
2011-05-24 19:24:52 +02:00
|
|
|
left_block_mv(mic, i);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
if (left_mv.as_int == this_mv->as_int)
|
2010-05-18 17:58:33 +02:00
|
|
|
m = LEFT4X4;
|
|
|
|
}
|
|
|
|
|
|
|
|
cost = x->inter_bmode_costs[ m];
|
|
|
|
}
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
d->bmi.mv.as_int = this_mv->as_int;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
x->partition_info->bmi[i].mode = m;
|
|
|
|
x->partition_info->bmi[i].mv.as_int = this_mv->as_int;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
while (++i < 16);
|
|
|
|
|
|
|
|
cost += thismvcost ;
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
2010-08-31 16:49:57 +02:00
|
|
|
static int rdcost_mbsegment_y(MACROBLOCK *mb, const int *labels,
|
|
|
|
int which_label, ENTROPY_CONTEXT *ta,
|
|
|
|
ENTROPY_CONTEXT *tl)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int cost = 0;
|
|
|
|
int b;
|
|
|
|
MACROBLOCKD *x = &mb->e_mbd;
|
|
|
|
|
|
|
|
for (b = 0; b < 16; b++)
|
|
|
|
if (labels[ b] == which_label)
|
2011-02-23 22:37:08 +01:00
|
|
|
cost += cost_coeffs(mb, x->block + b, PLANE_TYPE_Y_WITH_DC,
|
2010-08-31 16:49:57 +02:00
|
|
|
ta + vp8_block2above[b],
|
|
|
|
tl + vp8_block2left[b]);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
return cost;
|
|
|
|
|
|
|
|
}
|
|
|
|
static unsigned int vp8_encode_inter_mb_segment(MACROBLOCK *x, int const *labels, int which_label, const vp8_encodemb_rtcd_vtable_t *rtcd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned int distortion = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
if (labels[i] == which_label)
|
|
|
|
{
|
|
|
|
BLOCKD *bd = &x->e_mbd.block[i];
|
|
|
|
BLOCK *be = &x->block[i];
|
|
|
|
|
|
|
|
|
|
|
|
vp8_build_inter_predictors_b(bd, 16, x->e_mbd.subpixel_predict);
|
|
|
|
ENCODEMB_INVOKE(rtcd, subb)(be, bd, 16);
|
2010-06-16 21:52:18 +02:00
|
|
|
x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// set to 0 no way to account for 2nd order DC so discount
|
|
|
|
//be->coeff[0] = 0;
|
2010-06-04 00:08:44 +02:00
|
|
|
x->quantize_b(be, bd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
distortion += ENCODEMB_INVOKE(rtcd, berr)(be->coeff, bd->dqcoeff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return distortion;
|
|
|
|
}
|
|
|
|
|
2011-06-23 00:07:04 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv *ref_mv;
|
|
|
|
int_mv mvp;
|
2010-12-06 22:42:52 +01:00
|
|
|
|
|
|
|
int segment_rd;
|
|
|
|
int segment_num;
|
|
|
|
int r;
|
|
|
|
int d;
|
|
|
|
int segment_yrate;
|
|
|
|
B_PREDICTION_MODE modes[16];
|
2010-12-16 23:01:27 +01:00
|
|
|
int_mv mvs[16];
|
2010-12-06 22:42:52 +01:00
|
|
|
unsigned char eobs[16];
|
|
|
|
|
|
|
|
int mvthresh;
|
|
|
|
int *mdcounts;
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv sv_mvp[4]; // save 4 mvp from 8x8
|
2010-12-23 17:23:03 +01:00
|
|
|
int sv_istep[2]; // save 2 initial step_param for 16x8/8x16
|
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
} BEST_SEG_INFO;
|
|
|
|
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
|
|
|
|
BEST_SEG_INFO *bsi, unsigned int segmentation)
|
2010-12-06 22:42:52 +01:00
|
|
|
{
|
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
int const *labels;
|
|
|
|
int br = 0;
|
|
|
|
int bd = 0;
|
2010-12-06 22:42:52 +01:00
|
|
|
B_PREDICTION_MODE this_mode;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-10-26 21:34:16 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
int label_count;
|
|
|
|
int this_segment_rd = 0;
|
|
|
|
int label_mv_thresh;
|
|
|
|
int rate = 0;
|
|
|
|
int sbr = 0;
|
|
|
|
int sbd = 0;
|
|
|
|
int segmentyrate = 0;
|
|
|
|
|
|
|
|
vp8_variance_fn_ptr_t *v_fn_ptr;
|
|
|
|
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above, t_left;
|
|
|
|
ENTROPY_CONTEXT *ta;
|
|
|
|
ENTROPY_CONTEXT *tl;
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above_b, t_left_b;
|
|
|
|
ENTROPY_CONTEXT *ta_b;
|
|
|
|
ENTROPY_CONTEXT *tl_b;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
vpx_memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
ta = (ENTROPY_CONTEXT *)&t_above;
|
|
|
|
tl = (ENTROPY_CONTEXT *)&t_left;
|
|
|
|
ta_b = (ENTROPY_CONTEXT *)&t_above_b;
|
|
|
|
tl_b = (ENTROPY_CONTEXT *)&t_left_b;
|
|
|
|
|
|
|
|
br = 0;
|
|
|
|
bd = 0;
|
2010-06-11 20:33:49 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
v_fn_ptr = &cpi->fn_ptr[segmentation];
|
|
|
|
labels = vp8_mbsplits[segmentation];
|
|
|
|
label_count = vp8_mbsplit_count[segmentation];
|
2010-06-11 20:33:49 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
// 64 makes this threshold really big effectively
|
|
|
|
// making it so that we very rarely check mvs on
|
|
|
|
// segments. setting this to 1 would make mv thresh
|
|
|
|
// roughly equal to what it is for macroblocks
|
|
|
|
label_mv_thresh = 1 * bsi->mvthresh / label_count ;
|
|
|
|
|
|
|
|
// Segmentation method overheads
|
|
|
|
rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encodings + segmentation);
|
2011-12-06 21:03:42 +01:00
|
|
|
rate += vp8_cost_mv_ref(&cpi->common, SPLITMV, bsi->mdcounts);
|
2011-01-07 15:41:13 +01:00
|
|
|
this_segment_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
|
2010-12-06 22:42:52 +01:00
|
|
|
br += rate;
|
|
|
|
|
|
|
|
for (i = 0; i < label_count; i++)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv mode_mv[B_MODE_COUNT];
|
2010-12-06 22:42:52 +01:00
|
|
|
int best_label_rd = INT_MAX;
|
|
|
|
B_PREDICTION_MODE mode_selected = ZERO4X4;
|
|
|
|
int bestlabelyrate = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
// search for the best motion vector on this segment
|
|
|
|
for (this_mode = LEFT4X4; this_mode <= NEW4X4 ; this_mode ++)
|
|
|
|
{
|
|
|
|
int this_rd;
|
|
|
|
int distortion;
|
|
|
|
int labelyrate;
|
|
|
|
ENTROPY_CONTEXT_PLANES t_above_s, t_left_s;
|
|
|
|
ENTROPY_CONTEXT *ta_s;
|
|
|
|
ENTROPY_CONTEXT *tl_s;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
vpx_memcpy(&t_above_s, &t_above, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(&t_left_s, &t_left, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
ta_s = (ENTROPY_CONTEXT *)&t_above_s;
|
|
|
|
tl_s = (ENTROPY_CONTEXT *)&t_left_s;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
if (this_mode == NEW4X4)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2010-12-06 22:42:52 +01:00
|
|
|
int sseshift;
|
2010-05-18 17:58:33 +02:00
|
|
|
int num00;
|
2010-12-06 22:42:52 +01:00
|
|
|
int step_param = 0;
|
2010-12-23 17:23:03 +01:00
|
|
|
int further_steps;
|
2010-12-06 22:42:52 +01:00
|
|
|
int n;
|
|
|
|
int thissme;
|
|
|
|
int bestsme = INT_MAX;
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv temp_mv;
|
2010-12-06 22:42:52 +01:00
|
|
|
BLOCK *c;
|
|
|
|
BLOCKD *e;
|
2010-08-31 16:49:57 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
// Is the best so far sufficiently good that we cant justify doing and new motion search.
|
|
|
|
if (best_label_rd < label_mv_thresh)
|
|
|
|
break;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-23 17:23:03 +01:00
|
|
|
if(cpi->compressor_speed)
|
|
|
|
{
|
|
|
|
if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8)
|
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
bsi->mvp.as_int = bsi->sv_mvp[i].as_int;
|
|
|
|
if (i==1 && segmentation == BLOCK_16X8)
|
|
|
|
bsi->mvp.as_int = bsi->sv_mvp[2].as_int;
|
2010-12-23 17:23:03 +01:00
|
|
|
|
|
|
|
step_param = bsi->sv_istep[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// use previous block's result as next block's MV predictor.
|
|
|
|
if (segmentation == BLOCK_4X4 && i>0)
|
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
bsi->mvp.as_int = x->e_mbd.block[i-1].bmi.mv.as_int;
|
|
|
|
if (i==4 || i==8 || i==12)
|
|
|
|
bsi->mvp.as_int = x->e_mbd.block[i-4].bmi.mv.as_int;
|
2010-12-23 17:23:03 +01:00
|
|
|
step_param = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-06-01 20:41:05 +02:00
|
|
|
int sadpb = x->sadperbit4;
|
2011-07-07 17:21:41 +02:00
|
|
|
int_mv mvp_full;
|
|
|
|
|
|
|
|
mvp_full.as_mv.row = bsi->mvp.as_mv.row >>3;
|
|
|
|
mvp_full.as_mv.col = bsi->mvp.as_mv.col >>3;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
// find first label
|
2011-03-17 22:07:59 +01:00
|
|
|
n = vp8_mbsplit_offset[segmentation][i];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
c = &x->block[n];
|
|
|
|
e = &x->e_mbd.block[n];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
{
|
2011-07-07 17:21:41 +02:00
|
|
|
bestsme = cpi->diamond_search_sad(x, c, e, &mvp_full,
|
2010-07-01 03:58:54 +02:00
|
|
|
&mode_mv[NEW4X4], step_param,
|
|
|
|
sadpb, &num00, v_fn_ptr,
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST,
|
2012-02-27 19:22:38 +01:00
|
|
|
bsi->ref_mv);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
n = num00;
|
|
|
|
num00 = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
while (n < further_steps)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2010-12-06 22:42:52 +01:00
|
|
|
n++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
if (num00)
|
|
|
|
num00--;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
{
|
2010-07-01 03:58:54 +02:00
|
|
|
thissme = cpi->diamond_search_sad(x, c, e,
|
2011-07-07 17:21:41 +02:00
|
|
|
&mvp_full, &temp_mv,
|
2010-07-01 03:58:54 +02:00
|
|
|
step_param + n, sadpb,
|
|
|
|
&num00, v_fn_ptr,
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST,
|
2012-02-27 19:22:38 +01:00
|
|
|
bsi->ref_mv);
|
2010-12-06 22:42:52 +01:00
|
|
|
|
|
|
|
if (thissme < bestsme)
|
|
|
|
{
|
|
|
|
bestsme = thissme;
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEW4X4].as_int = temp_mv.as_int;
|
2010-12-06 22:42:52 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
sseshift = segmentation_to_sseshift[segmentation];
|
|
|
|
|
|
|
|
// Should we do a full search (best quality only)
|
|
|
|
if ((cpi->compressor_speed == 0) && (bestsme >> sseshift) > 4000)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-07-22 22:01:11 +02:00
|
|
|
/* Check if mvp_full is within the range. */
|
|
|
|
vp8_clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
|
|
|
|
|
2011-07-07 17:21:41 +02:00
|
|
|
thissme = cpi->full_search_sad(x, c, e, &mvp_full,
|
2010-07-01 03:58:54 +02:00
|
|
|
sadpb, 16, v_fn_ptr,
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST, bsi->ref_mv);
|
2010-12-06 22:42:52 +01:00
|
|
|
|
|
|
|
if (thissme < bestsme)
|
|
|
|
{
|
|
|
|
bestsme = thissme;
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEW4X4].as_int = e->bmi.mv.as_int;
|
2010-12-06 22:42:52 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
2010-12-06 22:42:52 +01:00
|
|
|
{
|
|
|
|
// The full search result is actually worse so re-instate the previous best vector
|
2011-05-12 16:50:16 +02:00
|
|
|
e->bmi.mv.as_int = mode_mv[NEW4X4].as_int;
|
2010-12-06 22:42:52 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
if (bestsme < INT_MAX)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-04-14 21:53:33 +02:00
|
|
|
int distortion;
|
2011-04-18 21:48:34 +02:00
|
|
|
unsigned int sse;
|
2011-06-01 20:41:05 +02:00
|
|
|
cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
|
2012-03-01 12:10:21 +01:00
|
|
|
bsi->ref_mv, x->errorperbit, v_fn_ptr, XMVCOST,
|
2011-06-01 20:41:05 +02:00
|
|
|
&distortion, &sse);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2010-12-06 22:42:52 +01:00
|
|
|
} /* NEW4X4 */
|
|
|
|
|
|
|
|
rate = labels2mode(x, labels, i, this_mode, &mode_mv[this_mode],
|
2012-03-01 12:10:21 +01:00
|
|
|
bsi->ref_mv, XMVCOST);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
// Trap vectors that reach beyond the UMV borders
|
2011-05-12 16:50:16 +02:00
|
|
|
if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
|
|
|
|
((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
|
2010-12-06 22:42:52 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
distortion = vp8_encode_inter_mb_segment(x, labels, i, IF_RTCD(&cpi->rtcd.encodemb)) / 4;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
labelyrate = rdcost_mbsegment_y(x, labels, i, ta_s, tl_s);
|
|
|
|
rate += labelyrate;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-07 15:41:13 +01:00
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
|
2010-08-31 16:49:57 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
if (this_rd < best_label_rd)
|
|
|
|
{
|
|
|
|
sbr = rate;
|
|
|
|
sbd = distortion;
|
|
|
|
bestlabelyrate = labelyrate;
|
|
|
|
mode_selected = this_mode;
|
|
|
|
best_label_rd = this_rd;
|
|
|
|
|
|
|
|
vpx_memcpy(ta_b, ta_s, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(tl_b, tl_s, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
}
|
2010-12-06 22:42:52 +01:00
|
|
|
} /*for each 4x4 mode*/
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
vpx_memcpy(ta, ta_b, sizeof(ENTROPY_CONTEXT_PLANES));
|
|
|
|
vpx_memcpy(tl, tl_b, sizeof(ENTROPY_CONTEXT_PLANES));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
labels2mode(x, labels, i, mode_selected, &mode_mv[mode_selected],
|
2012-03-01 12:10:21 +01:00
|
|
|
bsi->ref_mv, XMVCOST);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
br += sbr;
|
|
|
|
bd += sbd;
|
|
|
|
segmentyrate += bestlabelyrate;
|
|
|
|
this_segment_rd += best_label_rd;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-16 18:29:54 +01:00
|
|
|
if (this_segment_rd >= bsi->segment_rd) {
|
2010-12-06 22:42:52 +01:00
|
|
|
break;
|
2012-02-16 18:29:54 +01:00
|
|
|
}
|
|
|
|
|
2010-12-23 17:23:03 +01:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
} /* for each label */
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
if (this_segment_rd < bsi->segment_rd)
|
|
|
|
{
|
|
|
|
bsi->r = br;
|
|
|
|
bsi->d = bd;
|
|
|
|
bsi->segment_yrate = segmentyrate;
|
|
|
|
bsi->segment_rd = this_segment_rd;
|
|
|
|
bsi->segment_num = segmentation;
|
|
|
|
|
|
|
|
// store everything needed to come back to this!!
|
|
|
|
for (i = 0; i < 16; i++)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2010-12-06 22:42:52 +01:00
|
|
|
BLOCKD *bd = &x->e_mbd.block[i];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
bsi->mvs[i].as_mv = x->partition_info->bmi[i].mv.as_mv;
|
|
|
|
bsi->modes[i] = x->partition_info->bmi[i].mode;
|
2010-12-06 22:42:52 +01:00
|
|
|
bsi->eobs[i] = bd->eob;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 22:42:52 +01:00
|
|
|
}
|
2010-12-23 17:23:03 +01:00
|
|
|
|
|
|
|
static __inline
|
|
|
|
void vp8_cal_step_param(int sr, int *sp)
|
|
|
|
{
|
|
|
|
int step = 0;
|
|
|
|
|
|
|
|
if (sr > MAX_FIRST_STEP) sr = MAX_FIRST_STEP;
|
|
|
|
else if (sr < 1) sr = 1;
|
|
|
|
|
|
|
|
while (sr>>=1)
|
|
|
|
step++;
|
|
|
|
|
|
|
|
*sp = MAX_MVSEARCH_STEPS - 1 - step;
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv *best_ref_mv, int best_rd,
|
2010-12-06 22:42:52 +01:00
|
|
|
int *mdcounts, int *returntotrate,
|
|
|
|
int *returnyrate, int *returndistortion,
|
|
|
|
int mvthresh)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BEST_SEG_INFO bsi;
|
|
|
|
|
|
|
|
vpx_memset(&bsi, 0, sizeof(bsi));
|
|
|
|
|
|
|
|
bsi.segment_rd = best_rd;
|
|
|
|
bsi.ref_mv = best_ref_mv;
|
2011-05-12 16:50:16 +02:00
|
|
|
bsi.mvp.as_int = best_ref_mv->as_int;
|
2010-12-06 22:42:52 +01:00
|
|
|
bsi.mvthresh = mvthresh;
|
|
|
|
bsi.mdcounts = mdcounts;
|
|
|
|
|
|
|
|
for(i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
bsi.modes[i] = ZERO4X4;
|
|
|
|
}
|
2010-12-23 17:23:03 +01:00
|
|
|
|
2010-12-16 23:01:27 +01:00
|
|
|
if(cpi->compressor_speed == 0)
|
|
|
|
{
|
|
|
|
/* for now, we will keep the original segmentation order
|
|
|
|
when in best quality mode */
|
2011-03-17 22:07:59 +01:00
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
|
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
|
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
|
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
|
2010-12-16 23:01:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-23 17:23:03 +01:00
|
|
|
int sr;
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_8X8);
|
2010-12-23 17:23:03 +01:00
|
|
|
|
2012-02-16 18:29:54 +01:00
|
|
|
|
2010-12-16 23:01:27 +01:00
|
|
|
if (bsi.segment_rd < best_rd)
|
|
|
|
{
|
2011-07-07 17:21:41 +02:00
|
|
|
int col_min = (best_ref_mv->as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv->as_mv.col & 7)?1:0);
|
|
|
|
int row_min = (best_ref_mv->as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv->as_mv.row & 7)?1:0);
|
|
|
|
int col_max = (best_ref_mv->as_mv.col>>3) + MAX_FULL_PEL_VAL;
|
|
|
|
int row_max = (best_ref_mv->as_mv.row>>3) + MAX_FULL_PEL_VAL;
|
2010-12-28 19:23:07 +01:00
|
|
|
|
|
|
|
int tmp_col_min = x->mv_col_min;
|
|
|
|
int tmp_col_max = x->mv_col_max;
|
|
|
|
int tmp_row_min = x->mv_row_min;
|
|
|
|
int tmp_row_max = x->mv_row_max;
|
|
|
|
|
|
|
|
/* Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. */
|
|
|
|
if (x->mv_col_min < col_min )
|
|
|
|
x->mv_col_min = col_min;
|
|
|
|
if (x->mv_col_max > col_max )
|
|
|
|
x->mv_col_max = col_max;
|
|
|
|
if (x->mv_row_min < row_min )
|
|
|
|
x->mv_row_min = row_min;
|
|
|
|
if (x->mv_row_max > row_max )
|
|
|
|
x->mv_row_max = row_max;
|
|
|
|
|
|
|
|
/* Get 8x8 result */
|
2011-05-12 16:50:16 +02:00
|
|
|
bsi.sv_mvp[0].as_int = bsi.mvs[0].as_int;
|
|
|
|
bsi.sv_mvp[1].as_int = bsi.mvs[2].as_int;
|
|
|
|
bsi.sv_mvp[2].as_int = bsi.mvs[8].as_int;
|
|
|
|
bsi.sv_mvp[3].as_int = bsi.mvs[10].as_int;
|
2010-12-23 17:23:03 +01:00
|
|
|
|
2010-12-28 19:23:07 +01:00
|
|
|
/* Use 8x8 result as 16x8/8x16's predictor MV. Adjust search range according to the closeness of 2 MV. */
|
|
|
|
/* block 8X16 */
|
2010-12-23 17:23:03 +01:00
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[2].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[2].as_mv.col))>>3);
|
2010-12-23 17:23:03 +01:00
|
|
|
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
sr = MAXF((abs(bsi.sv_mvp[1].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[1].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
|
2010-12-23 17:23:03 +01:00
|
|
|
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
|
2010-12-23 17:23:03 +01:00
|
|
|
}
|
|
|
|
|
2010-12-28 19:23:07 +01:00
|
|
|
/* block 16X8 */
|
2010-12-23 17:23:03 +01:00
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[1].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[1].as_mv.col))>>3);
|
2010-12-23 17:23:03 +01:00
|
|
|
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
sr = MAXF((abs(bsi.sv_mvp[2].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[2].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
|
2010-12-23 17:23:03 +01:00
|
|
|
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
|
2010-12-23 17:23:03 +01:00
|
|
|
}
|
|
|
|
|
2010-12-28 19:23:07 +01:00
|
|
|
/* If 8x8 is better than 16x8/8x16, then do 4x4 search */
|
2011-01-10 23:21:55 +01:00
|
|
|
/* Not skip 4x4 if speed=0 (good quality) */
|
|
|
|
if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8) /* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */
|
2010-12-23 17:23:03 +01:00
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
bsi.mvp.as_int = bsi.sv_mvp[0].as_int;
|
2011-03-17 22:07:59 +01:00
|
|
|
rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
|
2010-12-23 17:23:03 +01:00
|
|
|
}
|
2010-12-28 19:23:07 +01:00
|
|
|
|
|
|
|
/* restore UMV window */
|
|
|
|
x->mv_col_min = tmp_col_min;
|
|
|
|
x->mv_col_max = tmp_col_max;
|
|
|
|
x->mv_row_min = tmp_row_min;
|
|
|
|
x->mv_row_max = tmp_row_max;
|
2010-12-16 23:01:27 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 22:42:52 +01:00
|
|
|
|
|
|
|
/* set it to the best */
|
2010-05-18 17:58:33 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
BLOCKD *bd = &x->e_mbd.block[i];
|
|
|
|
|
2011-06-02 19:46:41 +02:00
|
|
|
bd->bmi.mv.as_int = bsi.mvs[i].as_int;
|
2010-12-06 22:42:52 +01:00
|
|
|
bd->eob = bsi.eobs[i];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
*returntotrate = bsi.r;
|
|
|
|
*returndistortion = bsi.d;
|
|
|
|
*returnyrate = bsi.segment_yrate;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
/* save partitions */
|
|
|
|
x->e_mbd.mode_info_context->mbmi.partitioning = bsi.segment_num;
|
|
|
|
x->partition_info->count = vp8_mbsplit_count[bsi.segment_num];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-09-02 22:17:52 +02:00
|
|
|
for (i = 0; i < x->partition_info->count; i++)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
2011-03-17 22:07:59 +01:00
|
|
|
j = vp8_mbsplit_offset[bsi.segment_num][i];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
x->partition_info->bmi[i].mode = bsi.modes[j];
|
|
|
|
x->partition_info->bmi[i].mv.as_mv = bsi.mvs[j].as_mv;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-05-19 21:03:36 +02:00
|
|
|
/*
|
|
|
|
* used to set x->e_mbd.mode_info_context->mbmi.mv.as_int
|
|
|
|
*/
|
|
|
|
x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
return bsi.segment_rd;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:04:40 +01:00
|
|
|
/* Order arr in increasing order, original position stored in idx */
|
2011-04-27 19:40:39 +02:00
|
|
|
static void insertsortmv(int arr[], int len)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-04-27 19:40:39 +02:00
|
|
|
int i, j, k;
|
2010-12-03 17:26:21 +01:00
|
|
|
|
2011-04-27 19:40:39 +02:00
|
|
|
for ( i = 1 ; i <= len-1 ; i++ )
|
|
|
|
{
|
|
|
|
for ( j = 0 ; j < i ; j++ )
|
|
|
|
{
|
|
|
|
if ( arr[j] > arr[i] )
|
|
|
|
{
|
|
|
|
int temp;
|
2010-12-03 17:26:21 +01:00
|
|
|
|
2011-04-27 19:40:39 +02:00
|
|
|
temp = arr[i];
|
|
|
|
|
|
|
|
for ( k = i; k >j; k--)
|
|
|
|
arr[k] = arr[k - 1] ;
|
|
|
|
|
|
|
|
arr[j] = temp ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
|
2011-04-27 19:40:39 +02:00
|
|
|
static void insertsortsad(int arr[],int idx[], int len)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-04-27 19:40:39 +02:00
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
for ( i = 1 ; i <= len-1 ; i++ )
|
|
|
|
{
|
|
|
|
for ( j = 0 ; j < i ; j++ )
|
|
|
|
{
|
|
|
|
if ( arr[j] > arr[i] )
|
|
|
|
{
|
|
|
|
int temp, tempi;
|
|
|
|
|
|
|
|
temp = arr[i];
|
|
|
|
tempi = idx[i];
|
|
|
|
|
|
|
|
for ( k = i; k >j; k--)
|
|
|
|
{
|
|
|
|
arr[k] = arr[k - 1] ;
|
|
|
|
idx[k] = idx[k - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
arr[j] = temp ;
|
|
|
|
idx[j] = tempi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//The improved MV prediction
|
2011-01-26 18:03:13 +01:00
|
|
|
void vp8_mv_pred
|
2010-12-03 17:26:21 +01:00
|
|
|
(
|
|
|
|
VP8_COMP *cpi,
|
|
|
|
MACROBLOCKD *xd,
|
|
|
|
const MODE_INFO *here,
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv *mvp,
|
2010-12-03 17:26:21 +01:00
|
|
|
int refframe,
|
|
|
|
int *ref_frame_sign_bias,
|
|
|
|
int *sr,
|
|
|
|
int near_sadidx[]
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const MODE_INFO *above = here - xd->mode_info_stride;
|
|
|
|
const MODE_INFO *left = here - 1;
|
|
|
|
const MODE_INFO *aboveleft = above - 1;
|
2011-01-25 21:54:34 +01:00
|
|
|
int_mv near_mvs[8];
|
|
|
|
int near_ref[8];
|
2010-12-03 17:26:21 +01:00
|
|
|
int_mv mv;
|
|
|
|
int vcnt=0;
|
|
|
|
int find=0;
|
|
|
|
int mb_offset;
|
|
|
|
|
2011-01-25 21:54:34 +01:00
|
|
|
int mvx[8];
|
|
|
|
int mvy[8];
|
2010-12-03 17:26:21 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
mv.as_int = 0;
|
|
|
|
|
|
|
|
if(here->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
near_mvs[0].as_int = near_mvs[1].as_int = near_mvs[2].as_int = near_mvs[3].as_int = near_mvs[4].as_int = near_mvs[5].as_int = near_mvs[6].as_int = near_mvs[7].as_int = 0;
|
|
|
|
near_ref[0] = near_ref[1] = near_ref[2] = near_ref[3] = near_ref[4] = near_ref[5] = near_ref[6] = near_ref[7] = 0;
|
2010-12-03 17:26:21 +01:00
|
|
|
|
|
|
|
// read in 3 nearby block's MVs from current frame as prediction candidates.
|
|
|
|
if (above->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
near_mvs[vcnt].as_int = above->mbmi.mv.as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
near_ref[vcnt] = above->mbmi.ref_frame;
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
if (left->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
near_mvs[vcnt].as_int = left->mbmi.mv.as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
near_ref[vcnt] = left->mbmi.ref_frame;
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
near_mvs[vcnt].as_int = aboveleft->mbmi.mv.as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
near_ref[vcnt] = aboveleft->mbmi.ref_frame;
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
|
2011-01-25 21:54:34 +01:00
|
|
|
// read in 5 nearby block's MVs from last frame.
|
2010-12-03 17:26:21 +01:00
|
|
|
if(cpi->common.last_frame_type != KEY_FRAME)
|
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
mb_offset = (-xd->mb_to_top_edge/128 + 1) * (xd->mode_info_stride +1) + (-xd->mb_to_left_edge/128 +1) ;
|
2010-12-03 17:26:21 +01:00
|
|
|
|
|
|
|
// current in last frame
|
|
|
|
if (cpi->lf_ref_frame[mb_offset] != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
near_mvs[vcnt].as_int = cpi->lfmv[mb_offset].as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
near_ref[vcnt] = cpi->lf_ref_frame[mb_offset];
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
|
|
|
|
// above in last frame
|
2011-01-25 21:54:34 +01:00
|
|
|
if (cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1] != INTRA_FRAME)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
near_mvs[vcnt].as_int = cpi->lfmv[mb_offset - xd->mode_info_stride-1].as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset - xd->mode_info_stride-1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2011-01-25 21:54:34 +01:00
|
|
|
near_ref[vcnt] = cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1];
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
|
|
|
|
// left in last frame
|
|
|
|
if (cpi->lf_ref_frame[mb_offset-1] != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
near_mvs[vcnt].as_int = cpi->lfmv[mb_offset -1].as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset -1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2010-12-03 17:26:21 +01:00
|
|
|
near_ref[vcnt] = cpi->lf_ref_frame[mb_offset - 1];
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
|
2011-01-25 21:54:34 +01:00
|
|
|
// right in last frame
|
|
|
|
if (cpi->lf_ref_frame[mb_offset +1] != INTRA_FRAME)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
near_mvs[vcnt].as_int = cpi->lfmv[mb_offset +1].as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2011-01-25 21:54:34 +01:00
|
|
|
near_ref[vcnt] = cpi->lf_ref_frame[mb_offset +1];
|
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
|
|
|
|
// below in last frame
|
|
|
|
if (cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1] != INTRA_FRAME)
|
2010-12-03 17:26:21 +01:00
|
|
|
{
|
2011-01-25 21:54:34 +01:00
|
|
|
near_mvs[vcnt].as_int = cpi->lfmv[mb_offset + xd->mode_info_stride +1].as_int;
|
2011-01-26 18:03:13 +01:00
|
|
|
mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset + xd->mode_info_stride +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias);
|
2011-01-25 21:54:34 +01:00
|
|
|
near_ref[vcnt] = cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1];
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
vcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i< vcnt; i++)
|
|
|
|
{
|
|
|
|
if(near_ref[near_sadidx[i]] != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if(here->mbmi.ref_frame == near_ref[near_sadidx[i]])
|
|
|
|
{
|
|
|
|
mv.as_int = near_mvs[near_sadidx[i]].as_int;
|
|
|
|
find = 1;
|
2011-01-25 21:54:34 +01:00
|
|
|
if (i < 3)
|
2010-12-03 17:26:21 +01:00
|
|
|
*sr = 3;
|
|
|
|
else
|
|
|
|
*sr = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!find)
|
|
|
|
{
|
|
|
|
for(i=0; i<vcnt; i++)
|
|
|
|
{
|
|
|
|
mvx[i] = near_mvs[i].as_mv.row;
|
|
|
|
mvy[i] = near_mvs[i].as_mv.col;
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:40:39 +02:00
|
|
|
insertsortmv(mvx, vcnt);
|
|
|
|
insertsortmv(mvy, vcnt);
|
2010-12-03 17:26:21 +01:00
|
|
|
mv.as_mv.row = mvx[vcnt/2];
|
|
|
|
mv.as_mv.col = mvy[vcnt/2];
|
|
|
|
|
|
|
|
find = 1;
|
|
|
|
//sr is set to 0 to allow calling function to decide the search range.
|
|
|
|
*sr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up return values */
|
2011-05-12 16:50:16 +02:00
|
|
|
mvp->as_int = mv.as_int;
|
|
|
|
vp8_clamp_mv2(mvp, xd);
|
2010-12-03 17:26:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-28 16:00:20 +01:00
|
|
|
void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[])
|
|
|
|
{
|
|
|
|
|
|
|
|
int near_sad[8] = {0}; // 0-cf above, 1-cf left, 2-cf aboveleft, 3-lf current, 4-lf above, 5-lf left, 6-lf right, 7-lf below
|
2011-06-23 19:54:02 +02:00
|
|
|
BLOCK *b = &x->block[0];
|
|
|
|
unsigned char *src_y_ptr = *(b->base_src);
|
2011-01-28 16:00:20 +01:00
|
|
|
|
|
|
|
//calculate sad for current frame 3 nearby MBs.
|
|
|
|
if( xd->mb_to_top_edge==0 && xd->mb_to_left_edge ==0)
|
|
|
|
{
|
|
|
|
near_sad[0] = near_sad[1] = near_sad[2] = INT_MAX;
|
|
|
|
}else if(xd->mb_to_top_edge==0)
|
|
|
|
{ //only has left MB for sad calculation.
|
|
|
|
near_sad[0] = near_sad[2] = INT_MAX;
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
}else if(xd->mb_to_left_edge ==0)
|
|
|
|
{ //only has left MB for sad calculation.
|
|
|
|
near_sad[1] = near_sad[2] = INT_MAX;
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
}else
|
|
|
|
{
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
|
|
|
|
near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
|
|
|
|
near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(cpi->common.last_frame_type != KEY_FRAME)
|
|
|
|
{
|
|
|
|
//calculate sad for last frame 5 nearby MBs.
|
|
|
|
unsigned char *pre_y_buffer = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_buffer + recon_yoffset;
|
|
|
|
int pre_y_stride = cpi->common.yv12_fb[cpi->common.lst_fb_idx].y_stride;
|
|
|
|
|
|
|
|
if(xd->mb_to_top_edge==0) near_sad[4] = INT_MAX;
|
|
|
|
if(xd->mb_to_left_edge ==0) near_sad[5] = INT_MAX;
|
|
|
|
if(xd->mb_to_right_edge ==0) near_sad[6] = INT_MAX;
|
|
|
|
if(xd->mb_to_bottom_edge==0) near_sad[7] = INT_MAX;
|
|
|
|
|
|
|
|
if(near_sad[4] != INT_MAX)
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - pre_y_stride *16, pre_y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
if(near_sad[5] != INT_MAX)
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - 16, pre_y_stride, 0x7fffffff);
|
|
|
|
near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer, pre_y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
if(near_sad[6] != INT_MAX)
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + 16, pre_y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
if(near_sad[7] != INT_MAX)
|
2011-06-23 19:54:02 +02:00
|
|
|
near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + pre_y_stride *16, pre_y_stride, 0x7fffffff);
|
2011-01-28 16:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(cpi->common.last_frame_type != KEY_FRAME)
|
|
|
|
{
|
2011-04-27 19:40:39 +02:00
|
|
|
insertsortsad(near_sad, near_sadidx, 8);
|
2011-01-28 16:00:20 +01:00
|
|
|
}else
|
|
|
|
{
|
2011-04-27 19:40:39 +02:00
|
|
|
insertsortsad(near_sad, near_sadidx, 3);
|
2011-01-28 16:00:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
|
2011-05-13 16:56:45 +02:00
|
|
|
{
|
2011-05-19 21:03:36 +02:00
|
|
|
if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
|
2011-05-13 16:56:45 +02:00
|
|
|
{
|
2011-05-19 21:03:36 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < x->partition_info->count; i++)
|
2011-05-13 16:56:45 +02:00
|
|
|
{
|
2011-05-19 21:03:36 +02:00
|
|
|
if (x->partition_info->bmi[i].mode == NEW4X4)
|
2011-05-13 16:56:45 +02:00
|
|
|
{
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
if (x->e_mbd.allow_high_precision_mv)
|
|
|
|
{
|
|
|
|
cpi->MVcount_hp[0][mv_max_hp+(x->partition_info->bmi[i].mv.as_mv.row
|
|
|
|
- best_ref_mv->as_mv.row)]++;
|
|
|
|
cpi->MVcount_hp[1][mv_max_hp+(x->partition_info->bmi[i].mv.as_mv.col
|
|
|
|
- best_ref_mv->as_mv.col)]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row
|
|
|
|
- best_ref_mv->as_mv.row) >> 1)]++;
|
|
|
|
cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
|
|
|
|
- best_ref_mv->as_mv.col) >> 1)]++;
|
|
|
|
}
|
2011-05-13 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-19 21:03:36 +02:00
|
|
|
else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
|
2011-05-13 16:56:45 +02:00
|
|
|
{
|
2012-02-27 19:22:38 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
if (x->e_mbd.allow_high_precision_mv)
|
|
|
|
{
|
|
|
|
cpi->MVcount_hp[0][mv_max_hp+(x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
|
|
|
|
- best_ref_mv->as_mv.row)]++;
|
|
|
|
cpi->MVcount_hp[1][mv_max_hp+(x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
|
|
|
|
- best_ref_mv->as_mv.col)]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
|
|
|
|
- best_ref_mv->as_mv.row) >> 1)]++;
|
|
|
|
cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
|
|
|
|
- best_ref_mv->as_mv.col) >> 1)]++;
|
|
|
|
}
|
2011-05-13 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
static void set_i8x8_block_modes(MACROBLOCK *x, int modes[2][4])
|
2011-12-01 01:25:00 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
for(i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
int ib = vp8_i8x8_block[i];
|
2012-02-29 02:12:08 +01:00
|
|
|
x->e_mbd.mode_info_context->bmi[ib+0].as_mode.first= modes[0][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+1].as_mode.first= modes[0][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+4].as_mode.first= modes[0][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+5].as_mode.first= modes[0][i];
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+0].as_mode.second= modes[1][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+1].as_mode.second= modes[1][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+4].as_mode.second= modes[1][i];
|
|
|
|
x->e_mbd.mode_info_context->bmi[ib+5].as_mode.second= modes[1][i];
|
|
|
|
#endif
|
|
|
|
//printf("%d,%d,%d,%d %d,%d,%d,%d\n",
|
|
|
|
// modes[0][0], modes[0][1], modes[0][2], modes[0][3],
|
|
|
|
// modes[1][0], modes[1][1], modes[1][2], modes[1][3]);
|
2011-12-01 01:25:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
xd->block[i].bmi = xd->mode_info_context->bmi[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-28 13:20:14 +01:00
|
|
|
void vp8_estimate_ref_frame_costs(VP8_COMP *cpi, unsigned int * ref_costs )
|
|
|
|
{
|
|
|
|
VP8_COMMON *cm = &cpi->common;
|
|
|
|
MACROBLOCKD *xd = &cpi->mb.e_mbd;
|
|
|
|
vp8_prob * mod_refprobs;
|
|
|
|
|
|
|
|
unsigned int cost;
|
|
|
|
int pred_ref ;
|
|
|
|
int pred_flag;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vp8_prob pred_prob;
|
|
|
|
|
|
|
|
// Get the predicted reference for this mb
|
|
|
|
pred_ref = get_pred_ref( cm, xd );
|
|
|
|
|
|
|
|
// Get the context probability for the prediction flag
|
|
|
|
pred_prob = get_pred_prob( cm, xd, PRED_REF );
|
|
|
|
|
|
|
|
// Get the set of probailities to use if prediction fails
|
|
|
|
mod_refprobs = cm->mod_refprobs[pred_ref];
|
|
|
|
|
|
|
|
// For each possible selected reference frame work out a cost.
|
|
|
|
// TODO: correct handling of costs if segment indicates only a subset of
|
|
|
|
// reference frames are allowed... though mostly this should come out
|
|
|
|
// in the wash.
|
|
|
|
for ( i = 0; i < MAX_REF_FRAMES; i++ )
|
|
|
|
{
|
|
|
|
pred_flag = (i == pred_ref);
|
|
|
|
|
|
|
|
// Get the prediction for the current mb
|
|
|
|
cost = vp8_cost_bit( pred_prob, pred_flag );
|
|
|
|
|
|
|
|
// for incorectly predicted cases
|
|
|
|
if ( ! pred_flag )
|
|
|
|
{
|
|
|
|
if ( mod_refprobs[0] )
|
|
|
|
cost += vp8_cost_bit( (i != INTRA_FRAME), mod_refprobs[0] );
|
|
|
|
|
|
|
|
// Inter coded
|
|
|
|
if (i != INTRA_FRAME)
|
|
|
|
{
|
|
|
|
if ( mod_refprobs[1] )
|
|
|
|
cost += vp8_cost_bit( (i != LAST_FRAME), mod_refprobs[1] );
|
|
|
|
|
|
|
|
if (i != LAST_FRAME)
|
|
|
|
{
|
|
|
|
if ( mod_refprobs[2] )
|
|
|
|
cost += vp8_cost_bit( (i != GOLDEN_FRAME),
|
|
|
|
mod_refprobs[2] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ref_costs[i] = cost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset,
|
|
|
|
int *returnrate, int *returndistortion, int *returnintra,
|
2012-02-29 02:25:45 +01:00
|
|
|
int *best_single_rd_diff, int *best_comp_rd_diff,
|
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
|
|
|
int *best_hybrid_rd_diff)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-02 15:33:34 +01:00
|
|
|
VP8_COMMON *cm = &cpi->common;
|
2010-05-18 17:58:33 +02:00
|
|
|
BLOCK *b = &x->block[0];
|
|
|
|
BLOCKD *d = &x->e_mbd.block[0];
|
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
2011-06-02 19:46:41 +02:00
|
|
|
union b_mode_info best_bmodes[16];
|
2010-05-18 17:58:33 +02:00
|
|
|
MB_MODE_INFO best_mbmode;
|
2010-09-02 22:17:52 +02:00
|
|
|
PARTITION_INFO best_partition;
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv best_ref_mv;
|
|
|
|
int_mv mode_mv[MB_MODE_COUNT];
|
2010-05-18 17:58:33 +02:00
|
|
|
MB_PREDICTION_MODE this_mode;
|
|
|
|
int num00;
|
|
|
|
int best_mode_index = 0;
|
2012-02-29 02:12:08 +01:00
|
|
|
int mode8x8[2][4];
|
2011-11-03 18:45:27 +01:00
|
|
|
unsigned char segment_id = xd->mode_info_context->mbmi.segment_id;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
int mode_index;
|
|
|
|
int mdcounts[4];
|
|
|
|
int rate;
|
|
|
|
int distortion;
|
2011-04-08 15:21:36 +02:00
|
|
|
int best_rd = INT_MAX;
|
|
|
|
int best_intra_rd = INT_MAX;
|
2012-02-29 02:25:45 +01:00
|
|
|
int best_comp_rd = 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
|
|
|
int best_single_rd = INT_MAX;
|
|
|
|
int best_hybrid_rd = INT_MAX;
|
2010-05-18 17:58:33 +02:00
|
|
|
int rate2, distortion2;
|
|
|
|
int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly;
|
2012-02-22 03:10:18 +01:00
|
|
|
int uv_intra_skippable = 0;
|
|
|
|
int uv_intra_skippable_8x8=0;
|
2010-05-18 17:58:33 +02:00
|
|
|
int rate_y, UNINITIALIZED_IS_SAFE(rate_uv);
|
2010-12-16 15:38:02 +01:00
|
|
|
int distortion_uv;
|
|
|
|
int best_yrd = INT_MAX;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
//int all_rds[MAX_MODES]; // Experimental debug code.
|
|
|
|
//int all_rates[MAX_MODES];
|
|
|
|
//int all_dist[MAX_MODES];
|
|
|
|
//int intermodecost[MAX_MODES];
|
|
|
|
|
|
|
|
MB_PREDICTION_MODE uv_intra_mode;
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv mvp;
|
2011-01-25 21:54:34 +01:00
|
|
|
int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
2010-12-03 17:26:21 +01:00
|
|
|
int saddone=0;
|
|
|
|
int sr=0; //search range got from mv_pred(). It uses step_param levels. (0-7)
|
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
int_mv frame_nearest_mv[4];
|
|
|
|
int_mv frame_near_mv[4];
|
|
|
|
int_mv frame_best_ref_mv[4];
|
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
|
|
|
int_mv mc_search_result[4];
|
2011-01-11 21:00:00 +01:00
|
|
|
int frame_mdcounts[4][4];
|
|
|
|
unsigned char *y_buffer[4];
|
|
|
|
unsigned char *u_buffer[4];
|
|
|
|
unsigned char *v_buffer[4];
|
|
|
|
|
2012-01-28 13:20:14 +01:00
|
|
|
unsigned int ref_costs[MAX_REF_FRAMES];
|
|
|
|
|
2011-01-11 21:00:00 +01:00
|
|
|
vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
|
2011-06-02 19:46:41 +02:00
|
|
|
vpx_memset(&best_bmodes, 0, sizeof(best_bmodes));
|
2012-01-28 13:20:14 +01: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
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
#define INVALID_MV 0x80008000
|
|
|
|
mc_search_result[i].as_int = INVALID_MV;
|
|
|
|
}
|
2011-01-11 21:00:00 +01:00
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
|
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
|
|
|
|
x->e_mbd.prev_mode_info_context,
|
|
|
|
&frame_nearest_mv[LAST_FRAME], &frame_near_mv[LAST_FRAME],
|
|
|
|
&frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
|
2011-01-11 21:00:00 +01:00
|
|
|
|
|
|
|
y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
|
|
|
|
u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
|
|
|
|
v_buffer[LAST_FRAME] = lst_yv12->v_buffer + recon_uvoffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
|
|
|
|
x->e_mbd.prev_mode_info_context,
|
|
|
|
&frame_nearest_mv[GOLDEN_FRAME], &frame_near_mv[GOLDEN_FRAME],
|
|
|
|
&frame_best_ref_mv[GOLDEN_FRAME], frame_mdcounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
|
2010-06-11 20:33:49 +02:00
|
|
|
|
2011-01-11 21:00:00 +01:00
|
|
|
y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset;
|
|
|
|
u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
|
|
|
|
v_buffer[GOLDEN_FRAME] = gld_yv12->v_buffer + recon_uvoffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpi->ref_frame_flags & VP8_ALT_FLAG)
|
|
|
|
{
|
|
|
|
YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
|
|
|
|
|
2011-11-16 01:16:30 +01:00
|
|
|
vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context,
|
|
|
|
x->e_mbd.prev_mode_info_context,
|
|
|
|
&frame_nearest_mv[ALTREF_FRAME], &frame_near_mv[ALTREF_FRAME],
|
2011-01-11 21:00:00 +01:00
|
|
|
&frame_best_ref_mv[ALTREF_FRAME], frame_mdcounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias);
|
|
|
|
|
|
|
|
y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;
|
|
|
|
u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset;
|
|
|
|
v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
*returnintra = INT_MAX;
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->mbs_tested_so_far++; // Count of the number of MBs tested so far this frame
|
|
|
|
|
|
|
|
x->skip = 0;
|
|
|
|
|
|
|
|
vpx_memset(mode_mv, 0, sizeof(mode_mv));
|
|
|
|
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
|
2012-03-02 05:16:49 +01:00
|
|
|
|
|
|
|
/* Initialize zbin mode boost for uv costing */
|
|
|
|
cpi->zbin_mode_boost = 0;
|
|
|
|
vp8_update_zbin_extra(cpi, x);
|
2011-06-08 18:05:05 +02:00
|
|
|
rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, &uv_intra_rate_tokenonly, &uv_intra_distortion);
|
2010-08-12 22:25:43 +02:00
|
|
|
uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode;
|
2012-02-18 00:52:30 +01:00
|
|
|
|
2012-02-22 03:10:18 +01:00
|
|
|
uv_intra_skippable = mbuv_is_skippable(&x->e_mbd);
|
|
|
|
|
|
|
|
/* rough estimate for now */
|
|
|
|
uv_intra_skippable_8x8 = uv_intra_skippable;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-01-28 13:20:14 +01:00
|
|
|
// Get estimates of reference frame costs for each reference frame
|
|
|
|
// that depend on the current prediction etc.
|
|
|
|
vp8_estimate_ref_frame_costs( cpi, ref_costs );
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
|
|
|
|
{
|
|
|
|
int this_rd = INT_MAX;
|
|
|
|
int disable_skip = 0;
|
2010-12-16 15:38:02 +01:00
|
|
|
int other_cost = 0;
|
2012-02-29 02:25:45 +01:00
|
|
|
int compmode_cost = 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
|
|
|
int mode_excluded = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Test best rd so far against threshold for trying this mode.
|
|
|
|
if (best_rd <= cpi->rd_threshes[mode_index])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// These variables hold are rolling total cost and distortion for this mode
|
|
|
|
rate2 = 0;
|
|
|
|
distortion2 = 0;
|
|
|
|
|
|
|
|
this_mode = vp8_mode_order[mode_index];
|
|
|
|
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = this_mode;
|
2012-02-29 02:12:08 +01:00
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mode = (MB_PREDICTION_MODE) (DC_PRED - 1);
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_uv_mode = (MB_PREDICTION_MODE) (DC_PRED - 1);
|
|
|
|
#endif
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame = vp8_ref_frame_order[mode_index];
|
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
|
|
|
x->e_mbd.mode_info_context->mbmi.second_ref_frame = vp8_second_ref_frame_order[mode_index];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-11-03 18:45:27 +01:00
|
|
|
// If the segment reference frame feature is enabled....
|
|
|
|
// then do nothing if the current ref frame is not allowed..
|
|
|
|
if ( segfeature_active( xd, segment_id, SEG_LVL_REF_FRAME ) &&
|
|
|
|
!check_segref( xd, segment_id,
|
|
|
|
xd->mode_info_context->mbmi.ref_frame ) )
|
2011-09-30 17:45:16 +02:00
|
|
|
{
|
2011-11-03 18:45:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// If the segment mode feature is enabled....
|
|
|
|
// then do nothing if the current mode is not allowed..
|
|
|
|
else if ( segfeature_active( xd, segment_id, SEG_LVL_MODE ) &&
|
|
|
|
( this_mode !=
|
|
|
|
get_segdata( xd, segment_id, SEG_LVL_MODE ) ) )
|
|
|
|
{
|
|
|
|
continue;
|
2011-09-30 17:45:16 +02:00
|
|
|
}
|
2011-11-18 20:44:57 +01:00
|
|
|
|
2011-11-03 18:45:27 +01:00
|
|
|
// Disable this drop out case if either the mode or ref frame
|
|
|
|
// segment level feature is enabled for this segment. This is to
|
|
|
|
// prevent the possibility that the we end up unable to pick any mode.
|
|
|
|
else if ( !segfeature_active( xd, segment_id, SEG_LVL_REF_FRAME ) &&
|
|
|
|
!segfeature_active( xd, segment_id, SEG_LVL_MODE ) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-11-03 18:45:27 +01:00
|
|
|
// Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
|
|
|
|
// unless ARNR filtering is enabled in which case we want
|
|
|
|
// an unfiltered alternative
|
|
|
|
if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
|
|
|
|
{
|
|
|
|
if (this_mode != ZEROMV ||
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame != ALTREF_FRAME)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-01-11 21:00:00 +01:00
|
|
|
/* everything but intra */
|
|
|
|
if (x->e_mbd.mode_info_context->mbmi.ref_frame)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-01-11 21:00:00 +01:00
|
|
|
x->e_mbd.pre.y_buffer = y_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
x->e_mbd.pre.u_buffer = u_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
mode_mv[NEARESTMV] = frame_nearest_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
mode_mv[NEARMV] = frame_near_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
|
|
|
vpx_memcpy(mdcounts, frame_mdcounts[x->e_mbd.mode_info_context->mbmi.ref_frame], sizeof(mdcounts));
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:04:40 +01:00
|
|
|
// Experimental code. Special case for gf and arf zeromv modes.
|
|
|
|
// Increase zbin size to suppress noise
|
2010-05-18 17:58:33 +02:00
|
|
|
if (cpi->zbin_mode_boost_enabled)
|
|
|
|
{
|
2010-11-08 16:28:54 +01:00
|
|
|
if ( vp8_ref_frame_order[mode_index] == INTRA_FRAME )
|
2010-05-18 17:58:33 +02:00
|
|
|
cpi->zbin_mode_boost = 0;
|
2010-11-08 16:28:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (vp8_mode_order[mode_index] == ZEROMV)
|
|
|
|
{
|
|
|
|
if (vp8_ref_frame_order[mode_index] != LAST_FRAME)
|
|
|
|
cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
|
|
|
|
else
|
|
|
|
cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
|
|
|
|
}
|
2011-03-08 02:58:37 +01:00
|
|
|
else if (vp8_mode_order[mode_index] == SPLITMV)
|
2010-11-08 16:28:54 +01:00
|
|
|
cpi->zbin_mode_boost = 0;
|
|
|
|
else
|
|
|
|
cpi->zbin_mode_boost = MV_ZBIN_BOOST;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-29 20:30:57 +01:00
|
|
|
vp8_update_zbin_extra(cpi, x);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-16 18:29:54 +01: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
|
|
|
if (!x->e_mbd.mode_info_context->mbmi.second_ref_frame)
|
2010-05-18 17:58:33 +02:00
|
|
|
switch (this_mode)
|
|
|
|
{
|
|
|
|
case B_PRED:
|
2011-02-08 22:50:43 +01:00
|
|
|
{
|
|
|
|
int tmp_rd;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Note the rate value returned here includes the cost of coding the BPRED mode : x->mbmode_cost[x->e_mbd.frame_type][BPRED];
|
2011-06-08 18:05:05 +02:00
|
|
|
tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion, best_yrd);
|
2010-05-18 17:58:33 +02:00
|
|
|
rate2 += rate;
|
|
|
|
distortion2 += distortion;
|
2011-02-08 22:50:43 +01:00
|
|
|
|
|
|
|
if(tmp_rd < best_yrd)
|
|
|
|
{
|
|
|
|
rate2 += uv_intra_rate;
|
|
|
|
rate_uv = uv_intra_rate_tokenonly;
|
|
|
|
distortion2 += uv_intra_distortion;
|
|
|
|
distortion_uv = uv_intra_distortion;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this_rd = INT_MAX;
|
|
|
|
disable_skip = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-12-01 01:25:00 +01:00
|
|
|
case I8X8_PRED:
|
|
|
|
{
|
|
|
|
int tmp_rd;
|
|
|
|
tmp_rd = rd_pick_intra8x8mby_modes(cpi,
|
|
|
|
x, &rate, &rate_y, &distortion, best_yrd);
|
|
|
|
rate2 += rate;
|
|
|
|
distortion2 += distortion;
|
|
|
|
|
2012-02-29 02:12:08 +01:00
|
|
|
mode8x8[0][0]= x->e_mbd.mode_info_context->bmi[0].as_mode.first;
|
|
|
|
mode8x8[0][1]= x->e_mbd.mode_info_context->bmi[2].as_mode.first;
|
|
|
|
mode8x8[0][2]= x->e_mbd.mode_info_context->bmi[8].as_mode.first;
|
|
|
|
mode8x8[0][3]= x->e_mbd.mode_info_context->bmi[10].as_mode.first;
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mode8x8[1][0]= x->e_mbd.mode_info_context->bmi[0].as_mode.second;
|
|
|
|
mode8x8[1][1]= x->e_mbd.mode_info_context->bmi[2].as_mode.second;
|
|
|
|
mode8x8[1][2]= x->e_mbd.mode_info_context->bmi[8].as_mode.second;
|
|
|
|
mode8x8[1][3]= x->e_mbd.mode_info_context->bmi[10].as_mode.second;
|
|
|
|
#endif
|
2011-12-01 01:25:00 +01:00
|
|
|
|
|
|
|
/* TODO: uv rate maybe over-estimated here since there is UV intra
|
|
|
|
mode coded in I8X8_PRED prediction */
|
|
|
|
if(tmp_rd < best_yrd)
|
|
|
|
{
|
|
|
|
rate2 += uv_intra_rate;
|
|
|
|
rate_uv = uv_intra_rate_tokenonly;
|
|
|
|
distortion2 += uv_intra_distortion;
|
|
|
|
distortion_uv = uv_intra_distortion;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this_rd = INT_MAX;
|
|
|
|
disable_skip = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
case SPLITMV:
|
|
|
|
{
|
|
|
|
int tmp_rd;
|
2010-12-06 22:42:52 +01:00
|
|
|
int this_rd_thresh;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-06 22:42:52 +01:00
|
|
|
this_rd_thresh = (x->e_mbd.mode_info_context->mbmi.ref_frame == LAST_FRAME) ? cpi->rd_threshes[THR_NEWMV] : cpi->rd_threshes[THR_NEWA];
|
|
|
|
this_rd_thresh = (x->e_mbd.mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) ? cpi->rd_threshes[THR_NEWG]: this_rd_thresh;
|
|
|
|
|
|
|
|
tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
|
2010-12-16 15:38:02 +01:00
|
|
|
best_yrd, mdcounts,
|
2010-12-06 22:42:52 +01:00
|
|
|
&rate, &rate_y, &distortion, this_rd_thresh) ;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
rate2 += rate;
|
|
|
|
distortion2 += distortion;
|
|
|
|
|
|
|
|
// If even the 'Y' rd value of split is higher than best so far then dont bother looking at UV
|
2010-12-16 15:38:02 +01:00
|
|
|
if (tmp_rd < best_yrd)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
// Now work out UV cost and add it in
|
2011-08-24 20:42:26 +02:00
|
|
|
rd_inter4x4_uv(cpi, x, &rate_uv, &distortion_uv, cpi->common.full_pixel);
|
2010-12-16 15:38:02 +01:00
|
|
|
rate2 += rate_uv;
|
|
|
|
distortion2 += distortion_uv;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this_rd = INT_MAX;
|
|
|
|
disable_skip = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DC_PRED:
|
|
|
|
case V_PRED:
|
|
|
|
case H_PRED:
|
|
|
|
case TM_PRED:
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
|
2012-02-29 02:12:08 +01:00
|
|
|
// FIXME compound intra prediction
|
2011-03-11 17:35:38 +01:00
|
|
|
RECON_INVOKE(&cpi->common.rtcd.recon, build_intra_predictors_mby)
|
|
|
|
(&x->e_mbd);
|
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
|
|
|
if(cpi->common.txfm_mode == ALLOW_8X8)
|
|
|
|
macro_block_yrd_8x8(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd)) ;
|
|
|
|
else
|
|
|
|
macro_block_yrd(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd.encodemb)) ;
|
2011-02-01 18:55:51 +01:00
|
|
|
rate2 += rate_y;
|
|
|
|
distortion2 += distortion;
|
|
|
|
rate2 += x->mbmode_cost[x->e_mbd.frame_type][x->e_mbd.mode_info_context->mbmi.mode];
|
|
|
|
rate2 += uv_intra_rate;
|
|
|
|
rate_uv = uv_intra_rate_tokenonly;
|
|
|
|
distortion2 += uv_intra_distortion;
|
|
|
|
distortion_uv = uv_intra_distortion;
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NEWMV:
|
2011-05-06 18:51:31 +02:00
|
|
|
{
|
|
|
|
int thissme;
|
|
|
|
int bestsme = INT_MAX;
|
|
|
|
int step_param = cpi->sf.first_step;
|
|
|
|
int further_steps;
|
|
|
|
int n;
|
|
|
|
int do_refine=1; /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
|
|
|
|
we will do a final 1-away diamond refining search */
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-06-01 20:41:05 +02:00
|
|
|
int sadpb = x->sadperbit16;
|
2011-07-07 17:21:41 +02:00
|
|
|
int_mv mvp_full;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-07-07 17:21:41 +02:00
|
|
|
int col_min = (best_ref_mv.as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.col & 7)?1:0);
|
|
|
|
int row_min = (best_ref_mv.as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.row & 7)?1:0);
|
|
|
|
int col_max = (best_ref_mv.as_mv.col>>3) + MAX_FULL_PEL_VAL;
|
|
|
|
int row_max = (best_ref_mv.as_mv.row>>3) + MAX_FULL_PEL_VAL;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
int tmp_col_min = x->mv_col_min;
|
|
|
|
int tmp_col_max = x->mv_col_max;
|
|
|
|
int tmp_row_min = x->mv_row_min;
|
|
|
|
int tmp_row_max = x->mv_row_max;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-07-08 20:08:45 +02:00
|
|
|
if(!saddone)
|
|
|
|
{
|
|
|
|
vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
|
|
|
|
saddone = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias, &sr, &near_sadidx[0]);
|
|
|
|
|
2011-07-07 17:21:41 +02:00
|
|
|
mvp_full.as_mv.col = mvp.as_mv.col>>3;
|
|
|
|
mvp_full.as_mv.row = mvp.as_mv.row>>3;
|
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
// Get intersection of UMV window and valid MV window to reduce # of checks in diamond search.
|
|
|
|
if (x->mv_col_min < col_min )
|
|
|
|
x->mv_col_min = col_min;
|
|
|
|
if (x->mv_col_max > col_max )
|
|
|
|
x->mv_col_max = col_max;
|
|
|
|
if (x->mv_row_min < row_min )
|
|
|
|
x->mv_row_min = row_min;
|
|
|
|
if (x->mv_row_max > row_max )
|
|
|
|
x->mv_row_max = row_max;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
//adjust search range according to sr from mv prediction
|
|
|
|
if(sr > step_param)
|
|
|
|
step_param = sr;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
// Initial step/diamond search
|
|
|
|
{
|
2011-07-07 17:21:41 +02:00
|
|
|
bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.mv,
|
2010-07-01 03:58:54 +02:00
|
|
|
step_param, sadpb, &num00,
|
|
|
|
&cpi->fn_ptr[BLOCK_16X16],
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST, &best_ref_mv);
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
// Further step/diamond searches as necessary
|
|
|
|
n = 0;
|
|
|
|
further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
n = num00;
|
|
|
|
num00 = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
/* If there won't be more n-step search, check to see if refining search is needed. */
|
|
|
|
if (n > further_steps)
|
|
|
|
do_refine = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
while (n < further_steps)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-06 18:51:31 +02:00
|
|
|
n++;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
if (num00)
|
|
|
|
num00--;
|
2010-05-18 17:58:33 +02:00
|
|
|
else
|
|
|
|
{
|
2011-07-07 17:21:41 +02:00
|
|
|
thissme = cpi->diamond_search_sad(x, b, d, &mvp_full,
|
2010-07-01 03:58:54 +02:00
|
|
|
&d->bmi.mv, step_param + n, sadpb, &num00,
|
2012-02-27 19:22:38 +01:00
|
|
|
&cpi->fn_ptr[BLOCK_16X16],
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST, &best_ref_mv);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
/* check to see if refining search is needed. */
|
|
|
|
if (num00 > (further_steps-n))
|
|
|
|
do_refine = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
if (thissme < bestsme)
|
|
|
|
{
|
|
|
|
bestsme = thissme;
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
|
2011-05-06 18:51:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
|
2011-05-06 18:51:31 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-06 18:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* final 1-away diamond refining search */
|
|
|
|
if (do_refine == 1)
|
|
|
|
{
|
|
|
|
int search_range;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
//It seems not a good way to set search_range. Need further investigation.
|
|
|
|
//search_range = MAXF(abs((mvp.row>>3) - d->bmi.mv.as_mv.row), abs((mvp.col>>3) - d->bmi.mv.as_mv.col));
|
|
|
|
search_range = 8;
|
2010-12-14 23:39:25 +01:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
//thissme = cpi->full_search_sad(x, b, d, &d->bmi.mv.as_mv, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv);
|
2010-07-01 03:58:54 +02:00
|
|
|
thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb,
|
|
|
|
search_range, &cpi->fn_ptr[BLOCK_16X16],
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST, &best_ref_mv);
|
2011-05-06 18:51:31 +02:00
|
|
|
|
|
|
|
if (thissme < bestsme)
|
2011-04-18 21:48:34 +02:00
|
|
|
{
|
2011-05-06 18:51:31 +02:00
|
|
|
bestsme = thissme;
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
|
2011-04-14 21:53:33 +02:00
|
|
|
}
|
2011-05-06 18:51:31 +02:00
|
|
|
else
|
|
|
|
{
|
2011-05-12 16:50:16 +02:00
|
|
|
d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
|
2011-05-06 18:51:31 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
x->mv_col_min = tmp_col_min;
|
|
|
|
x->mv_col_max = tmp_col_max;
|
|
|
|
x->mv_row_min = tmp_row_min;
|
|
|
|
x->mv_row_max = tmp_row_max;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-06 18:51:31 +02:00
|
|
|
if (bestsme < INT_MAX)
|
|
|
|
{
|
|
|
|
int dis; /* TODO: use dis in distortion calculation later. */
|
|
|
|
unsigned int sse;
|
2011-06-01 20:41:05 +02:00
|
|
|
cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
|
|
|
|
x->errorperbit,
|
|
|
|
&cpi->fn_ptr[BLOCK_16X16],
|
2012-03-01 12:10:21 +01:00
|
|
|
XMVCOST, &dis, &sse);
|
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
|
|
|
mc_search_result[x->e_mbd.mode_info_context->mbmi.ref_frame].as_int = d->bmi.mv.as_int;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-12 16:50:16 +02:00
|
|
|
mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
|
2011-05-06 18:51:31 +02:00
|
|
|
|
|
|
|
// Add the new motion vector cost to our rolling cost variable
|
2012-03-01 12:10:21 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
|
|
|
rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv,
|
|
|
|
XMVCOST, 96,
|
|
|
|
x->e_mbd.allow_high_precision_mv);
|
|
|
|
#else
|
|
|
|
rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv,
|
|
|
|
XMVCOST, 96);
|
|
|
|
#endif
|
2011-05-06 18:51:31 +02:00
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
case NEARESTMV:
|
|
|
|
case NEARMV:
|
|
|
|
// Clip "next_nearest" so that it does not extend to far out of image
|
2011-05-12 16:50:16 +02:00
|
|
|
vp8_clamp_mv2(&mode_mv[this_mode], xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Do not bother proceeding if the vector (from newmv,nearest or near) is 0,0 as this should then be coded using the zeromv mode.
|
2011-05-12 16:50:16 +02:00
|
|
|
if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) && (mode_mv[this_mode].as_int == 0))
|
2010-05-18 17:58:33 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case ZEROMV:
|
|
|
|
|
|
|
|
// Trap vectors that reach beyond the UMV borders
|
|
|
|
// Note that ALL New MV, Nearest MV Near MV and Zero MV code drops through to this point
|
|
|
|
// because of the lack of break statements in the previous two cases.
|
2011-05-12 16:50:16 +02:00
|
|
|
if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
|
|
|
|
((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
|
2010-05-18 17:58:33 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
vp8_set_mbmode_and_mvs(x, this_mode, &mode_mv[this_mode]);
|
2011-04-19 17:42:15 +02:00
|
|
|
vp8_build_inter16x16_predictors_mby(&x->e_mbd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
compmode_cost =
|
|
|
|
vp8_cost_bit( get_pred_prob( cm, xd, PRED_COMP ), 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
|
|
|
|
2010-12-07 22:07:23 +01:00
|
|
|
if (cpi->active_map_enabled && x->active_ptr[0] == 0) {
|
2010-05-18 17:58:33 +02:00
|
|
|
x->skip = 1;
|
|
|
|
}
|
2010-12-09 21:59:22 +01:00
|
|
|
else if (x->encode_breakout)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-04-18 21:48:34 +02:00
|
|
|
unsigned int sse;
|
2011-06-07 01:42:58 +02:00
|
|
|
unsigned int var;
|
change the threshold of DC check for encode breakout
Previously, the DC check is to make sure there is no code-able
DC shift for quantizer Q0, which has been verified rather
conservative. This commit changes the criteria to have two
components, DC and AC, to address the conservativeness. First,
it checks if all AC energy is enough to contribute a single
non-zero quantized AC coefficient. Second, for DC, the decision
to skip further considers two possible scenarios: 1. There is
no code-able 2nd order DC coefficient at all; 2 The residue is
relatively flat, but the uniform DC change is very small, i.e.
less than 1/2 gray level per pixel.
Comparing to previous criteria, the new criteria is about 10%
to 15% faster in encoding time with a very small quality loss.
(threshold ~1000 and quality range 33db-45db)
It should be noted that this commit enables "automatic" static
threshold for encodebreakout if a non-zero small value is passed
in to encoder.
Change-Id: I0f77719a1ac2c2dfddbd950d84920df374515ce3
2011-01-20 01:21:01 +01:00
|
|
|
int threshold = (xd->block[0].dequant[1]
|
|
|
|
* xd->block[0].dequant[1] >>4);
|
|
|
|
|
|
|
|
if(threshold < x->encode_breakout)
|
|
|
|
threshold = x->encode_breakout;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-06-07 01:42:58 +02:00
|
|
|
var = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16)
|
2011-06-23 19:54:02 +02:00
|
|
|
(*(b->base_src), b->src_stride,
|
2011-06-07 01:42:58 +02:00
|
|
|
x->e_mbd.predictor, 16, &sse);
|
2010-12-09 21:59:22 +01:00
|
|
|
|
change the threshold of DC check for encode breakout
Previously, the DC check is to make sure there is no code-able
DC shift for quantizer Q0, which has been verified rather
conservative. This commit changes the criteria to have two
components, DC and AC, to address the conservativeness. First,
it checks if all AC energy is enough to contribute a single
non-zero quantized AC coefficient. Second, for DC, the decision
to skip further considers two possible scenarios: 1. There is
no code-able 2nd order DC coefficient at all; 2 The residue is
relatively flat, but the uniform DC change is very small, i.e.
less than 1/2 gray level per pixel.
Comparing to previous criteria, the new criteria is about 10%
to 15% faster in encoding time with a very small quality loss.
(threshold ~1000 and quality range 33db-45db)
It should be noted that this commit enables "automatic" static
threshold for encodebreakout if a non-zero small value is passed
in to encoder.
Change-Id: I0f77719a1ac2c2dfddbd950d84920df374515ce3
2011-01-20 01:21:01 +01:00
|
|
|
if (sse < threshold)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-06-07 01:42:58 +02:00
|
|
|
unsigned int q2dc = xd->block[24].dequant[0];
|
change the threshold of DC check for encode breakout
Previously, the DC check is to make sure there is no code-able
DC shift for quantizer Q0, which has been verified rather
conservative. This commit changes the criteria to have two
components, DC and AC, to address the conservativeness. First,
it checks if all AC energy is enough to contribute a single
non-zero quantized AC coefficient. Second, for DC, the decision
to skip further considers two possible scenarios: 1. There is
no code-able 2nd order DC coefficient at all; 2 The residue is
relatively flat, but the uniform DC change is very small, i.e.
less than 1/2 gray level per pixel.
Comparing to previous criteria, the new criteria is about 10%
to 15% faster in encoding time with a very small quality loss.
(threshold ~1000 and quality range 33db-45db)
It should be noted that this commit enables "automatic" static
threshold for encodebreakout if a non-zero small value is passed
in to encoder.
Change-Id: I0f77719a1ac2c2dfddbd950d84920df374515ce3
2011-01-20 01:21:01 +01:00
|
|
|
/* If theres is no codeable 2nd order dc
|
|
|
|
or a very small uniform pixel change change */
|
2011-06-07 01:42:58 +02:00
|
|
|
if ((sse - var < q2dc * q2dc >>4) ||
|
|
|
|
(sse /2 > var && sse-var < 64))
|
2010-12-07 22:07:23 +01:00
|
|
|
{
|
2011-06-07 01:42:58 +02:00
|
|
|
// Check u and v to make sure skip is ok
|
|
|
|
int sse2= VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance));
|
change the threshold of DC check for encode breakout
Previously, the DC check is to make sure there is no code-able
DC shift for quantizer Q0, which has been verified rather
conservative. This commit changes the criteria to have two
components, DC and AC, to address the conservativeness. First,
it checks if all AC energy is enough to contribute a single
non-zero quantized AC coefficient. Second, for DC, the decision
to skip further considers two possible scenarios: 1. There is
no code-able 2nd order DC coefficient at all; 2 The residue is
relatively flat, but the uniform DC change is very small, i.e.
less than 1/2 gray level per pixel.
Comparing to previous criteria, the new criteria is about 10%
to 15% faster in encoding time with a very small quality loss.
(threshold ~1000 and quality range 33db-45db)
It should be noted that this commit enables "automatic" static
threshold for encodebreakout if a non-zero small value is passed
in to encoder.
Change-Id: I0f77719a1ac2c2dfddbd950d84920df374515ce3
2011-01-20 01:21:01 +01:00
|
|
|
if (sse2 * 2 < threshold)
|
2010-12-09 21:59:22 +01:00
|
|
|
{
|
|
|
|
x->skip = 1;
|
2010-12-16 15:38:02 +01:00
|
|
|
distortion2 = sse + sse2;
|
2010-12-09 21:59:22 +01:00
|
|
|
rate2 = 500;
|
2010-12-16 15:38:02 +01:00
|
|
|
|
|
|
|
/* for best_yrd calculation */
|
|
|
|
rate_uv = 0;
|
|
|
|
distortion_uv = sse2;
|
|
|
|
|
2010-12-09 21:59:22 +01:00
|
|
|
disable_skip = 1;
|
2011-04-18 21:48:34 +02:00
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
|
2010-12-09 21:59:22 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2010-12-07 22:07:23 +01:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//intermodecost[mode_index] = vp8_cost_mv_ref(this_mode, mdcounts); // Experimental debug code
|
|
|
|
|
|
|
|
// Add in the Mv/mode cost
|
2011-12-06 21:03:42 +01:00
|
|
|
rate2 += vp8_cost_mv_ref(&cpi->common, this_mode, mdcounts);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Y cost and distortion
|
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
|
|
|
if(cpi->common.txfm_mode == ALLOW_8X8)
|
|
|
|
macro_block_yrd_8x8(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd));
|
|
|
|
else
|
|
|
|
macro_block_yrd(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd.encodemb));
|
|
|
|
|
2010-12-16 15:38:02 +01:00
|
|
|
rate2 += rate_y;
|
2010-05-18 17:58:33 +02:00
|
|
|
distortion2 += distortion;
|
|
|
|
|
|
|
|
// UV cost and distortion
|
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
|
|
|
vp8_build_inter16x16_predictors_mbuv(&x->e_mbd);
|
2012-01-21 00:30:31 +01:00
|
|
|
|
|
|
|
if(cpi->common.txfm_mode == ALLOW_8X8)
|
|
|
|
rd_inter16x16_uv_8x8(cpi, x, &rate_uv,
|
|
|
|
&distortion_uv,
|
|
|
|
cpi->common.full_pixel);
|
|
|
|
else
|
|
|
|
rd_inter16x16_uv(cpi, x, &rate_uv,
|
|
|
|
&distortion_uv,
|
|
|
|
cpi->common.full_pixel);
|
2010-12-16 15:38:02 +01:00
|
|
|
rate2 += rate_uv;
|
|
|
|
distortion2 += distortion_uv;
|
2012-02-29 02:25:45 +01:00
|
|
|
mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY;
|
2010-05-18 17:58:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
else /* x->e_mbd.mode_info_context->mbmi.second_ref_frame != 0 */
|
|
|
|
{
|
|
|
|
int ref1 = x->e_mbd.mode_info_context->mbmi.ref_frame;
|
|
|
|
int ref2 = x->e_mbd.mode_info_context->mbmi.second_ref_frame;
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY;
|
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
|
|
|
switch (this_mode)
|
|
|
|
{
|
|
|
|
case NEWMV:
|
|
|
|
if (mc_search_result[ref1].as_int == INVALID_MV ||
|
|
|
|
mc_search_result[ref2].as_int == INVALID_MV)
|
|
|
|
continue;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = mc_search_result[ref1].as_int;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mv.as_int = mc_search_result[ref2].as_int;
|
2012-03-01 12:10:21 +01:00
|
|
|
#if CONFIG_HIGH_PRECISION_MV
|
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
|
|
|
rate2 += vp8_mv_bit_cost(&mc_search_result[ref1],
|
2012-03-01 12:10:21 +01:00
|
|
|
&frame_best_ref_mv[ref1],
|
|
|
|
XMVCOST, 96,
|
|
|
|
x->e_mbd.allow_high_precision_mv);
|
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
|
|
|
rate2 += vp8_mv_bit_cost(&mc_search_result[ref2],
|
2012-03-01 12:10:21 +01:00
|
|
|
&frame_best_ref_mv[ref2],
|
|
|
|
XMVCOST, 96,
|
|
|
|
x->e_mbd.allow_high_precision_mv);
|
|
|
|
#else
|
|
|
|
rate2 += vp8_mv_bit_cost(&mc_search_result[ref1],
|
|
|
|
&frame_best_ref_mv[ref1],
|
|
|
|
XMVCOST, 96);
|
|
|
|
rate2 += vp8_mv_bit_cost(&mc_search_result[ref2],
|
|
|
|
&frame_best_ref_mv[ref2],
|
|
|
|
XMVCOST, 96);
|
|
|
|
#endif
|
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
|
|
|
break;
|
|
|
|
case ZEROMV:
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mv.as_int = 0;
|
|
|
|
break;
|
|
|
|
case NEARMV:
|
|
|
|
if (frame_near_mv[ref1].as_int == 0 || frame_near_mv[ref2].as_int == 0)
|
|
|
|
continue;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = frame_near_mv[ref1].as_int;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mv.as_int = frame_near_mv[ref2].as_int;
|
|
|
|
break;
|
|
|
|
case NEARESTMV:
|
|
|
|
if (frame_nearest_mv[ref1].as_int == 0 || frame_nearest_mv[ref2].as_int == 0)
|
|
|
|
continue;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = frame_nearest_mv[ref1].as_int;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.second_mv.as_int = frame_nearest_mv[ref2].as_int;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add in the Mv/mode cost */
|
2011-12-06 21:03:42 +01:00
|
|
|
rate2 += vp8_cost_mv_ref(&cpi->common,this_mode, mdcounts);
|
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
|
|
|
|
|
|
|
vp8_clamp_mv2(&x->e_mbd.mode_info_context->mbmi.mv, xd);
|
|
|
|
vp8_clamp_mv2(&x->e_mbd.mode_info_context->mbmi.second_mv, xd);
|
|
|
|
if (((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row >> 3) < x->mv_row_min) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row >> 3) > x->mv_row_max) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col >> 3) < x->mv_col_min) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col >> 3) > x->mv_col_max) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.second_mv.as_mv.row >> 3) < x->mv_row_min) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.second_mv.as_mv.row >> 3) > x->mv_row_max) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.second_mv.as_mv.col >> 3) < x->mv_col_min) ||
|
|
|
|
((x->e_mbd.mode_info_context->mbmi.second_mv.as_mv.col >> 3) > x->mv_col_max))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* build first and second prediction */
|
|
|
|
vp8_build_inter16x16_predictors_mby(&x->e_mbd);
|
|
|
|
vp8_build_inter16x16_predictors_mbuv(&x->e_mbd);
|
|
|
|
/* do second round and average the results */
|
|
|
|
x->e_mbd.second_pre.y_buffer = y_buffer[ref2];
|
|
|
|
x->e_mbd.second_pre.u_buffer = u_buffer[ref2];
|
|
|
|
x->e_mbd.second_pre.v_buffer = v_buffer[ref2];
|
|
|
|
vp8_build_2nd_inter16x16_predictors_mb(&x->e_mbd, x->e_mbd.predictor,
|
|
|
|
&x->e_mbd.predictor[256],
|
|
|
|
&x->e_mbd.predictor[320], 16, 8);
|
|
|
|
|
|
|
|
/* Y cost and distortion */
|
2012-02-13 23:34:19 +01:00
|
|
|
if(cpi->common.txfm_mode == ALLOW_8X8)
|
|
|
|
macro_block_yrd_8x8(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd));
|
|
|
|
else
|
|
|
|
macro_block_yrd(x, &rate_y, &distortion,
|
|
|
|
IF_RTCD(&cpi->rtcd.encodemb));
|
|
|
|
|
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
|
|
|
rate2 += rate_y;
|
|
|
|
distortion2 += distortion;
|
|
|
|
|
|
|
|
/* UV cost and distortion */
|
2012-01-21 00:30:31 +01:00
|
|
|
if(cpi->common.txfm_mode == ALLOW_8X8)
|
|
|
|
rd_inter16x16_uv_8x8(cpi, x, &rate_uv,
|
|
|
|
&distortion_uv,
|
|
|
|
cpi->common.full_pixel);
|
|
|
|
else
|
|
|
|
rd_inter16x16_uv(cpi, x, &rate_uv,
|
|
|
|
&distortion_uv,
|
|
|
|
cpi->common.full_pixel);
|
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
|
|
|
rate2 += rate_uv;
|
|
|
|
distortion2 += distortion_uv;
|
|
|
|
|
|
|
|
/* don't bother w/ skip, we would never have come here if skip were enabled */
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = this_mode;
|
|
|
|
|
|
|
|
/* We don't include the cost of the second reference here, because there are only
|
|
|
|
* three options: Last/Golden, ARF/Last or Golden/ARF, or in other words if you
|
|
|
|
* present them in that order, the second one is always known if the first is known */
|
2012-02-29 02:25:45 +01:00
|
|
|
compmode_cost =
|
|
|
|
vp8_cost_bit( get_pred_prob( cm, xd, PRED_COMP ), 1 );
|
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
|
|
|
|
2010-12-16 15:38:02 +01:00
|
|
|
// Where skip is allowable add in the default per mb cost for the no skip case.
|
|
|
|
// where we then decide to skip we have to delete this and replace it with the
|
|
|
|
// cost of signallying a skip
|
|
|
|
if (cpi->common.mb_no_coeff_skip)
|
|
|
|
{
|
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
|
|
|
int prob_skip_cost = vp8_cost_bit(cpi->prob_skip_false, 0);
|
|
|
|
other_cost += prob_skip_cost;
|
|
|
|
rate2 += prob_skip_cost;
|
2010-12-16 15:38:02 +01:00
|
|
|
}
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
if (cpi->common.comp_pred_mode == HYBRID_PREDICTION)
|
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
|
|
|
rate2 += compmode_cost;
|
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-01-28 13:20:14 +01:00
|
|
|
|
|
|
|
// Estimate the reference frame signaling cost and add it
|
|
|
|
// to the rolling cost variable.
|
|
|
|
rate2 += ref_costs[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
2010-12-16 15:38:02 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (!disable_skip)
|
|
|
|
{
|
|
|
|
// Test for the condition where skip block will be activated because there are no non zero coefficients and make any necessary adjustment for rate
|
|
|
|
if (cpi->common.mb_no_coeff_skip)
|
|
|
|
{
|
2012-02-22 03:10:18 +01:00
|
|
|
int mb_skippable;
|
|
|
|
int has_y2 = ( this_mode!=SPLITMV
|
2012-02-18 00:52:30 +01:00
|
|
|
&&this_mode!=B_PRED
|
|
|
|
&&this_mode!=I8X8_PRED);
|
2012-02-22 03:10:18 +01:00
|
|
|
if((cpi->common.txfm_mode == ALLOW_8X8) && has_y2)
|
2012-02-18 00:52:30 +01:00
|
|
|
{
|
|
|
|
if(x->e_mbd.mode_info_context->mbmi.ref_frame!=INTRA_FRAME)
|
2012-02-22 03:10:18 +01:00
|
|
|
mb_skippable = mb_is_skippable_8x8(&x->e_mbd);
|
2012-02-18 00:52:30 +01:00
|
|
|
else
|
2012-02-22 03:10:18 +01:00
|
|
|
mb_skippable = uv_intra_skippable_8x8
|
|
|
|
& mby_is_skippable_8x8(&x->e_mbd);
|
2012-02-18 00:52:30 +01:00
|
|
|
}
|
|
|
|
else
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2012-02-18 00:52:30 +01:00
|
|
|
if(x->e_mbd.mode_info_context->mbmi.ref_frame!=INTRA_FRAME)
|
2012-02-22 03:10:18 +01:00
|
|
|
mb_skippable = mb_is_skippable(&x->e_mbd, has_y2);
|
2012-02-18 00:52:30 +01:00
|
|
|
else
|
2012-02-22 03:10:18 +01:00
|
|
|
mb_skippable = uv_intra_skippable
|
|
|
|
& mby_is_skippable(&x->e_mbd, has_y2);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-02-22 03:10:18 +01:00
|
|
|
if (mb_skippable)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
|
|
|
rate2 -= (rate_y + rate_uv);
|
2010-12-16 15:38:02 +01:00
|
|
|
//for best_yrd calculation
|
|
|
|
rate_uv = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
// Back out no skip flag costing and add in skip flag costing
|
|
|
|
if (cpi->prob_skip_false)
|
|
|
|
{
|
2010-12-16 15:38:02 +01:00
|
|
|
int prob_skip_cost;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2010-12-16 15:38:02 +01:00
|
|
|
prob_skip_cost = vp8_cost_bit(cpi->prob_skip_false, 1);
|
|
|
|
prob_skip_cost -= vp8_cost_bit(cpi->prob_skip_false, 0);
|
|
|
|
rate2 += prob_skip_cost;
|
|
|
|
other_cost += prob_skip_cost;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Calculate the final RD estimate for this mode
|
2011-01-07 15:41:13 +01:00
|
|
|
this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Experimental debug code.
|
|
|
|
//all_rds[mode_index] = this_rd;
|
|
|
|
//all_rates[mode_index] = rate2;
|
|
|
|
//all_dist[mode_index] = distortion2;
|
|
|
|
|
2011-04-08 15:21:36 +02:00
|
|
|
// Keep record of best intra distortion
|
|
|
|
if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) &&
|
|
|
|
(this_rd < best_intra_rd) )
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-04-08 15:21:36 +02:00
|
|
|
best_intra_rd = this_rd;
|
|
|
|
*returnintra = distortion2 ;
|
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
|
|
|
if (!disable_skip &&
|
|
|
|
(this_mode == SPLITMV || x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME))
|
|
|
|
{
|
2012-02-29 02:25:45 +01:00
|
|
|
if (this_rd < best_comp_rd)
|
|
|
|
best_comp_rd = this_rd;
|
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 (this_rd < best_single_rd)
|
|
|
|
best_single_rd = this_rd;
|
|
|
|
if (this_rd < best_hybrid_rd)
|
|
|
|
best_hybrid_rd = this_rd;
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// Did this mode help.. i.i is it the new best mode
|
|
|
|
if (this_rd < best_rd || x->skip)
|
|
|
|
{
|
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 (!mode_excluded)
|
|
|
|
{
|
2012-02-10 01:12:23 +01:00
|
|
|
// Note index of best mode so far
|
|
|
|
best_mode_index = mode_index;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-10 01:12:23 +01:00
|
|
|
if (this_mode <= B_PRED)
|
|
|
|
{
|
|
|
|
x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
|
|
|
|
/* required for left and above block mv */
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
|
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-10 01:12:23 +01:00
|
|
|
other_cost += ref_costs[x->e_mbd.mode_info_context->mbmi.ref_frame];
|
2010-12-16 15:38:02 +01:00
|
|
|
|
2012-02-10 01:12:23 +01:00
|
|
|
/* Calculate the final y RD estimate for this mode */
|
|
|
|
best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2-rate_uv-other_cost),
|
|
|
|
(distortion2-distortion_uv));
|
2010-12-16 15:38:02 +01:00
|
|
|
|
2012-02-10 01:12:23 +01:00
|
|
|
*returnrate = rate2;
|
|
|
|
*returndistortion = distortion2;
|
|
|
|
best_rd = this_rd;
|
|
|
|
vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(MB_MODE_INFO));
|
|
|
|
vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-02-10 01:12:23 +01:00
|
|
|
if ((this_mode == B_PRED)
|
|
|
|
||(this_mode == I8X8_PRED)
|
|
|
|
|| (this_mode == SPLITMV))
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
best_bmodes[i] = x->e_mbd.block[i].bmi;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// Testing this mode gave rise to an improvement in best error score. Lower threshold a bit for next time
|
|
|
|
cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
|
|
|
|
cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the mode did not help improve the best error case then raise the threshold for testing that mode next time around.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cpi->rd_thresh_mult[mode_index] += 4;
|
|
|
|
|
|
|
|
if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
|
|
|
|
cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
|
|
|
|
|
|
|
|
cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
|
|
|
|
}
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
/* keep record of best compound/single-only prediction */
|
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 (!disable_skip &&
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame != INTRA_FRAME &&
|
|
|
|
this_mode != SPLITMV)
|
|
|
|
{
|
|
|
|
int single_rd, hybrid_rd, single_rate, hybrid_rate;
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
if (cpi->common.comp_pred_mode == HYBRID_PREDICTION)
|
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
|
|
|
single_rate = rate2 - compmode_cost;
|
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
|
|
|
hybrid_rate = rate2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
single_rate = rate2;
|
2012-02-29 02:25:45 +01:00
|
|
|
hybrid_rate = rate2 + compmode_cost;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
|
|
|
|
hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
|
|
|
|
|
|
|
|
if (x->e_mbd.mode_info_context->mbmi.second_ref_frame == INTRA_FRAME &&
|
|
|
|
single_rd < best_single_rd)
|
|
|
|
{
|
|
|
|
best_single_rd = single_rd;
|
|
|
|
}
|
|
|
|
else if (x->e_mbd.mode_info_context->mbmi.second_ref_frame != INTRA_FRAME &&
|
2012-02-29 02:25:45 +01:00
|
|
|
single_rd < best_comp_rd)
|
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
|
|
|
best_comp_rd = single_rd;
|
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 (hybrid_rd < best_hybrid_rd)
|
|
|
|
{
|
|
|
|
best_hybrid_rd = hybrid_rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
if (x->skip)
|
|
|
|
break;
|
change the threshold of DC check for encode breakout
Previously, the DC check is to make sure there is no code-able
DC shift for quantizer Q0, which has been verified rather
conservative. This commit changes the criteria to have two
components, DC and AC, to address the conservativeness. First,
it checks if all AC energy is enough to contribute a single
non-zero quantized AC coefficient. Second, for DC, the decision
to skip further considers two possible scenarios: 1. There is
no code-able 2nd order DC coefficient at all; 2 The residue is
relatively flat, but the uniform DC change is very small, i.e.
less than 1/2 gray level per pixel.
Comparing to previous criteria, the new criteria is about 10%
to 15% faster in encoding time with a very small quality loss.
(threshold ~1000 and quality range 33db-45db)
It should be noted that this commit enables "automatic" static
threshold for encodebreakout if a non-zero small value is passed
in to encoder.
Change-Id: I0f77719a1ac2c2dfddbd950d84920df374515ce3
2011-01-20 01:21:01 +01:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce the activation RD thresholds for the best choice mode
|
|
|
|
if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
|
|
|
|
{
|
|
|
|
int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2);
|
|
|
|
|
|
|
|
cpi->rd_thresh_mult[best_mode_index] = (cpi->rd_thresh_mult[best_mode_index] >= (MIN_THRESHMULT + best_adjustment)) ? cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT;
|
|
|
|
cpi->rd_threshes[best_mode_index] = (cpi->rd_baseline_thresh[best_mode_index] >> 7) * cpi->rd_thresh_mult[best_mode_index];
|
|
|
|
|
|
|
|
// If we chose a split mode then reset the new MV thresholds as well
|
|
|
|
/*if ( vp8_mode_order[best_mode_index] == SPLITMV )
|
|
|
|
{
|
|
|
|
best_adjustment = 4; //(cpi->rd_thresh_mult[THR_NEWMV] >> 4);
|
|
|
|
cpi->rd_thresh_mult[THR_NEWMV] = (cpi->rd_thresh_mult[THR_NEWMV] >= (MIN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWMV]-best_adjustment: MIN_THRESHMULT;
|
|
|
|
cpi->rd_threshes[THR_NEWMV] = (cpi->rd_baseline_thresh[THR_NEWMV] >> 7) * cpi->rd_thresh_mult[THR_NEWMV];
|
|
|
|
|
|
|
|
best_adjustment = 4; //(cpi->rd_thresh_mult[THR_NEWG] >> 4);
|
|
|
|
cpi->rd_thresh_mult[THR_NEWG] = (cpi->rd_thresh_mult[THR_NEWG] >= (MIN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWG]-best_adjustment: MIN_THRESHMULT;
|
|
|
|
cpi->rd_threshes[THR_NEWG] = (cpi->rd_baseline_thresh[THR_NEWG] >> 7) * cpi->rd_thresh_mult[THR_NEWG];
|
|
|
|
|
|
|
|
best_adjustment = 4; //(cpi->rd_thresh_mult[THR_NEWA] >> 4);
|
|
|
|
cpi->rd_thresh_mult[THR_NEWA] = (cpi->rd_thresh_mult[THR_NEWA] >= (MIN_THRESHMULT+best_adjustment)) ? cpi->rd_thresh_mult[THR_NEWA]-best_adjustment: MIN_THRESHMULT;
|
|
|
|
cpi->rd_threshes[THR_NEWA] = (cpi->rd_baseline_thresh[THR_NEWA] >> 7) * cpi->rd_thresh_mult[THR_NEWA];
|
|
|
|
}*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note how often each mode chosen as best
|
|
|
|
cpi->mode_chosen_counts[best_mode_index] ++;
|
|
|
|
|
2011-11-03 18:45:27 +01:00
|
|
|
// This code force Altref,0,0 and skip for the frame that overlays a
|
|
|
|
// an alrtef unless Altref is filtered. However, this is unsafe if
|
|
|
|
// segment level coding of ref frame or mode is enabled for this
|
|
|
|
// segment.
|
|
|
|
if (!segfeature_active( xd, segment_id, SEG_LVL_REF_FRAME ) &&
|
|
|
|
!segfeature_active( xd, segment_id, SEG_LVL_MODE ) &&
|
|
|
|
cpi->is_src_frame_alt_ref &&
|
|
|
|
(cpi->oxcf.arnr_max_frames == 0) &&
|
2011-05-31 20:24:42 +02:00
|
|
|
(best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-31 20:24:42 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
|
2010-08-12 22:25:43 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
|
2011-05-31 20:24:42 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
|
|
|
|
(cpi->common.mb_no_coeff_skip) ? 1 : 0;
|
|
|
|
x->e_mbd.mode_info_context->mbmi.partitioning = 0;
|
|
|
|
|
2012-02-29 02:25:45 +01:00
|
|
|
*best_single_rd_diff = *best_comp_rd_diff = *best_hybrid_rd_diff = 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
|
|
|
|
2011-04-11 19:05:08 +02:00
|
|
|
return;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-05-31 20:24:42 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
// macroblock modes
|
2010-08-12 22:25:43 +02:00
|
|
|
vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-05-24 19:24:52 +02:00
|
|
|
if (best_mbmode.mode == B_PRED)
|
2010-05-18 17:58:33 +02:00
|
|
|
{
|
2011-05-24 19:24:52 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2011-12-01 01:25:00 +01:00
|
|
|
{
|
2011-08-24 20:42:26 +02:00
|
|
|
xd->mode_info_context->bmi[i].as_mode = best_bmodes[i].as_mode;
|
2011-12-01 01:25:00 +01:00
|
|
|
xd->block[i].bmi.as_mode = xd->mode_info_context->bmi[i].as_mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_mbmode.mode == I8X8_PRED)
|
|
|
|
{
|
2012-02-29 02:12:08 +01:00
|
|
|
//printf("inter\n");
|
2011-12-01 01:25:00 +01:00
|
|
|
set_i8x8_block_modes(x, mode8x8);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
if (best_mbmode.mode == SPLITMV)
|
|
|
|
{
|
2011-05-24 19:24:52 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2011-08-24 20:42:26 +02:00
|
|
|
xd->mode_info_context->bmi[i].mv.as_int = best_bmodes[i].mv.as_int;
|
2011-05-24 19:24:52 +02:00
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
|
2011-05-24 19:24:52 +02:00
|
|
|
|
2011-05-19 21:03:36 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mv.as_int =
|
|
|
|
x->partition_info->bmi[15].mv.as_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
rd_update_mvcount(cpi, x, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]);
|
2011-05-13 16:56:45 +02:00
|
|
|
|
2012-02-15 17:30:36 +01:00
|
|
|
if (best_single_rd == INT_MAX)
|
|
|
|
*best_single_rd_diff = INT_MIN;
|
|
|
|
else
|
|
|
|
*best_single_rd_diff = best_rd - best_single_rd;
|
2012-02-29 02:25:45 +01:00
|
|
|
if (best_comp_rd == INT_MAX)
|
|
|
|
*best_comp_rd_diff = INT_MIN;
|
2012-02-15 17:30:36 +01:00
|
|
|
else
|
2012-02-29 02:25:45 +01:00
|
|
|
*best_comp_rd_diff = best_rd - best_comp_rd;
|
2012-02-15 17:30:36 +01:00
|
|
|
if (best_hybrid_rd == INT_MAX)
|
|
|
|
*best_hybrid_rd_diff = INT_MIN;
|
|
|
|
else
|
|
|
|
*best_hybrid_rd_diff = best_rd - best_hybrid_rd;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-06-08 18:05:05 +02:00
|
|
|
|
|
|
|
void vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_)
|
|
|
|
{
|
2011-11-18 20:44:57 +01:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
2011-06-08 18:05:05 +02:00
|
|
|
int error4x4, error16x16;
|
|
|
|
int rate4x4, rate16x16 = 0, rateuv;
|
|
|
|
int dist4x4, dist16x16, distuv;
|
|
|
|
int rate;
|
|
|
|
int rate4x4_tokenonly = 0;
|
|
|
|
int rate16x16_tokenonly = 0;
|
|
|
|
int rateuv_tokenonly = 0;
|
2011-08-05 01:30:27 +02:00
|
|
|
int error8x8, rate8x8_tokenonly=0;
|
|
|
|
int rate8x8, dist8x8;
|
|
|
|
int mode16x16;
|
2012-02-29 02:12:08 +01:00
|
|
|
int mode8x8[2][4];
|
2011-06-08 18:05:05 +02:00
|
|
|
|
|
|
|
x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
|
|
|
|
|
|
|
|
rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv);
|
|
|
|
rate = rateuv;
|
|
|
|
|
|
|
|
error16x16 = rd_pick_intra16x16mby_mode(cpi, x,
|
|
|
|
&rate16x16, &rate16x16_tokenonly,
|
|
|
|
&dist16x16);
|
2011-08-05 01:30:27 +02:00
|
|
|
mode16x16 = x->e_mbd.mode_info_context->mbmi.mode;
|
2011-11-18 20:44:57 +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
|
|
|
error8x8 = rd_pick_intra8x8mby_modes(cpi, x,
|
|
|
|
&rate8x8, &rate8x8_tokenonly,
|
|
|
|
&dist8x8, error16x16);
|
2012-02-29 02:12:08 +01:00
|
|
|
mode8x8[0][0]= x->e_mbd.mode_info_context->bmi[0].as_mode.first;
|
|
|
|
mode8x8[0][1]= x->e_mbd.mode_info_context->bmi[2].as_mode.first;
|
|
|
|
mode8x8[0][2]= x->e_mbd.mode_info_context->bmi[8].as_mode.first;
|
|
|
|
mode8x8[0][3]= x->e_mbd.mode_info_context->bmi[10].as_mode.first;
|
|
|
|
#if CONFIG_COMP_INTRA_PRED
|
|
|
|
mode8x8[1][0]= x->e_mbd.mode_info_context->bmi[0].as_mode.second;
|
|
|
|
mode8x8[1][1]= x->e_mbd.mode_info_context->bmi[2].as_mode.second;
|
|
|
|
mode8x8[1][2]= x->e_mbd.mode_info_context->bmi[8].as_mode.second;
|
|
|
|
mode8x8[1][3]= x->e_mbd.mode_info_context->bmi[10].as_mode.second;
|
|
|
|
#endif
|
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
|
|
|
|
2011-06-08 18:05:05 +02:00
|
|
|
error4x4 = rd_pick_intra4x4mby_modes(cpi, x,
|
|
|
|
&rate4x4, &rate4x4_tokenonly,
|
|
|
|
&dist4x4, error16x16);
|
|
|
|
|
2011-08-05 01:30:27 +02:00
|
|
|
if(error8x8> error16x16)
|
|
|
|
{
|
2011-12-07 22:03:57 +01:00
|
|
|
if (error4x4 < error16x16)
|
|
|
|
{
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
|
|
|
|
rate += rate4x4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = mode16x16;
|
|
|
|
rate += rate16x16;
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2011-12-07 22:03:57 +01:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (error4x4 < error8x8)
|
|
|
|
{
|
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
|
|
|
|
rate += rate4x4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-08 18:05:05 +02:00
|
|
|
|
2011-08-05 01:30:27 +02:00
|
|
|
x->e_mbd.mode_info_context->mbmi.mode = I8X8_PRED;
|
2012-02-29 02:12:08 +01:00
|
|
|
//printf("intra\n");
|
2011-08-05 01:30:27 +02:00
|
|
|
set_i8x8_block_modes(x, mode8x8);
|
|
|
|
rate += rate8x8;
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 18:05:05 +02:00
|
|
|
*rate_ = rate;
|
|
|
|
}
|