vp9_firstpass.h 3.53 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

Paul Wilkins's avatar
Paul Wilkins committed
42
43
#define VLOW_MOTION_THRESHOLD 950

44
45
typedef struct {
  double frame;
46
  double weight;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  double intra_error;
  double coded_error;
  double sr_coded_error;
  double pcnt_inter;
  double pcnt_motion;
  double pcnt_second_ref;
  double pcnt_neutral;
  double MVr;
  double mvr_abs;
  double MVc;
  double mvc_abs;
  double MVrv;
  double MVcv;
  double mv_in_out_count;
  double new_mv_count;
  double duration;
  double count;
64
  int64_t spatial_layer_id;
65
} FIRSTPASS_STATS;
John Koleszar's avatar
John Koleszar committed
66

67
68
69
70
71
72
73
74
75
76
77
typedef enum {
  KF_UPDATE = 0,
  LF_UPDATE = 1,
  GF_UPDATE = 2,
  ARF_UPDATE = 3,
  OVERLAY_UPDATE = 4,
  FRAME_UPDATE_TYPES = 5
} FRAME_UPDATE_TYPE;

typedef struct {
  unsigned char index;
78
79
80
81
82
83
  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];
84
85
} GF_GROUP;

Paul Wilkins's avatar
Paul Wilkins committed
86
typedef struct {
87
88
  unsigned int section_intra_rating;
  FIRSTPASS_STATS total_stats;
89
  FIRSTPASS_STATS this_frame_stats;
90
91
92
  const FIRSTPASS_STATS *stats_in;
  const FIRSTPASS_STATS *stats_in_start;
  const FIRSTPASS_STATS *stats_in_end;
93
94
95
96
97
98
  FIRSTPASS_STATS total_left_stats;
  int first_pass_done;
  int64_t bits_left;
  double modified_error_min;
  double modified_error_max;
  double modified_error_left;
Paul Wilkins's avatar
Paul Wilkins committed
99
  double mb_av_energy;
100

101
#if CONFIG_FP_MB_STATS
102
103
104
  uint8_t *frame_mb_stats_buf;
  uint8_t *this_frame_mb_stats;
  FIRSTPASS_MB_STATS firstpass_mb_stats;
105
106
#endif

107
108
109
110
111
112
113
114
  // 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
  int64_t kf_group_error_left;
  int sr_update_lag;

  int kf_zeromotion_pct;
115
  int last_kfgroup_zeromotion_pct;
Paul Wilkins's avatar
Paul Wilkins committed
116
  int gf_zeromotion_pct;
117
  int active_worst_quality;
Paul Wilkins's avatar
Paul Wilkins committed
118
119
  int extend_minq;
  int extend_maxq;
120

121
  GF_GROUP gf_group;
Paul Wilkins's avatar
Paul Wilkins committed
122
} TWO_PASS;
123
124
125
126
127

struct VP9_COMP;

void vp9_init_first_pass(struct VP9_COMP *cpi);
void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
128
void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
129
130
131
132
void vp9_end_first_pass(struct VP9_COMP *cpi);

void vp9_init_second_pass(struct VP9_COMP *cpi);
void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
John Koleszar's avatar
John Koleszar committed
133

134
// Post encode update of the rate control parameters for 2-pass
135
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
136
137
138
139
#ifdef __cplusplus
}  // extern "C"
#endif

140
#endif  // VP9_ENCODER_VP9_FIRSTPASS_H_