/* * Copyright (c) 2010 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef VPX_VP9_ENCODER_VP9_ENCODER_H_#define VPX_VP9_ENCODER_VP9_ENCODER_H_ #include <stdio.h> #include "./vpx_config.h"#include "vpx/internal/vpx_codec_internal.h"#include "vpx/vpx_ext_ratectrl.h"#include "vpx/vp8cx.h"#if CONFIG_INTERNAL_STATS#include "vpx_dsp/ssim.h"#endif#include "vpx_dsp/variance.h"#include "vpx_dsp/psnr.h"#include "vpx_ports/system_state.h"#include "vpx_util/vpx_thread.h"#include "vpx_util/vpx_timestamp.h" #include "vp9/common/vp9_alloccommon.h"#include "vp9/common/vp9_ppflags.h"#include "vp9/common/vp9_entropymode.h"#include "vp9/common/vp9_thread_common.h"#include "vp9/common/vp9_onyxc_int.h" #if !CONFIG_REALTIME_ONLY#include "vp9/encoder/vp9_alt_ref_aq.h"#endif#include "vp9/encoder/vp9_aq_cyclicrefresh.h"#include "vp9/encoder/vp9_context_tree.h"#include "vp9/encoder/vp9_encodemb.h"#include "vp9/encoder/vp9_ethread.h"#include "vp9/encoder/vp9_ext_ratectrl.h"#include "vp9/encoder/vp9_firstpass.h"#include "vp9/encoder/vp9_job_queue.h"#include "vp9/encoder/vp9_lookahead.h"#include "vp9/encoder/vp9_mbgraph.h"#include "vp9/encoder/vp9_mcomp.h"#include "vp9/encoder/vp9_noise_estimate.h"#include "vp9/encoder/vp9_quantize.h"#include "vp9/encoder/vp9_ratectrl.h"#include "vp9/encoder/vp9_rd.h"#include "vp9/encoder/vp9_speed_features.h"#include "vp9/encoder/vp9_svc_layercontext.h"#include "vp9/encoder/vp9_tokenize.h" #if CONFIG_VP9_TEMPORAL_DENOISING#include "vp9/encoder/vp9_denoiser.h"#endif #ifdef __cplusplusextern "C" {#endif // vp9 uses 10,000,000 ticks/second as time stamp#define TICKS_PER_SEC 10000000 typedef struct { int nmvjointcost[MV_JOINTS]; int nmvcosts[2][MV_VALS]; int nmvcosts_hp[2][MV_VALS]; vpx_prob segment_pred_probs[PREDICTION_PROBS]; unsigned char *last_frame_seg_map_copy; // 0 = Intra, Last, GF, ARF signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; // 0 = ZERO_MV, MV signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; FRAME_CONTEXT fc;} CODING_CONTEXT; typedef enum { // encode_breakout is disabled. ENCODE_BREAKOUT_DISABLED = 0, // encode_breakout is enabled. ENCODE_BREAKOUT_ENABLED = 1, // encode_breakout is enabled with small max_thresh limit. ENCODE_BREAKOUT_LIMITED = 2} ENCODE_BREAKOUT_TYPE; typedef enum { NORMAL = 0, FOURFIVE = 1, THREEFIVE = 2, ONETWO = 3} VPX_SCALING; typedef enum { // Good Quality Fast Encoding. The encoder balances quality with the amount of // time it takes to encode the output. Speed setting controls how fast. GOOD, // The encoder places priority on the quality of the output over encoding // speed. The output is compressed at the highest possible quality. This // option takes the longest amount of time to encode. Speed setting ignored. BEST, // Realtime/Live Encoding. This mode is optimized for realtime encoding (for // example, capturing a television signal or feed from a live camera). Speed // setting controls how fast. REALTIME} MODE; typedef enum { FRAMEFLAGS_KEY = 1 << 0, FRAMEFLAGS_GOLDEN = 1 << 1, FRAMEFLAGS_ALTREF = 1 << 2,} FRAMETYPE_FLAGS; typedef enum { NO_AQ = 0, VARIANCE_AQ = 1, COMPLEXITY_AQ = 2, CYCLIC_REFRESH_AQ = 3, EQUATOR360_AQ = 4, PERCEPTUAL_AQ = 5, PSNR_AQ = 6, // AQ based on lookahead temporal // variance (only valid for altref frames) LOOKAHEAD_AQ = 7, AQ_MODE_COUNT // This should always be the last member of the enum} AQ_MODE; typedef enum { RESIZE_NONE = 0, // No frame resizing allowed (except for SVC). RESIZE_FIXED = 1, // All frames are coded at the specified dimension. RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.} RESIZE_TYPE; typedef enum { kInvalid = 0, kLowSadLowSumdiff = 1, kLowSadHighSumdiff = 2, kHighSadLowSumdiff = 3, kHighSadHighSumdiff = 4, kLowVarHighSumdiff = 5, kVeryHighSad = 6,} CONTENT_STATE_SB; typedef enum { LOOPFILTER_ALL = 0, LOOPFILTER_REFERENCE = 1, // Disable loopfilter on non reference frames. NO_LOOPFILTER = 2, // Disable loopfilter on all frames.} LOOPFILTER_CONTROL; typedef struct VP9EncoderConfig { BITSTREAM_PROFILE profile; vpx_bit_depth_t bit_depth; // Codec bit-depth. int width; // width of data passed to the compressor int height; // height of data passed to the compressor unsigned int input_bit_depth; // Input bit depth. double init_framerate; // set to passed in framerate vpx_rational_t g_timebase; // equivalent to g_timebase in vpx_codec_enc_cfg_t vpx_rational64_t g_timebase_in_ts; // g_timebase * TICKS_PER_SEC int64_t target_bandwidth; // bandwidth to be used in bits per second int noise_sensitivity; // pre processing blur: recommendation 0 int sharpness; // sharpening output: recommendation 0: int speed; // maximum allowed bitrate for any intra frame in % of bitrate target. unsigned int rc_max_intra_bitrate_pct; // maximum allowed bitrate for any inter frame in % of bitrate target. unsigned int rc_max_inter_bitrate_pct; // percent of rate boost for golden frame in CBR mode. unsigned int gf_cbr_boost_pct; MODE mode; int pass; // Key Framing Operations int auto_key; // autodetect cut scenes and set the keyframes int key_freq; // maximum distance to key frame. int lag_in_frames; // how many frames lag before we start encoding // ---------------------------------------------------------------- // DATARATE CONTROL OPTIONS // vbr, cbr, constrained quality or constant quality enum vpx_rc_mode rc_mode; // buffer targeting aggressiveness int under_shoot_pct; int over_shoot_pct; // buffering parameters int64_t starting_buffer_level_ms; int64_t optimal_buffer_level_ms; int64_t maximum_buffer_size_ms; // Frame drop threshold. int drop_frames_water_mark; // controlling quality int fixed_q; int worst_allowed_q; int best_allowed_q; int cq_level; AQ_MODE aq_mode; // Adaptive Quantization mode // Special handling of Adaptive Quantization for AltRef frames int alt_ref_aq; // Internal frame size scaling. RESIZE_TYPE resize_mode; int scaled_frame_width; int scaled_frame_height; // Enable feature to reduce the frame quantization every x frames. int frame_periodic_boost; // two pass datarate control int two_pass_vbrbias; // two pass datarate control tweaks int two_pass_vbrmin_section; int two_pass_vbrmax_section; int vbr_corpus_complexity; // 0 indicates corpus vbr disabled // END DATARATE CONTROL OPTIONS // ---------------------------------------------------------------- // Spatial and temporal scalability. int ss_number_layers; // Number of spatial layers. int ts_number_layers; // Number of temporal layers. // Bitrate allocation for spatial layers. int layer_target_bitrate[VPX_MAX_LAYERS]; int ss_target_bitrate[VPX_SS_MAX_LAYERS]; int ss_enable_auto_arf[VPX_SS_MAX_LAYERS]; // Bitrate allocation (CBR mode) and framerate factor, for temporal layers. int ts_rate_decimator[VPX_TS_MAX_LAYERS]; int enable_auto_arf; int encode_breakout; // early breakout : for video conf recommend 800 /* Bitfield defining the error resiliency features to enable. * Can provide decodable frames after losses in previous * frames and decodable partitions after losses in the same frame. */ unsigned int error_resilient_mode; /* Bitfield defining the parallel decoding mode where the * decoding in successive frames may be conducted in parallel * just by decoding the frame headers. */ unsigned int frame_parallel_decoding_mode; int arnr_max_frames; int arnr_strength; int min_gf_interval; int max_gf_interval; int tile_columns; int tile_rows; int enable_tpl_model; int max_threads; unsigned int target_level; vpx_fixed_buf_t two_pass_stats_in; vp8e_tuning tuning; vp9e_tune_content content;#if CONFIG_VP9_HIGHBITDEPTH int use_highbitdepth;#endif vpx_color_space_t color_space; vpx_color_range_t color_range; int render_width; int render_height; VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode; int row_mt; unsigned int motion_vector_unit_test; int delta_q_uv; int use_simple_encode_api; // Use SimpleEncode APIs or not} VP9EncoderConfig; static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) { return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;} typedef struct TplDepStats { int64_t intra_cost; int64_t inter_cost; int64_t mc_flow; int64_t mc_dep_cost; int64_t mc_ref_cost; int ref_frame_index; int_mv mv;} TplDepStats; #if CONFIG_NON_GREEDY_MV #define ZERO_MV_MODE 0#define NEW_MV_MODE 1#define NEAREST_MV_MODE 2#define NEAR_MV_MODE 3#define MAX_MV_MODE 4#endif typedef struct TplDepFrame { uint8_t is_valid; TplDepStats *tpl_stats_ptr; int stride; int width; int height; int mi_rows; int mi_cols; int base_qindex;#if CONFIG_NON_GREEDY_MV int lambda; int *mv_mode_arr[3]; double *rd_diff_arr[3];#endif} TplDepFrame; #define TPL_DEP_COST_SCALE_LOG2 4 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.typedef struct TileDataEnc { TileInfo tile_info; int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];#if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int thresh_freq_fact_prev[BLOCK_SIZES][MAX_MODES];#endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int8_t mode_map[BLOCK_SIZES][MAX_MODES]; FIRSTPASS_DATA fp_data; VP9RowMTSync row_mt_sync; // Used for adaptive_rd_thresh with row multithreading int *row_base_thresh_freq_fact;} TileDataEnc; typedef struct RowMTInfo { JobQueueHandle job_queue_hdl;#if CONFIG_MULTITHREAD pthread_mutex_t job_mutex;#endif} RowMTInfo; typedef struct { TOKENEXTRA *start; TOKENEXTRA *stop; unsigned int count;} TOKENLIST; typedef struct MultiThreadHandle { int allocated_tile_rows; int allocated_tile_cols; int allocated_vert_unit_rows; // Frame level params int num_tile_vert_sbs[MAX_NUM_TILE_ROWS]; // Job Queue structure and handles JobQueue *job_queue; int jobs_per_tile_col; RowMTInfo row_mt_info[MAX_NUM_TILE_COLS]; int thread_id_to_tile_id[MAX_NUM_THREADS]; // Mapping of threads to tiles} MultiThreadHandle; typedef struct RD_COUNTS { vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES]; int64_t comp_pred_diff[REFERENCE_MODES]; int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];} RD_COUNTS; typedef struct ThreadData { MACROBLOCK mb; RD_COUNTS rd_counts; FRAME_COUNTS *counts; PICK_MODE_CONTEXT *leaf_tree; PC_TREE *pc_tree; PC_TREE *pc_root;} ThreadData; struct EncWorkerData; typedef struct ActiveMap { int enabled; int update; unsigned char *map;} ActiveMap; typedef enum { Y, U, V, ALL } STAT_TYPE; typedef struct IMAGE_STAT { double stat[ALL + 1]; double worst;} ImageStat; // Kf noise filtering currently disabled by default in build.// #define ENABLE_KF_DENOISE 1 #define CPB_WINDOW_SIZE 4#define FRAME_WINDOW_SIZE 128#define SAMPLE_RATE_GRACE_P 0.015#define VP9_LEVELS 14 typedef enum { LEVEL_UNKNOWN = 0, LEVEL_AUTO = 1, LEVEL_1 = 10, LEVEL_1_1 = 11, LEVEL_2 = 20, LEVEL_2_1 = 21, LEVEL_3 = 30, LEVEL_3_1 = 31, LEVEL_4 = 40, LEVEL_4_1 = 41, LEVEL_5 = 50, LEVEL_5_1 = 51, LEVEL_5_2 = 52, LEVEL_6 = 60, LEVEL_6_1 = 61, LEVEL_6_2 = 62, LEVEL_MAX = 255} VP9_LEVEL; typedef struct { VP9_LEVEL level; uint64_t max_luma_sample_rate; uint32_t max_luma_picture_size; uint32_t max_luma_picture_breadth; double average_bitrate; // in kilobits per second double max_cpb_size; // in kilobits double compression_ratio; uint8_t max_col_tiles; uint32_t min_altref_distance; uint8_t max_ref_frame_buffers;} Vp9LevelSpec; extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS]; typedef struct { int64_t ts; // timestamp uint32_t luma_samples; uint32_t size; // in bytes} FrameRecord; typedef struct { FrameRecord buf[FRAME_WINDOW_SIZE]; uint8_t start; uint8_t len;} FrameWindowBuffer; typedef struct { uint8_t seen_first_altref; uint32_t frames_since_last_altref; uint64_t total_compressed_size; uint64_t total_uncompressed_size; double time_encoded; // in seconds FrameWindowBuffer frame_window_buffer; int ref_refresh_map;} Vp9LevelStats; typedef struct { Vp9LevelStats level_stats; Vp9LevelSpec level_spec;} Vp9LevelInfo; typedef enum { BITRATE_TOO_LARGE = 0, LUMA_PIC_SIZE_TOO_LARGE, LUMA_PIC_BREADTH_TOO_LARGE, LUMA_SAMPLE_RATE_TOO_LARGE, CPB_TOO_LARGE, COMPRESSION_RATIO_TOO_SMALL, TOO_MANY_COLUMN_TILE, ALTREF_DIST_TOO_SMALL, TOO_MANY_REF_BUFFER, TARGET_LEVEL_FAIL_IDS} TARGET_LEVEL_FAIL_ID; typedef struct { int8_t level_index; uint8_t fail_flag; int max_frame_size; // in bits double max_cpb_size; // in bits} LevelConstraint; Lines 1–500 of 1390. Load more
/* * Copyright (c) 2010 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef VPX_VP9_ENCODER_VP9_ENCODER_H_ #define VPX_VP9_ENCODER_VP9_ENCODER_H_ #include <stdio.h> #include "./vpx_config.h" #include "vpx/internal/vpx_codec_internal.h" #include "vpx/vpx_ext_ratectrl.h" #include "vpx/vp8cx.h" #if CONFIG_INTERNAL_STATS #include "vpx_dsp/ssim.h" #endif #include "vpx_dsp/variance.h" #include "vpx_dsp/psnr.h" #include "vpx_ports/system_state.h" #include "vpx_util/vpx_thread.h" #include "vpx_util/vpx_timestamp.h" #include "vp9/common/vp9_alloccommon.h" #include "vp9/common/vp9_ppflags.h" #include "vp9/common/vp9_entropymode.h" #include "vp9/common/vp9_thread_common.h" #include "vp9/common/vp9_onyxc_int.h" #if !CONFIG_REALTIME_ONLY #include "vp9/encoder/vp9_alt_ref_aq.h" #endif #include "vp9/encoder/vp9_aq_cyclicrefresh.h" #include "vp9/encoder/vp9_context_tree.h" #include "vp9/encoder/vp9_encodemb.h" #include "vp9/encoder/vp9_ethread.h" #include "vp9/encoder/vp9_ext_ratectrl.h" #include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_job_queue.h" #include "vp9/encoder/vp9_lookahead.h" #include "vp9/encoder/vp9_mbgraph.h" #include "vp9/encoder/vp9_mcomp.h" #include "vp9/encoder/vp9_noise_estimate.h" #include "vp9/encoder/vp9_quantize.h" #include "vp9/encoder/vp9_ratectrl.h" #include "vp9/encoder/vp9_rd.h" #include "vp9/encoder/vp9_speed_features.h" #include "vp9/encoder/vp9_svc_layercontext.h" #include "vp9/encoder/vp9_tokenize.h" #if CONFIG_VP9_TEMPORAL_DENOISING #include "vp9/encoder/vp9_denoiser.h" #endif #ifdef __cplusplus extern "C" { #endif // vp9 uses 10,000,000 ticks/second as time stamp #define TICKS_PER_SEC 10000000 typedef struct { int nmvjointcost[MV_JOINTS]; int nmvcosts[2][MV_VALS]; int nmvcosts_hp[2][MV_VALS]; vpx_prob segment_pred_probs[PREDICTION_PROBS]; unsigned char *last_frame_seg_map_copy; // 0 = Intra, Last, GF, ARF signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; // 0 = ZERO_MV, MV signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; FRAME_CONTEXT fc; } CODING_CONTEXT; typedef enum { // encode_breakout is disabled. ENCODE_BREAKOUT_DISABLED = 0, // encode_breakout is enabled. ENCODE_BREAKOUT_ENABLED = 1, // encode_breakout is enabled with small max_thresh limit. ENCODE_BREAKOUT_LIMITED = 2 } ENCODE_BREAKOUT_TYPE; typedef enum { NORMAL = 0, FOURFIVE = 1, THREEFIVE = 2, ONETWO = 3 } VPX_SCALING; typedef enum { // Good Quality Fast Encoding. The encoder balances quality with the amount of // time it takes to encode the output. Speed setting controls how fast. GOOD, // The encoder places priority on the quality of the output over encoding // speed. The output is compressed at the highest possible quality. This // option takes the longest amount of time to encode. Speed setting ignored. BEST, // Realtime/Live Encoding. This mode is optimized for realtime encoding (for // example, capturing a television signal or feed from a live camera). Speed // setting controls how fast. REALTIME } MODE; typedef enum { FRAMEFLAGS_KEY = 1 << 0, FRAMEFLAGS_GOLDEN = 1 << 1, FRAMEFLAGS_ALTREF = 1 << 2, } FRAMETYPE_FLAGS; typedef enum { NO_AQ = 0, VARIANCE_AQ = 1, COMPLEXITY_AQ = 2, CYCLIC_REFRESH_AQ = 3, EQUATOR360_AQ = 4, PERCEPTUAL_AQ = 5, PSNR_AQ = 6, // AQ based on lookahead temporal // variance (only valid for altref frames) LOOKAHEAD_AQ = 7, AQ_MODE_COUNT // This should always be the last member of the enum } AQ_MODE; typedef enum { RESIZE_NONE = 0, // No frame resizing allowed (except for SVC). RESIZE_FIXED = 1, // All frames are coded at the specified dimension. RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec. } RESIZE_TYPE; typedef enum { kInvalid = 0, kLowSadLowSumdiff = 1, kLowSadHighSumdiff = 2, kHighSadLowSumdiff = 3, kHighSadHighSumdiff = 4, kLowVarHighSumdiff = 5, kVeryHighSad = 6, } CONTENT_STATE_SB; typedef enum { LOOPFILTER_ALL = 0, LOOPFILTER_REFERENCE = 1, // Disable loopfilter on non reference frames. NO_LOOPFILTER = 2, // Disable loopfilter on all frames. } LOOPFILTER_CONTROL; typedef struct VP9EncoderConfig { BITSTREAM_PROFILE profile; vpx_bit_depth_t bit_depth; // Codec bit-depth. int width; // width of data passed to the compressor int height; // height of data passed to the compressor unsigned int input_bit_depth; // Input bit depth. double init_framerate; // set to passed in framerate vpx_rational_t g_timebase; // equivalent to g_timebase in vpx_codec_enc_cfg_t vpx_rational64_t g_timebase_in_ts; // g_timebase * TICKS_PER_SEC int64_t target_bandwidth; // bandwidth to be used in bits per second int noise_sensitivity; // pre processing blur: recommendation 0 int sharpness; // sharpening output: recommendation 0: int speed; // maximum allowed bitrate for any intra frame in % of bitrate target. unsigned int rc_max_intra_bitrate_pct; // maximum allowed bitrate for any inter frame in % of bitrate target. unsigned int rc_max_inter_bitrate_pct; // percent of rate boost for golden frame in CBR mode. unsigned int gf_cbr_boost_pct; MODE mode; int pass; // Key Framing Operations int auto_key; // autodetect cut scenes and set the keyframes int key_freq; // maximum distance to key frame. int lag_in_frames; // how many frames lag before we start encoding // ---------------------------------------------------------------- // DATARATE CONTROL OPTIONS // vbr, cbr, constrained quality or constant quality enum vpx_rc_mode rc_mode; // buffer targeting aggressiveness int under_shoot_pct; int over_shoot_pct; // buffering parameters int64_t starting_buffer_level_ms; int64_t optimal_buffer_level_ms; int64_t maximum_buffer_size_ms; // Frame drop threshold. int drop_frames_water_mark; // controlling quality int fixed_q; int worst_allowed_q; int best_allowed_q; int cq_level; AQ_MODE aq_mode; // Adaptive Quantization mode // Special handling of Adaptive Quantization for AltRef frames int alt_ref_aq; // Internal frame size scaling. RESIZE_TYPE resize_mode; int scaled_frame_width; int scaled_frame_height; // Enable feature to reduce the frame quantization every x frames. int frame_periodic_boost; // two pass datarate control int two_pass_vbrbias; // two pass datarate control tweaks int two_pass_vbrmin_section; int two_pass_vbrmax_section; int vbr_corpus_complexity; // 0 indicates corpus vbr disabled // END DATARATE CONTROL OPTIONS // ---------------------------------------------------------------- // Spatial and temporal scalability. int ss_number_layers; // Number of spatial layers. int ts_number_layers; // Number of temporal layers. // Bitrate allocation for spatial layers. int layer_target_bitrate[VPX_MAX_LAYERS]; int ss_target_bitrate[VPX_SS_MAX_LAYERS]; int ss_enable_auto_arf[VPX_SS_MAX_LAYERS]; // Bitrate allocation (CBR mode) and framerate factor, for temporal layers. int ts_rate_decimator[VPX_TS_MAX_LAYERS]; int enable_auto_arf; int encode_breakout; // early breakout : for video conf recommend 800 /* Bitfield defining the error resiliency features to enable. * Can provide decodable frames after losses in previous * frames and decodable partitions after losses in the same frame. */ unsigned int error_resilient_mode; /* Bitfield defining the parallel decoding mode where the * decoding in successive frames may be conducted in parallel * just by decoding the frame headers. */ unsigned int frame_parallel_decoding_mode; int arnr_max_frames; int arnr_strength; int min_gf_interval; int max_gf_interval; int tile_columns; int tile_rows; int enable_tpl_model; int max_threads; unsigned int target_level; vpx_fixed_buf_t two_pass_stats_in; vp8e_tuning tuning; vp9e_tune_content content; #if CONFIG_VP9_HIGHBITDEPTH int use_highbitdepth; #endif vpx_color_space_t color_space; vpx_color_range_t color_range; int render_width; int render_height; VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode; int row_mt; unsigned int motion_vector_unit_test; int delta_q_uv; int use_simple_encode_api; // Use SimpleEncode APIs or not } VP9EncoderConfig; static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) { return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; } typedef struct TplDepStats { int64_t intra_cost; int64_t inter_cost; int64_t mc_flow; int64_t mc_dep_cost; int64_t mc_ref_cost; int ref_frame_index; int_mv mv; } TplDepStats; #if CONFIG_NON_GREEDY_MV #define ZERO_MV_MODE 0 #define NEW_MV_MODE 1 #define NEAREST_MV_MODE 2 #define NEAR_MV_MODE 3 #define MAX_MV_MODE 4 #endif typedef struct TplDepFrame { uint8_t is_valid; TplDepStats *tpl_stats_ptr; int stride; int width; int height; int mi_rows; int mi_cols; int base_qindex; #if CONFIG_NON_GREEDY_MV int lambda; int *mv_mode_arr[3]; double *rd_diff_arr[3]; #endif } TplDepFrame; #define TPL_DEP_COST_SCALE_LOG2 4 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. typedef struct TileDataEnc { TileInfo tile_info; int thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; #if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int thresh_freq_fact_prev[BLOCK_SIZES][MAX_MODES]; #endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int8_t mode_map[BLOCK_SIZES][MAX_MODES]; FIRSTPASS_DATA fp_data; VP9RowMTSync row_mt_sync; // Used for adaptive_rd_thresh with row multithreading int *row_base_thresh_freq_fact; } TileDataEnc; typedef struct RowMTInfo { JobQueueHandle job_queue_hdl; #if CONFIG_MULTITHREAD pthread_mutex_t job_mutex; #endif } RowMTInfo; typedef struct { TOKENEXTRA *start; TOKENEXTRA *stop; unsigned int count; } TOKENLIST; typedef struct MultiThreadHandle { int allocated_tile_rows; int allocated_tile_cols; int allocated_vert_unit_rows; // Frame level params int num_tile_vert_sbs[MAX_NUM_TILE_ROWS]; // Job Queue structure and handles JobQueue *job_queue; int jobs_per_tile_col; RowMTInfo row_mt_info[MAX_NUM_TILE_COLS]; int thread_id_to_tile_id[MAX_NUM_THREADS]; // Mapping of threads to tiles } MultiThreadHandle; typedef struct RD_COUNTS { vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES]; int64_t comp_pred_diff[REFERENCE_MODES]; int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS]; } RD_COUNTS; typedef struct ThreadData { MACROBLOCK mb; RD_COUNTS rd_counts; FRAME_COUNTS *counts; PICK_MODE_CONTEXT *leaf_tree; PC_TREE *pc_tree; PC_TREE *pc_root; } ThreadData; struct EncWorkerData; typedef struct ActiveMap { int enabled; int update; unsigned char *map; } ActiveMap; typedef enum { Y, U, V, ALL } STAT_TYPE; typedef struct IMAGE_STAT { double stat[ALL + 1]; double worst; } ImageStat; // Kf noise filtering currently disabled by default in build. // #define ENABLE_KF_DENOISE 1 #define CPB_WINDOW_SIZE 4 #define FRAME_WINDOW_SIZE 128 #define SAMPLE_RATE_GRACE_P 0.015 #define VP9_LEVELS 14 typedef enum { LEVEL_UNKNOWN = 0, LEVEL_AUTO = 1, LEVEL_1 = 10, LEVEL_1_1 = 11, LEVEL_2 = 20, LEVEL_2_1 = 21, LEVEL_3 = 30, LEVEL_3_1 = 31, LEVEL_4 = 40, LEVEL_4_1 = 41, LEVEL_5 = 50, LEVEL_5_1 = 51, LEVEL_5_2 = 52, LEVEL_6 = 60, LEVEL_6_1 = 61, LEVEL_6_2 = 62, LEVEL_MAX = 255 } VP9_LEVEL; typedef struct { VP9_LEVEL level; uint64_t max_luma_sample_rate; uint32_t max_luma_picture_size; uint32_t max_luma_picture_breadth; double average_bitrate; // in kilobits per second double max_cpb_size; // in kilobits double compression_ratio; uint8_t max_col_tiles; uint32_t min_altref_distance; uint8_t max_ref_frame_buffers; } Vp9LevelSpec; extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS]; typedef struct { int64_t ts; // timestamp uint32_t luma_samples; uint32_t size; // in bytes } FrameRecord; typedef struct { FrameRecord buf[FRAME_WINDOW_SIZE]; uint8_t start; uint8_t len; } FrameWindowBuffer; typedef struct { uint8_t seen_first_altref; uint32_t frames_since_last_altref; uint64_t total_compressed_size; uint64_t total_uncompressed_size; double time_encoded; // in seconds FrameWindowBuffer frame_window_buffer; int ref_refresh_map; } Vp9LevelStats; typedef struct { Vp9LevelStats level_stats; Vp9LevelSpec level_spec; } Vp9LevelInfo; typedef enum { BITRATE_TOO_LARGE = 0, LUMA_PIC_SIZE_TOO_LARGE, LUMA_PIC_BREADTH_TOO_LARGE, LUMA_SAMPLE_RATE_TOO_LARGE, CPB_TOO_LARGE, COMPRESSION_RATIO_TOO_SMALL, TOO_MANY_COLUMN_TILE, ALTREF_DIST_TOO_SMALL, TOO_MANY_REF_BUFFER, TARGET_LEVEL_FAIL_IDS } TARGET_LEVEL_FAIL_ID; typedef struct { int8_t level_index; uint8_t fail_flag; int max_frame_size; // in bits double max_cpb_size; // in bits } LevelConstraint;