onyx_int.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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. #ifndef VPX_VP8_ENCODER_ONYX_INT_H_
  11. #define VPX_VP8_ENCODER_ONYX_INT_H_
  12. #include <stdio.h>
  13. #include "vpx_config.h"
  14. #include "vp8/common/onyx.h"
  15. #include "treewriter.h"
  16. #include "tokenize.h"
  17. #include "vp8/common/onyxc_int.h"
  18. #include "vpx_dsp/variance.h"
  19. #include "encodemb.h"
  20. #include "vp8/encoder/quantize.h"
  21. #include "vp8/common/entropy.h"
  22. #include "vp8/common/threading.h"
  23. #include "vpx_ports/mem.h"
  24. #include "vpx/internal/vpx_codec_internal.h"
  25. #include "vpx/vp8.h"
  26. #include "mcomp.h"
  27. #include "vp8/common/findnearmv.h"
  28. #include "lookahead.h"
  29. #if CONFIG_TEMPORAL_DENOISING
  30. #include "vp8/encoder/denoising.h"
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #define MIN_GF_INTERVAL 4
  36. #define DEFAULT_GF_INTERVAL 7
  37. #define KEY_FRAME_CONTEXT 5
  38. #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY ? 1 : 25)
  39. #define AF_THRESH 25
  40. #define AF_THRESH2 100
  41. #define ARF_DECAY_THRESH 12
  42. #define MIN_THRESHMULT 32
  43. #define MAX_THRESHMULT 512
  44. #define GF_ZEROMV_ZBIN_BOOST 12
  45. #define LF_ZEROMV_ZBIN_BOOST 6
  46. #define MV_ZBIN_BOOST 4
  47. #define ZBIN_OQ_MAX 192
  48. #define VP8_TEMPORAL_ALT_REF !CONFIG_REALTIME_ONLY
  49. /* vp8 uses 10,000,000 ticks/second as time stamp */
  50. #define TICKS_PER_SEC 10000000
  51. typedef struct {
  52. int kf_indicated;
  53. unsigned int frames_since_key;
  54. unsigned int frames_since_golden;
  55. int filter_level;
  56. int frames_till_gf_update_due;
  57. int recent_ref_frame_usage[MAX_REF_FRAMES];
  58. MV_CONTEXT mvc[2];
  59. int mvcosts[2][MVvals + 1];
  60. #ifdef MODE_STATS
  61. int y_modes[5];
  62. int uv_modes[4];
  63. int b_modes[10];
  64. int inter_y_modes[10];
  65. int inter_uv_modes[4];
  66. int inter_b_modes[10];
  67. #endif
  68. vp8_prob ymode_prob[4], uv_mode_prob[3]; /* interframe intra mode probs */
  69. vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3]; /* keyframe "" */
  70. int ymode_count[5], uv_mode_count[4]; /* intra MB type cts this frame */
  71. int count_mb_ref_frame_usage[MAX_REF_FRAMES];
  72. int this_frame_percent_intra;
  73. int last_frame_percent_intra;
  74. } CODING_CONTEXT;
  75. typedef struct {
  76. double frame;
  77. double intra_error;
  78. double coded_error;
  79. double ssim_weighted_pred_err;
  80. double pcnt_inter;
  81. double pcnt_motion;
  82. double pcnt_second_ref;
  83. double pcnt_neutral;
  84. double MVr;
  85. double mvr_abs;
  86. double MVc;
  87. double mvc_abs;
  88. double MVrv;
  89. double MVcv;
  90. double mv_in_out_count;
  91. double new_mv_count;
  92. double duration;
  93. double count;
  94. } FIRSTPASS_STATS;
  95. typedef struct {
  96. int frames_so_far;
  97. double frame_intra_error;
  98. double frame_coded_error;
  99. double frame_pcnt_inter;
  100. double frame_pcnt_motion;
  101. double frame_mvr;
  102. double frame_mvr_abs;
  103. double frame_mvc;
  104. double frame_mvc_abs;
  105. } ONEPASS_FRAMESTATS;
  106. typedef enum {
  107. THR_ZERO1 = 0,
  108. THR_DC = 1,
  109. THR_NEAREST1 = 2,
  110. THR_NEAR1 = 3,
  111. THR_ZERO2 = 4,
  112. THR_NEAREST2 = 5,
  113. THR_ZERO3 = 6,
  114. THR_NEAREST3 = 7,
  115. THR_NEAR2 = 8,
  116. THR_NEAR3 = 9,
  117. THR_V_PRED = 10,
  118. THR_H_PRED = 11,
  119. THR_TM = 12,
  120. THR_NEW1 = 13,
  121. THR_NEW2 = 14,
  122. THR_NEW3 = 15,
  123. THR_SPLIT1 = 16,
  124. THR_SPLIT2 = 17,
  125. THR_SPLIT3 = 18,
  126. THR_B_PRED = 19
  127. } THR_MODES;
  128. typedef enum { DIAMOND = 0, NSTEP = 1, HEX = 2 } SEARCH_METHODS;
  129. typedef struct {
  130. int RD;
  131. SEARCH_METHODS search_method;
  132. int improved_quant;
  133. int improved_dct;
  134. int auto_filter;
  135. int recode_loop;
  136. int iterative_sub_pixel;
  137. int half_pixel_search;
  138. int quarter_pixel_search;
  139. int thresh_mult[MAX_MODES];
  140. int max_step_search_steps;
  141. int first_step;
  142. int optimize_coefficients;
  143. int use_fastquant_for_pick;
  144. int no_skip_block4x4_search;
  145. int improved_mv_pred;
  146. } SPEED_FEATURES;
  147. typedef struct {
  148. MACROBLOCK mb;
  149. int segment_counts[MAX_MB_SEGMENTS];
  150. int totalrate;
  151. } MB_ROW_COMP;
  152. typedef struct {
  153. TOKENEXTRA *start;
  154. TOKENEXTRA *stop;
  155. } TOKENLIST;
  156. typedef struct {
  157. int ithread;
  158. void *ptr1;
  159. void *ptr2;
  160. } ENCODETHREAD_DATA;
  161. typedef struct {
  162. int ithread;
  163. void *ptr1;
  164. } LPFTHREAD_DATA;
  165. enum {
  166. BLOCK_16X8,
  167. BLOCK_8X16,
  168. BLOCK_8X8,
  169. BLOCK_4X4,
  170. BLOCK_16X16,
  171. BLOCK_MAX_SEGMENTS
  172. };
  173. typedef struct {
  174. /* Layer configuration */
  175. double framerate;
  176. int target_bandwidth;
  177. /* Layer specific coding parameters */
  178. int64_t starting_buffer_level;
  179. int64_t optimal_buffer_level;
  180. int64_t maximum_buffer_size;
  181. int64_t starting_buffer_level_in_ms;
  182. int64_t optimal_buffer_level_in_ms;
  183. int64_t maximum_buffer_size_in_ms;
  184. int avg_frame_size_for_layer;
  185. int64_t buffer_level;
  186. int64_t bits_off_target;
  187. int64_t total_actual_bits;
  188. int total_target_vs_actual;
  189. int worst_quality;
  190. int active_worst_quality;
  191. int best_quality;
  192. int active_best_quality;
  193. int ni_av_qi;
  194. int ni_tot_qi;
  195. int ni_frames;
  196. int avg_frame_qindex;
  197. double rate_correction_factor;
  198. double key_frame_rate_correction_factor;
  199. double gf_rate_correction_factor;
  200. int zbin_over_quant;
  201. int inter_frame_target;
  202. int64_t total_byte_count;
  203. int filter_level;
  204. int frames_since_last_drop_overshoot;
  205. int force_maxqp;
  206. int last_frame_percent_intra;
  207. int count_mb_ref_frame_usage[MAX_REF_FRAMES];
  208. int last_q[2];
  209. } LAYER_CONTEXT;
  210. typedef struct VP8_COMP {
  211. DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
  212. DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]);
  213. DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
  214. DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
  215. DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
  216. DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]);
  217. DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
  218. DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
  219. DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
  220. DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]);
  221. DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
  222. DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
  223. DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
  224. DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
  225. DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
  226. DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
  227. DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
  228. DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
  229. MACROBLOCK mb;
  230. VP8_COMMON common;
  231. vp8_writer bc[9]; /* one boolcoder for each partition */
  232. VP8_CONFIG oxcf;
  233. struct lookahead_ctx *lookahead;
  234. struct lookahead_entry *source;
  235. struct lookahead_entry *alt_ref_source;
  236. struct lookahead_entry *last_source;
  237. YV12_BUFFER_CONFIG *Source;
  238. YV12_BUFFER_CONFIG *un_scaled_source;
  239. YV12_BUFFER_CONFIG scaled_source;
  240. YV12_BUFFER_CONFIG *last_frame_unscaled_source;
  241. unsigned int frames_till_alt_ref_frame;
  242. /* frame in src_buffers has been identified to be encoded as an alt ref */
  243. int source_alt_ref_pending;
  244. /* an alt ref frame has been encoded and is usable */
  245. int source_alt_ref_active;
  246. /* source of frame to encode is an exact copy of an alt ref frame */
  247. int is_src_frame_alt_ref;
  248. /* golden frame same as last frame ( short circuit gold searches) */
  249. int gold_is_last;
  250. /* Alt reference frame same as last ( short circuit altref search) */
  251. int alt_is_last;
  252. /* don't do both alt and gold search ( just do gold). */
  253. int gold_is_alt;
  254. YV12_BUFFER_CONFIG pick_lf_lvl_frame;
  255. TOKENEXTRA *tok;
  256. unsigned int tok_count;
  257. unsigned int frames_since_key;
  258. unsigned int key_frame_frequency;
  259. unsigned int this_key_frame_forced;
  260. unsigned int next_key_frame_forced;
  261. /* Ambient reconstruction err target for force key frames */
  262. int ambient_err;
  263. unsigned int mode_check_freq[MAX_MODES];
  264. int rd_baseline_thresh[MAX_MODES];
  265. int RDMULT;
  266. int RDDIV;
  267. CODING_CONTEXT coding_context;
  268. /* Rate targetting variables */
  269. int64_t last_prediction_error;
  270. int64_t last_intra_error;
  271. int this_frame_target;
  272. int projected_frame_size;
  273. int last_q[2]; /* Separate values for Intra/Inter */
  274. double rate_correction_factor;
  275. double key_frame_rate_correction_factor;
  276. double gf_rate_correction_factor;
  277. int frames_since_golden;
  278. /* Count down till next GF */
  279. int frames_till_gf_update_due;
  280. /* GF interval chosen when we coded the last GF */
  281. int current_gf_interval;
  282. /* Total bits overspent becasue of GF boost (cumulative) */
  283. int gf_overspend_bits;
  284. /* Used in the few frames following a GF to recover the extra bits
  285. * spent in that GF
  286. */
  287. int non_gf_bitrate_adjustment;
  288. /* Extra bits spent on key frames that need to be recovered */
  289. int kf_overspend_bits;
  290. /* Current number of bit s to try and recover on each inter frame. */
  291. int kf_bitrate_adjustment;
  292. int max_gf_interval;
  293. int baseline_gf_interval;
  294. int active_arnr_frames;
  295. int64_t key_frame_count;
  296. int prior_key_frame_distance[KEY_FRAME_CONTEXT];
  297. /* Current section per frame bandwidth target */
  298. int per_frame_bandwidth;
  299. /* Average frame size target for clip */
  300. int av_per_frame_bandwidth;
  301. /* Minimum allocation that should be used for any frame */
  302. int min_frame_bandwidth;
  303. int inter_frame_target;
  304. double output_framerate;
  305. int64_t last_time_stamp_seen;
  306. int64_t last_end_time_stamp_seen;
  307. int64_t first_time_stamp_ever;
  308. int ni_av_qi;
  309. int ni_tot_qi;
  310. int ni_frames;
  311. int avg_frame_qindex;
  312. int64_t total_byte_count;
  313. int buffered_mode;
  314. double framerate;
  315. double ref_framerate;
  316. int64_t buffer_level;
  317. int64_t bits_off_target;
  318. int rolling_target_bits;
  319. int rolling_actual_bits;
  320. int long_rolling_target_bits;
  321. int long_rolling_actual_bits;
  322. int64_t total_actual_bits;
  323. int total_target_vs_actual; /* debug stats */
  324. int worst_quality;
  325. int active_worst_quality;
  326. int best_quality;
  327. int active_best_quality;
  328. int cq_target_quality;
  329. int drop_frames_allowed; /* Are we permitted to drop frames? */
  330. int drop_frame; /* Drop this frame? */
  331. #if defined(DROP_UNCODED_FRAMES)
  332. int drop_frame_count;
  333. #endif
  334. vp8_prob frame_coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
  335. [ENTROPY_NODES];
  336. char update_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
  337. unsigned int frame_branch_ct[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
  338. [ENTROPY_NODES][2];
  339. int gfu_boost;
  340. int kf_boost;
  341. int last_boost;
  342. int target_bandwidth;
  343. struct vpx_codec_pkt_list *output_pkt_list;
  344. #if 0
  345. /* Experimental code for lagged and one pass */
  346. ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
  347. int one_pass_frame_index;
  348. #endif
  349. int decimation_factor;
  350. int decimation_count;
  351. /* for real time encoding */
  352. int avg_encode_time; /* microsecond */
  353. int avg_pick_mode_time; /* microsecond */
  354. int Speed;
  355. int compressor_speed;
  356. int auto_gold;
  357. int auto_adjust_gold_quantizer;
  358. int auto_worst_q;
  359. int cpu_used;
  360. int pass;
  361. int prob_intra_coded;
  362. int prob_last_coded;
  363. int prob_gf_coded;
  364. int prob_skip_false;
  365. int last_skip_false_probs[3];
  366. int last_skip_probs_q[3];
  367. int recent_ref_frame_usage[MAX_REF_FRAMES];
  368. int this_frame_percent_intra;
  369. int last_frame_percent_intra;
  370. int ref_frame_flags;
  371. SPEED_FEATURES sf;
  372. /* Count ZEROMV on all reference frames. */
  373. int zeromv_count;
  374. int lf_zeromv_pct;
  375. unsigned char *skin_map;
  376. unsigned char *segmentation_map;
  377. signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
  378. int segment_encode_breakout[MAX_MB_SEGMENTS];
  379. unsigned char *active_map;
  380. unsigned int active_map_enabled;
  381. /* Video conferencing cyclic refresh mode flags. This is a mode
  382. * designed to clean up the background over time in live encoding
  383. * scenarious. It uses segmentation.
  384. */
  385. int cyclic_refresh_mode_enabled;
  386. int cyclic_refresh_mode_max_mbs_perframe;
  387. int cyclic_refresh_mode_index;
  388. int cyclic_refresh_q;
  389. signed char *cyclic_refresh_map;
  390. // Count on how many (consecutive) times a macroblock uses ZER0MV_LAST.
  391. unsigned char *consec_zero_last;
  392. // Counter that is reset when a block is checked for a mode-bias against
  393. // ZEROMV_LASTREF.
  394. unsigned char *consec_zero_last_mvbias;
  395. // Frame counter for the temporal pattern. Counter is rest when the temporal
  396. // layers are changed dynamically (run-time change).
  397. unsigned int temporal_pattern_counter;
  398. // Temporal layer id.
  399. int temporal_layer_id;
  400. // Measure of average squared difference between source and denoised signal.
  401. int mse_source_denoised;
  402. int force_maxqp;
  403. int frames_since_last_drop_overshoot;
  404. int last_pred_err_mb;
  405. // GF update for 1 pass cbr.
  406. int gf_update_onepass_cbr;
  407. int gf_interval_onepass_cbr;
  408. int gf_noboost_onepass_cbr;
  409. #if CONFIG_MULTITHREAD
  410. /* multithread data */
  411. vpx_atomic_int *mt_current_mb_col;
  412. int mt_sync_range;
  413. vpx_atomic_int b_multi_threaded;
  414. int encoding_thread_count;
  415. int b_lpf_running;
  416. pthread_t *h_encoding_thread;
  417. pthread_t h_filter_thread;
  418. MB_ROW_COMP *mb_row_ei;
  419. ENCODETHREAD_DATA *en_thread_data;
  420. LPFTHREAD_DATA lpf_thread_data;
  421. /* events */
  422. sem_t *h_event_start_encoding;
  423. sem_t *h_event_end_encoding;
  424. sem_t h_event_start_lpf;
  425. sem_t h_event_end_lpf;
  426. #endif
  427. TOKENLIST *tplist;
  428. unsigned int partition_sz[MAX_PARTITIONS];
  429. unsigned char *partition_d[MAX_PARTITIONS];
  430. unsigned char *partition_d_end[MAX_PARTITIONS];
  431. fractional_mv_step_fp *find_fractional_mv_step;
  432. vp8_full_search_fn_t full_search_sad;
  433. vp8_refining_search_fn_t refining_search_sad;
  434. vp8_diamond_search_fn_t diamond_search_sad;
  435. vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
  436. uint64_t time_receive_data;
  437. uint64_t time_compress_data;
  438. uint64_t time_pick_lpf;
  439. uint64_t time_encode_mb_row;
  440. int base_skip_false_prob[128];
  441. FRAME_CONTEXT lfc_n; /* last frame entropy */
  442. FRAME_CONTEXT lfc_a; /* last alt ref entropy */
  443. FRAME_CONTEXT lfc_g; /* last gold ref entropy */
  444. struct twopass_rc {
  445. unsigned int section_intra_rating;
  446. double section_max_qfactor;
  447. unsigned int next_iiratio;
  448. unsigned int this_iiratio;
  449. FIRSTPASS_STATS total_stats;
  450. FIRSTPASS_STATS this_frame_stats;
  451. FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
  452. FIRSTPASS_STATS total_left_stats;
  453. int first_pass_done;
  454. int64_t bits_left;
  455. int64_t clip_bits_total;
  456. double avg_iiratio;
  457. double modified_error_total;
  458. double modified_error_used;
  459. double modified_error_left;
  460. double kf_intra_err_min;
  461. double gf_intra_err_min;
  462. int frames_to_key;
  463. int maxq_max_limit;
  464. int maxq_min_limit;
  465. int gf_decay_rate;
  466. int static_scene_max_gf_interval;
  467. int kf_bits;
  468. /* Remaining error from uncoded frames in a gf group. */
  469. int gf_group_error_left;
  470. /* Projected total bits available for a key frame group of frames */
  471. int64_t kf_group_bits;
  472. /* Error score of frames still to be coded in kf group */
  473. int64_t kf_group_error_left;
  474. /* Projected Bits available for a group including 1 GF or ARF */
  475. int64_t gf_group_bits;
  476. /* Bits for the golden frame or ARF */
  477. int gf_bits;
  478. int alt_extra_bits;
  479. double est_max_qcorrection_factor;
  480. } twopass;
  481. #if VP8_TEMPORAL_ALT_REF
  482. YV12_BUFFER_CONFIG alt_ref_buffer;
  483. YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
  484. int fixed_divide[512];
  485. #endif
  486. #if CONFIG_INTERNAL_STATS
  487. int count;
  488. double total_y;
  489. double total_u;
  490. double total_v;
  491. double total;
  492. double total_sq_error;
  493. double totalp_y;
  494. double totalp_u;
  495. double totalp_v;
  496. double totalp;
  497. double total_sq_error2;
  498. int bytes;
  499. double summed_quality;
  500. double summed_weights;
  501. unsigned int tot_recode_hits;
  502. int b_calculate_ssimg;
  503. #endif
  504. int b_calculate_psnr;
  505. /* Per MB activity measurement */
  506. unsigned int activity_avg;
  507. unsigned int *mb_activity_map;
  508. /* Record of which MBs still refer to last golden frame either
  509. * directly or through 0,0
  510. */
  511. unsigned char *gf_active_flags;
  512. int gf_active_count;
  513. int output_partition;
  514. /* Store last frame's MV info for next frame MV prediction */
  515. int_mv *lfmv;
  516. int *lf_ref_frame_sign_bias;
  517. int *lf_ref_frame;
  518. /* force next frame to intra when kf_auto says so */
  519. int force_next_frame_intra;
  520. int droppable;
  521. int initial_width;
  522. int initial_height;
  523. #if CONFIG_TEMPORAL_DENOISING
  524. VP8_DENOISER denoiser;
  525. #endif
  526. /* Coding layer state variables */
  527. unsigned int current_layer;
  528. LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
  529. int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
  530. int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
  531. double sum_psnr[VPX_TS_MAX_LAYERS];
  532. double sum_psnr_p[VPX_TS_MAX_LAYERS];
  533. double total_error2[VPX_TS_MAX_LAYERS];
  534. double total_error2_p[VPX_TS_MAX_LAYERS];
  535. double sum_ssim[VPX_TS_MAX_LAYERS];
  536. double sum_weights[VPX_TS_MAX_LAYERS];
  537. double total_ssimg_y_in_layer[VPX_TS_MAX_LAYERS];
  538. double total_ssimg_u_in_layer[VPX_TS_MAX_LAYERS];
  539. double total_ssimg_v_in_layer[VPX_TS_MAX_LAYERS];
  540. double total_ssimg_all_in_layer[VPX_TS_MAX_LAYERS];
  541. #if CONFIG_MULTI_RES_ENCODING
  542. /* Number of MBs per row at lower-resolution level */
  543. int mr_low_res_mb_cols;
  544. /* Indicate if lower-res mv info is available */
  545. unsigned char mr_low_res_mv_avail;
  546. #endif
  547. /* The frame number of each reference frames */
  548. unsigned int current_ref_frames[MAX_REF_FRAMES];
  549. // Closest reference frame to current frame.
  550. MV_REFERENCE_FRAME closest_reference_frame;
  551. struct rd_costs_struct {
  552. int mvcosts[2][MVvals + 1];
  553. int mvsadcosts[2][MVfpvals + 1];
  554. int mbmode_cost[2][MB_MODE_COUNT];
  555. int intra_uv_mode_cost[2][MB_MODE_COUNT];
  556. int bmode_costs[10][10][10];
  557. int inter_bmode_costs[B_MODE_COUNT];
  558. int token_costs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
  559. [MAX_ENTROPY_TOKENS];
  560. } rd_costs;
  561. // Use the static threshold from ROI settings.
  562. int use_roi_static_threshold;
  563. int ext_refresh_frame_flags_pending;
  564. } VP8_COMP;
  565. void vp8_initialize_enc(void);
  566. void vp8_alloc_compressor_data(VP8_COMP *cpi);
  567. int vp8_reverse_trans(int x);
  568. void vp8_new_framerate(VP8_COMP *cpi, double framerate);
  569. void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
  570. void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest,
  571. unsigned char *dest_end, size_t *size);
  572. void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **);
  573. void vp8_set_speed_features(VP8_COMP *cpi);
  574. #if CONFIG_DEBUG
  575. #define CHECK_MEM_ERROR(lval, expr) \
  576. do { \
  577. (lval) = (expr); \
  578. if (!(lval)) \
  579. vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \
  580. "Failed to allocate " #lval " at %s:%d", __FILE__, \
  581. __LINE__); \
  582. } while (0)
  583. #else
  584. #define CHECK_MEM_ERROR(lval, expr) \
  585. do { \
  586. (lval) = (expr); \
  587. if (!(lval)) \
  588. vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \
  589. "Failed to allocate " #lval); \
  590. } while (0)
  591. #endif
  592. #ifdef __cplusplus
  593. } // extern "C"
  594. #endif
  595. #endif // VPX_VP8_ENCODER_ONYX_INT_H_