onyx_int.h 19 KB

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