vp9_firstpass.h 5.58 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9 10
 */

11
#ifndef VP9_ENCODER_VP9_FIRSTPASS_H_
12
#define VP9_ENCODER_VP9_FIRSTPASS_H_
John Koleszar's avatar
John Koleszar committed
13

14
#include "vp9/encoder/vp9_lookahead.h"
15
#include "vp9/encoder/vp9_ratectrl.h"
16

17 18 19 20
#ifdef __cplusplus
extern "C" {
#endif

21
#if CONFIG_FP_MB_STATS
22 23

#define FPMB_DCINTRA_MASK 0x01
24 25 26 27 28 29 30 31 32 33 34

#define FPMB_MOTION_ZERO_MASK 0x02
#define FPMB_MOTION_LEFT_MASK 0x04
#define FPMB_MOTION_RIGHT_MASK 0x08
#define FPMB_MOTION_UP_MASK 0x10
#define FPMB_MOTION_DOWN_MASK 0x20

#define FPMB_ERROR_SMALL_MASK 0x40
#define FPMB_ERROR_LARGE_MASK 0x80
#define FPMB_ERROR_SMALL_TH 2000
#define FPMB_ERROR_LARGE_TH 48000
35

36
typedef struct {
37 38
  uint8_t *mb_stats_start;
  uint8_t *mb_stats_end;
39 40 41
} FIRSTPASS_MB_STATS;
#endif

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#define INVALID_ROW -1

typedef struct {
  double frame_mb_intra_factor;
  double frame_mb_brightness_factor;
  double frame_mb_neutral_count;
} FP_MB_FLOAT_STATS;

typedef struct {
  double intra_factor;
  double brightness_factor;
  int64_t coded_error;
  int64_t sr_coded_error;
  int64_t frame_noise_energy;
  int64_t intra_error;
  int intercount;
  int second_ref_count;
  double neutral_count;
60 61
  double intra_count_low;   // Coded intra but low variance
  double intra_count_high;  // Coded intra high variance
62 63 64 65 66 67 68 69 70 71 72 73 74
  int intra_skip_count;
  int image_data_start_row;
  int mvcount;
  int sum_mvr;
  int sum_mvr_abs;
  int sum_mvc;
  int sum_mvc_abs;
  int64_t sum_mvrs;
  int64_t sum_mvcs;
  int sum_in_vectors;
  int intra_smooth_count;
} FIRSTPASS_DATA;

75 76
typedef struct {
  double frame;
77
  double weight;
78 79 80
  double intra_error;
  double coded_error;
  double sr_coded_error;
81
  double frame_noise_energy;
82 83 84 85
  double pcnt_inter;
  double pcnt_motion;
  double pcnt_second_ref;
  double pcnt_neutral;
86 87
  double pcnt_intra_low;   // Coded intra but low variance
  double pcnt_intra_high;  // Coded intra high variance
88
  double intra_skip_pct;
89
  double intra_smooth_pct;    // % of blocks that are smooth
90
  double inactive_zone_rows;  // Image mask rows top and bottom.
91
  double inactive_zone_cols;  // Image mask columns at left and right edges.
92 93 94 95 96 97 98 99 100
  double MVr;
  double mvr_abs;
  double MVc;
  double mvc_abs;
  double MVrv;
  double MVcv;
  double mv_in_out_count;
  double duration;
  double count;
101
  int64_t spatial_layer_id;
102
} FIRSTPASS_STATS;
John Koleszar's avatar
John Koleszar committed
103

104 105 106 107 108 109 110 111 112
typedef enum {
  KF_UPDATE = 0,
  LF_UPDATE = 1,
  GF_UPDATE = 2,
  ARF_UPDATE = 3,
  OVERLAY_UPDATE = 4,
  FRAME_UPDATE_TYPES = 5
} FRAME_UPDATE_TYPE;

113 114 115 116 117 118 119
#define FC_ANIMATION_THRESH 0.15
typedef enum {
  FC_NORMAL = 0,
  FC_GRAPHICS_ANIMATION = 1,
  FRAME_CONTENT_TYPES = 2
} FRAME_CONTENT_TYPE;

120 121
typedef struct {
  unsigned char index;
122
  unsigned char first_inter_index;
123 124 125 126 127 128
  RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
  FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
  unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
  unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
  unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
  int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
129 130
} GF_GROUP;

Paul Wilkins's avatar
Paul Wilkins committed
131
typedef struct {
132 133
  unsigned int section_intra_rating;
  FIRSTPASS_STATS total_stats;
134
  FIRSTPASS_STATS this_frame_stats;
135 136 137
  const FIRSTPASS_STATS *stats_in;
  const FIRSTPASS_STATS *stats_in_start;
  const FIRSTPASS_STATS *stats_in_end;
138 139 140
  FIRSTPASS_STATS total_left_stats;
  int first_pass_done;
  int64_t bits_left;
paulwilkins's avatar
paulwilkins committed
141 142
  double mean_mod_score;
  double normalized_score_left;
143
  double mb_av_energy;
144
  double mb_smooth_pct;
145

146
#if CONFIG_FP_MB_STATS
147 148 149
  uint8_t *frame_mb_stats_buf;
  uint8_t *this_frame_mb_stats;
  FIRSTPASS_MB_STATS firstpass_mb_stats;
150
#endif
151 152 153

  FP_MB_FLOAT_STATS *fp_mb_float_stats;

154 155
  // An indication of the content type of the current frame
  FRAME_CONTENT_TYPE fr_content_type;
156

157 158 159 160
  // Projected total bits available for a key frame group of frames
  int64_t kf_group_bits;

  // Error score of frames still to be coded in kf group
161
  double kf_group_error_left;
162

163 164 165
  double bpm_factor;
  int rolling_arf_group_target_bits;
  int rolling_arf_group_actual_bits;
166

167
  int sr_update_lag;
168
  int kf_zeromotion_pct;
169
  int last_kfgroup_zeromotion_pct;
170
  int active_worst_quality;
171
  int baseline_active_worst_quality;
172 173
  int extend_minq;
  int extend_maxq;
174
  int extend_minq_fast;
175
  int arnr_strength_adjustment;
176

177
  GF_GROUP gf_group;
Paul Wilkins's avatar
Paul Wilkins committed
178
} TWO_PASS;
179 180

struct VP9_COMP;
181 182
struct ThreadData;
struct TileDataEnc;
183 184 185

void vp9_init_first_pass(struct VP9_COMP *cpi);
void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
186
void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
187 188
void vp9_end_first_pass(struct VP9_COMP *cpi);

189 190 191 192 193 194
void vp9_first_pass_encode_tile_mb_row(struct VP9_COMP *cpi,
                                       struct ThreadData *td,
                                       FIRSTPASS_DATA *fp_acc_data,
                                       struct TileDataEnc *tile_data,
                                       MV *best_ref_mv, int mb_row);

195 196
void vp9_init_second_pass(struct VP9_COMP *cpi);
void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
197
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
John Koleszar's avatar
John Koleszar committed
198

199
// Post encode update of the rate control parameters for 2-pass
200
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
201

202
void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
203 204
                          int *scaled_frame_height);

205 206 207 208
#ifdef __cplusplus
}  // extern "C"
#endif

209
#endif  // VP9_ENCODER_VP9_FIRSTPASS_H_