2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
11 #ifndef VP9_ENCODER_VP9_ENCODER_H_
12 #define VP9_ENCODER_VP9_ENCODER_H_
16 #include "./vpx_config.h"
17 #include "vpx/internal/vpx_codec_internal.h"
18 #include "vpx/vp8cx.h"
19 #if CONFIG_INTERNAL_STATS
20 #include "vpx_dsp/ssim.h"
22 #include "vpx_dsp/variance.h"
23 #include "vpx_ports/system_state.h"
24 #include "vpx_util/vpx_thread.h"
26 #include "vp9/common/vp9_alloccommon.h"
27 #include "vp9/common/vp9_ppflags.h"
28 #include "vp9/common/vp9_entropymode.h"
29 #include "vp9/common/vp9_thread_common.h"
30 #include "vp9/common/vp9_onyxc_int.h"
32 #include "vp9/encoder/vp9_alt_ref_aq.h"
33 #include "vp9/encoder/vp9_aq_cyclicrefresh.h"
34 #include "vp9/encoder/vp9_context_tree.h"
35 #include "vp9/encoder/vp9_encodemb.h"
36 #include "vp9/encoder/vp9_ethread.h"
37 #include "vp9/encoder/vp9_firstpass.h"
38 #include "vp9/encoder/vp9_job_queue.h"
39 #include "vp9/encoder/vp9_lookahead.h"
40 #include "vp9/encoder/vp9_mbgraph.h"
41 #include "vp9/encoder/vp9_mcomp.h"
42 #include "vp9/encoder/vp9_noise_estimate.h"
43 #include "vp9/encoder/vp9_quantize.h"
44 #include "vp9/encoder/vp9_ratectrl.h"
45 #include "vp9/encoder/vp9_rd.h"
46 #include "vp9/encoder/vp9_speed_features.h"
47 #include "vp9/encoder/vp9_svc_layercontext.h"
48 #include "vp9/encoder/vp9_tokenize.h"
50 #if CONFIG_VP9_TEMPORAL_DENOISING
51 #include "vp9/encoder/vp9_denoiser.h"
58 // vp9 uses 10,000,000 ticks/second as time stamp
59 #define TICKS_PER_SEC 10000000
62 int nmvjointcost[MV_JOINTS];
63 int nmvcosts[2][MV_VALS];
64 int nmvcosts_hp[2][MV_VALS];
66 vpx_prob segment_pred_probs[PREDICTION_PROBS];
68 unsigned char *last_frame_seg_map_copy;
70 // 0 = Intra, Last, GF, ARF
71 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
73 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
79 // encode_breakout is disabled.
80 ENCODE_BREAKOUT_DISABLED = 0,
81 // encode_breakout is enabled.
82 ENCODE_BREAKOUT_ENABLED = 1,
83 // encode_breakout is enabled with small max_thresh limit.
84 ENCODE_BREAKOUT_LIMITED = 2
85 } ENCODE_BREAKOUT_TYPE;
95 // Good Quality Fast Encoding. The encoder balances quality with the amount of
96 // time it takes to encode the output. Speed setting controls how fast.
99 // The encoder places priority on the quality of the output over encoding
100 // speed. The output is compressed at the highest possible quality. This
101 // option takes the longest amount of time to encode. Speed setting ignored.
104 // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
105 // example, capturing a television signal or feed from a live camera). Speed
106 // setting controls how fast.
111 FRAMEFLAGS_KEY = 1 << 0,
112 FRAMEFLAGS_GOLDEN = 1 << 1,
113 FRAMEFLAGS_ALTREF = 1 << 2,
120 CYCLIC_REFRESH_AQ = 3,
122 // AQ based on lookahead temporal
123 // variance (only valid for altref frames)
125 AQ_MODE_COUNT // This should always be the last member of the enum
129 RESIZE_NONE = 0, // No frame resizing allowed (except for SVC).
130 RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
131 RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.
136 kLowSadLowSumdiff = 1,
137 kLowSadHighSumdiff = 2,
138 kHighSadLowSumdiff = 3,
139 kHighSadHighSumdiff = 4,
140 kLowVarHighSumdiff = 5,
143 typedef struct VP9EncoderConfig {
144 BITSTREAM_PROFILE profile;
145 vpx_bit_depth_t bit_depth; // Codec bit-depth.
146 int width; // width of data passed to the compressor
147 int height; // height of data passed to the compressor
148 unsigned int input_bit_depth; // Input bit depth.
149 double init_framerate; // set to passed in framerate
150 int64_t target_bandwidth; // bandwidth to be used in bits per second
152 int noise_sensitivity; // pre processing blur: recommendation 0
153 int sharpness; // sharpening output: recommendation 0:
155 // maximum allowed bitrate for any intra frame in % of bitrate target.
156 unsigned int rc_max_intra_bitrate_pct;
157 // maximum allowed bitrate for any inter frame in % of bitrate target.
158 unsigned int rc_max_inter_bitrate_pct;
159 // percent of rate boost for golden frame in CBR mode.
160 unsigned int gf_cbr_boost_pct;
165 // Key Framing Operations
166 int auto_key; // autodetect cut scenes and set the keyframes
167 int key_freq; // maximum distance to key frame.
169 int lag_in_frames; // how many frames lag before we start encoding
171 // ----------------------------------------------------------------
172 // DATARATE CONTROL OPTIONS
174 // vbr, cbr, constrained quality or constant quality
175 enum vpx_rc_mode rc_mode;
177 // buffer targeting aggressiveness
181 // buffering parameters
182 int64_t starting_buffer_level_ms;
183 int64_t optimal_buffer_level_ms;
184 int64_t maximum_buffer_size_ms;
186 // Frame drop threshold.
187 int drop_frames_water_mark;
189 // controlling quality
194 AQ_MODE aq_mode; // Adaptive Quantization mode
196 // Special handling of Adaptive Quantization for AltRef frames
199 // Internal frame size scaling.
200 RESIZE_TYPE resize_mode;
201 int scaled_frame_width;
202 int scaled_frame_height;
204 // Enable feature to reduce the frame quantization every x frames.
205 int frame_periodic_boost;
207 // two pass datarate control
208 int two_pass_vbrbias; // two pass datarate control tweaks
209 int two_pass_vbrmin_section;
210 int two_pass_vbrmax_section;
211 // END DATARATE CONTROL OPTIONS
212 // ----------------------------------------------------------------
214 // Spatial and temporal scalability.
215 int ss_number_layers; // Number of spatial layers.
216 int ts_number_layers; // Number of temporal layers.
217 // Bitrate allocation for spatial layers.
218 int layer_target_bitrate[VPX_MAX_LAYERS];
219 int ss_target_bitrate[VPX_SS_MAX_LAYERS];
220 int ss_enable_auto_arf[VPX_SS_MAX_LAYERS];
221 // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
222 int ts_rate_decimator[VPX_TS_MAX_LAYERS];
226 int encode_breakout; // early breakout : for video conf recommend 800
228 /* Bitfield defining the error resiliency features to enable.
229 * Can provide decodable frames after losses in previous
230 * frames and decodable partitions after losses in the same frame.
232 unsigned int error_resilient_mode;
234 /* Bitfield defining the parallel decoding mode where the
235 * decoding in successive frames may be conducted in parallel
236 * just by decoding the frame headers.
238 unsigned int frame_parallel_decoding_mode;
251 unsigned int target_level;
253 vpx_fixed_buf_t two_pass_stats_in;
254 struct vpx_codec_pkt_list *output_pkt_list;
256 #if CONFIG_FP_MB_STATS
257 vpx_fixed_buf_t firstpass_mb_stats_in;
261 vp9e_tune_content content;
262 #if CONFIG_VP9_HIGHBITDEPTH
263 int use_highbitdepth;
265 vpx_color_space_t color_space;
266 vpx_color_range_t color_range;
269 VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
272 unsigned int motion_vector_unit_test;
275 static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
276 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
279 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
280 typedef struct TileDataEnc {
282 int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
283 int mode_map[BLOCK_SIZES][MAX_MODES];
284 FIRSTPASS_DATA fp_data;
285 VP9RowMTSync row_mt_sync;
287 // Used for adaptive_rd_thresh with row multithreading
288 int *row_base_thresh_freq_fact;
291 typedef struct RowMTInfo {
292 JobQueueHandle job_queue_hdl;
293 #if CONFIG_MULTITHREAD
294 pthread_mutex_t job_mutex;
304 typedef struct MultiThreadHandle {
305 int allocated_tile_rows;
306 int allocated_tile_cols;
307 int allocated_vert_unit_rows;
309 // Frame level params
310 int num_tile_vert_sbs[MAX_NUM_TILE_ROWS];
312 // Job Queue structure and handles
315 int jobs_per_tile_col;
317 RowMTInfo row_mt_info[MAX_NUM_TILE_COLS];
318 int thread_id_to_tile_id[MAX_NUM_THREADS]; // Mapping of threads to tiles
321 typedef struct RD_COUNTS {
322 vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
323 int64_t comp_pred_diff[REFERENCE_MODES];
324 int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
327 typedef struct ThreadData {
330 FRAME_COUNTS *counts;
332 PICK_MODE_CONTEXT *leaf_tree;
337 struct EncWorkerData;
339 typedef struct ActiveMap {
345 typedef enum { Y, U, V, ALL } STAT_TYPE;
347 typedef struct IMAGE_STAT {
348 double stat[ALL + 1];
352 // Kf noise filtering currently disabled by default in build.
353 // #define ENABLE_KF_DENOISE 1
355 #define CPB_WINDOW_SIZE 4
356 #define FRAME_WINDOW_SIZE 128
357 #define SAMPLE_RATE_GRACE_P 0.015
358 #define VP9_LEVELS 14
381 uint64_t max_luma_sample_rate;
382 uint32_t max_luma_picture_size;
383 double average_bitrate; // in kilobits per second
384 double max_cpb_size; // in kilobits
385 double compression_ratio;
386 uint8_t max_col_tiles;
387 uint32_t min_altref_distance;
388 uint8_t max_ref_frame_buffers;
391 extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS];
394 int64_t ts; // timestamp
395 uint32_t luma_samples;
396 uint32_t size; // in bytes
400 FrameRecord buf[FRAME_WINDOW_SIZE];
406 uint8_t seen_first_altref;
407 uint32_t frames_since_last_altref;
408 uint64_t total_compressed_size;
409 uint64_t total_uncompressed_size;
410 double time_encoded; // in seconds
411 FrameWindowBuffer frame_window_buffer;
416 Vp9LevelStats level_stats;
417 Vp9LevelSpec level_spec;
421 BITRATE_TOO_LARGE = 0,
422 LUMA_PIC_SIZE_TOO_LARGE = 1,
423 LUMA_SAMPLE_RATE_TOO_LARGE = 2,
425 COMPRESSION_RATIO_TOO_SMALL = 4,
426 TOO_MANY_COLUMN_TILE = 5,
427 ALTREF_DIST_TOO_SMALL = 6,
428 TOO_MANY_REF_BUFFER = 7,
429 TARGET_LEVEL_FAIL_IDS = 8
430 } TARGET_LEVEL_FAIL_ID;
434 uint8_t rc_config_updated;
436 int max_frame_size; // in bits
437 double max_cpb_size; // in bits
440 typedef struct ARNRFilterData {
441 YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
445 struct scale_factors sf;
448 typedef struct VP9_COMP {
451 MB_MODE_INFO_EXT *mbmi_ext_base;
452 DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
453 DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
455 VP9EncoderConfig oxcf;
456 struct lookahead_ctx *lookahead;
457 struct lookahead_entry *alt_ref_source;
459 YV12_BUFFER_CONFIG *Source;
460 YV12_BUFFER_CONFIG *Last_Source; // NULL for first frame and alt_ref frames
461 YV12_BUFFER_CONFIG *un_scaled_source;
462 YV12_BUFFER_CONFIG scaled_source;
463 YV12_BUFFER_CONFIG *unscaled_last_source;
464 YV12_BUFFER_CONFIG scaled_last_source;
465 #ifdef ENABLE_KF_DENOISE
466 YV12_BUFFER_CONFIG raw_unscaled_source;
467 YV12_BUFFER_CONFIG raw_scaled_source;
469 YV12_BUFFER_CONFIG *raw_source_frame;
471 TileDataEnc *tile_data;
472 int allocated_tiles; // Keep track of memory allocated for tiles.
474 // For a still frame, this flag is set to 1 to skip partition search.
475 int partition_search_skippable_frame;
477 int scaled_ref_idx[MAX_REF_FRAMES];
482 int refresh_last_frame;
483 int refresh_golden_frame;
484 int refresh_alt_ref_frame;
486 int ext_refresh_frame_flags_pending;
487 int ext_refresh_last_frame;
488 int ext_refresh_golden_frame;
489 int ext_refresh_alt_ref_frame;
491 int ext_refresh_frame_context_pending;
492 int ext_refresh_frame_context;
494 YV12_BUFFER_CONFIG last_frame_uf;
496 TOKENEXTRA *tile_tok[4][1 << 6];
497 uint32_t tok_count[4][1 << 6];
498 TOKENLIST *tplist[4][1 << 6];
500 // Ambient reconstruction err target for force key frames
505 CODING_CONTEXT coding_context;
510 int *nmvsadcosts_hp[2];
512 int64_t last_time_stamp_seen;
513 int64_t last_end_time_stamp_seen;
514 int64_t first_time_stamp_ever;
519 int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
521 struct vpx_codec_pkt_list *output_pkt_list;
523 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
524 int mbgraph_n_frames; // number of frames filled in the above
525 int static_mb_pct; // % forced skip mbs by segmentation
530 uint32_t max_mv_magnitude;
533 int allow_comp_inter_inter;
535 // Default value is 1. From first pass stats, encode_breakout may be disabled.
536 ENCODE_BREAKOUT_TYPE allow_encode_breakout;
538 // Get threshold from external input. A suggested threshold is 800 for HD
539 // clips, and 300 for < HD clips.
542 uint8_t *segmentation_map;
544 // segment threashold for encode breakout
545 int segment_encode_breakout[MAX_SEGMENTS];
547 CYCLIC_REFRESH *cyclic_refresh;
548 ActiveMap active_map;
550 fractional_mv_step_fp *find_fractional_mv_step;
551 vp9_full_search_fn_t full_search_sad;
552 vp9_diamond_search_fn_t diamond_search_sad;
553 vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
554 uint64_t time_receive_data;
555 uint64_t time_compress_data;
556 uint64_t time_pick_lpf;
557 uint64_t time_encode_sb_row;
559 #if CONFIG_FP_MB_STATS
565 // Force recalculation of segment_ids for each mode info
566 uint8_t force_update_segmentation;
568 YV12_BUFFER_CONFIG alt_ref_buffer;
570 // class responsible for adaptive
571 // quantization of altref frames
572 struct ALT_REF_AQ *alt_ref_aq;
574 #if CONFIG_INTERNAL_STATS
575 unsigned int mode_chosen_counts[MAX_MODES];
578 uint64_t total_sq_error;
579 uint64_t total_samples;
582 uint64_t totalp_sq_error;
583 uint64_t totalp_samples;
586 double total_blockiness;
587 double worst_blockiness;
590 double summed_quality;
591 double summed_weights;
592 double summedp_quality;
593 double summedp_weights;
594 unsigned int tot_recode_hits;
601 int b_calculate_ssimg;
602 int b_calculate_blockiness;
604 int b_calculate_consistency;
606 double total_inconsistency;
607 double worst_consistency;
611 int b_calculate_psnr;
617 int initial_mbs; // Number of MBs in the full-size frame; to be used to
618 // normalize the firstpass stats. This will differ from the
619 // number of MBs in the current frame when the frame is
626 // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
627 diff *source_diff_var;
628 // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
629 unsigned int source_var_thresh;
630 int frames_till_next_var_check;
634 search_site_config ss_cfg;
636 int mbmode_cost[INTRA_MODES];
637 unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
638 int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES][INTRA_MODES];
639 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
640 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
641 int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
643 int multi_arf_allowed;
644 int multi_arf_enabled;
645 int multi_arf_last_grp_enabled;
647 #if CONFIG_VP9_TEMPORAL_DENOISING
648 VP9_DENOISER denoiser;
652 RESIZE_STATE resize_state;
654 int resize_scale_num;
655 int resize_scale_den;
657 int resize_buffer_underflow;
660 int use_skin_detection;
664 NOISE_ESTIMATE noise_estimate;
666 // Count on how many consecutive times a block uses small/zeromv for encoding.
667 uint8_t *consec_zero_mv;
669 // VAR_BASED_PARTITION thresholds
670 // 0 - threshold_64x64; 1 - threshold_32x32;
671 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
672 int64_t vbp_thresholds[4];
673 int64_t vbp_threshold_minmax;
674 int64_t vbp_threshold_sad;
675 // Threshold used for partition copy
676 int64_t vbp_threshold_copy;
677 BLOCK_SIZE vbp_bsize_min;
682 struct EncWorkerData *tile_thr_data;
683 VP9LfSync lf_row_sync;
684 struct VP9BitstreamWorkerData *vp9_bitstream_worker_data;
686 int keep_level_stats;
687 Vp9LevelInfo level_info;
688 MultiThreadHandle multi_thread_ctxt;
689 void (*row_mt_sync_read_ptr)(VP9RowMTSync *const, int, int);
690 void (*row_mt_sync_write_ptr)(VP9RowMTSync *const, int, int, const int);
691 ARNRFilterData arnr_filter_data;
694 unsigned int row_mt_bit_exact;
696 // Previous Partition Info
697 BLOCK_SIZE *prev_partition;
698 int8_t *prev_segment_id;
699 // Used to save the status of whether a block has a low variance in
700 // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
701 // 32x32, 9~24 for 16x16.
702 // This is for the last frame and is copied to the current frame
703 // when partition copy happens.
704 uint8_t *prev_variance_low;
705 uint8_t *copied_frame_cnt;
706 uint8_t max_copied_frame;
708 // For each superblock: keeps track of the last time (in frame distance) the
709 // the superblock did not have low source sad.
710 uint8_t *content_state_sb_fd;
712 int compute_source_sad_onepass;
714 LevelConstraint level_constraint;
717 void vp9_initialize_enc(void);
719 struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
720 BufferPool *const pool);
721 void vp9_remove_compressor(VP9_COMP *cpi);
723 void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
725 // receive a frames worth of data. caller can assume that a copy of this
726 // frame is made and not just a copy of the pointer..
727 int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags,
728 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
729 int64_t end_time_stamp);
731 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
732 size_t *size, uint8_t *dest, int64_t *time_stamp,
733 int64_t *time_end, int flush);
735 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
736 vp9_ppflags_t *flags);
738 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
740 void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
742 int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
743 YV12_BUFFER_CONFIG *sd);
745 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
746 YV12_BUFFER_CONFIG *sd);
748 int vp9_update_entropy(VP9_COMP *cpi, int update);
750 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
752 int vp9_get_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
754 int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING horiz_mode,
755 VPX_SCALING vert_mode);
757 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
758 unsigned int height);
760 void vp9_set_svc(VP9_COMP *cpi, int use_svc);
762 int vp9_get_quantizer(struct VP9_COMP *cpi);
764 static INLINE int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
765 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
766 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
769 static INLINE int get_ref_frame_map_idx(const VP9_COMP *cpi,
770 MV_REFERENCE_FRAME ref_frame) {
771 if (ref_frame == LAST_FRAME) {
772 return cpi->lst_fb_idx;
773 } else if (ref_frame == GOLDEN_FRAME) {
774 return cpi->gld_fb_idx;
776 return cpi->alt_fb_idx;
780 static INLINE int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
782 const VP9_COMMON *const cm = &cpi->common;
783 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
784 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
787 static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
788 VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
789 VP9_COMMON *const cm = &cpi->common;
790 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
791 return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
795 static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
796 // TODO(JBB): double check we can't exceed this token count if we have a
797 // 32x32 transform crossing a boundary at a multiple of 16.
798 // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
799 // resolution. We assume up to 1 token per pixel, and then allow
801 return mb_rows * mb_cols * (16 * 16 * 3 + 4);
804 // Get the allocated token size for a tile. It does the same calculation as in
805 // the frame token allocation.
806 static INLINE int allocated_tokens(TileInfo tile) {
807 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
808 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
810 return get_token_alloc(tile_mb_rows, tile_mb_cols);
813 static INLINE void get_start_tok(VP9_COMP *cpi, int tile_row, int tile_col,
814 int mi_row, TOKENEXTRA **tok) {
815 VP9_COMMON *const cm = &cpi->common;
816 const int tile_cols = 1 << cm->log2_tile_cols;
817 TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col];
818 const TileInfo *const tile_info = &this_tile->tile_info;
820 int tile_mb_cols = (tile_info->mi_col_end - tile_info->mi_col_start + 1) >> 1;
821 const int mb_row = (mi_row - tile_info->mi_row_start) >> 1;
824 cpi->tile_tok[tile_row][tile_col] + get_token_alloc(mb_row, tile_mb_cols);
827 int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
828 #if CONFIG_VP9_HIGHBITDEPTH
829 int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
830 const YV12_BUFFER_CONFIG *b);
831 #endif // CONFIG_VP9_HIGHBITDEPTH
833 void vp9_scale_references(VP9_COMP *cpi);
835 void vp9_update_reference_frames(VP9_COMP *cpi);
837 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
839 YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(
840 VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled,
841 YV12_BUFFER_CONFIG *scaled_temp, INTERP_FILTER filter_type,
842 int phase_scaler, INTERP_FILTER filter_type2, int phase_scaler2);
844 YV12_BUFFER_CONFIG *vp9_scale_if_required(
845 VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled,
846 int use_normative_scaler, INTERP_FILTER filter_type, int phase_scaler);
848 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
850 static INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
851 return cpi->use_svc && cpi->oxcf.pass != 0;
854 static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) {
855 return (cpi->use_svc && cpi->oxcf.pass == 0);
858 #if CONFIG_VP9_TEMPORAL_DENOISING
859 static INLINE int denoise_svc(const struct VP9_COMP *const cpi) {
860 return (!cpi->use_svc ||
862 cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1));
866 static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
867 return !(cpi->oxcf.mode == REALTIME && cpi->oxcf.rc_mode == VPX_CBR) &&
868 cpi->oxcf.lag_in_frames > 0 &&
869 (cpi->oxcf.enable_auto_arf &&
870 (!is_two_pass_svc(cpi) ||
871 cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]));
874 static INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
875 MV_REFERENCE_FRAME ref0,
876 MV_REFERENCE_FRAME ref1) {
878 &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
880 &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
883 static INLINE int get_chessboard_index(const int frame_index) {
884 return frame_index & 0x1;
887 static INLINE int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
888 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
891 static INLINE int get_num_vert_units(TileInfo tile, int shift) {
893 (tile.mi_row_end - tile.mi_row_start + (1 << shift) - 1) >> shift;
894 return num_vert_units;
897 static INLINE int get_num_cols(TileInfo tile, int shift) {
899 (tile.mi_col_end - tile.mi_col_start + (1 << shift) - 1) >> shift;
903 static INLINE int get_level_index(VP9_LEVEL level) {
905 for (i = 0; i < VP9_LEVELS; ++i) {
906 if (level == vp9_level_defs[i].level) return i;
911 VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec);
913 void vp9_new_framerate(VP9_COMP *cpi, double framerate);
915 void vp9_set_row_mt(VP9_COMP *cpi);
917 #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
923 #endif // VP9_ENCODER_VP9_ENCODER_H_