2010-05-18 11:58:33 -04:00
|
|
|
/*
|
2010-09-09 08:16:39 -04:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 11:58:33 -04:00
|
|
|
*
|
2010-06-18 12:39:21 -04:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 16:19:40 -04: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 12:39:21 -04:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 16:19:40 -04:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 11:58:33 -04:00
|
|
|
*/
|
|
|
|
|
2012-11-29 16:36:10 -08:00
|
|
|
#ifndef VP9_ENCODER_VP9_BLOCK_H_
|
|
|
|
#define VP9_ENCODER_VP9_BLOCK_H_
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2012-11-27 13:59:17 -08:00
|
|
|
#include "vp9/common/vp9_entropymv.h"
|
|
|
|
#include "vp9/common/vp9_entropy.h"
|
2010-05-18 11:58:33 -04:00
|
|
|
#include "vpx_ports/mem.h"
|
2012-11-27 13:59:17 -08:00
|
|
|
#include "vp9/common/vp9_onyxc_int.h"
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2014-01-18 12:16:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 11:58:33 -04:00
|
|
|
// motion search site
|
2012-07-13 15:21:29 -07:00
|
|
|
typedef struct {
|
|
|
|
MV mv;
|
|
|
|
int offset;
|
2010-05-18 11:58:33 -04:00
|
|
|
} search_site;
|
|
|
|
|
2012-04-06 16:38:34 -07:00
|
|
|
// Structure to hold snapshot of coding context during the mode picking process
|
2012-07-13 15:21:29 -07:00
|
|
|
typedef struct {
|
|
|
|
MODE_INFO mic;
|
2013-10-16 12:43:03 -07:00
|
|
|
uint8_t *zcoeff_blk;
|
2013-11-07 14:56:58 -08:00
|
|
|
int16_t *coeff[MAX_MB_PLANE][3];
|
|
|
|
int16_t *qcoeff[MAX_MB_PLANE][3];
|
|
|
|
int16_t *dqcoeff[MAX_MB_PLANE][3];
|
|
|
|
uint16_t *eobs[MAX_MB_PLANE][3];
|
2013-11-01 12:53:37 -07:00
|
|
|
|
2013-11-05 21:07:08 -08:00
|
|
|
// dual buffer pointers, 0: in use, 1: best in store
|
2013-11-07 14:56:58 -08:00
|
|
|
int16_t *coeff_pbuf[MAX_MB_PLANE][3];
|
|
|
|
int16_t *qcoeff_pbuf[MAX_MB_PLANE][3];
|
|
|
|
int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3];
|
|
|
|
uint16_t *eobs_pbuf[MAX_MB_PLANE][3];
|
2013-11-01 12:53:37 -07:00
|
|
|
|
2013-11-05 21:07:08 -08:00
|
|
|
int is_coded;
|
2013-10-16 12:43:03 -07:00
|
|
|
int num_4x4_blk;
|
2013-01-07 11:02:14 -08:00
|
|
|
int skip;
|
2014-01-03 11:31:00 -08:00
|
|
|
int_mv best_ref_mv[2];
|
2012-12-04 17:21:05 +00:00
|
|
|
int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
|
2012-07-13 15:21:29 -07:00
|
|
|
int rate;
|
|
|
|
int distortion;
|
|
|
|
int best_mode_index;
|
|
|
|
int rddiv;
|
|
|
|
int rdmult;
|
2012-08-20 14:43:34 -07:00
|
|
|
int hybrid_pred_diff;
|
|
|
|
int comp_pred_diff;
|
|
|
|
int single_pred_diff;
|
2013-08-02 17:28:23 -07:00
|
|
|
int64_t tx_rd_diff[TX_MODES];
|
2013-10-30 14:40:34 -07:00
|
|
|
int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
|
2013-04-22 15:42:41 -07:00
|
|
|
|
2013-09-12 10:06:47 -07:00
|
|
|
// motion vector cache for adaptive motion search control in partition
|
|
|
|
// search loop
|
|
|
|
int_mv pred_mv[MAX_REF_FRAMES];
|
2014-01-24 12:26:57 -08:00
|
|
|
INTERP_FILTER pred_interp_filter;
|
2012-04-06 16:38:34 -07:00
|
|
|
} PICK_MODE_CONTEXT;
|
|
|
|
|
2013-04-23 08:26:10 -07:00
|
|
|
struct macroblock_plane {
|
2013-10-15 11:50:25 -07:00
|
|
|
DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
|
2013-11-26 18:52:10 -08:00
|
|
|
int16_t *qcoeff;
|
2013-11-01 12:53:37 -07:00
|
|
|
int16_t *coeff;
|
2013-12-03 17:59:32 -08:00
|
|
|
uint16_t *eobs;
|
2013-04-23 16:22:47 -07:00
|
|
|
struct buf_2d src;
|
2013-04-23 15:22:18 -07:00
|
|
|
|
|
|
|
// Quantizer setings
|
|
|
|
int16_t *quant;
|
2013-07-01 11:36:07 -07:00
|
|
|
int16_t *quant_shift;
|
2013-04-23 15:22:18 -07:00
|
|
|
int16_t *zbin;
|
|
|
|
int16_t *round;
|
|
|
|
|
|
|
|
// Zbin Over Quant value
|
|
|
|
int16_t zbin_extra;
|
2013-04-23 08:26:10 -07:00
|
|
|
};
|
|
|
|
|
2013-07-24 15:13:58 -07:00
|
|
|
/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
|
|
|
|
* coefficient in this block was zero) or not. */
|
2013-12-06 10:54:00 -08:00
|
|
|
typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
|
2013-12-05 17:08:06 -08:00
|
|
|
[COEFF_CONTEXTS][ENTROPY_TOKENS];
|
2013-07-24 15:13:58 -07:00
|
|
|
|
2013-02-27 10:00:24 -08:00
|
|
|
typedef struct macroblock MACROBLOCK;
|
|
|
|
struct macroblock {
|
2013-04-23 08:26:10 -07:00
|
|
|
struct macroblock_plane plane[MAX_MB_PLANE];
|
2012-07-13 15:21:29 -07:00
|
|
|
|
|
|
|
MACROBLOCKD e_mbd;
|
2013-04-23 16:22:47 -07:00
|
|
|
int skip_block;
|
2013-11-05 21:07:08 -08:00
|
|
|
int select_txfm_size;
|
2013-11-07 14:56:58 -08:00
|
|
|
int skip_recode;
|
2013-11-05 21:07:08 -08:00
|
|
|
int skip_optimize;
|
2013-11-12 17:28:27 -08:00
|
|
|
int q_index;
|
2012-07-13 15:21:29 -07:00
|
|
|
|
|
|
|
search_site *ss;
|
|
|
|
int ss_count;
|
|
|
|
int searches_per_step;
|
|
|
|
|
|
|
|
int errorperbit;
|
|
|
|
int sadperbit16;
|
|
|
|
int sadperbit4;
|
|
|
|
int rddiv;
|
|
|
|
int rdmult;
|
2013-10-07 19:20:10 +01:00
|
|
|
unsigned int mb_energy;
|
2012-07-13 15:21:29 -07:00
|
|
|
|
2012-12-05 16:23:38 +00:00
|
|
|
int mv_best_ref_index[MAX_REF_FRAMES];
|
2013-07-12 09:52:24 -07:00
|
|
|
unsigned int max_mv_context[MAX_REF_FRAMES];
|
2013-07-31 09:33:58 -07:00
|
|
|
unsigned int source_variance;
|
2013-12-20 15:24:22 -08:00
|
|
|
unsigned int pred_sse[MAX_REF_FRAMES];
|
|
|
|
int pred_mv_sad[MAX_REF_FRAMES];
|
2012-12-05 16:23:38 +00:00
|
|
|
|
2012-07-26 13:42:07 -07:00
|
|
|
int nmvjointcost[MV_JOINTS];
|
|
|
|
int nmvcosts[2][MV_VALS];
|
|
|
|
int *nmvcost[2];
|
|
|
|
int nmvcosts_hp[2][MV_VALS];
|
|
|
|
int *nmvcost_hp[2];
|
2012-11-08 15:44:39 -08:00
|
|
|
int **mvcost;
|
2012-07-26 13:42:07 -07:00
|
|
|
|
|
|
|
int nmvjointsadcost[MV_JOINTS];
|
|
|
|
int nmvsadcosts[2][MV_VALS];
|
|
|
|
int *nmvsadcost[2];
|
|
|
|
int nmvsadcosts_hp[2][MV_VALS];
|
|
|
|
int *nmvsadcost_hp[2];
|
2012-11-08 15:44:39 -08:00
|
|
|
int **mvsadcost;
|
2012-08-03 12:17:18 -07:00
|
|
|
|
2014-03-05 12:28:30 -08:00
|
|
|
int mbmode_cost[INTRA_MODES];
|
2013-10-18 14:31:56 -07:00
|
|
|
unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
|
2014-03-05 12:28:30 -08:00
|
|
|
int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES];
|
2013-08-22 18:40:34 -07:00
|
|
|
int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
|
2013-10-30 14:40:34 -07:00
|
|
|
int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
|
2012-07-13 15:21:29 -07:00
|
|
|
|
2013-11-11 15:58:57 -08:00
|
|
|
unsigned char sb_index; // index of 32x32 block inside the 64x64 block
|
|
|
|
unsigned char mb_index; // index of 16x16 block inside the 32x32 block
|
|
|
|
unsigned char b_index; // index of 8x8 block inside the 16x16 block
|
|
|
|
unsigned char ab_index; // index of 4x4 block inside the 8x8 block
|
|
|
|
|
2012-10-22 14:43:01 -07:00
|
|
|
// These define limits to motion vector components to prevent them
|
|
|
|
// from extending outside the UMV borders
|
2012-07-13 15:21:29 -07:00
|
|
|
int mv_col_min;
|
|
|
|
int mv_col_max;
|
|
|
|
int mv_row_min;
|
|
|
|
int mv_row_max;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-10-14 16:03:23 -07:00
|
|
|
uint8_t zcoeff_blk[TX_SIZES][256];
|
2012-07-13 15:21:29 -07:00
|
|
|
int skip;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2012-07-13 15:21:29 -07:00
|
|
|
int encode_breakout;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2014-03-07 18:15:33 -08:00
|
|
|
int in_active_map;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-05-08 10:04:14 -07:00
|
|
|
// note that token_costs is the cost when eob node is skipped
|
2013-07-26 17:15:37 -07:00
|
|
|
vp9_coeff_cost token_costs[TX_SIZES];
|
2012-01-26 14:36:20 -08:00
|
|
|
|
2012-07-13 15:21:29 -07:00
|
|
|
int optimize;
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-06-14 11:28:56 -07:00
|
|
|
// indicate if it is in the rd search loop or encoding process
|
2013-08-07 15:22:51 -07:00
|
|
|
int use_lp32x32fdct;
|
2013-07-08 16:48:47 -07:00
|
|
|
int skip_encode;
|
2013-06-14 11:28:56 -07:00
|
|
|
|
2013-07-03 14:43:23 -07:00
|
|
|
// Used to store sub partition's choices.
|
2013-09-12 10:06:47 -07:00
|
|
|
int_mv pred_mv[MAX_REF_FRAMES];
|
2013-07-03 14:43:23 -07:00
|
|
|
|
2013-05-08 14:24:43 -07:00
|
|
|
// TODO(jingning): Need to refactor the structure arrays that buffers the
|
|
|
|
// coding mode decisions of each partition type.
|
2013-05-10 17:06:37 -07:00
|
|
|
PICK_MODE_CONTEXT ab4x4_context[4][4][4];
|
|
|
|
PICK_MODE_CONTEXT sb8x4_context[4][4][4];
|
|
|
|
PICK_MODE_CONTEXT sb4x8_context[4][4][4];
|
|
|
|
PICK_MODE_CONTEXT sb8x8_context[4][4][4];
|
2013-04-30 16:13:20 -07:00
|
|
|
PICK_MODE_CONTEXT sb8x16_context[4][4][2];
|
|
|
|
PICK_MODE_CONTEXT sb16x8_context[4][4][2];
|
2013-01-05 18:20:25 -08:00
|
|
|
PICK_MODE_CONTEXT mb_context[4][4];
|
2013-04-09 21:28:27 -07:00
|
|
|
PICK_MODE_CONTEXT sb32x16_context[4][2];
|
|
|
|
PICK_MODE_CONTEXT sb16x32_context[4][2];
|
2012-07-13 15:21:29 -07:00
|
|
|
// when 4 MBs share coding parameters:
|
2013-01-05 18:20:25 -08:00
|
|
|
PICK_MODE_CONTEXT sb32_context[4];
|
2013-04-09 21:28:27 -07:00
|
|
|
PICK_MODE_CONTEXT sb32x64_context[2];
|
|
|
|
PICK_MODE_CONTEXT sb64x32_context[2];
|
2013-01-05 18:20:25 -08:00
|
|
|
PICK_MODE_CONTEXT sb64_context;
|
2013-10-18 17:44:19 -07:00
|
|
|
int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
|
2012-04-06 16:38:34 -07:00
|
|
|
|
2013-08-27 11:05:08 -07:00
|
|
|
BLOCK_SIZE b_partitioning[4][4][4];
|
|
|
|
BLOCK_SIZE mb_partitioning[4][4];
|
|
|
|
BLOCK_SIZE sb_partitioning[4];
|
|
|
|
BLOCK_SIZE sb64_partitioning;
|
2013-05-08 14:24:43 -07:00
|
|
|
|
2013-10-24 11:48:25 -07:00
|
|
|
void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride);
|
2013-02-27 10:00:24 -08:00
|
|
|
};
|
2010-05-18 11:58:33 -04:00
|
|
|
|
2013-10-16 12:43:03 -07:00
|
|
|
// TODO(jingning): the variables used here are little complicated. need further
|
|
|
|
// refactoring on organizing the temporary buffers, when recursive
|
|
|
|
// partition down to 4x4 block size is enabled.
|
2014-03-11 09:28:45 -07:00
|
|
|
static INLINE PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x,
|
|
|
|
BLOCK_SIZE bsize) {
|
2013-10-16 12:43:03 -07:00
|
|
|
switch (bsize) {
|
|
|
|
case BLOCK_64X64:
|
|
|
|
return &x->sb64_context;
|
|
|
|
case BLOCK_64X32:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb64x32_context[x->sb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_32X64:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb32x64_context[x->sb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_32X32:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb32_context[x->sb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_32X16:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb32x16_context[x->sb_index][x->mb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_16X32:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb16x32_context[x->sb_index][x->mb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_16X16:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->mb_context[x->sb_index][x->mb_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_16X8:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_8X16:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_8X8:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_8X4:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_4X8:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
case BLOCK_4X4:
|
2013-11-11 15:58:57 -08:00
|
|
|
return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index];
|
2013-10-16 12:43:03 -07:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 12:16:11 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 15:31:19 -08:00
|
|
|
#endif // VP9_ENCODER_VP9_BLOCK_H_
|