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
|
|
|
*/
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#ifndef VP9_ENCODER_VP9_FIRSTPASS_H_
|
2012-11-30 01:36:10 +01:00
|
|
|
#define VP9_ENCODER_VP9_FIRSTPASS_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2014-05-16 16:12:31 +02:00
|
|
|
#include "vp9/encoder/vp9_lookahead.h"
|
2014-06-09 17:25:31 +02:00
|
|
|
#include "vp9/encoder/vp9_ratectrl.h"
|
2014-05-16 16:12:31 +02:00
|
|
|
|
2014-01-18 21:16:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-06-30 18:52:27 +02:00
|
|
|
#if CONFIG_FP_MB_STATS
|
2014-07-25 20:07:44 +02:00
|
|
|
|
|
|
|
#define FPMB_DCINTRA_MASK 0x01
|
2014-07-31 18:01:06 +02:00
|
|
|
|
|
|
|
#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
|
2014-07-25 20:07:44 +02:00
|
|
|
|
2014-06-30 18:52:27 +02:00
|
|
|
typedef struct {
|
2014-07-14 18:13:38 +02:00
|
|
|
uint8_t *mb_stats_start;
|
|
|
|
uint8_t *mb_stats_end;
|
2014-06-30 18:52:27 +02:00
|
|
|
} FIRSTPASS_MB_STATS;
|
|
|
|
#endif
|
|
|
|
|
2016-12-27 14:15:43 +01:00
|
|
|
#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;
|
|
|
|
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;
|
|
|
|
|
2014-02-06 03:28:28 +01:00
|
|
|
typedef struct {
|
|
|
|
double frame;
|
2014-11-04 14:13:39 +01:00
|
|
|
double weight;
|
2014-02-06 03:28:28 +01:00
|
|
|
double intra_error;
|
|
|
|
double coded_error;
|
|
|
|
double sr_coded_error;
|
2016-06-10 13:00:26 +02:00
|
|
|
double frame_noise_energy;
|
2014-02-06 03:28:28 +01:00
|
|
|
double pcnt_inter;
|
|
|
|
double pcnt_motion;
|
|
|
|
double pcnt_second_ref;
|
|
|
|
double pcnt_neutral;
|
2015-06-04 01:22:11 +02:00
|
|
|
double intra_skip_pct;
|
2016-04-09 15:24:18 +02:00
|
|
|
double intra_smooth_pct; // % of blocks that are smooth
|
2015-06-04 01:22:11 +02:00
|
|
|
double inactive_zone_rows; // Image mask rows top and bottom.
|
2015-06-24 12:36:51 +02:00
|
|
|
double inactive_zone_cols; // Image mask columns at left and right edges.
|
2014-02-06 03:28:28 +01:00
|
|
|
double MVr;
|
|
|
|
double mvr_abs;
|
|
|
|
double MVc;
|
|
|
|
double mvc_abs;
|
|
|
|
double MVrv;
|
|
|
|
double MVcv;
|
|
|
|
double mv_in_out_count;
|
|
|
|
double duration;
|
|
|
|
double count;
|
2014-03-28 19:42:26 +01:00
|
|
|
int64_t spatial_layer_id;
|
2014-02-06 03:28:28 +01:00
|
|
|
} FIRSTPASS_STATS;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2014-06-09 17:25:31 +02:00
|
|
|
typedef enum {
|
|
|
|
KF_UPDATE = 0,
|
|
|
|
LF_UPDATE = 1,
|
|
|
|
GF_UPDATE = 2,
|
|
|
|
ARF_UPDATE = 3,
|
|
|
|
OVERLAY_UPDATE = 4,
|
|
|
|
FRAME_UPDATE_TYPES = 5
|
|
|
|
} FRAME_UPDATE_TYPE;
|
|
|
|
|
2015-05-30 01:56:19 +02:00
|
|
|
#define FC_ANIMATION_THRESH 0.15
|
|
|
|
typedef enum {
|
|
|
|
FC_NORMAL = 0,
|
|
|
|
FC_GRAPHICS_ANIMATION = 1,
|
|
|
|
FRAME_CONTENT_TYPES = 2
|
|
|
|
} FRAME_CONTENT_TYPE;
|
|
|
|
|
2014-06-09 17:25:31 +02:00
|
|
|
typedef struct {
|
|
|
|
unsigned char index;
|
2016-08-09 11:10:16 +02:00
|
|
|
unsigned char first_inter_index;
|
2014-06-23 14:07:24 +02:00
|
|
|
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];
|
2014-06-09 17:25:31 +02:00
|
|
|
} GF_GROUP;
|
|
|
|
|
2014-05-16 12:31:30 +02:00
|
|
|
typedef struct {
|
2014-02-06 03:28:28 +01:00
|
|
|
unsigned int section_intra_rating;
|
|
|
|
FIRSTPASS_STATS total_stats;
|
2014-06-06 19:37:22 +02:00
|
|
|
FIRSTPASS_STATS this_frame_stats;
|
2014-03-07 03:58:17 +01:00
|
|
|
const FIRSTPASS_STATS *stats_in;
|
|
|
|
const FIRSTPASS_STATS *stats_in_start;
|
|
|
|
const FIRSTPASS_STATS *stats_in_end;
|
2014-02-06 03:28:28 +01:00
|
|
|
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;
|
2014-11-21 00:03:01 +01:00
|
|
|
double mb_av_energy;
|
2016-04-09 15:24:18 +02:00
|
|
|
double mb_smooth_pct;
|
2014-05-16 16:12:31 +02:00
|
|
|
|
2014-06-30 18:52:27 +02:00
|
|
|
#if CONFIG_FP_MB_STATS
|
2014-07-14 18:13:38 +02:00
|
|
|
uint8_t *frame_mb_stats_buf;
|
|
|
|
uint8_t *this_frame_mb_stats;
|
|
|
|
FIRSTPASS_MB_STATS firstpass_mb_stats;
|
2014-06-30 18:52:27 +02:00
|
|
|
#endif
|
2016-12-27 14:15:43 +01:00
|
|
|
|
|
|
|
FP_MB_FLOAT_STATS *fp_mb_float_stats;
|
|
|
|
|
2015-05-30 01:56:19 +02:00
|
|
|
// An indication of the content type of the current frame
|
|
|
|
FRAME_CONTENT_TYPE fr_content_type;
|
2014-06-30 18:52:27 +02:00
|
|
|
|
2014-02-06 03:28:28 +01:00
|
|
|
// 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;
|
Adjust active maxq for GF groups.
Currently disabled by default: enabled using
#define GROUP_ADAPTIVE_MAXQ
In this patch the active max Q is adjusted for each GF
group based on the vbr bit allocation and raw first pass
group error.
This will tend to give a lower q for easy sections
and a higher value for very hard sections. As such it is
expected to improve quality in some of the easier
sections where quality issues have been reported.
This change tends to hurt overall psnr but help
average psnr. SSIM also shows a small gain.
Average results for derf, yt, std-hd and yt-hd test sets were
as follows (%change for average psnr, overal psnr and ssim):-
derf +0.291, - 0.252, -0.021
yt +6.466, -1.436, +0.552
std-hd +0.490, +0.014, +0.380
yt-hd +5.565, - 1.573, +0.099
Change-Id: Icc015499cebbf2a45054a05e8e31f3dfb43f944a
2015-01-21 00:23:57 +01:00
|
|
|
|
2016-05-23 14:57:11 +02:00
|
|
|
double bpm_factor;
|
|
|
|
int rolling_arf_group_target_bits;
|
|
|
|
int rolling_arf_group_actual_bits;
|
2014-02-06 03:28:28 +01:00
|
|
|
|
2016-05-23 14:57:11 +02:00
|
|
|
int sr_update_lag;
|
2014-02-06 03:28:28 +01:00
|
|
|
int kf_zeromotion_pct;
|
2014-08-15 15:49:34 +02:00
|
|
|
int last_kfgroup_zeromotion_pct;
|
2014-02-11 02:52:44 +01:00
|
|
|
int active_worst_quality;
|
2014-11-15 00:29:18 +01:00
|
|
|
int baseline_active_worst_quality;
|
2014-10-13 11:12:12 +02:00
|
|
|
int extend_minq;
|
|
|
|
int extend_maxq;
|
2015-05-07 12:55:53 +02:00
|
|
|
int extend_minq_fast;
|
2016-06-10 13:00:26 +02:00
|
|
|
int arnr_strength_adjustment;
|
2014-05-16 16:12:31 +02:00
|
|
|
|
2014-06-09 17:25:31 +02:00
|
|
|
GF_GROUP gf_group;
|
2014-05-16 12:31:30 +02:00
|
|
|
} TWO_PASS;
|
2014-02-06 03:28:28 +01:00
|
|
|
|
|
|
|
struct VP9_COMP;
|
2016-12-27 14:15:43 +01:00
|
|
|
struct ThreadData;
|
|
|
|
struct TileDataEnc;
|
2014-02-06 03:28:28 +01:00
|
|
|
|
|
|
|
void vp9_init_first_pass(struct VP9_COMP *cpi);
|
|
|
|
void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
|
2014-08-23 01:57:08 +02:00
|
|
|
void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
|
2014-02-06 03:28:28 +01:00
|
|
|
void vp9_end_first_pass(struct VP9_COMP *cpi);
|
|
|
|
|
2016-12-27 14:15:43 +01:00
|
|
|
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);
|
|
|
|
|
2014-02-06 03:28:28 +01:00
|
|
|
void vp9_init_second_pass(struct VP9_COMP *cpi);
|
|
|
|
void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
|
2015-05-07 12:55:53 +02:00
|
|
|
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2014-02-04 20:42:50 +01:00
|
|
|
// Post encode update of the rate control parameters for 2-pass
|
2014-04-02 02:31:59 +02:00
|
|
|
void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
|
2014-11-15 00:29:18 +01:00
|
|
|
|
2016-07-27 05:43:23 +02:00
|
|
|
void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
|
2014-11-15 00:29:18 +01:00
|
|
|
int *scaled_frame_height);
|
|
|
|
|
2014-01-18 21:16:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#endif // VP9_ENCODER_VP9_FIRSTPASS_H_
|