Bug Summary

File:root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h
Warning:line 593, column 16
Excessive padding in 'struct VP9_COMP' (79 padding bytes, where 15 is optimal). Optimal fields order: y_dequant, uv_dequant, common, quants, td, mbmi_ext_base, lookahead, alt_ref_source, Source, Last_Source, un_scaled_source, unscaled_last_source, raw_source_frame, kmeans_data_arr, tile_data, norm_wiener_variance, mb_wiener_variance, mi_ssim_rdmult_scaling_factors, sb_mul_scale, ambient_err, last_time_stamp_seen, last_end_time_stamp_seen, first_time_stamp_ever, framerate, output_pkt_list, segmentation_map, skin_map, cyclic_refresh, find_fractional_mv_step, diamond_search_sad, alt_ref_aq, consec_zero_mv, vbp_threshold_minmax, vbp_threshold_sad, vbp_threshold_copy, workers, tile_thr_data, vp9_bitstream_worker_data, row_mt_sync_read_ptr, row_mt_sync_write_ptr, prev_partition, prev_segment_id, prev_variance_low, copied_frame_cnt, content_state_sb_fd, count_arf_frame_usage, count_lastgolden_frame_usage, tpl_gop_stats, nmvcosts, nmvcosts_hp, nmvsadcosts, nmvsadcosts_hp, active_map, level_constraint, rd_ctrl, vbp_thresholds, kmeans_mutex, tpl_recon_frames, kmeans_ctr_ls, kmeans_boundary_ls, lf_row_sync, me_sf, scaled_source, scaled_last_source, last_frame_uf, tf_buffer, roi, ext_ratectrl, mbgraph_stats, arnr_filter_data, oxcf, sf, rc, fn_ptr, ss_cfg, enc_frame_buf, tpl_stats, tile_tok, tplist, level_info, multi_thread_ctxt, twopass, rd, svc, coding_context, kmeans_data_arr_alloc, kmeans_data_size, kmeans_data_stride, kmeans_ctr_num, allocated_tiles, lst_fb_idx, gld_fb_idx, alt_fb_idx, refresh_last_frame, refresh_golden_frame, refresh_alt_ref_frame, ext_refresh_frame_flags_pending, ext_refresh_last_frame, ext_refresh_golden_frame, ext_refresh_alt_ref_frame, ext_refresh_frame_context_pending, ext_refresh_frame_context, mb_wiener_var_rows, mb_wiener_var_cols, mi_ssim_rdmult_scaling_factors_rows, mi_ssim_rdmult_scaling_factors_cols, mbgraph_n_frames, static_mb_pct, ref_frame_flags, max_mv_magnitude, mv_step_param, allow_comp_inter_inter, allow_encode_breakout, encode_breakout, b_calculate_psnr, droppable, initial_width, initial_height, initial_mbs, last_coded_width, last_coded_height, use_svc, frame_flags, resize_pending, resize_state, external_resize, resize_scale_num, resize_scale_den, resize_avg_qp, resize_buffer_underflow, resize_count, use_skin_detection, target_level, num_workers, keep_level_stats, row_mt, row_mt_bit_exact, compute_source_sad_onepass, compute_frame_low_motion_onepass, multi_layer_arf, loopfilter_ctrl, fixed_qp_onepass, deadline_mode_previous_frame, disable_scene_detection_rtc_ratectrl, scaled_ref_idx, kmeans_count_ls, ref_fb_idx, segment_encode_breakout, noise_estimate, frame_info, mbmode_cost, switchable_interp_costs, tx_size_cost, inter_mode_cost, interp_filter_selected, partition_cost, intra_uv_mode_cost, y_mode_costs, tpl_bsize, force_update_segmentation, vbp_bsize_min, max_copied_frame, last_frame_dropped, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name vp9_alt_ref_aq.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libvpx -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libvpx -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_CONFIG_H=vpx_config.h -D MOZ_HAS_MOZGLUE -I /root/firefox-clang/media/libvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libvpx -I /root/firefox-clang/media/libvpx/config/linux/x64 -I /root/firefox-clang/media/libvpx/config -I /root/firefox-clang/media/libvpx/libvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-sign-compare -Wno-unused-function -Wno-unreachable-code -Wno-unneeded-internal-declaration -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_alt_ref_aq.c
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 VPX_VP9_ENCODER_VP9_ENCODER_H_
12#define VPX_VP9_ENCODER_VP9_ENCODER_H_
13
14#include <stdio.h>
15
16#include "./vpx_config.h"
17#include "./vpx_dsp_rtcd.h"
18#include "vpx/internal/vpx_codec_internal.h"
19#include "vpx/vpx_ext_ratectrl.h"
20#include "vpx/vp8cx.h"
21#include "vpx/vpx_tpl.h"
22#if CONFIG_INTERNAL_STATS0
23#include "vpx_dsp/ssim.h"
24#endif
25#include "vpx_dsp/variance.h"
26#include "vpx_dsp/psnr.h"
27#include "vpx_ports/system_state.h"
28#include "vpx_util/vpx_pthread.h"
29#include "vpx_util/vpx_thread.h"
30#include "vpx_util/vpx_timestamp.h"
31
32#include "vp9/common/vp9_alloccommon.h"
33#include "vp9/common/vp9_ppflags.h"
34#include "vp9/common/vp9_entropymode.h"
35#include "vp9/common/vp9_thread_common.h"
36#include "vp9/common/vp9_onyxc_int.h"
37
38#if !CONFIG_REALTIME_ONLY0
39#include "vp9/encoder/vp9_alt_ref_aq.h"
40#endif
41#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
42#include "vp9/encoder/vp9_context_tree.h"
43#include "vp9/encoder/vp9_encodemb.h"
44#include "vp9/encoder/vp9_ethread.h"
45#include "vp9/encoder/vp9_ext_ratectrl.h"
46#include "vp9/encoder/vp9_firstpass.h"
47#include "vp9/encoder/vp9_job_queue.h"
48#include "vp9/encoder/vp9_lookahead.h"
49#include "vp9/encoder/vp9_mbgraph.h"
50#include "vp9/encoder/vp9_mcomp.h"
51#include "vp9/encoder/vp9_noise_estimate.h"
52#include "vp9/encoder/vp9_quantize.h"
53#include "vp9/encoder/vp9_ratectrl.h"
54#include "vp9/encoder/vp9_rd.h"
55#include "vp9/encoder/vp9_speed_features.h"
56#include "vp9/encoder/vp9_svc_layercontext.h"
57#include "vp9/encoder/vp9_tokenize.h"
58
59#if CONFIG_VP9_TEMPORAL_DENOISING0
60#include "vp9/encoder/vp9_denoiser.h"
61#endif
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67// vp9 uses 10,000,000 ticks/second as time stamp
68#define TICKS_PER_SEC10000000 10000000
69
70typedef struct {
71 int nmvjointcost[MV_JOINTS4];
72 int nmvcosts[2][MV_VALS((((1 << (11 + 1 + 2)) - 1) << 1) + 1)];
73 int nmvcosts_hp[2][MV_VALS((((1 << (11 + 1 + 2)) - 1) << 1) + 1)];
74
75 vpx_prob segment_pred_probs[PREDICTION_PROBS3];
76
77 unsigned char *last_frame_seg_map_copy;
78
79 // 0 = Intra, Last, GF, ARF
80 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS4];
81 // 0 = ZERO_MV, MV
82 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS2];
83
84 FRAME_CONTEXT fc;
85} CODING_CONTEXT;
86
87typedef enum {
88 // encode_breakout is disabled.
89 ENCODE_BREAKOUT_DISABLED = 0,
90 // encode_breakout is enabled.
91 ENCODE_BREAKOUT_ENABLED = 1,
92 // encode_breakout is enabled with small max_thresh limit.
93 ENCODE_BREAKOUT_LIMITED = 2
94} ENCODE_BREAKOUT_TYPE;
95
96typedef enum {
97 // Good Quality Fast Encoding. The encoder balances quality with the amount of
98 // time it takes to encode the output. Speed setting controls how fast.
99 GOOD,
100
101 // The encoder places priority on the quality of the output over encoding
102 // speed. The output is compressed at the highest possible quality. This
103 // option takes the longest amount of time to encode. Speed setting ignored.
104 BEST,
105
106 // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
107 // example, capturing a television signal or feed from a live camera). Speed
108 // setting controls how fast.
109 REALTIME
110} MODE;
111
112typedef enum {
113 FRAMEFLAGS_KEY = 1 << 0,
114 FRAMEFLAGS_GOLDEN = 1 << 1,
115 FRAMEFLAGS_ALTREF = 1 << 2,
116} FRAMETYPE_FLAGS;
117
118typedef enum {
119 NO_AQ = 0,
120 VARIANCE_AQ = 1,
121 COMPLEXITY_AQ = 2,
122 CYCLIC_REFRESH_AQ = 3,
123 EQUATOR360_AQ = 4,
124 PERCEPTUAL_AQ = 5,
125 PSNR_AQ = 6,
126 // AQ based on lookahead temporal
127 // variance (only valid for altref frames)
128 LOOKAHEAD_AQ = 7,
129 AQ_MODE_COUNT // This should always be the last member of the enum
130} AQ_MODE;
131
132typedef enum {
133 RESIZE_NONE = 0, // No frame resizing allowed (except for SVC).
134 RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
135 RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.
136} RESIZE_TYPE;
137
138typedef enum {
139 kInvalid = 0,
140 kLowSadLowSumdiff = 1,
141 kLowSadHighSumdiff = 2,
142 kHighSadLowSumdiff = 3,
143 kHighSadHighSumdiff = 4,
144 kLowVarHighSumdiff = 5,
145 kVeryHighSad = 6,
146} CONTENT_STATE_SB;
147
148typedef enum {
149 LOOPFILTER_ALL = 0,
150 LOOPFILTER_REFERENCE = 1, // Disable loopfilter on non reference frames.
151 NO_LOOPFILTER = 2, // Disable loopfilter on all frames.
152} LOOPFILTER_CONTROL;
153
154typedef struct VP9EncoderConfig {
155 BITSTREAM_PROFILE profile;
156 vpx_bit_depth_t bit_depth; // Codec bit-depth.
157 int width; // width of data passed to the compressor
158 int height; // height of data passed to the compressor
159 unsigned int input_bit_depth; // Actual bit-depth of the input source
160 double init_framerate; // set to passed in framerate
161 vpx_rational_t g_timebase; // equivalent to g_timebase in vpx_codec_enc_cfg_t
162 vpx_rational64_t g_timebase_in_ts; // g_timebase * TICKS_PER_SEC
163
164 int64_t target_bandwidth; // bandwidth to be used in bits per second
165
166 int noise_sensitivity; // pre processing blur: recommendation 0
167 int sharpness; // sharpening output: recommendation 0:
168 int speed;
169 // maximum allowed bitrate for any intra frame in % of bitrate target.
170 unsigned int rc_max_intra_bitrate_pct;
171 // maximum allowed bitrate for any inter frame in % of bitrate target.
172 unsigned int rc_max_inter_bitrate_pct;
173 // percent of rate boost for golden frame in CBR mode.
174 unsigned int gf_cbr_boost_pct;
175
176 MODE mode;
177 int pass;
178
179 // Key Framing Operations
180 int auto_key; // autodetect cut scenes and set the keyframes
181 int key_freq; // maximum distance to key frame.
182
183 int lag_in_frames; // how many frames lag before we start encoding
184
185 // ----------------------------------------------------------------
186 // DATARATE CONTROL OPTIONS
187
188 // vbr, cbr, constrained quality or constant quality
189 enum vpx_rc_mode rc_mode;
190
191 // buffer targeting aggressiveness
192 int under_shoot_pct;
193 int over_shoot_pct;
194
195 // buffering parameters
196 int64_t starting_buffer_level_ms;
197 int64_t optimal_buffer_level_ms;
198 int64_t maximum_buffer_size_ms;
199
200 // Frame drop threshold.
201 int drop_frames_water_mark;
202
203 // controlling quality
204 int fixed_q;
205 int worst_allowed_q;
206 int best_allowed_q;
207 int cq_level;
208 AQ_MODE aq_mode; // Adaptive Quantization mode
209
210 // Special handling of Adaptive Quantization for AltRef frames
211 int alt_ref_aq;
212
213 // Internal frame size scaling.
214 RESIZE_TYPE resize_mode;
215 int scaled_frame_width;
216 int scaled_frame_height;
217
218 // Enable feature to reduce the frame quantization every x frames.
219 int frame_periodic_boost;
220
221 // two pass datarate control
222 int two_pass_vbrbias; // two pass datarate control tweaks
223 int two_pass_vbrmin_section;
224 int two_pass_vbrmax_section;
225 int vbr_corpus_complexity; // 0 indicates corpus vbr disabled
226 // END DATARATE CONTROL OPTIONS
227 // ----------------------------------------------------------------
228
229 // Spatial and temporal scalability.
230 int ss_number_layers; // Number of spatial layers.
231 int ts_number_layers; // Number of temporal layers.
232 // Bitrate allocation for spatial layers.
233 int layer_target_bitrate[VPX_MAX_LAYERS12];
234 int ss_target_bitrate[VPX_SS_MAX_LAYERS5];
235 int ss_enable_auto_arf[VPX_SS_MAX_LAYERS5];
236 // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
237 int ts_rate_decimator[VPX_TS_MAX_LAYERS5];
238
239 int enable_auto_arf;
240
241 int encode_breakout; // early breakout : for video conf recommend 800
242
243 /* Bitfield defining the error resiliency features to enable.
244 * Can provide decodable frames after losses in previous
245 * frames and decodable partitions after losses in the same frame.
246 */
247 unsigned int error_resilient_mode;
248
249 /* Bitfield defining the parallel decoding mode where the
250 * decoding in successive frames may be conducted in parallel
251 * just by decoding the frame headers.
252 */
253 unsigned int frame_parallel_decoding_mode;
254
255 int arnr_max_frames;
256 int arnr_strength;
257
258 int min_gf_interval;
259 int max_gf_interval;
260
261 int tile_columns;
262 int tile_rows;
263
264 int enable_tpl_model;
265
266 int enable_keyframe_filtering;
267
268 int max_threads;
269
270 unsigned int target_level;
271
272 vpx_fixed_buf_t two_pass_stats_in;
273
274 vp8e_tuning tuning;
275 vp9e_tune_content content;
276#if CONFIG_VP9_HIGHBITDEPTH0
277 int use_highbitdepth;
278#endif
279 vpx_color_space_t color_space;
280 vpx_color_range_t color_range;
281 int render_width;
282 int render_height;
283 VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
284
285 int row_mt;
286 unsigned int motion_vector_unit_test;
287 int delta_q_uv;
288} VP9EncoderConfig;
289
290static INLINEinline int is_lossless_requested(const VP9EncoderConfig *cfg) {
291 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
292}
293
294typedef struct TplDepStats {
295 int64_t intra_cost;
296 int64_t inter_cost;
297 int64_t mc_flow;
298 int64_t mc_dep_cost;
299 int64_t mc_ref_cost;
300
301 int ref_frame_index;
302 int_mv mv;
303} TplDepStats;
304
305#if CONFIG_NON_GREEDY_MV0
306
307#define ZERO_MV_MODE 0
308#define NEW_MV_MODE 1
309#define NEAREST_MV_MODE 2
310#define NEAR_MV_MODE 3
311#define MAX_MV_MODE 4
312#endif
313
314typedef struct TplDepFrame {
315 uint8_t is_valid;
316 TplDepStats *tpl_stats_ptr;
317 int stride;
318 int width;
319 int height;
320 int mi_rows;
321 int mi_cols;
322 int base_qindex;
323#if CONFIG_NON_GREEDY_MV0
324 int lambda;
325 int *mv_mode_arr[3];
326 double *rd_diff_arr[3];
327#endif
328} TplDepFrame;
329
330#define TPL_DEP_COST_SCALE_LOG24 4
331
332// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
333typedef struct TileDataEnc {
334 TileInfo tile_info;
335 int thresh_freq_fact[BLOCK_SIZES13][MAX_MODES30];
336 int thresh_freq_fact_prev[BLOCK_SIZES13][MAX_MODES30];
337 int8_t mode_map[BLOCK_SIZES13][MAX_MODES30];
338 FIRSTPASS_DATA fp_data;
339 VP9RowMTSync row_mt_sync;
340
341 // Used for adaptive_rd_thresh with row multithreading
342 int *row_base_thresh_freq_fact;
343 // The value of sb_rows when row_base_thresh_freq_fact is allocated.
344 // The row_base_thresh_freq_fact array has sb_rows * BLOCK_SIZES * MAX_MODES
345 // elements.
346 int sb_rows;
347 MV firstpass_top_mv;
348} TileDataEnc;
349
350typedef struct RowMTInfo {
351 JobQueueHandle job_queue_hdl;
352#if CONFIG_MULTITHREAD1
353 pthread_mutex_t job_mutex;
354#endif
355} RowMTInfo;
356
357typedef struct {
358 TOKENEXTRA *start;
359 TOKENEXTRA *stop;
360 unsigned int count;
361} TOKENLIST;
362
363typedef struct MultiThreadHandle {
364 int allocated_tile_rows;
365 int allocated_tile_cols;
366 int allocated_vert_unit_rows;
367
368 // Frame level params
369 int num_tile_vert_sbs[MAX_NUM_TILE_ROWS4];
370
371 // Job Queue structure and handles
372 JobQueue *job_queue;
373
374 int jobs_per_tile_col;
375
376 RowMTInfo row_mt_info[MAX_NUM_TILE_COLS(1 << 6)];
377 int thread_id_to_tile_id[MAX_NUM_THREADS64]; // Mapping of threads to tiles
378} MultiThreadHandle;
379
380typedef struct RD_COUNTS {
381 vp9_coeff_count coef_counts[TX_SIZES((TX_SIZE)4)][PLANE_TYPES];
382 int64_t comp_pred_diff[REFERENCE_MODES];
383 int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS(3 + 1)];
384} RD_COUNTS;
385
386typedef struct ThreadData {
387 MACROBLOCK mb;
388 RD_COUNTS rd_counts;
389 FRAME_COUNTS *counts;
390
391 PICK_MODE_CONTEXT *leaf_tree;
392 PC_TREE *pc_tree;
393 PC_TREE *pc_root;
394} ThreadData;
395
396struct EncWorkerData;
397
398typedef struct ActiveMap {
399 int enabled;
400 int update;
401 unsigned char *map;
402} ActiveMap;
403
404typedef enum { Y, U, V, ALL } STAT_TYPE;
405
406typedef struct IMAGE_STAT {
407 double stat[ALL + 1];
408 double worst;
409} ImageStat;
410
411// Kf noise filtering currently disabled by default in build.
412// #define ENABLE_KF_DENOISE 1
413
414#define CPB_WINDOW_SIZE4 4
415#define FRAME_WINDOW_SIZE128 128
416#define SAMPLE_RATE_GRACE_P0.015 0.015
417#define VP9_LEVELS14 14
418
419typedef enum {
420 LEVEL_UNKNOWN = 0,
421 LEVEL_AUTO = 1,
422 LEVEL_1 = 10,
423 LEVEL_1_1 = 11,
424 LEVEL_2 = 20,
425 LEVEL_2_1 = 21,
426 LEVEL_3 = 30,
427 LEVEL_3_1 = 31,
428 LEVEL_4 = 40,
429 LEVEL_4_1 = 41,
430 LEVEL_5 = 50,
431 LEVEL_5_1 = 51,
432 LEVEL_5_2 = 52,
433 LEVEL_6 = 60,
434 LEVEL_6_1 = 61,
435 LEVEL_6_2 = 62,
436 LEVEL_MAX = 255
437} VP9_LEVEL;
438
439typedef struct {
440 VP9_LEVEL level;
441 uint64_t max_luma_sample_rate;
442 uint32_t max_luma_picture_size;
443 uint32_t max_luma_picture_breadth;
444 double average_bitrate; // in kilobits per second
445 double max_cpb_size; // in kilobits
446 double compression_ratio;
447 uint8_t max_col_tiles;
448 uint32_t min_altref_distance;
449 uint8_t max_ref_frame_buffers;
450} Vp9LevelSpec;
451
452extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS14];
453
454typedef struct {
455 int64_t ts; // timestamp
456 uint32_t luma_samples;
457 uint32_t size; // in bytes
458} FrameRecord;
459
460typedef struct {
461 FrameRecord buf[FRAME_WINDOW_SIZE128];
462 uint8_t start;
463 uint8_t len;
464} FrameWindowBuffer;
465
466typedef struct {
467 uint8_t seen_first_altref;
468 uint32_t frames_since_last_altref;
469 uint64_t total_compressed_size;
470 uint64_t total_uncompressed_size;
471 double time_encoded; // in seconds
472 FrameWindowBuffer frame_window_buffer;
473 int ref_refresh_map;
474} Vp9LevelStats;
475
476typedef struct {
477 Vp9LevelStats level_stats;
478 Vp9LevelSpec level_spec;
479} Vp9LevelInfo;
480
481typedef enum {
482 BITRATE_TOO_LARGE = 0,
483 LUMA_PIC_SIZE_TOO_LARGE,
484 LUMA_PIC_BREADTH_TOO_LARGE,
485 LUMA_SAMPLE_RATE_TOO_LARGE,
486 CPB_TOO_LARGE,
487 COMPRESSION_RATIO_TOO_SMALL,
488 TOO_MANY_COLUMN_TILE,
489 ALTREF_DIST_TOO_SMALL,
490 TOO_MANY_REF_BUFFER,
491 TARGET_LEVEL_FAIL_IDS
492} TARGET_LEVEL_FAIL_ID;
493
494typedef struct {
495 int8_t level_index;
496 uint8_t fail_flag;
497 int max_frame_size; // in bits
498 double max_cpb_size; // in bits
499} LevelConstraint;
500
501typedef struct ARNRFilterData {
502 YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS25];
503 int strength;
504 int frame_count;
505 int alt_ref_index;
506 struct scale_factors sf;
507 YV12_BUFFER_CONFIG *dst;
508} ARNRFilterData;
509
510typedef struct EncFrameBuf {
511 int mem_valid;
512 int released;
513 YV12_BUFFER_CONFIG frame;
514} EncFrameBuf;
515
516// Maximum operating frame buffer size needed for a GOP using ARF reference.
517// This is used to allocate the memory for TPL stats for a GOP.
518#define MAX_ARF_GOP_SIZE(2 * 25) (2 * MAX_LAG_BUFFERS25)
519#define MAX_KMEANS_GROUPS8 8
520
521typedef struct KMEANS_DATA {
522 double value;
523 int pos;
524 int group_idx;
525} KMEANS_DATA;
526
527#if CONFIG_COLLECT_COMPONENT_TIMING0
528#include "vpx_ports/vpx_timer.h"
529// Adjust the following to add new components.
530typedef enum {
531 vp9_get_compressed_data_time,
532 vp9_temporal_filter_time,
533 vp9_rc_get_second_pass_params_time,
534 setup_tpl_stats_time,
535 Pass2Encode_time,
536
537 encode_with_recode_loop_time,
538 loopfilter_frame_time,
539 vp9_pack_bitstream_time,
540
541 encode_frame_internal_time,
542 rd_pick_partition_time,
543 rd_pick_sb_modes_time,
544 encode_sb_time,
545
546 vp9_rd_pick_inter_mode_sb_time,
547 vp9_rd_pick_inter_mode_sub8x8_time,
548
549 intra_mode_search_time,
550 handle_inter_mode_time,
551 single_motion_search_time,
552 joint_motion_search_time,
553 interp_filter_time,
554
555 kTimingComponents,
556} TIMING_COMPONENT;
557
558static INLINEinline char const *get_component_name(int index) {
559 switch (index) {
560 case vp9_get_compressed_data_time: return "vp9_get_compressed_data_time";
561 case vp9_temporal_filter_time: return "vp9_temporal_filter_time";
562 case vp9_rc_get_second_pass_params_time:
563 return "vp9_rc_get_second_pass_params_time";
564 case setup_tpl_stats_time: return "setup_tpl_stats_time";
565 case Pass2Encode_time: return "Pass2Encode_time";
566
567 case encode_with_recode_loop_time: return "encode_with_recode_loop_time";
568 case loopfilter_frame_time: return "loopfilter_frame_time";
569 case vp9_pack_bitstream_time: return "vp9_pack_bitstream_time";
570
571 case encode_frame_internal_time: return "encode_frame_internal_time";
572 case rd_pick_partition_time: return "rd_pick_partition_time";
573 case rd_pick_sb_modes_time: return "rd_pick_sb_modes_time";
574 case encode_sb_time: return "encode_sb_time";
575
576 case vp9_rd_pick_inter_mode_sb_time:
577 return "vp9_rd_pick_inter_mode_sb_time";
578 case vp9_rd_pick_inter_mode_sub8x8_time:
579 return "vp9_rd_pick_inter_mode_sub8x8_time";
580
581 case intra_mode_search_time: return "intra_mode_search_time";
582 case handle_inter_mode_time: return "handle_inter_mode_time";
583 case single_motion_search_time: return "single_motion_search_time";
584 case joint_motion_search_time: return "joint_motion_search_time";
585 case interp_filter_time: return "interp_filter_time";
586
587 default: assert(0)((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail
("0", "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 587, __extension__ __PRETTY_FUNCTION__); }))
;
588 }
589 return "error";
590}
591#endif
592
593typedef struct VP9_COMP {
Excessive padding in 'struct VP9_COMP' (79 padding bytes, where 15 is optimal). Optimal fields order: y_dequant, uv_dequant, common, quants, td, mbmi_ext_base, lookahead, alt_ref_source, Source, Last_Source, un_scaled_source, unscaled_last_source, raw_source_frame, kmeans_data_arr, tile_data, norm_wiener_variance, mb_wiener_variance, mi_ssim_rdmult_scaling_factors, sb_mul_scale, ambient_err, last_time_stamp_seen, last_end_time_stamp_seen, first_time_stamp_ever, framerate, output_pkt_list, segmentation_map, skin_map, cyclic_refresh, find_fractional_mv_step, diamond_search_sad, alt_ref_aq, consec_zero_mv, vbp_threshold_minmax, vbp_threshold_sad, vbp_threshold_copy, workers, tile_thr_data, vp9_bitstream_worker_data, row_mt_sync_read_ptr, row_mt_sync_write_ptr, prev_partition, prev_segment_id, prev_variance_low, copied_frame_cnt, content_state_sb_fd, count_arf_frame_usage, count_lastgolden_frame_usage, tpl_gop_stats, nmvcosts, nmvcosts_hp, nmvsadcosts, nmvsadcosts_hp, active_map, level_constraint, rd_ctrl, vbp_thresholds, kmeans_mutex, tpl_recon_frames, kmeans_ctr_ls, kmeans_boundary_ls, lf_row_sync, me_sf, scaled_source, scaled_last_source, last_frame_uf, tf_buffer, roi, ext_ratectrl, mbgraph_stats, arnr_filter_data, oxcf, sf, rc, fn_ptr, ss_cfg, enc_frame_buf, tpl_stats, tile_tok, tplist, level_info, multi_thread_ctxt, twopass, rd, svc, coding_context, kmeans_data_arr_alloc, kmeans_data_size, kmeans_data_stride, kmeans_ctr_num, allocated_tiles, lst_fb_idx, gld_fb_idx, alt_fb_idx, refresh_last_frame, refresh_golden_frame, refresh_alt_ref_frame, ext_refresh_frame_flags_pending, ext_refresh_last_frame, ext_refresh_golden_frame, ext_refresh_alt_ref_frame, ext_refresh_frame_context_pending, ext_refresh_frame_context, mb_wiener_var_rows, mb_wiener_var_cols, mi_ssim_rdmult_scaling_factors_rows, mi_ssim_rdmult_scaling_factors_cols, mbgraph_n_frames, static_mb_pct, ref_frame_flags, max_mv_magnitude, mv_step_param, allow_comp_inter_inter, allow_encode_breakout, encode_breakout, b_calculate_psnr, droppable, initial_width, initial_height, initial_mbs, last_coded_width, last_coded_height, use_svc, frame_flags, resize_pending, resize_state, external_resize, resize_scale_num, resize_scale_den, resize_avg_qp, resize_buffer_underflow, resize_count, use_skin_detection, target_level, num_workers, keep_level_stats, row_mt, row_mt_bit_exact, compute_source_sad_onepass, compute_frame_low_motion_onepass, multi_layer_arf, loopfilter_ctrl, fixed_qp_onepass, deadline_mode_previous_frame, disable_scene_detection_rtc_ratectrl, scaled_ref_idx, kmeans_count_ls, ref_fb_idx, segment_encode_breakout, noise_estimate, frame_info, mbmode_cost, switchable_interp_costs, tx_size_cost, inter_mode_cost, interp_filter_selected, partition_cost, intra_uv_mode_cost, y_mode_costs, tpl_bsize, force_update_segmentation, vbp_bsize_min, max_copied_frame, last_frame_dropped, consider reordering the fields or adding explicit padding members
594 FRAME_INFO frame_info;
595 QUANTS quants;
596 ThreadData td;
597 MB_MODE_INFO_EXT *mbmi_ext_base;
598 DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8])int16_t y_dequant[(255 - 0 + 1)][8] __attribute__((aligned(16
)))
;
599 DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8])int16_t uv_dequant[(255 - 0 + 1)][8] __attribute__((aligned(16
)))
;
600 VP9_COMMON common;
601 VP9EncoderConfig oxcf;
602 struct lookahead_ctx *lookahead;
603 struct lookahead_entry *alt_ref_source;
604
605 YV12_BUFFER_CONFIG *Source;
606 YV12_BUFFER_CONFIG *Last_Source; // NULL for first frame and alt_ref frames
607 YV12_BUFFER_CONFIG *un_scaled_source;
608 YV12_BUFFER_CONFIG scaled_source;
609 YV12_BUFFER_CONFIG *unscaled_last_source;
610 YV12_BUFFER_CONFIG scaled_last_source;
611#ifdef ENABLE_KF_DENOISE
612 YV12_BUFFER_CONFIG raw_unscaled_source;
613 YV12_BUFFER_CONFIG raw_scaled_source;
614#endif
615 YV12_BUFFER_CONFIG *raw_source_frame;
616
617 BLOCK_SIZE tpl_bsize;
618 TplDepFrame tpl_stats[MAX_ARF_GOP_SIZE(2 * 25)];
619 // Used to store TPL stats before propagation
620 VpxTplGopStats tpl_gop_stats;
621 YV12_BUFFER_CONFIG *tpl_recon_frames[REF_FRAMES(1 << 3)];
622 EncFrameBuf enc_frame_buf[REF_FRAMES(1 << 3)];
623#if CONFIG_MULTITHREAD1
624 pthread_mutex_t kmeans_mutex;
625#endif
626 int kmeans_data_arr_alloc;
627 KMEANS_DATA *kmeans_data_arr;
628 int kmeans_data_size;
629 int kmeans_data_stride;
630 double kmeans_ctr_ls[MAX_KMEANS_GROUPS8];
631 double kmeans_boundary_ls[MAX_KMEANS_GROUPS8];
632 int kmeans_count_ls[MAX_KMEANS_GROUPS8];
633 int kmeans_ctr_num;
634#if CONFIG_NON_GREEDY_MV0
635 MotionFieldInfo motion_field_info;
636 int tpl_ready;
637 int_mv *select_mv_arr;
638#endif
639
640 TileDataEnc *tile_data;
641 int allocated_tiles; // Keep track of memory allocated for tiles.
642
643 int scaled_ref_idx[REFS_PER_FRAME3];
644 int lst_fb_idx;
645 int gld_fb_idx;
646 int alt_fb_idx;
647
648 int ref_fb_idx[REF_FRAMES(1 << 3)];
649
650 int refresh_last_frame;
651 int refresh_golden_frame;
652 int refresh_alt_ref_frame;
653
654 int ext_refresh_frame_flags_pending;
655 int ext_refresh_last_frame;
656 int ext_refresh_golden_frame;
657 int ext_refresh_alt_ref_frame;
658
659 int ext_refresh_frame_context_pending;
660 int ext_refresh_frame_context;
661
662 int64_t norm_wiener_variance;
663 int64_t *mb_wiener_variance;
664 int mb_wiener_var_rows;
665 int mb_wiener_var_cols;
666 double *mi_ssim_rdmult_scaling_factors;
667 int mi_ssim_rdmult_scaling_factors_rows;
668 int mi_ssim_rdmult_scaling_factors_cols;
669
670 int64_t *sb_mul_scale;
671
672 YV12_BUFFER_CONFIG last_frame_uf;
673
674 TOKENEXTRA *tile_tok[4][1 << 6];
675 TOKENLIST *tplist[4][1 << 6];
676
677 // Ambient reconstruction err target for force key frames
678 int64_t ambient_err;
679
680 RD_CONTROL rd_ctrl;
681 RD_OPT rd;
682
683 CODING_CONTEXT coding_context;
684
685 int *nmvcosts[2];
686 int *nmvcosts_hp[2];
687 int *nmvsadcosts[2];
688 int *nmvsadcosts_hp[2];
689
690 int64_t last_time_stamp_seen;
691 int64_t last_end_time_stamp_seen;
692 int64_t first_time_stamp_ever;
693
694 RATE_CONTROL rc;
695 double framerate;
696
697 int interp_filter_selected[REF_FRAMES(1 << 3)][SWITCHABLE4];
698
699 struct vpx_codec_pkt_list *output_pkt_list;
700
701 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS25];
702 int mbgraph_n_frames; // number of frames filled in the above
703 int static_mb_pct; // % forced skip mbs by segmentation
704 int ref_frame_flags;
705
706 SPEED_FEATURES sf;
707
708 uint32_t max_mv_magnitude;
709 int mv_step_param;
710
711 int allow_comp_inter_inter;
712
713 // Default value is 1. From first pass stats, encode_breakout may be disabled.
714 ENCODE_BREAKOUT_TYPE allow_encode_breakout;
715
716 // Get threshold from external input. A suggested threshold is 800 for HD
717 // clips, and 300 for < HD clips.
718 int encode_breakout;
719
720 uint8_t *segmentation_map;
721
722 uint8_t *skin_map;
723
724 // segment threshold for encode breakout
725 int segment_encode_breakout[MAX_SEGMENTS8];
726
727 CYCLIC_REFRESH *cyclic_refresh;
728 ActiveMap active_map;
729
730 fractional_mv_step_fp *find_fractional_mv_step;
731 struct scale_factors me_sf;
732 vp9_diamond_search_fn_t diamond_search_sad;
733 vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES13];
734#if CONFIG_INTERNAL_STATS0
735 uint64_t time_receive_data;
736 uint64_t time_compress_data;
737 uint64_t time_pick_lpf;
738 uint64_t time_encode_sb_row;
739#endif
740
741 TWO_PASS twopass;
742
743 // Force recalculation of segment_ids for each mode info
744 uint8_t force_update_segmentation;
745
746 YV12_BUFFER_CONFIG tf_buffer;
747
748 // class responsible for adaptive
749 // quantization of altref frames
750 struct ALT_REF_AQ *alt_ref_aq;
751
752#if CONFIG_INTERNAL_STATS0
753 unsigned int mode_chosen_counts[MAX_MODES30];
754
755 int count;
756 uint64_t total_sq_error;
757 uint64_t total_samples;
758 ImageStat psnr;
759
760 uint64_t totalp_sq_error;
761 uint64_t totalp_samples;
762 ImageStat psnrp;
763
764 double total_blockiness;
765 double worst_blockiness;
766
767 uint64_t bytes;
768 double summed_quality;
769 double summed_weights;
770 double summedp_quality;
771 double summedp_weights;
772 unsigned int tot_recode_hits;
773 double worst_ssim;
774
775 ImageStat ssimg;
776 ImageStat fastssim;
777 ImageStat psnrhvs;
778
779 int b_calculate_ssimg;
780 int b_calculate_blockiness;
781
782 int b_calculate_consistency;
783
784 double total_inconsistency;
785 double worst_consistency;
786 Ssimv *ssim_vars;
787 Metrics metrics;
788#endif
789 int b_calculate_psnr;
790
791 int droppable;
792
793 int initial_width;
794 int initial_height;
795 int initial_mbs; // Number of MBs in the full-size frame; to be used to
796 // normalize the firstpass stats. This will differ from the
797 // number of MBs in the current frame when the frame is
798 // scaled.
799
800 int last_coded_width;
801 int last_coded_height;
802
803 int use_svc;
804
805 SVC svc;
806
807 int frame_flags;
808
809 search_site_config ss_cfg;
810
811 int mbmode_cost[INTRA_MODES(9 + 1)];
812 unsigned int inter_mode_cost[INTER_MODE_CONTEXTS7][INTER_MODES(1 + 13 - 10)];
813 int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)];
814 int y_mode_costs[INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)];
815 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS(3 + 1)][SWITCHABLE_FILTERS3];
816 int partition_cost[PARTITION_CONTEXTS(4 * 4)][PARTITION_TYPES];
817 // Indices are: max_tx_size-1, tx_size_ctx, tx_size
818 int tx_size_cost[TX_SIZES((TX_SIZE)4) - 1][TX_SIZE_CONTEXTS2][TX_SIZES((TX_SIZE)4)];
819
820#if CONFIG_VP9_TEMPORAL_DENOISING0
821 VP9_DENOISER denoiser;
822#endif
823
824 int resize_pending;
825 RESIZE_STATE resize_state;
826 int external_resize;
827 int resize_scale_num;
828 int resize_scale_den;
829 int resize_avg_qp;
830 int resize_buffer_underflow;
831 int resize_count;
832
833 int use_skin_detection;
834
835 int target_level;
836
837 NOISE_ESTIMATE noise_estimate;
838
839 // Count on how many consecutive times a block uses small/zeromv for encoding.
840 uint8_t *consec_zero_mv;
841
842 // VAR_BASED_PARTITION thresholds
843 // 0 - threshold_64x64; 1 - threshold_32x32;
844 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
845 int64_t vbp_thresholds[4];
846 int64_t vbp_threshold_minmax;
847 int64_t vbp_threshold_sad;
848 // Threshold used for partition copy
849 int64_t vbp_threshold_copy;
850 BLOCK_SIZE vbp_bsize_min;
851
852 // Multi-threading
853 int num_workers;
854 VPxWorker *workers;
855 struct EncWorkerData *tile_thr_data;
856 VP9LfSync lf_row_sync;
857 struct VP9BitstreamWorkerData *vp9_bitstream_worker_data;
858
859 int keep_level_stats;
860 Vp9LevelInfo level_info;
861 MultiThreadHandle multi_thread_ctxt;
862 void (*row_mt_sync_read_ptr)(VP9RowMTSync *const, int, int);
863 void (*row_mt_sync_write_ptr)(VP9RowMTSync *const, int, int, const int);
864 ARNRFilterData arnr_filter_data;
865
866 int row_mt;
867 unsigned int row_mt_bit_exact;
868
869 // Previous Partition Info
870 BLOCK_SIZE *prev_partition;
871 int8_t *prev_segment_id;
872 // Used to save the status of whether a block has a low variance in
873 // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
874 // 32x32, 9~24 for 16x16.
875 // This is for the last frame and is copied to the current frame
876 // when partition copy happens.
877 uint8_t *prev_variance_low;
878 uint8_t *copied_frame_cnt;
879 uint8_t max_copied_frame;
880 // If the last frame is dropped, we don't copy partition.
881 uint8_t last_frame_dropped;
882
883 // For each superblock: keeps track of the last time (in frame distance) the
884 // the superblock did not have low source sad.
885 uint8_t *content_state_sb_fd;
886
887 int compute_source_sad_onepass;
888
889 int compute_frame_low_motion_onepass;
890
891 LevelConstraint level_constraint;
892
893 uint8_t *count_arf_frame_usage;
894 uint8_t *count_lastgolden_frame_usage;
895
896 int multi_layer_arf;
897 vpx_roi_map_t roi;
898
899 LOOPFILTER_CONTROL loopfilter_ctrl;
900 EXT_RATECTRL ext_ratectrl;
901
902 int fixed_qp_onepass;
903
904 // Flag to keep track of dynamic change in deadline mode
905 // (good/best/realtime).
906 MODE deadline_mode_previous_frame;
907
908 // Flag to disable scene detection when rtc rate control library is used.
909 int disable_scene_detection_rtc_ratectrl;
910
911#if CONFIG_COLLECT_COMPONENT_TIMING0
912 /*!
913 * component_time[] are initialized to zero while encoder starts.
914 */
915 uint64_t component_time[kTimingComponents];
916 /*!
917 * Stores timing for individual components between calls of start_timing()
918 * and end_timing().
919 */
920 struct vpx_usec_timer component_timer[kTimingComponents];
921 /*!
922 * frame_component_time[] are initialized to zero at beginning of each frame.
923 */
924 uint64_t frame_component_time[kTimingComponents];
925#endif
926} VP9_COMP;
927
928typedef struct ENCODE_FRAME_RESULT {
929 int show_idx;
930 FRAME_UPDATE_TYPE update_type;
931 int quantize_index;
932} ENCODE_FRAME_RESULT;
933
934void vp9_init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result);
935
936void vp9_initialize_enc(void);
937
938struct VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf,
939 BufferPool *const pool);
940void vp9_remove_compressor(VP9_COMP *cpi);
941
942void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
943
944// receive a frames worth of data. caller can assume that a copy of this
945// frame is made and not just a copy of the pointer..
946int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags,
947 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
948 int64_t end_time);
949
950int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
951 size_t *size, uint8_t *dest, size_t dest_size,
952 int64_t *time_stamp, int64_t *time_end, int flush,
953 ENCODE_FRAME_RESULT *encode_frame_result);
954
955int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
956 vp9_ppflags_t *flags);
957
958int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
959
960void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
961
962int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
963 YV12_BUFFER_CONFIG *sd);
964
965int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
966 YV12_BUFFER_CONFIG *sd);
967
968int vp9_update_entropy(VP9_COMP *cpi, int update);
969
970int vp9_set_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows,
971 int cols);
972
973int vp9_get_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows,
974 int cols);
975
976int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING_MODE horiz_mode,
977 VPX_SCALING_MODE vert_mode);
978
979int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
980 unsigned int height);
981
982void vp9_set_svc(VP9_COMP *cpi, int use_svc);
983
984// Check for resetting the rc flags (rc_1_frame, rc_2_frame) if the
985// configuration change has a large change in avg_frame_bandwidth.
986// For SVC check for resetting based on spatial layer average bandwidth.
987// Also reset buffer level to optimal level.
988void vp9_check_reset_rc_flag(VP9_COMP *cpi);
989
990void vp9_set_rc_buffer_sizes(VP9_COMP *cpi);
991
992static INLINEinline int stack_pop(int *stack, int stack_size) {
993 int idx;
994 const int r = stack[0];
995 for (idx = 1; idx < stack_size; ++idx) stack[idx - 1] = stack[idx];
996
997 return r;
998}
999
1000static INLINEinline int stack_top(const int *stack) { return stack[0]; }
1001
1002static INLINEinline void stack_push(int *stack, int new_item, int stack_size) {
1003 int idx;
1004 for (idx = stack_size; idx > 0; --idx) stack[idx] = stack[idx - 1];
1005 stack[0] = new_item;
1006}
1007
1008static INLINEinline void stack_init(int *stack, int length) {
1009 int idx;
1010 for (idx = 0; idx < length; ++idx) stack[idx] = -1;
1011}
1012
1013int vp9_get_quantizer(const VP9_COMP *cpi);
1014
1015static INLINEinline int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
1016 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
1017 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
1018}
1019
1020static INLINEinline int ref_frame_to_flag(int8_t ref_frame) {
1021 static const int kVp9RefFlagList[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
1022 VP9_ALT_FLAG };
1023 assert(ref_frame >= LAST_FRAME && ref_frame <= ALTREF_FRAME)((void) sizeof ((ref_frame >= 1 && ref_frame <=
3) ? 1 : 0), __extension__ ({ if (ref_frame >= 1 &&
ref_frame <= 3) ; else __assert_fail ("ref_frame >= LAST_FRAME && ref_frame <= ALTREF_FRAME"
, "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1023, __extension__ __PRETTY_FUNCTION__); }))
;
1024 return kVp9RefFlagList[ref_frame];
1025}
1026
1027static INLINEinline int get_ref_frame_map_idx(const VP9_COMP *cpi,
1028 MV_REFERENCE_FRAME ref_frame) {
1029 if (ref_frame == LAST_FRAME1) {
1030 return cpi->lst_fb_idx;
1031 } else if (ref_frame == GOLDEN_FRAME2) {
1032 return cpi->gld_fb_idx;
1033 } else {
1034 return cpi->alt_fb_idx;
1035 }
1036}
1037
1038static INLINEinline int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
1039 int ref_frame) {
1040 const VP9_COMMON *const cm = &cpi->common;
1041 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
1042 return (map_idx != INVALID_IDX(-1)) ? cm->ref_frame_map[map_idx] : INVALID_IDX(-1);
1043}
1044
1045static INLINEinline RefCntBuffer *get_ref_cnt_buffer(const VP9_COMMON *cm,
1046 int fb_idx) {
1047 return fb_idx != INVALID_IDX(-1) ? &cm->buffer_pool->frame_bufs[fb_idx] : NULL((void*)0);
1048}
1049
1050static INLINEinline void get_ref_frame_bufs(
1051 const VP9_COMP *cpi, RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES3]) {
1052 const VP9_COMMON *const cm = &cpi->common;
1053 MV_REFERENCE_FRAME ref_frame;
1054 for (ref_frame = LAST_FRAME1; ref_frame < MAX_REF_FRAMES4; ++ref_frame) {
1055 int ref_frame_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
1056 int inter_ref_idx = mv_ref_frame_to_inter_ref_idx(ref_frame);
1057 ref_frame_bufs[inter_ref_idx] = get_ref_cnt_buffer(cm, ref_frame_buf_idx);
1058 }
1059}
1060
1061static INLINEinline YV12_BUFFER_CONFIG *get_ref_frame_buffer(
1062 const VP9_COMP *const cpi, MV_REFERENCE_FRAME ref_frame) {
1063 const VP9_COMMON *const cm = &cpi->common;
1064 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
1065 return buf_idx != INVALID_IDX(-1) ? &cm->buffer_pool->frame_bufs[buf_idx].buf
1066 : NULL((void*)0);
1067}
1068
1069static INLINEinline int64_t get_token_alloc(int mb_rows, int mb_cols) {
1070 // TODO(JBB): double check we can't exceed this token count if we have a
1071 // 32x32 transform crossing a boundary at a multiple of 16.
1072 // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
1073 // resolution. We assume up to 1 token per pixel, and then allow
1074 // a head room of 4.
1075
1076 // Use aligned mb_rows and mb_cols to better align with actual token sizes.
1077 const int aligned_mb_rows =
1078 ALIGN_POWER_OF_TWO(mb_rows, MI_BLOCK_SIZE_LOG2 - 1)(((mb_rows) + ((1 << ((6 - 3) - 1)) - 1)) & ~((1 <<
((6 - 3) - 1)) - 1))
;
1079 const int aligned_mb_cols =
1080 ALIGN_POWER_OF_TWO(mb_cols, MI_BLOCK_SIZE_LOG2 - 1)(((mb_cols) + ((1 << ((6 - 3) - 1)) - 1)) & ~((1 <<
((6 - 3) - 1)) - 1))
;
1081 return (int64_t)aligned_mb_rows * aligned_mb_cols * (16 * 16 * 3 + 4);
1082}
1083
1084// Get the allocated token size for a tile. It does the same calculation as in
1085// the frame token allocation.
1086static INLINEinline int64_t allocated_tokens(TileInfo tile) {
1087 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
1088 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
1089
1090 return get_token_alloc(tile_mb_rows, tile_mb_cols);
1091}
1092
1093static INLINEinline void get_start_tok(VP9_COMP *cpi, int tile_row, int tile_col,
1094 int mi_row, TOKENEXTRA **tok) {
1095 VP9_COMMON *const cm = &cpi->common;
1096 const int tile_cols = 1 << cm->log2_tile_cols;
1097 TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col];
1098 const TileInfo *const tile_info = &this_tile->tile_info;
1099
1100 int tile_mb_cols = (tile_info->mi_col_end - tile_info->mi_col_start + 1) >> 1;
1101 const int mb_row = (mi_row - tile_info->mi_row_start) >> 1;
1102
1103 *tok =
1104 cpi->tile_tok[tile_row][tile_col] + get_token_alloc(mb_row, tile_mb_cols);
1105}
1106
1107int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
1108#if CONFIG_VP9_HIGHBITDEPTH0
1109int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
1110 const YV12_BUFFER_CONFIG *b);
1111#endif // CONFIG_VP9_HIGHBITDEPTH
1112
1113void vp9_scale_references(VP9_COMP *cpi);
1114
1115void vp9_update_reference_frames(VP9_COMP *cpi);
1116
1117void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags,
1118 RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES3],
1119 int *ref_frame_coding_indexes,
1120 int *ref_frame_valid_list);
1121
1122void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
1123
1124#if CONFIG_VP9_HIGHBITDEPTH0
1125void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
1126 YV12_BUFFER_CONFIG *dst, int bd);
1127#else
1128void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
1129 YV12_BUFFER_CONFIG *dst);
1130#endif // CONFIG_VP9_HIGHBITDEPTH
1131
1132YV12_BUFFER_CONFIG *vp9_scale_if_required(
1133 VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled,
1134 int use_normative_scaler, INTERP_FILTER filter_type, int phase_scaler);
1135
1136void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
1137
1138static INLINEinline int is_one_pass_svc(const struct VP9_COMP *const cpi) {
1139 return (cpi->use_svc && cpi->oxcf.pass == 0);
1140}
1141
1142#if CONFIG_VP9_TEMPORAL_DENOISING0
1143static INLINEinline int denoise_svc(const struct VP9_COMP *const cpi) {
1144 return (!cpi->use_svc || (cpi->use_svc && cpi->svc.spatial_layer_id >=
1145 cpi->svc.first_layer_denoise));
1146}
1147#endif
1148
1149#define MIN_LOOKAHEAD_FOR_ARFS4 4
1150static INLINEinline int is_altref_enabled(const VP9_COMP *const cpi) {
1151 return !(cpi->oxcf.mode == REALTIME && cpi->oxcf.rc_mode == VPX_CBR) &&
1152 cpi->oxcf.lag_in_frames >= MIN_LOOKAHEAD_FOR_ARFS4 &&
1153 cpi->oxcf.enable_auto_arf;
1154}
1155
1156static INLINEinline void set_ref_ptrs(const VP9_COMMON *const cm, MACROBLOCKD *xd,
1157 MV_REFERENCE_FRAME ref0,
1158 MV_REFERENCE_FRAME ref1) {
1159 xd->block_refs[0] =
1160 &cm->frame_refs[ref0 >= LAST_FRAME1 ? ref0 - LAST_FRAME1 : 0];
1161 xd->block_refs[1] =
1162 &cm->frame_refs[ref1 >= LAST_FRAME1 ? ref1 - LAST_FRAME1 : 0];
1163}
1164
1165static INLINEinline int get_chessboard_index(const int frame_index) {
1166 return frame_index & 0x1;
1167}
1168
1169static INLINEinline int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
1170 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL((void*)0);
1171}
1172
1173static INLINEinline int get_num_vert_units(TileInfo tile, int shift) {
1174 int num_vert_units =
1175 (tile.mi_row_end - tile.mi_row_start + (1 << shift) - 1) >> shift;
1176 return num_vert_units;
1177}
1178
1179static INLINEinline int get_num_cols(TileInfo tile, int shift) {
1180 int num_cols =
1181 (tile.mi_col_end - tile.mi_col_start + (1 << shift) - 1) >> shift;
1182 return num_cols;
1183}
1184
1185static INLINEinline int get_level_index(VP9_LEVEL level) {
1186 int i;
1187 for (i = 0; i < VP9_LEVELS14; ++i) {
1188 if (level == vp9_level_defs[i].level) return i;
1189 }
1190 return -1;
1191}
1192
1193// Return the log2 value of max column tiles corresponding to the level that
1194// the picture size fits into.
1195static INLINEinline int log_tile_cols_from_picsize_level(uint32_t width,
1196 uint32_t height) {
1197 int i;
1198 const uint32_t pic_size = width * height;
1199 const uint32_t pic_breadth = VPXMAX(width, height)(((width) > (height)) ? (width) : (height));
1200 for (i = 0; i < VP9_LEVELS14; ++i) {
1201 if (vp9_level_defs[i].max_luma_picture_size >= pic_size &&
1202 vp9_level_defs[i].max_luma_picture_breadth >= pic_breadth) {
1203 return get_msb(vp9_level_defs[i].max_col_tiles);
1204 }
1205 }
1206 return INT_MAX2147483647;
1207}
1208
1209VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec);
1210
1211vpx_codec_err_t vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map,
1212 unsigned int rows, unsigned int cols,
1213 int delta_q[8], int delta_lf[8], int skip[8],
1214 int ref_frame[8]);
1215
1216void vp9_new_framerate(VP9_COMP *cpi, double framerate);
1217
1218void vp9_set_row_mt(VP9_COMP *cpi);
1219
1220int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr);
1221
1222#define LAYER_IDS_TO_IDX(sl, tl, num_tl)((sl) * (num_tl) + (tl)) ((sl) * (num_tl) + (tl))
1223
1224static INLINEinline void alloc_frame_mvs(VP9_COMMON *const cm, int buffer_idx) {
1225 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
1226 if (new_fb_ptr->mvs == NULL((void*)0) || new_fb_ptr->mi_rows < cm->mi_rows ||
1227 new_fb_ptr->mi_cols < cm->mi_cols) {
1228 vpx_free(new_fb_ptr->mvs);
1229 CHECK_MEM_ERROR(&cm->error, new_fb_ptr->mvs,do { ((void) sizeof (((&cm->error)->setjmp) ? 1 : 0
), __extension__ ({ if ((&cm->error)->setjmp) ; else
__assert_fail ("(&cm->error)->setjmp", "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1231, __extension__ __PRETTY_FUNCTION__); })); (new_fb_ptr->
mvs) = ((MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*new_fb_ptr->mvs))); if (!(new_fb_ptr->mvs)) vpx_internal_error
(&cm->error, VPX_CODEC_MEM_ERROR, "Failed to allocate "
"new_fb_ptr->mvs"); } while (0)
1230 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,do { ((void) sizeof (((&cm->error)->setjmp) ? 1 : 0
), __extension__ ({ if ((&cm->error)->setjmp) ; else
__assert_fail ("(&cm->error)->setjmp", "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1231, __extension__ __PRETTY_FUNCTION__); })); (new_fb_ptr->
mvs) = ((MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*new_fb_ptr->mvs))); if (!(new_fb_ptr->mvs)) vpx_internal_error
(&cm->error, VPX_CODEC_MEM_ERROR, "Failed to allocate "
"new_fb_ptr->mvs"); } while (0)
1231 sizeof(*new_fb_ptr->mvs)))do { ((void) sizeof (((&cm->error)->setjmp) ? 1 : 0
), __extension__ ({ if ((&cm->error)->setjmp) ; else
__assert_fail ("(&cm->error)->setjmp", "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1231, __extension__ __PRETTY_FUNCTION__); })); (new_fb_ptr->
mvs) = ((MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
sizeof(*new_fb_ptr->mvs))); if (!(new_fb_ptr->mvs)) vpx_internal_error
(&cm->error, VPX_CODEC_MEM_ERROR, "Failed to allocate "
"new_fb_ptr->mvs"); } while (0)
;
1232 new_fb_ptr->mi_rows = cm->mi_rows;
1233 new_fb_ptr->mi_cols = cm->mi_cols;
1234 }
1235}
1236
1237static INLINEinline int mv_cost(const MV *mv, const int *joint_cost,
1238 int *const comp_cost[2]) {
1239 assert(mv->row >= -MV_MAX && mv->row < MV_MAX)((void) sizeof ((mv->row >= -((1 << (11 + 1 + 2))
- 1) && mv->row < ((1 << (11 + 1 + 2)) -
1)) ? 1 : 0), __extension__ ({ if (mv->row >= -((1 <<
(11 + 1 + 2)) - 1) && mv->row < ((1 << (
11 + 1 + 2)) - 1)) ; else __assert_fail ("mv->row >= -MV_MAX && mv->row < MV_MAX"
, "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1239, __extension__ __PRETTY_FUNCTION__); }))
;
1240 assert(mv->col >= -MV_MAX && mv->col < MV_MAX)((void) sizeof ((mv->col >= -((1 << (11 + 1 + 2))
- 1) && mv->col < ((1 << (11 + 1 + 2)) -
1)) ? 1 : 0), __extension__ ({ if (mv->col >= -((1 <<
(11 + 1 + 2)) - 1) && mv->col < ((1 << (
11 + 1 + 2)) - 1)) ; else __assert_fail ("mv->col >= -MV_MAX && mv->col < MV_MAX"
, "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1240, __extension__ __PRETTY_FUNCTION__); }))
;
1241 return joint_cost[vp9_get_mv_joint(mv)] + comp_cost[0][mv->row] +
1242 comp_cost[1][mv->col];
1243}
1244
1245static INLINEinline int mvsad_err_cost(const MACROBLOCK *x, const MV *mv,
1246 const MV *ref, int sad_per_bit) {
1247 MV diff;
1248 diff.row = mv->row - ref->row;
1249 diff.col = mv->col - ref->col;
1250 return ROUND_POWER_OF_TWO(((((unsigned)mv_cost(&diff, x->nmvjointsadcost, x->
nmvsadcost) * sad_per_bit) + (1 << ((9) - 1))) >>
(9))
1251 (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->nmvsadcost) * sad_per_bit,((((unsigned)mv_cost(&diff, x->nmvjointsadcost, x->
nmvsadcost) * sad_per_bit) + (1 << ((9) - 1))) >>
(9))
1252 VP9_PROB_COST_SHIFT)((((unsigned)mv_cost(&diff, x->nmvjointsadcost, x->
nmvsadcost) * sad_per_bit) + (1 << ((9) - 1))) >>
(9))
;
1253}
1254
1255static INLINEinline uint32_t get_start_mv_sad(const MACROBLOCK *x, const MV *mvp_full,
1256 const MV *ref_mv_full,
1257 vpx_sad_fn_t sad_fn_ptr, int sadpb) {
1258 const int src_buf_stride = x->plane[0].src.stride;
1259 const uint8_t *const src_buf = x->plane[0].src.buf;
1260 const MACROBLOCKD *const xd = &x->e_mbd;
1261 const int pred_buf_stride = xd->plane[0].pre[0].stride;
1262 const uint8_t *const pred_buf =
1263 xd->plane[0].pre[0].buf + mvp_full->row * pred_buf_stride + mvp_full->col;
1264 uint32_t start_mv_sad =
1265 sad_fn_ptr(src_buf, src_buf_stride, pred_buf, pred_buf_stride);
1266 start_mv_sad += mvsad_err_cost(x, mvp_full, ref_mv_full, sadpb);
1267
1268 return start_mv_sad;
1269}
1270
1271static INLINEinline int num_4x4_to_edge(int plane_4x4_dim, int mb_to_edge_dim,
1272 int subsampling_dim, int blk_dim) {
1273 return plane_4x4_dim + (mb_to_edge_dim >> (5 + subsampling_dim)) - blk_dim;
1274}
1275
1276// Compute the sum of squares on all visible 4x4s in the transform block.
1277static int64_t sum_squares_visible(const MACROBLOCKD *xd,
1278 const struct macroblockd_plane *const pd,
1279 const int16_t *diff, const int diff_stride,
1280 int blk_row, int blk_col,
1281 const BLOCK_SIZE plane_bsize,
1282 const BLOCK_SIZE tx_bsize,
1283 int *visible_width, int *visible_height) {
1284 int64_t sse;
1285 const int plane_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
1286 const int plane_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
1287 const int tx_4x4_w = num_4x4_blocks_wide_lookup[tx_bsize];
1288 const int tx_4x4_h = num_4x4_blocks_high_lookup[tx_bsize];
1289 const int b4x4s_to_right_edge = num_4x4_to_edge(
1290 plane_4x4_w, xd->mb_to_right_edge, pd->subsampling_x, blk_col);
1291 const int b4x4s_to_bottom_edge = num_4x4_to_edge(
1292 plane_4x4_h, xd->mb_to_bottom_edge, pd->subsampling_y, blk_row);
1293 if (tx_bsize == BLOCK_4X40 ||
1294 (b4x4s_to_right_edge >= tx_4x4_w && b4x4s_to_bottom_edge >= tx_4x4_h)) {
1295 assert(tx_4x4_w == tx_4x4_h)((void) sizeof ((tx_4x4_w == tx_4x4_h) ? 1 : 0), __extension__
({ if (tx_4x4_w == tx_4x4_h) ; else __assert_fail ("tx_4x4_w == tx_4x4_h"
, "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1295, __extension__ __PRETTY_FUNCTION__); }))
;
1296 sse = (int64_t)vpx_sum_squares_2d_i16vpx_sum_squares_2d_i16_sse2(diff, diff_stride, tx_4x4_w << 2);
1297 *visible_width = tx_4x4_w << 2;
1298 *visible_height = tx_4x4_h << 2;
1299 } else {
1300 int r, c;
1301 const int max_r = VPXMIN(b4x4s_to_bottom_edge, tx_4x4_h)(((b4x4s_to_bottom_edge) < (tx_4x4_h)) ? (b4x4s_to_bottom_edge
) : (tx_4x4_h))
;
1302 const int max_c = VPXMIN(b4x4s_to_right_edge, tx_4x4_w)(((b4x4s_to_right_edge) < (tx_4x4_w)) ? (b4x4s_to_right_edge
) : (tx_4x4_w))
;
1303 sse = 0;
1304 // if we are in the unrestricted motion border.
1305 for (r = 0; r < max_r; ++r) {
1306 // Skip visiting the sub blocks that are wholly within the UMV.
1307 for (c = 0; c < max_c; ++c) {
1308 sse += (int64_t)vpx_sum_squares_2d_i16vpx_sum_squares_2d_i16_sse2(
1309 diff + r * diff_stride * 4 + c * 4, diff_stride, 4);
1310 }
1311 }
1312 *visible_width = max_c << 2;
1313 *visible_height = max_r << 2;
1314 }
1315 return sse;
1316}
1317
1318// Check if trellis coefficient optimization of the transform block is enabled.
1319static INLINEinline int do_trellis_opt(const struct macroblockd_plane *pd,
1320 const int16_t *src_diff, int diff_stride,
1321 int blk_row, int blk_col,
1322 BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
1323 void *arg) {
1324 const struct encode_b_args *const args = (struct encode_b_args *)arg;
1325 const MACROBLOCK *const x = args->x;
1326
1327 switch (args->enable_trellis_opt) {
1328 case DISABLE_TRELLIS_OPT: return 0;
1329 case ENABLE_TRELLIS_OPT: return 1;
1330 case ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR: {
1331 vpx_clear_system_state();
1332
1333 return (args->trellis_opt_thresh > 0.0)
1334 ? (x->log_block_src_var <= args->trellis_opt_thresh)
1335 : 1;
1336 }
1337 case ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE: {
1338 const MACROBLOCKD *const xd = &x->e_mbd;
1339 const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size];
1340#if CONFIG_VP9_HIGHBITDEPTH0
1341 const int dequant_shift =
1342 (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH8) ? xd->bd - 5 : 3;
1343#else
1344 const int dequant_shift = 3;
1345#endif // CONFIG_VP9_HIGHBITDEPTH
1346 const int qstep = pd->dequant[1] >> dequant_shift;
1347 int *sse_calc_done = args->sse_calc_done;
1348 int64_t *sse = args->sse;
1349 int visible_width = 0, visible_height = 0;
1350
1351 // TODO: Enable the sf for high bit-depth case
1352 if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH8) || !sse ||
1353 !sse_calc_done)
1354 return 1;
1355
1356 *sse = sum_squares_visible(xd, pd, src_diff, diff_stride, blk_row,
1357 blk_col, plane_bsize, tx_bsize, &visible_width,
1358 &visible_height);
1359 *sse_calc_done = 1;
1360
1361 vpx_clear_system_state();
1362
1363 return (*(sse) <= (int64_t)visible_width * visible_height * qstep *
1364 qstep * args->trellis_opt_thresh);
1365 }
1366 default: assert(0 && "Invalid trellis optimization method.")((void) sizeof ((0 && "Invalid trellis optimization method."
) ? 1 : 0), __extension__ ({ if (0 && "Invalid trellis optimization method."
) ; else __assert_fail ("0 && \"Invalid trellis optimization method.\""
, "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1366, __extension__ __PRETTY_FUNCTION__); }))
; return 1;
1367 }
1368}
1369
1370#if CONFIG_COLLECT_COMPONENT_TIMING0
1371static INLINEinline void start_timing(VP9_COMP *cpi, int component) {
1372 vpx_usec_timer_start(&cpi->component_timer[component]);
1373}
1374static INLINEinline void end_timing(VP9_COMP *cpi, int component) {
1375 vpx_usec_timer_mark(&cpi->component_timer[component]);
1376 cpi->frame_component_time[component] +=
1377 vpx_usec_timer_elapsed(&cpi->component_timer[component]);
1378}
1379static INLINEinline char const *get_frame_type_enum(int type) {
1380 switch (type) {
1381 case 0: return "KEY_FRAME";
1382 case 1: return "INTER_FRAME";
1383 default: assert(0)((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail
("0", "/root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h"
, 1383, __extension__ __PRETTY_FUNCTION__); }))
;
1384 }
1385 return "error";
1386}
1387#endif
1388
1389#ifdef __cplusplus
1390} // extern "C"
1391#endif
1392
1393#endif // VPX_VP9_ENCODER_VP9_ENCODER_H_