16fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org/*
26fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
36fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *
46fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Use of this source code is governed by a BSD-style license
56fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  that can be found in the LICENSE file in the root of the source
66fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  tree. An additional intellectual property rights grant can be found
76fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  in the file PATENTS.  All contributing project authors may
86fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  be found in the AUTHORS file in the root of the source tree.
96fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org */
106fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
11693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com#ifndef VP9_ENCODER_VP9_ENCODER_H_
12693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com#define VP9_ENCODER_VP9_ENCODER_H_
136fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
146fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include <stdio.h>
1576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
16d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org#include "./vpx_config.h"
1776e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vpx_ports/mem.h"
1876e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vpx/internal/vpx_codec_internal.h"
1993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vpx/vp8cx.h"
2076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
2193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vp9/common/vp9_ppflags.h"
2276e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/common/vp9_entropy.h"
2376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/common/vp9_entropymode.h"
246fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vp9/common/vp9_onyxc_int.h"
2576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
2693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
2788b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org#include "vp9/encoder/vp9_context_tree.h"
286fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vp9/encoder/vp9_encodemb.h"
2976e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_firstpass.h"
306fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vp9/encoder/vp9_lookahead.h"
3176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_mbgraph.h"
3276e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_mcomp.h"
3376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_quantize.h"
3476e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_ratectrl.h"
35e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org#include "vp9/encoder/vp9_rd.h"
3693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vp9/encoder/vp9_speed_features.h"
3793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org#include "vp9/encoder/vp9_svc_layercontext.h"
3876e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_tokenize.h"
3976e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#include "vp9/encoder/vp9_variance.h"
4041294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org#if CONFIG_VP9_TEMPORAL_DENOISING
4188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org#include "vp9/encoder/vp9_denoiser.h"
4288b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org#endif
436fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
44dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
45dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgextern "C" {
46dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
47dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
4876e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org#define DEFAULT_GF_INTERVAL         10
496fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
506fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.orgtypedef struct {
516fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int nmvjointcost[MV_JOINTS];
526fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int nmvcosts[2][MV_VALS];
536fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int nmvcosts_hp[2][MV_VALS];
546fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
556fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  vp9_prob segment_pred_probs[PREDICTION_PROBS];
566fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
576fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  unsigned char *last_frame_seg_map_copy;
586fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
596fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  // 0 = Intra, Last, GF, ARF
606fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
6110a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  // 0 = ZERO_MV, MV
626fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
636fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
64ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org  FRAME_CONTEXT fc;
656fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org} CODING_CONTEXT;
666fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
67ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
68ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgtypedef enum {
6976e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  // encode_breakout is disabled.
7076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  ENCODE_BREAKOUT_DISABLED = 0,
7176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  // encode_breakout is enabled.
7276e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  ENCODE_BREAKOUT_ENABLED = 1,
7376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  // encode_breakout is enabled with small max_thresh limit.
7476e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  ENCODE_BREAKOUT_LIMITED = 2
7576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org} ENCODE_BREAKOUT_TYPE;
7676e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
77411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.orgtypedef enum {
7893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  NORMAL      = 0,
7993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  FOURFIVE    = 1,
8093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  THREEFIVE   = 2,
8193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  ONETWO      = 3
8293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org} VPX_SCALING;
83411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
8493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgtypedef enum {
85ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // Good Quality Fast Encoding. The encoder balances quality with the amount of
86ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // time it takes to encode the output. Speed setting controls how fast.
87ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  GOOD,
88ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org
89ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // The encoder places priority on the quality of the output over encoding
90ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // speed. The output is compressed at the highest possible quality. This
91ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // option takes the longest amount of time to encode. Speed setting ignored.
92ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  BEST,
93ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org
94ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
95ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // example, capturing a television signal or feed from a live camera). Speed
96ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  // setting controls how fast.
97ace65784417788374f0b19ce5a8abd06c9ccd007johannkoenig@chromium.org  REALTIME
9893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org} MODE;
99dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
10093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgtypedef enum {
10193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  FRAMEFLAGS_KEY    = 1 << 0,
10293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  FRAMEFLAGS_GOLDEN = 1 << 1,
10393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  FRAMEFLAGS_ALTREF = 1 << 2,
10493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org} FRAMETYPE_FLAGS;
105dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
10693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgtypedef enum {
10793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  NO_AQ = 0,
10893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  VARIANCE_AQ = 1,
10993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  COMPLEXITY_AQ = 2,
11093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  CYCLIC_REFRESH_AQ = 3,
11193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  AQ_MODE_COUNT  // This should always be the last member of the enum
11293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org} AQ_MODE;
11393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
114693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
115693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.comtypedef struct VP9EncoderConfig {
116693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  BITSTREAM_PROFILE profile;
117d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  vpx_bit_depth_t bit_depth;     // Codec bit-depth.
11893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int width;  // width of data passed to the compressor
11993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int height;  // height of data passed to the compressor
120d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  unsigned int input_bit_depth;  // Input bit depth.
12141294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  double init_framerate;  // set to passed in framerate
12293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int64_t target_bandwidth;  // bandwidth to be used in kilobits per second
12393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
12493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int noise_sensitivity;  // pre processing blur: recommendation 0
12593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int sharpness;  // sharpening output: recommendation 0:
126693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  int speed;
12793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  unsigned int rc_max_intra_bitrate_pct;
128dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
12993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  MODE mode;
13041294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  int pass;
131dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
13293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Key Framing Operations
13393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int auto_key;  // autodetect cut scenes and set the keyframes
13493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int key_freq;  // maximum distance to key frame.
135dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
13693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int lag_in_frames;  // how many frames lag before we start encoding
137dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
13893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // ----------------------------------------------------------------
13993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // DATARATE CONTROL OPTIONS
14076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
14188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  // vbr, cbr, constrained quality or constant quality
14288b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  enum vpx_rc_mode rc_mode;
143411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
14493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // buffer targeting aggressiveness
14593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int under_shoot_pct;
14693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int over_shoot_pct;
1476fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
14893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // buffering parameters
14988b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  int64_t starting_buffer_level_ms;
15088b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  int64_t optimal_buffer_level_ms;
15188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  int64_t maximum_buffer_size_ms;
152d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
15393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Frame drop threshold.
15493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int drop_frames_water_mark;
15593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
15693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // controlling quality
15793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int fixed_q;
15893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int worst_allowed_q;
15993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int best_allowed_q;
16093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int cq_level;
16193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  AQ_MODE aq_mode;  // Adaptive Quantization mode
16293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
163693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  // Internal frame size scaling.
164693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  int allow_spatial_resampling;
165693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  int scaled_frame_width;
166693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  int scaled_frame_height;
167693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
16893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Enable feature to reduce the frame quantization every x frames.
16993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int frame_periodic_boost;
17093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
17193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // two pass datarate control
17293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int two_pass_vbrbias;        // two pass datarate control tweaks
17393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int two_pass_vbrmin_section;
17493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int two_pass_vbrmax_section;
17593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // END DATARATE CONTROL OPTIONS
17693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // ----------------------------------------------------------------
17793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
17893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Spatial and temporal scalability.
17993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int ss_number_layers;  // Number of spatial layers.
18093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int ts_number_layers;  // Number of temporal layers.
18193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Bitrate allocation for spatial layers.
18293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int ss_target_bitrate[VPX_SS_MAX_LAYERS];
183ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org  int ss_play_alternate[VPX_SS_MAX_LAYERS];
18493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
18593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int ts_target_bitrate[VPX_TS_MAX_LAYERS];
18693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int ts_rate_decimator[VPX_TS_MAX_LAYERS];
18793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
18893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // these parameters aren't to be used in final build don't use!!!
18993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int play_alternate;
19093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
19193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int encode_breakout;  // early breakout : for video conf recommend 800
19293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
19393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  /* Bitfield defining the error resiliency features to enable.
19493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   * Can provide decodable frames after losses in previous
19593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   * frames and decodable partitions after losses in the same frame.
19693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   */
19793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  unsigned int error_resilient_mode;
19893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
19993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  /* Bitfield defining the parallel decoding mode where the
20093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   * decoding in successive frames may be conducted in parallel
20193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   * just by decoding the frame headers.
20293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org   */
20393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  unsigned int frame_parallel_decoding_mode;
20493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
20593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int arnr_max_frames;
20693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int arnr_strength;
20793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
20893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int tile_columns;
20993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  int tile_rows;
21093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
211d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  vpx_fixed_buf_t two_pass_stats_in;
212d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  struct vpx_codec_pkt_list *output_pkt_list;
21393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
214ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org#if CONFIG_FP_MB_STATS
215d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  vpx_fixed_buf_t firstpass_mb_stats_in;
216ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org#endif
217ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org
21893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  vp8e_tuning tuning;
21941294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  vp9e_tune_content content;
22087997d490ae52aa962a985c95b3cddf7f8832641johannkoenig@chromium.org#if CONFIG_VP9_HIGHBITDEPTH
22187997d490ae52aa962a985c95b3cddf7f8832641johannkoenig@chromium.org  int use_highbitdepth;
22287997d490ae52aa962a985c95b3cddf7f8832641johannkoenig@chromium.org#endif
223693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com} VP9EncoderConfig;
224693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
22588b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.orgstatic INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
22688b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
22788b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org}
228693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
22993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgtypedef struct VP9_COMP {
23093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  QUANTS quants;
2316fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  MACROBLOCK mb;
2326fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  VP9_COMMON common;
233693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  VP9EncoderConfig oxcf;
2346fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  struct lookahead_ctx    *lookahead;
2356fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  struct lookahead_entry  *alt_ref_source;
2366fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2376fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  YV12_BUFFER_CONFIG *Source;
23893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  YV12_BUFFER_CONFIG *Last_Source;  // NULL for first frame and alt_ref frames
2396fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  YV12_BUFFER_CONFIG *un_scaled_source;
2406fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  YV12_BUFFER_CONFIG scaled_source;
24193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  YV12_BUFFER_CONFIG *unscaled_last_source;
24293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  YV12_BUFFER_CONFIG scaled_last_source;
2436fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
244e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  int skippable_frame;
245e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org
2463f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int scaled_ref_idx[3];
2473f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int lst_fb_idx;
2483f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int gld_fb_idx;
2493f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int alt_fb_idx;
250f9586bb54d74c97d07b09eb2512f8569c9c1c025fgalligan@chromium.org
2513f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int refresh_last_frame;
2523f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int refresh_golden_frame;
2533f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int refresh_alt_ref_frame;
254dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
255dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_frame_flags_pending;
256dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_last_frame;
257dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_golden_frame;
258dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_alt_ref_frame;
259dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
260dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_frame_context_pending;
261dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  int ext_refresh_frame_context;
262dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
2636fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  YV12_BUFFER_CONFIG last_frame_uf;
2646fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2656fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  TOKENEXTRA *tok;
2669317728b1000351b129816f2945bbcbb48add326fgalligan@chromium.org  unsigned int tok_count[4][1 << 6];
2676fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2686fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  // Ambient reconstruction err target for force key frames
2696fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int ambient_err;
2706fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
271693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  RD_OPT rd;
2726fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2736fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  CODING_CONTEXT coding_context;
2746fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
275d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  int *nmvcosts[2];
276d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  int *nmvcosts_hp[2];
277d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  int *nmvsadcosts[2];
278d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  int *nmvsadcosts_hp[2];
279d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
280d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  int zbin_mode_boost;
281d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  int zbin_mode_boost_enabled;
2826fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2836fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int64_t last_time_stamp_seen;
2846fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int64_t last_end_time_stamp_seen;
2856fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int64_t first_time_stamp_ever;
2866fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
287d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  RATE_CONTROL rc;
28841294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  double framerate;
2896fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
290d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
291d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
2926fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2936fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  struct vpx_codec_pkt_list  *output_pkt_list;
2946fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
2956fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
2966fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int mbgraph_n_frames;             // number of frames filled in the above
2976fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int static_mb_pct;                // % forced skip mbs by segmentation
2986fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int ref_frame_flags;
2996fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3006fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  SPEED_FEATURES sf;
3016fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
30247265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  unsigned int max_mv_magnitude;
30347265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  int mv_step_param;
30447265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
30576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  // Default value is 1. From first pass stats, encode_breakout may be disabled.
30676e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  ENCODE_BREAKOUT_TYPE allow_encode_breakout;
30776e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
30888b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  // Get threshold from external input. A suggested threshold is 800 for HD
30988b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  // clips, and 300 for < HD clips.
31076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  int encode_breakout;
31176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
3126fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  unsigned char *segmentation_map;
3136fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3146fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  // segment threashold for encode breakout
31547265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org  int  segment_encode_breakout[MAX_SEGMENTS];
3166fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
317d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  unsigned char *complexity_map;
318d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
31993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  CYCLIC_REFRESH *cyclic_refresh;
32093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
3216fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fractional_mv_step_fp *find_fractional_mv_step;
3226fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  vp9_full_search_fn_t full_search_sad;
3236fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  vp9_refining_search_fn_t refining_search_sad;
3246fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  vp9_diamond_search_fn_t diamond_search_sad;
32553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
3266fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  uint64_t time_receive_data;
3276fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  uint64_t time_compress_data;
3286fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  uint64_t time_pick_lpf;
32953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org  uint64_t time_encode_sb_row;
3306fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
331e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org#if CONFIG_FP_MB_STATS
332e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  int use_fp_mb_stats;
333e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org#endif
334e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org
33588b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  TWO_PASS twopass;
3366fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3376fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  YV12_BUFFER_CONFIG alt_ref_buffer;
338d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
3396fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3406fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#if CONFIG_INTERNAL_STATS
341411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org  unsigned int mode_chosen_counts[MAX_MODES];
342411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
3436fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int    count;
3446fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_y;
3456fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_u;
3466fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_v;
3476fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total;
348dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  uint64_t total_sq_error;
349dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  uint64_t total_samples;
350dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
3516fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double totalp_y;
3526fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double totalp_u;
3536fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double totalp_v;
3546fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double totalp;
355dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  uint64_t totalp_sq_error;
356dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org  uint64_t totalp_samples;
357dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
3586fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int    bytes;
3596fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double summed_quality;
3606fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double summed_weights;
36110a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  double summedp_quality;
36210a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  double summedp_weights;
3636fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  unsigned int tot_recode_hits;
3646fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3656fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3666fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_ssimg_y;
3676fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_ssimg_u;
3686fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_ssimg_v;
3696fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  double total_ssimg_all;
3706fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3716fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int b_calculate_ssimg;
3726fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#endif
3736fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int b_calculate_psnr;
3746fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3756fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  int droppable;
3766fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
3773f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int initial_width;
3783f0af3b06425f635f3559f0bd4f53efea95fa5e2johannkoenig@chromium.org  int initial_height;
37910a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org
38076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  int use_svc;
38176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org
38293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  SVC svc;
38393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
384e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
385e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  diff *source_diff_var;
386e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
387e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  unsigned int source_var_thresh;
388e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  int frames_till_next_var_check;
389693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
390693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com  int frame_flags;
391693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
39277496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  search_site_config ss_cfg;
39377496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org
394810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org  int mbmode_cost[INTRA_MODES];
395d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
396810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org  int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES];
397810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org  int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
398810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org  int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
399810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org
40088b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  PICK_MODE_CONTEXT *leaf_tree;
40188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  PC_TREE *pc_tree;
40288b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  PC_TREE *pc_root;
40388b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
40488b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org
405e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  int multi_arf_allowed;
40610a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  int multi_arf_enabled;
407e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org  int multi_arf_last_grp_enabled;
40888b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org
40941294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org#if CONFIG_VP9_TEMPORAL_DENOISING
41088b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org  VP9_DENOISER denoiser;
41188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org#endif
41293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org} VP9_COMP;
413ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
41493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_initialize_enc();
415ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
416693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.comstruct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf);
41793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_remove_compressor(VP9_COMP *cpi);
4186fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
419693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.comvoid vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
42093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
42193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // receive a frames worth of data. caller can assume that a copy of this
42293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // frame is made and not just a copy of the pointer..
42393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
42493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
42593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          int64_t end_time_stamp);
42693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
42793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
42893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                            size_t *size, uint8_t *dest,
42993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                            int64_t *time_stamp, int64_t *time_end, int flush);
43093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
43193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
43293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                              vp9_ppflags_t *flags);
43393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
43493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
43593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
43693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
43793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
43893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
43993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                           YV12_BUFFER_CONFIG *sd);
44093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
44193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
44293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          YV12_BUFFER_CONFIG *sd);
44393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
44493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_update_entropy(VP9_COMP *cpi, int update);
44593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
4467765c078fa920ba6c949c15f16b6cc979d8bb95bjohannkoenig@chromium.orgint vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
44793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
44893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_set_internal_size(VP9_COMP *cpi,
44993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
45093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
45193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
45293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                         unsigned int height);
45393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
45493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_set_svc(VP9_COMP *cpi, int use_svc);
45593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
45693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_quantizer(struct VP9_COMP *cpi);
45793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
45893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE int get_ref_frame_idx(const VP9_COMP *cpi,
45993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                                    MV_REFERENCE_FRAME ref_frame) {
46010a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  if (ref_frame == LAST_FRAME) {
46110a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org    return cpi->lst_fb_idx;
46210a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  } else if (ref_frame == GOLDEN_FRAME) {
46310a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org    return cpi->gld_fb_idx;
46410a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  } else {
46510a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org    return cpi->alt_fb_idx;
46610a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  }
46710a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org}
46810a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org
46993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
47093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
47193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  VP9_COMMON * const cm = &cpi->common;
47293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  return &cm->frame_bufs[cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]]
47393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org      .buf;
474f9586bb54d74c97d07b09eb2512f8569c9c1c025fgalligan@chromium.org}
475f9586bb54d74c97d07b09eb2512f8569c9c1c025fgalligan@chromium.org
47693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE int get_token_alloc(int mb_rows, int mb_cols) {
4773983288b51bb3c8f48a2d5f77523ef3ff1e94cd2johannkoenig@chromium.org  // TODO(JBB): double check we can't exceed this token count if we have a
4783983288b51bb3c8f48a2d5f77523ef3ff1e94cd2johannkoenig@chromium.org  // 32x32 transform crossing a boundary at a multiple of 16.
47993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
48093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // resolution. We assume up to 1 token per pixel, and then allow
48193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  // a head room of 4.
48293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org  return mb_rows * mb_cols * (16 * 16 * 3 + 4);
48393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org}
4846fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
48593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
486ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
487ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgvoid vp9_alloc_compressor_data(VP9_COMP *cpi);
4886fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
48993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_scale_references(VP9_COMP *cpi);
490ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
49193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgvoid vp9_update_reference_frames(VP9_COMP *cpi);
49293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
493e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.orgvoid vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
494e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org
495693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.comYV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
496693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com                                          YV12_BUFFER_CONFIG *unscaled,
497693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com                                          YV12_BUFFER_CONFIG *scaled);
498693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com
499e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.orgvoid vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
500e2064011d36b2008099446503f28e64d445060ecjohannkoenig@chromium.org
501d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.orgstatic INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
50241294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  return cpi->use_svc &&
503d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org         (cpi->svc.number_temporal_layers > 1 ||
504d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org          cpi->svc.number_spatial_layers > 1) &&
505d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org         (cpi->oxcf.pass == 1 || cpi->oxcf.pass == 2);
50641294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org}
50741294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org
508ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.orgstatic INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
509ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org  return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
510ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org         (cpi->oxcf.play_alternate &&
511d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org          (!is_two_pass_svc(cpi) ||
512ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org           cpi->oxcf.ss_play_alternate[cpi->svc.spatial_layer_id]));
513ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org}
514ac4e313c19203132648a2a271703b6ee76fe4284johannkoenig@chromium.org
51593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgstatic INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
51693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                                MV_REFERENCE_FRAME ref0,
51793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                                MV_REFERENCE_FRAME ref1) {
51876e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
51976e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                                         : 0];
52076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org  xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
52176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                                         : 0];
522dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org}
523dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
52441294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.orgstatic INLINE int get_chessboard_index(const int frame_index) {
52541294d96d7dbf9bc215b09832a8336c5fb158f0bjohannkoenig@chromium.org  return frame_index & 0x1;
52688b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org}
52788b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org
528d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.orgstatic INLINE int *cond_sad_list(const struct VP9_COMP *cpi, int *sad_list) {
529d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org  return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? sad_list : NULL;
530d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org}
531d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
532dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
533dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org}  // extern "C"
534dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
535dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
536693441efe611de7ca09c00f4e79776f604b689f4joeyparrish@google.com#endif  // VP9_ENCODER_VP9_ENCODER_H_
537