]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_firstpass.h
Modified ARF group allocation.
[libvpx] / vp9 / encoder / vp9_firstpass.h
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  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.
9  */
10
11 #ifndef VP9_ENCODER_VP9_FIRSTPASS_H_
12 #define VP9_ENCODER_VP9_FIRSTPASS_H_
13
14 #include "vp9/encoder/vp9_lookahead.h"
15 #include "vp9/encoder/vp9_ratectrl.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #if CONFIG_FP_MB_STATS
22
23 #define FPMB_DCINTRA_MASK 0x01
24
25 #define FPMB_MOTION_ZERO_MASK 0x02
26 #define FPMB_MOTION_LEFT_MASK 0x04
27 #define FPMB_MOTION_RIGHT_MASK 0x08
28 #define FPMB_MOTION_UP_MASK 0x10
29 #define FPMB_MOTION_DOWN_MASK 0x20
30
31 #define FPMB_ERROR_SMALL_MASK 0x40
32 #define FPMB_ERROR_LARGE_MASK 0x80
33 #define FPMB_ERROR_SMALL_TH 2000
34 #define FPMB_ERROR_LARGE_TH 48000
35
36 typedef struct {
37   uint8_t *mb_stats_start;
38   uint8_t *mb_stats_end;
39 } FIRSTPASS_MB_STATS;
40 #endif
41
42 typedef struct {
43   double frame;
44   double weight;
45   double intra_error;
46   double coded_error;
47   double sr_coded_error;
48   double frame_noise_energy;
49   double pcnt_inter;
50   double pcnt_motion;
51   double pcnt_second_ref;
52   double pcnt_neutral;
53   double intra_skip_pct;
54   double intra_smooth_pct;    // % of blocks that are smooth
55   double inactive_zone_rows;  // Image mask rows top and bottom.
56   double inactive_zone_cols;  // Image mask columns at left and right edges.
57   double MVr;
58   double mvr_abs;
59   double MVc;
60   double mvc_abs;
61   double MVrv;
62   double MVcv;
63   double mv_in_out_count;
64   double new_mv_count;
65   double duration;
66   double count;
67   int64_t spatial_layer_id;
68 } FIRSTPASS_STATS;
69
70 typedef enum {
71   KF_UPDATE = 0,
72   LF_UPDATE = 1,
73   GF_UPDATE = 2,
74   ARF_UPDATE = 3,
75   OVERLAY_UPDATE = 4,
76   FRAME_UPDATE_TYPES = 5
77 } FRAME_UPDATE_TYPE;
78
79 #define FC_ANIMATION_THRESH 0.15
80 typedef enum {
81   FC_NORMAL = 0,
82   FC_GRAPHICS_ANIMATION = 1,
83   FRAME_CONTENT_TYPES = 2
84 } FRAME_CONTENT_TYPE;
85
86 typedef struct {
87   unsigned char index;
88   unsigned char first_inter_index;
89   RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
90   FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
91   unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
92   unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
93   unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
94   int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
95 } GF_GROUP;
96
97 typedef struct {
98   unsigned int section_intra_rating;
99   FIRSTPASS_STATS total_stats;
100   FIRSTPASS_STATS this_frame_stats;
101   const FIRSTPASS_STATS *stats_in;
102   const FIRSTPASS_STATS *stats_in_start;
103   const FIRSTPASS_STATS *stats_in_end;
104   FIRSTPASS_STATS total_left_stats;
105   int first_pass_done;
106   int64_t bits_left;
107   double modified_error_min;
108   double modified_error_max;
109   double modified_error_left;
110   double mb_av_energy;
111   double mb_smooth_pct;
112
113 #if CONFIG_FP_MB_STATS
114   uint8_t *frame_mb_stats_buf;
115   uint8_t *this_frame_mb_stats;
116   FIRSTPASS_MB_STATS firstpass_mb_stats;
117 #endif
118   // An indication of the content type of the current frame
119   FRAME_CONTENT_TYPE fr_content_type;
120
121   // Projected total bits available for a key frame group of frames
122   int64_t kf_group_bits;
123
124   // Error score of frames still to be coded in kf group
125   int64_t kf_group_error_left;
126
127   double bpm_factor;
128   int rolling_arf_group_target_bits;
129   int rolling_arf_group_actual_bits;
130
131   int sr_update_lag;
132   int kf_zeromotion_pct;
133   int last_kfgroup_zeromotion_pct;
134   int active_worst_quality;
135   int baseline_active_worst_quality;
136   int extend_minq;
137   int extend_maxq;
138   int extend_minq_fast;
139   int arnr_strength_adjustment;
140
141   GF_GROUP gf_group;
142 } TWO_PASS;
143
144 struct VP9_COMP;
145
146 void vp9_init_first_pass(struct VP9_COMP *cpi);
147 void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
148 void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
149 void vp9_end_first_pass(struct VP9_COMP *cpi);
150
151 void vp9_init_second_pass(struct VP9_COMP *cpi);
152 void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
153 void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
154
155 // Post encode update of the rate control parameters for 2-pass
156 void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
157
158 void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
159                           int *scaled_frame_height);
160
161 #ifdef __cplusplus
162 }  // extern "C"
163 #endif
164
165 #endif  // VP9_ENCODER_VP9_FIRSTPASS_H_