File: | root/firefox-clang/media/libvpx/libvpx/vp9/encoder/vp9_encoder.h |
Warning: | line 593, column 16 Excessive padding in 'struct VP9_COMP' (87 padding bytes, where 7 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, source_diff_var, 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, 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, source_var_thresh, frames_till_next_var_check, 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 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 |
64 | extern "C" { |
65 | #endif |
66 | |
67 | // vp9 uses 10,000,000 ticks/second as time stamp |
68 | #define TICKS_PER_SEC10000000 10000000 |
69 | |
70 | typedef 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 | |
87 | typedef 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 | |
96 | typedef 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 | |
112 | typedef enum { |
113 | FRAMEFLAGS_KEY = 1 << 0, |
114 | FRAMEFLAGS_GOLDEN = 1 << 1, |
115 | FRAMEFLAGS_ALTREF = 1 << 2, |
116 | } FRAMETYPE_FLAGS; |
117 | |
118 | typedef 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 | |
132 | typedef 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 | |
138 | typedef 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 | |
148 | typedef 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 | |
154 | typedef 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; // Input bit depth. |
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 | |
290 | static INLINEinline int is_lossless_requested(const VP9EncoderConfig *cfg) { |
291 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
292 | } |
293 | |
294 | typedef 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 | |
314 | typedef 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. |
333 | typedef 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 | |
350 | typedef struct RowMTInfo { |
351 | JobQueueHandle job_queue_hdl; |
352 | #if CONFIG_MULTITHREAD1 |
353 | pthread_mutex_t job_mutex; |
354 | #endif |
355 | } RowMTInfo; |
356 | |
357 | typedef struct { |
358 | TOKENEXTRA *start; |
359 | TOKENEXTRA *stop; |
360 | unsigned int count; |
361 | } TOKENLIST; |
362 | |
363 | typedef 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 | |
380 | typedef 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 | |
386 | typedef 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 | |
396 | struct EncWorkerData; |
397 | |
398 | typedef struct ActiveMap { |
399 | int enabled; |
400 | int update; |
401 | unsigned char *map; |
402 | } ActiveMap; |
403 | |
404 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
405 | |
406 | typedef 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 | |
419 | typedef 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 | |
439 | typedef 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 | |
452 | extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS14]; |
453 | |
454 | typedef struct { |
455 | int64_t ts; // timestamp |
456 | uint32_t luma_samples; |
457 | uint32_t size; // in bytes |
458 | } FrameRecord; |
459 | |
460 | typedef struct { |
461 | FrameRecord buf[FRAME_WINDOW_SIZE128]; |
462 | uint8_t start; |
463 | uint8_t len; |
464 | } FrameWindowBuffer; |
465 | |
466 | typedef 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 | |
476 | typedef struct { |
477 | Vp9LevelStats level_stats; |
478 | Vp9LevelSpec level_spec; |
479 | } Vp9LevelInfo; |
480 | |
481 | typedef 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 | |
494 | typedef 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 | |
501 | typedef 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 | |
510 | typedef 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 | |
521 | typedef 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. |
530 | typedef 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 | |
558 | static 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 | |
593 | typedef struct VP9_COMP { |
Excessive padding in 'struct VP9_COMP' (87 padding bytes, where 7 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, source_diff_var, 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, 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, source_var_thresh, frames_till_next_var_check, 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 | |
668 | int64_t *sb_mul_scale; |
669 | |
670 | YV12_BUFFER_CONFIG last_frame_uf; |
671 | |
672 | TOKENEXTRA *tile_tok[4][1 << 6]; |
673 | TOKENLIST *tplist[4][1 << 6]; |
674 | |
675 | // Ambient reconstruction err target for force key frames |
676 | int64_t ambient_err; |
677 | |
678 | RD_CONTROL rd_ctrl; |
679 | RD_OPT rd; |
680 | |
681 | CODING_CONTEXT coding_context; |
682 | |
683 | int *nmvcosts[2]; |
684 | int *nmvcosts_hp[2]; |
685 | int *nmvsadcosts[2]; |
686 | int *nmvsadcosts_hp[2]; |
687 | |
688 | int64_t last_time_stamp_seen; |
689 | int64_t last_end_time_stamp_seen; |
690 | int64_t first_time_stamp_ever; |
691 | |
692 | RATE_CONTROL rc; |
693 | double framerate; |
694 | |
695 | int interp_filter_selected[REF_FRAMES(1 << 3)][SWITCHABLE4]; |
696 | |
697 | struct vpx_codec_pkt_list *output_pkt_list; |
698 | |
699 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS25]; |
700 | int mbgraph_n_frames; // number of frames filled in the above |
701 | int static_mb_pct; // % forced skip mbs by segmentation |
702 | int ref_frame_flags; |
703 | |
704 | SPEED_FEATURES sf; |
705 | |
706 | uint32_t max_mv_magnitude; |
707 | int mv_step_param; |
708 | |
709 | int allow_comp_inter_inter; |
710 | |
711 | // Default value is 1. From first pass stats, encode_breakout may be disabled. |
712 | ENCODE_BREAKOUT_TYPE allow_encode_breakout; |
713 | |
714 | // Get threshold from external input. A suggested threshold is 800 for HD |
715 | // clips, and 300 for < HD clips. |
716 | int encode_breakout; |
717 | |
718 | uint8_t *segmentation_map; |
719 | |
720 | uint8_t *skin_map; |
721 | |
722 | // segment threshold for encode breakout |
723 | int segment_encode_breakout[MAX_SEGMENTS8]; |
724 | |
725 | CYCLIC_REFRESH *cyclic_refresh; |
726 | ActiveMap active_map; |
727 | |
728 | fractional_mv_step_fp *find_fractional_mv_step; |
729 | struct scale_factors me_sf; |
730 | vp9_diamond_search_fn_t diamond_search_sad; |
731 | vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES13]; |
732 | #if CONFIG_INTERNAL_STATS0 |
733 | uint64_t time_receive_data; |
734 | uint64_t time_compress_data; |
735 | uint64_t time_pick_lpf; |
736 | uint64_t time_encode_sb_row; |
737 | #endif |
738 | |
739 | TWO_PASS twopass; |
740 | |
741 | // Force recalculation of segment_ids for each mode info |
742 | uint8_t force_update_segmentation; |
743 | |
744 | YV12_BUFFER_CONFIG tf_buffer; |
745 | |
746 | // class responsible for adaptive |
747 | // quantization of altref frames |
748 | struct ALT_REF_AQ *alt_ref_aq; |
749 | |
750 | #if CONFIG_INTERNAL_STATS0 |
751 | unsigned int mode_chosen_counts[MAX_MODES30]; |
752 | |
753 | int count; |
754 | uint64_t total_sq_error; |
755 | uint64_t total_samples; |
756 | ImageStat psnr; |
757 | |
758 | uint64_t totalp_sq_error; |
759 | uint64_t totalp_samples; |
760 | ImageStat psnrp; |
761 | |
762 | double total_blockiness; |
763 | double worst_blockiness; |
764 | |
765 | uint64_t bytes; |
766 | double summed_quality; |
767 | double summed_weights; |
768 | double summedp_quality; |
769 | double summedp_weights; |
770 | unsigned int tot_recode_hits; |
771 | double worst_ssim; |
772 | |
773 | ImageStat ssimg; |
774 | ImageStat fastssim; |
775 | ImageStat psnrhvs; |
776 | |
777 | int b_calculate_ssimg; |
778 | int b_calculate_blockiness; |
779 | |
780 | int b_calculate_consistency; |
781 | |
782 | double total_inconsistency; |
783 | double worst_consistency; |
784 | Ssimv *ssim_vars; |
785 | Metrics metrics; |
786 | #endif |
787 | int b_calculate_psnr; |
788 | |
789 | int droppable; |
790 | |
791 | int initial_width; |
792 | int initial_height; |
793 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
794 | // normalize the firstpass stats. This will differ from the |
795 | // number of MBs in the current frame when the frame is |
796 | // scaled. |
797 | |
798 | int last_coded_width; |
799 | int last_coded_height; |
800 | |
801 | int use_svc; |
802 | |
803 | SVC svc; |
804 | |
805 | // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type. |
806 | Diff *source_diff_var; |
807 | // The threshold used in SOURCE_VAR_BASED_PARTITION search type. |
808 | unsigned int source_var_thresh; |
809 | int frames_till_next_var_check; |
810 | |
811 | int frame_flags; |
812 | |
813 | search_site_config ss_cfg; |
814 | |
815 | int mbmode_cost[INTRA_MODES(9 + 1)]; |
816 | unsigned int inter_mode_cost[INTER_MODE_CONTEXTS7][INTER_MODES(1 + 13 - 10)]; |
817 | int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)]; |
818 | int y_mode_costs[INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)][INTRA_MODES(9 + 1)]; |
819 | int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS(3 + 1)][SWITCHABLE_FILTERS3]; |
820 | int partition_cost[PARTITION_CONTEXTS(4 * 4)][PARTITION_TYPES]; |
821 | // Indices are: max_tx_size-1, tx_size_ctx, tx_size |
822 | int tx_size_cost[TX_SIZES((TX_SIZE)4) - 1][TX_SIZE_CONTEXTS2][TX_SIZES((TX_SIZE)4)]; |
823 | |
824 | #if CONFIG_VP9_TEMPORAL_DENOISING0 |
825 | VP9_DENOISER denoiser; |
826 | #endif |
827 | |
828 | int resize_pending; |
829 | RESIZE_STATE resize_state; |
830 | int external_resize; |
831 | int resize_scale_num; |
832 | int resize_scale_den; |
833 | int resize_avg_qp; |
834 | int resize_buffer_underflow; |
835 | int resize_count; |
836 | |
837 | int use_skin_detection; |
838 | |
839 | int target_level; |
840 | |
841 | NOISE_ESTIMATE noise_estimate; |
842 | |
843 | // Count on how many consecutive times a block uses small/zeromv for encoding. |
844 | uint8_t *consec_zero_mv; |
845 | |
846 | // VAR_BASED_PARTITION thresholds |
847 | // 0 - threshold_64x64; 1 - threshold_32x32; |
848 | // 2 - threshold_16x16; 3 - vbp_threshold_8x8; |
849 | int64_t vbp_thresholds[4]; |
850 | int64_t vbp_threshold_minmax; |
851 | int64_t vbp_threshold_sad; |
852 | // Threshold used for partition copy |
853 | int64_t vbp_threshold_copy; |
854 | BLOCK_SIZE vbp_bsize_min; |
855 | |
856 | // Multi-threading |
857 | int num_workers; |
858 | VPxWorker *workers; |
859 | struct EncWorkerData *tile_thr_data; |
860 | VP9LfSync lf_row_sync; |
861 | struct VP9BitstreamWorkerData *vp9_bitstream_worker_data; |
862 | |
863 | int keep_level_stats; |
864 | Vp9LevelInfo level_info; |
865 | MultiThreadHandle multi_thread_ctxt; |
866 | void (*row_mt_sync_read_ptr)(VP9RowMTSync *const, int, int); |
867 | void (*row_mt_sync_write_ptr)(VP9RowMTSync *const, int, int, const int); |
868 | ARNRFilterData arnr_filter_data; |
869 | |
870 | int row_mt; |
871 | unsigned int row_mt_bit_exact; |
872 | |
873 | // Previous Partition Info |
874 | BLOCK_SIZE *prev_partition; |
875 | int8_t *prev_segment_id; |
876 | // Used to save the status of whether a block has a low variance in |
877 | // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for |
878 | // 32x32, 9~24 for 16x16. |
879 | // This is for the last frame and is copied to the current frame |
880 | // when partition copy happens. |
881 | uint8_t *prev_variance_low; |
882 | uint8_t *copied_frame_cnt; |
883 | uint8_t max_copied_frame; |
884 | // If the last frame is dropped, we don't copy partition. |
885 | uint8_t last_frame_dropped; |
886 | |
887 | // For each superblock: keeps track of the last time (in frame distance) the |
888 | // the superblock did not have low source sad. |
889 | uint8_t *content_state_sb_fd; |
890 | |
891 | int compute_source_sad_onepass; |
892 | |
893 | int compute_frame_low_motion_onepass; |
894 | |
895 | LevelConstraint level_constraint; |
896 | |
897 | uint8_t *count_arf_frame_usage; |
898 | uint8_t *count_lastgolden_frame_usage; |
899 | |
900 | int multi_layer_arf; |
901 | vpx_roi_map_t roi; |
902 | |
903 | LOOPFILTER_CONTROL loopfilter_ctrl; |
904 | EXT_RATECTRL ext_ratectrl; |
905 | |
906 | int fixed_qp_onepass; |
907 | |
908 | // Flag to keep track of dynamic change in deadline mode |
909 | // (good/best/realtime). |
910 | MODE deadline_mode_previous_frame; |
911 | |
912 | // Flag to disable scene detection when rtc rate control library is used. |
913 | int disable_scene_detection_rtc_ratectrl; |
914 | |
915 | #if CONFIG_COLLECT_COMPONENT_TIMING0 |
916 | /*! |
917 | * component_time[] are initialized to zero while encoder starts. |
918 | */ |
919 | uint64_t component_time[kTimingComponents]; |
920 | /*! |
921 | * Stores timing for individual components between calls of start_timing() |
922 | * and end_timing(). |
923 | */ |
924 | struct vpx_usec_timer component_timer[kTimingComponents]; |
925 | /*! |
926 | * frame_component_time[] are initialized to zero at beginning of each frame. |
927 | */ |
928 | uint64_t frame_component_time[kTimingComponents]; |
929 | #endif |
930 | } VP9_COMP; |
931 | |
932 | typedef struct ENCODE_FRAME_RESULT { |
933 | int show_idx; |
934 | FRAME_UPDATE_TYPE update_type; |
935 | int quantize_index; |
936 | } ENCODE_FRAME_RESULT; |
937 | |
938 | void vp9_init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result); |
939 | |
940 | void vp9_initialize_enc(void); |
941 | |
942 | void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt); |
943 | struct VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, |
944 | BufferPool *const pool); |
945 | void vp9_remove_compressor(VP9_COMP *cpi); |
946 | |
947 | void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf); |
948 | |
949 | // receive a frames worth of data. caller can assume that a copy of this |
950 | // frame is made and not just a copy of the pointer.. |
951 | int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, |
952 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
953 | int64_t end_time); |
954 | |
955 | int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
956 | size_t *size, uint8_t *dest, size_t dest_size, |
957 | int64_t *time_stamp, int64_t *time_end, int flush, |
958 | ENCODE_FRAME_RESULT *encode_frame_result); |
959 | |
960 | int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, |
961 | vp9_ppflags_t *flags); |
962 | |
963 | int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags); |
964 | |
965 | void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags); |
966 | |
967 | int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, |
968 | YV12_BUFFER_CONFIG *sd); |
969 | |
970 | int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, |
971 | YV12_BUFFER_CONFIG *sd); |
972 | |
973 | int vp9_update_entropy(VP9_COMP *cpi, int update); |
974 | |
975 | int vp9_set_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows, |
976 | int cols); |
977 | |
978 | int vp9_get_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows, |
979 | int cols); |
980 | |
981 | int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING_MODE horiz_mode, |
982 | VPX_SCALING_MODE vert_mode); |
983 | |
984 | int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, |
985 | unsigned int height); |
986 | |
987 | void vp9_set_svc(VP9_COMP *cpi, int use_svc); |
988 | |
989 | // Check for resetting the rc flags (rc_1_frame, rc_2_frame) if the |
990 | // configuration change has a large change in avg_frame_bandwidth. |
991 | // For SVC check for resetting based on spatial layer average bandwidth. |
992 | // Also reset buffer level to optimal level. |
993 | void vp9_check_reset_rc_flag(VP9_COMP *cpi); |
994 | |
995 | void vp9_set_rc_buffer_sizes(VP9_COMP *cpi); |
996 | |
997 | static INLINEinline int stack_pop(int *stack, int stack_size) { |
998 | int idx; |
999 | const int r = stack[0]; |
1000 | for (idx = 1; idx < stack_size; ++idx) stack[idx - 1] = stack[idx]; |
1001 | |
1002 | return r; |
1003 | } |
1004 | |
1005 | static INLINEinline int stack_top(const int *stack) { return stack[0]; } |
1006 | |
1007 | static INLINEinline void stack_push(int *stack, int new_item, int stack_size) { |
1008 | int idx; |
1009 | for (idx = stack_size; idx > 0; --idx) stack[idx] = stack[idx - 1]; |
1010 | stack[0] = new_item; |
1011 | } |
1012 | |
1013 | static INLINEinline void stack_init(int *stack, int length) { |
1014 | int idx; |
1015 | for (idx = 0; idx < length; ++idx) stack[idx] = -1; |
1016 | } |
1017 | |
1018 | int vp9_get_quantizer(const VP9_COMP *cpi); |
1019 | |
1020 | static INLINEinline int frame_is_kf_gf_arf(const VP9_COMP *cpi) { |
1021 | return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame || |
1022 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref); |
1023 | } |
1024 | |
1025 | static INLINEinline int ref_frame_to_flag(int8_t ref_frame) { |
1026 | static const int kVp9RefFlagList[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
1027 | VP9_ALT_FLAG }; |
1028 | 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" , 1028, __extension__ __PRETTY_FUNCTION__); })); |
1029 | return kVp9RefFlagList[ref_frame]; |
1030 | } |
1031 | |
1032 | static INLINEinline int get_ref_frame_map_idx(const VP9_COMP *cpi, |
1033 | MV_REFERENCE_FRAME ref_frame) { |
1034 | if (ref_frame == LAST_FRAME1) { |
1035 | return cpi->lst_fb_idx; |
1036 | } else if (ref_frame == GOLDEN_FRAME2) { |
1037 | return cpi->gld_fb_idx; |
1038 | } else { |
1039 | return cpi->alt_fb_idx; |
1040 | } |
1041 | } |
1042 | |
1043 | static INLINEinline int get_ref_frame_buf_idx(const VP9_COMP *const cpi, |
1044 | int ref_frame) { |
1045 | const VP9_COMMON *const cm = &cpi->common; |
1046 | const int map_idx = get_ref_frame_map_idx(cpi, ref_frame); |
1047 | return (map_idx != INVALID_IDX(-1)) ? cm->ref_frame_map[map_idx] : INVALID_IDX(-1); |
1048 | } |
1049 | |
1050 | static INLINEinline RefCntBuffer *get_ref_cnt_buffer(const VP9_COMMON *cm, |
1051 | int fb_idx) { |
1052 | return fb_idx != INVALID_IDX(-1) ? &cm->buffer_pool->frame_bufs[fb_idx] : NULL((void*)0); |
1053 | } |
1054 | |
1055 | static INLINEinline void get_ref_frame_bufs( |
1056 | const VP9_COMP *cpi, RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES3]) { |
1057 | const VP9_COMMON *const cm = &cpi->common; |
1058 | MV_REFERENCE_FRAME ref_frame; |
1059 | for (ref_frame = LAST_FRAME1; ref_frame < MAX_REF_FRAMES4; ++ref_frame) { |
1060 | int ref_frame_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
1061 | int inter_ref_idx = mv_ref_frame_to_inter_ref_idx(ref_frame); |
1062 | ref_frame_bufs[inter_ref_idx] = get_ref_cnt_buffer(cm, ref_frame_buf_idx); |
1063 | } |
1064 | } |
1065 | |
1066 | static INLINEinline YV12_BUFFER_CONFIG *get_ref_frame_buffer( |
1067 | const VP9_COMP *const cpi, MV_REFERENCE_FRAME ref_frame) { |
1068 | const VP9_COMMON *const cm = &cpi->common; |
1069 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
1070 | return buf_idx != INVALID_IDX(-1) ? &cm->buffer_pool->frame_bufs[buf_idx].buf |
1071 | : NULL((void*)0); |
1072 | } |
1073 | |
1074 | static INLINEinline int get_token_alloc(int mb_rows, int mb_cols) { |
1075 | // TODO(JBB): double check we can't exceed this token count if we have a |
1076 | // 32x32 transform crossing a boundary at a multiple of 16. |
1077 | // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full |
1078 | // resolution. We assume up to 1 token per pixel, and then allow |
1079 | // a head room of 4. |
1080 | |
1081 | // Use aligned mb_rows and mb_cols to better align with actual token sizes. |
1082 | const int aligned_mb_rows = |
1083 | ALIGN_POWER_OF_TWO(mb_rows, MI_BLOCK_SIZE_LOG2 - 1)(((mb_rows) + ((1 << ((6 - 3) - 1)) - 1)) & ~((1 << ((6 - 3) - 1)) - 1)); |
1084 | const int aligned_mb_cols = |
1085 | ALIGN_POWER_OF_TWO(mb_cols, MI_BLOCK_SIZE_LOG2 - 1)(((mb_cols) + ((1 << ((6 - 3) - 1)) - 1)) & ~((1 << ((6 - 3) - 1)) - 1)); |
1086 | return aligned_mb_rows * aligned_mb_cols * (16 * 16 * 3 + 4); |
1087 | } |
1088 | |
1089 | // Get the allocated token size for a tile. It does the same calculation as in |
1090 | // the frame token allocation. |
1091 | static INLINEinline int allocated_tokens(TileInfo tile) { |
1092 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1; |
1093 | int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1; |
1094 | |
1095 | return get_token_alloc(tile_mb_rows, tile_mb_cols); |
1096 | } |
1097 | |
1098 | static INLINEinline void get_start_tok(VP9_COMP *cpi, int tile_row, int tile_col, |
1099 | int mi_row, TOKENEXTRA **tok) { |
1100 | VP9_COMMON *const cm = &cpi->common; |
1101 | const int tile_cols = 1 << cm->log2_tile_cols; |
1102 | TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col]; |
1103 | const TileInfo *const tile_info = &this_tile->tile_info; |
1104 | |
1105 | int tile_mb_cols = (tile_info->mi_col_end - tile_info->mi_col_start + 1) >> 1; |
1106 | const int mb_row = (mi_row - tile_info->mi_row_start) >> 1; |
1107 | |
1108 | *tok = |
1109 | cpi->tile_tok[tile_row][tile_col] + get_token_alloc(mb_row, tile_mb_cols); |
1110 | } |
1111 | |
1112 | int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b); |
1113 | #if CONFIG_VP9_HIGHBITDEPTH0 |
1114 | int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a, |
1115 | const YV12_BUFFER_CONFIG *b); |
1116 | #endif // CONFIG_VP9_HIGHBITDEPTH |
1117 | |
1118 | void vp9_scale_references(VP9_COMP *cpi); |
1119 | |
1120 | void vp9_update_reference_frames(VP9_COMP *cpi); |
1121 | |
1122 | void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags, |
1123 | RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES3], |
1124 | int *ref_frame_coding_indexes, |
1125 | int *ref_frame_valid_list); |
1126 | |
1127 | void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv); |
1128 | |
1129 | #if CONFIG_VP9_HIGHBITDEPTH0 |
1130 | void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, |
1131 | YV12_BUFFER_CONFIG *dst, int bd); |
1132 | #else |
1133 | void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, |
1134 | YV12_BUFFER_CONFIG *dst); |
1135 | #endif // CONFIG_VP9_HIGHBITDEPTH |
1136 | |
1137 | YV12_BUFFER_CONFIG *vp9_scale_if_required( |
1138 | VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, |
1139 | int use_normative_scaler, INTERP_FILTER filter_type, int phase_scaler); |
1140 | |
1141 | void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags); |
1142 | |
1143 | static INLINEinline int is_one_pass_svc(const struct VP9_COMP *const cpi) { |
1144 | return (cpi->use_svc && cpi->oxcf.pass == 0); |
1145 | } |
1146 | |
1147 | #if CONFIG_VP9_TEMPORAL_DENOISING0 |
1148 | static INLINEinline int denoise_svc(const struct VP9_COMP *const cpi) { |
1149 | return (!cpi->use_svc || (cpi->use_svc && cpi->svc.spatial_layer_id >= |
1150 | cpi->svc.first_layer_denoise)); |
1151 | } |
1152 | #endif |
1153 | |
1154 | #define MIN_LOOKAHEAD_FOR_ARFS4 4 |
1155 | static INLINEinline int is_altref_enabled(const VP9_COMP *const cpi) { |
1156 | return !(cpi->oxcf.mode == REALTIME && cpi->oxcf.rc_mode == VPX_CBR) && |
1157 | cpi->oxcf.lag_in_frames >= MIN_LOOKAHEAD_FOR_ARFS4 && |
1158 | cpi->oxcf.enable_auto_arf; |
1159 | } |
1160 | |
1161 | static INLINEinline void set_ref_ptrs(const VP9_COMMON *const cm, MACROBLOCKD *xd, |
1162 | MV_REFERENCE_FRAME ref0, |
1163 | MV_REFERENCE_FRAME ref1) { |
1164 | xd->block_refs[0] = |
1165 | &cm->frame_refs[ref0 >= LAST_FRAME1 ? ref0 - LAST_FRAME1 : 0]; |
1166 | xd->block_refs[1] = |
1167 | &cm->frame_refs[ref1 >= LAST_FRAME1 ? ref1 - LAST_FRAME1 : 0]; |
1168 | } |
1169 | |
1170 | static INLINEinline int get_chessboard_index(const int frame_index) { |
1171 | return frame_index & 0x1; |
1172 | } |
1173 | |
1174 | static INLINEinline int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) { |
1175 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL((void*)0); |
1176 | } |
1177 | |
1178 | static INLINEinline int get_num_vert_units(TileInfo tile, int shift) { |
1179 | int num_vert_units = |
1180 | (tile.mi_row_end - tile.mi_row_start + (1 << shift) - 1) >> shift; |
1181 | return num_vert_units; |
1182 | } |
1183 | |
1184 | static INLINEinline int get_num_cols(TileInfo tile, int shift) { |
1185 | int num_cols = |
1186 | (tile.mi_col_end - tile.mi_col_start + (1 << shift) - 1) >> shift; |
1187 | return num_cols; |
1188 | } |
1189 | |
1190 | static INLINEinline int get_level_index(VP9_LEVEL level) { |
1191 | int i; |
1192 | for (i = 0; i < VP9_LEVELS14; ++i) { |
1193 | if (level == vp9_level_defs[i].level) return i; |
1194 | } |
1195 | return -1; |
1196 | } |
1197 | |
1198 | // Return the log2 value of max column tiles corresponding to the level that |
1199 | // the picture size fits into. |
1200 | static INLINEinline int log_tile_cols_from_picsize_level(uint32_t width, |
1201 | uint32_t height) { |
1202 | int i; |
1203 | const uint32_t pic_size = width * height; |
1204 | const uint32_t pic_breadth = VPXMAX(width, height)(((width) > (height)) ? (width) : (height)); |
1205 | for (i = LEVEL_1; i < LEVEL_MAX; ++i) { |
1206 | if (vp9_level_defs[i].max_luma_picture_size >= pic_size && |
1207 | vp9_level_defs[i].max_luma_picture_breadth >= pic_breadth) { |
1208 | return get_msb(vp9_level_defs[i].max_col_tiles); |
1209 | } |
1210 | } |
1211 | return INT_MAX2147483647; |
1212 | } |
1213 | |
1214 | VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec); |
1215 | |
1216 | vpx_codec_err_t vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, |
1217 | unsigned int rows, unsigned int cols, |
1218 | int delta_q[8], int delta_lf[8], int skip[8], |
1219 | int ref_frame[8]); |
1220 | |
1221 | void vp9_new_framerate(VP9_COMP *cpi, double framerate); |
1222 | |
1223 | void vp9_set_row_mt(VP9_COMP *cpi); |
1224 | |
1225 | int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr); |
1226 | |
1227 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl)((sl) * (num_tl) + (tl)) ((sl) * (num_tl) + (tl)) |
1228 | |
1229 | static INLINEinline void alloc_frame_mvs(VP9_COMMON *const cm, int buffer_idx) { |
1230 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
1231 | if (new_fb_ptr->mvs == NULL((void*)0) || new_fb_ptr->mi_rows < cm->mi_rows || |
1232 | new_fb_ptr->mi_cols < cm->mi_cols) { |
1233 | vpx_free(new_fb_ptr->mvs); |
1234 | 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" , 1236, __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) |
1235 | (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" , 1236, __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) |
1236 | 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" , 1236, __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); |
1237 | new_fb_ptr->mi_rows = cm->mi_rows; |
1238 | new_fb_ptr->mi_cols = cm->mi_cols; |
1239 | } |
1240 | } |
1241 | |
1242 | static INLINEinline int mv_cost(const MV *mv, const int *joint_cost, |
1243 | int *const comp_cost[2]) { |
1244 | 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" , 1244, __extension__ __PRETTY_FUNCTION__); })); |
1245 | 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" , 1245, __extension__ __PRETTY_FUNCTION__); })); |
1246 | return joint_cost[vp9_get_mv_joint(mv)] + comp_cost[0][mv->row] + |
1247 | comp_cost[1][mv->col]; |
1248 | } |
1249 | |
1250 | static INLINEinline int mvsad_err_cost(const MACROBLOCK *x, const MV *mv, |
1251 | const MV *ref, int sad_per_bit) { |
1252 | MV diff; |
1253 | diff.row = mv->row - ref->row; |
1254 | diff.col = mv->col - ref->col; |
1255 | return ROUND_POWER_OF_TWO(((((unsigned)mv_cost(&diff, x->nmvjointsadcost, x-> nmvsadcost) * sad_per_bit) + (1 << ((9)-1))) >> ( 9)) |
1256 | (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)) |
1257 | VP9_PROB_COST_SHIFT)((((unsigned)mv_cost(&diff, x->nmvjointsadcost, x-> nmvsadcost) * sad_per_bit) + (1 << ((9)-1))) >> ( 9)); |
1258 | } |
1259 | |
1260 | static INLINEinline uint32_t get_start_mv_sad(const MACROBLOCK *x, const MV *mvp_full, |
1261 | const MV *ref_mv_full, |
1262 | vpx_sad_fn_t sad_fn_ptr, int sadpb) { |
1263 | const int src_buf_stride = x->plane[0].src.stride; |
1264 | const uint8_t *const src_buf = x->plane[0].src.buf; |
1265 | const MACROBLOCKD *const xd = &x->e_mbd; |
1266 | const int pred_buf_stride = xd->plane[0].pre[0].stride; |
1267 | const uint8_t *const pred_buf = |
1268 | xd->plane[0].pre[0].buf + mvp_full->row * pred_buf_stride + mvp_full->col; |
1269 | uint32_t start_mv_sad = |
1270 | sad_fn_ptr(src_buf, src_buf_stride, pred_buf, pred_buf_stride); |
1271 | start_mv_sad += mvsad_err_cost(x, mvp_full, ref_mv_full, sadpb); |
1272 | |
1273 | return start_mv_sad; |
1274 | } |
1275 | |
1276 | static INLINEinline int num_4x4_to_edge(int plane_4x4_dim, int mb_to_edge_dim, |
1277 | int subsampling_dim, int blk_dim) { |
1278 | return plane_4x4_dim + (mb_to_edge_dim >> (5 + subsampling_dim)) - blk_dim; |
1279 | } |
1280 | |
1281 | // Compute the sum of squares on all visible 4x4s in the transform block. |
1282 | static int64_t sum_squares_visible(const MACROBLOCKD *xd, |
1283 | const struct macroblockd_plane *const pd, |
1284 | const int16_t *diff, const int diff_stride, |
1285 | int blk_row, int blk_col, |
1286 | const BLOCK_SIZE plane_bsize, |
1287 | const BLOCK_SIZE tx_bsize, |
1288 | int *visible_width, int *visible_height) { |
1289 | int64_t sse; |
1290 | const int plane_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
1291 | const int plane_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
1292 | const int tx_4x4_w = num_4x4_blocks_wide_lookup[tx_bsize]; |
1293 | const int tx_4x4_h = num_4x4_blocks_high_lookup[tx_bsize]; |
1294 | const int b4x4s_to_right_edge = num_4x4_to_edge( |
1295 | plane_4x4_w, xd->mb_to_right_edge, pd->subsampling_x, blk_col); |
1296 | const int b4x4s_to_bottom_edge = num_4x4_to_edge( |
1297 | plane_4x4_h, xd->mb_to_bottom_edge, pd->subsampling_y, blk_row); |
1298 | if (tx_bsize == BLOCK_4X40 || |
1299 | (b4x4s_to_right_edge >= tx_4x4_w && b4x4s_to_bottom_edge >= tx_4x4_h)) { |
1300 | 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" , 1300, __extension__ __PRETTY_FUNCTION__); })); |
1301 | sse = (int64_t)vpx_sum_squares_2d_i16vpx_sum_squares_2d_i16_sse2(diff, diff_stride, tx_4x4_w << 2); |
1302 | *visible_width = tx_4x4_w << 2; |
1303 | *visible_height = tx_4x4_h << 2; |
1304 | } else { |
1305 | int r, c; |
1306 | 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)); |
1307 | 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)); |
1308 | sse = 0; |
1309 | // if we are in the unrestricted motion border. |
1310 | for (r = 0; r < max_r; ++r) { |
1311 | // Skip visiting the sub blocks that are wholly within the UMV. |
1312 | for (c = 0; c < max_c; ++c) { |
1313 | sse += (int64_t)vpx_sum_squares_2d_i16vpx_sum_squares_2d_i16_sse2( |
1314 | diff + r * diff_stride * 4 + c * 4, diff_stride, 4); |
1315 | } |
1316 | } |
1317 | *visible_width = max_c << 2; |
1318 | *visible_height = max_r << 2; |
1319 | } |
1320 | return sse; |
1321 | } |
1322 | |
1323 | // Check if trellis coefficient optimization of the transform block is enabled. |
1324 | static INLINEinline int do_trellis_opt(const struct macroblockd_plane *pd, |
1325 | const int16_t *src_diff, int diff_stride, |
1326 | int blk_row, int blk_col, |
1327 | BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
1328 | void *arg) { |
1329 | const struct encode_b_args *const args = (struct encode_b_args *)arg; |
1330 | const MACROBLOCK *const x = args->x; |
1331 | |
1332 | switch (args->enable_trellis_opt) { |
1333 | case DISABLE_TRELLIS_OPT: return 0; |
1334 | case ENABLE_TRELLIS_OPT: return 1; |
1335 | case ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR: { |
1336 | vpx_clear_system_state(); |
1337 | |
1338 | return (args->trellis_opt_thresh > 0.0) |
1339 | ? (x->log_block_src_var <= args->trellis_opt_thresh) |
1340 | : 1; |
1341 | } |
1342 | case ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE: { |
1343 | const MACROBLOCKD *const xd = &x->e_mbd; |
1344 | const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size]; |
1345 | #if CONFIG_VP9_HIGHBITDEPTH0 |
1346 | const int dequant_shift = |
1347 | (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH8) ? xd->bd - 5 : 3; |
1348 | #else |
1349 | const int dequant_shift = 3; |
1350 | #endif // CONFIG_VP9_HIGHBITDEPTH |
1351 | const int qstep = pd->dequant[1] >> dequant_shift; |
1352 | int *sse_calc_done = args->sse_calc_done; |
1353 | int64_t *sse = args->sse; |
1354 | int visible_width = 0, visible_height = 0; |
1355 | |
1356 | // TODO: Enable the sf for high bit-depth case |
1357 | if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH8) || !sse || |
1358 | !sse_calc_done) |
1359 | return 1; |
1360 | |
1361 | *sse = sum_squares_visible(xd, pd, src_diff, diff_stride, blk_row, |
1362 | blk_col, plane_bsize, tx_bsize, &visible_width, |
1363 | &visible_height); |
1364 | *sse_calc_done = 1; |
1365 | |
1366 | vpx_clear_system_state(); |
1367 | |
1368 | return (*(sse) <= (int64_t)visible_width * visible_height * qstep * |
1369 | qstep * args->trellis_opt_thresh); |
1370 | } |
1371 | 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" , 1371, __extension__ __PRETTY_FUNCTION__); })); return 1; |
1372 | } |
1373 | } |
1374 | |
1375 | #if CONFIG_COLLECT_COMPONENT_TIMING0 |
1376 | static INLINEinline void start_timing(VP9_COMP *cpi, int component) { |
1377 | vpx_usec_timer_start(&cpi->component_timer[component]); |
1378 | } |
1379 | static INLINEinline void end_timing(VP9_COMP *cpi, int component) { |
1380 | vpx_usec_timer_mark(&cpi->component_timer[component]); |
1381 | cpi->frame_component_time[component] += |
1382 | vpx_usec_timer_elapsed(&cpi->component_timer[component]); |
1383 | } |
1384 | static INLINEinline char const *get_frame_type_enum(int type) { |
1385 | switch (type) { |
1386 | case 0: return "KEY_FRAME"; |
1387 | case 1: return "INTER_FRAME"; |
1388 | 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" , 1388, __extension__ __PRETTY_FUNCTION__); })); |
1389 | } |
1390 | return "error"; |
1391 | } |
1392 | #endif |
1393 | |
1394 | #ifdef __cplusplus |
1395 | } // extern "C" |
1396 | #endif |
1397 | |
1398 | #endif // VPX_VP9_ENCODER_VP9_ENCODER_H_ |