vp9_speed_features.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. #include <limits.h>
  11. #include "vp9/encoder/vp9_encoder.h"
  12. #include "vp9/encoder/vp9_speed_features.h"
  13. #include "vp9/encoder/vp9_rdopt.h"
  14. #include "vpx_dsp/vpx_dsp_common.h"
  15. // Mesh search patters for various speed settings
  16. static MESH_PATTERN best_quality_mesh_pattern[MAX_MESH_STEP] = {
  17. { 64, 4 }, { 28, 2 }, { 15, 1 }, { 7, 1 }
  18. };
  19. // Define 3 mesh density levels to control the number of searches.
  20. #define MESH_DENSITY_LEVELS 3
  21. static MESH_PATTERN
  22. good_quality_mesh_patterns[MESH_DENSITY_LEVELS][MAX_MESH_STEP] = {
  23. { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
  24. { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
  25. { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
  26. };
  27. // Intra only frames, golden frames (except alt ref overlays) and
  28. // alt ref frames tend to be coded at a higher than ambient quality
  29. static int frame_is_boosted(const VP9_COMP *cpi) {
  30. return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
  31. }
  32. // Sets a partition size down to which the auto partition code will always
  33. // search (can go lower), based on the image dimensions. The logic here
  34. // is that the extent to which ringing artefacts are offensive, depends
  35. // partly on the screen area that over which they propogate. Propogation is
  36. // limited by transform block size but the screen area take up by a given block
  37. // size will be larger for a small image format stretched to full screen.
  38. static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
  39. unsigned int screen_area = (cm->width * cm->height);
  40. // Select block size based on image format size.
  41. if (screen_area < 1280 * 720) {
  42. // Formats smaller in area than 720P
  43. return BLOCK_4X4;
  44. } else if (screen_area < 1920 * 1080) {
  45. // Format >= 720P and < 1080P
  46. return BLOCK_8X8;
  47. } else {
  48. // Formats 1080P and up
  49. return BLOCK_16X16;
  50. }
  51. }
  52. static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
  53. SPEED_FEATURES *sf,
  54. int speed) {
  55. VP9_COMMON *const cm = &cpi->common;
  56. // speed 0 features
  57. sf->partition_search_breakout_thr.dist = (1 << 20);
  58. sf->partition_search_breakout_thr.rate = 80;
  59. // Currently, the machine-learning based partition search early termination
  60. // is only used while VPXMIN(cm->width, cm->height) >= 480 and speed = 0.
  61. if (VPXMIN(cm->width, cm->height) >= 480) {
  62. sf->ml_partition_search_early_termination = 1;
  63. }
  64. if (speed >= 1) {
  65. sf->ml_partition_search_early_termination = 0;
  66. if (VPXMIN(cm->width, cm->height) >= 720) {
  67. sf->disable_split_mask =
  68. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  69. sf->partition_search_breakout_thr.dist = (1 << 23);
  70. } else {
  71. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  72. sf->partition_search_breakout_thr.dist = (1 << 21);
  73. }
  74. }
  75. if (speed >= 2) {
  76. if (VPXMIN(cm->width, cm->height) >= 720) {
  77. sf->disable_split_mask =
  78. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  79. sf->adaptive_pred_interp_filter = 0;
  80. sf->partition_search_breakout_thr.dist = (1 << 24);
  81. sf->partition_search_breakout_thr.rate = 120;
  82. } else {
  83. sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
  84. sf->partition_search_breakout_thr.dist = (1 << 22);
  85. sf->partition_search_breakout_thr.rate = 100;
  86. }
  87. sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
  88. // Use a set of speed features for 4k videos.
  89. if (VPXMIN(cm->width, cm->height) >= 2160) {
  90. sf->use_square_partition_only = 1;
  91. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  92. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
  93. sf->alt_ref_search_fp = 1;
  94. sf->cb_pred_filter_search = 1;
  95. sf->adaptive_interp_filter_search = 1;
  96. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  97. }
  98. }
  99. if (speed >= 3) {
  100. if (VPXMIN(cm->width, cm->height) >= 720) {
  101. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  102. sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
  103. sf->partition_search_breakout_thr.dist = (1 << 25);
  104. sf->partition_search_breakout_thr.rate = 200;
  105. } else {
  106. sf->max_intra_bsize = BLOCK_32X32;
  107. sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
  108. sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
  109. sf->partition_search_breakout_thr.dist = (1 << 23);
  110. sf->partition_search_breakout_thr.rate = 120;
  111. }
  112. }
  113. // If this is a two pass clip that fits the criteria for animated or
  114. // graphics content then reset disable_split_mask for speeds 1-4.
  115. // Also if the image edge is internal to the coded area.
  116. if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
  117. ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
  118. (vp9_internal_image_edge(cpi)))) {
  119. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  120. }
  121. if (speed >= 4) {
  122. sf->partition_search_breakout_thr.rate = 300;
  123. if (VPXMIN(cm->width, cm->height) >= 720) {
  124. sf->partition_search_breakout_thr.dist = (1 << 26);
  125. } else {
  126. sf->partition_search_breakout_thr.dist = (1 << 24);
  127. }
  128. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  129. }
  130. if (speed >= 5) {
  131. sf->partition_search_breakout_thr.rate = 500;
  132. }
  133. }
  134. static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
  135. static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
  136. static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
  137. VP9_COMMON *cm,
  138. SPEED_FEATURES *sf,
  139. int speed) {
  140. const int boosted = frame_is_boosted(cpi);
  141. int i;
  142. sf->tx_size_search_breakout = 1;
  143. sf->adaptive_rd_thresh = 1;
  144. sf->adaptive_rd_thresh_row_mt = 0;
  145. sf->allow_skip_recode = 1;
  146. sf->less_rectangular_check = 1;
  147. sf->use_square_partition_only = !frame_is_boosted(cpi);
  148. sf->use_square_only_threshold = BLOCK_16X16;
  149. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  150. sf->exhaustive_searches_thresh = (1 << 22);
  151. for (i = 0; i < MAX_MESH_STEP; ++i) {
  152. int mesh_density_level = 0;
  153. sf->mesh_patterns[i].range =
  154. good_quality_mesh_patterns[mesh_density_level][i].range;
  155. sf->mesh_patterns[i].interval =
  156. good_quality_mesh_patterns[mesh_density_level][i].interval;
  157. }
  158. } else {
  159. sf->exhaustive_searches_thresh = INT_MAX;
  160. }
  161. if (speed >= 1) {
  162. if (cpi->oxcf.pass == 2) {
  163. TWO_PASS *const twopass = &cpi->twopass;
  164. if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
  165. vp9_internal_image_edge(cpi)) {
  166. sf->use_square_partition_only = !frame_is_boosted(cpi);
  167. } else {
  168. sf->use_square_partition_only = !frame_is_intra_only(cm);
  169. }
  170. } else {
  171. sf->use_square_partition_only = !frame_is_intra_only(cm);
  172. }
  173. sf->allow_txfm_domain_distortion = 1;
  174. sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
  175. sf->allow_quant_coeff_opt = sf->optimize_coefficients;
  176. sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
  177. sf->use_square_only_threshold = BLOCK_4X4;
  178. sf->less_rectangular_check = 1;
  179. sf->use_rd_breakout = 1;
  180. sf->adaptive_motion_search = 1;
  181. sf->mv.auto_mv_step_size = 1;
  182. sf->adaptive_rd_thresh = 2;
  183. sf->mv.subpel_iters_per_step = 1;
  184. sf->mode_skip_start = 10;
  185. sf->adaptive_pred_interp_filter = 1;
  186. sf->allow_acl = 0;
  187. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
  188. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
  189. sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
  190. sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  191. sf->recode_tolerance_low = 15;
  192. sf->recode_tolerance_high = 30;
  193. sf->exhaustive_searches_thresh =
  194. (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
  195. : INT_MAX;
  196. }
  197. if (speed >= 2) {
  198. sf->recode_loop = ALLOW_RECODE_KFARFGF;
  199. sf->tx_size_search_method =
  200. frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
  201. // Reference masking is not supported in dynamic scaling mode.
  202. sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
  203. sf->mode_search_skip_flags =
  204. (cm->frame_type == KEY_FRAME)
  205. ? 0
  206. : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
  207. FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
  208. sf->disable_filter_search_var_thresh = 100;
  209. sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
  210. sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
  211. sf->allow_partition_search_skip = 1;
  212. sf->recode_tolerance_low = 15;
  213. sf->recode_tolerance_high = 45;
  214. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  215. for (i = 0; i < MAX_MESH_STEP; ++i) {
  216. int mesh_density_level = 1;
  217. sf->mesh_patterns[i].range =
  218. good_quality_mesh_patterns[mesh_density_level][i].range;
  219. sf->mesh_patterns[i].interval =
  220. good_quality_mesh_patterns[mesh_density_level][i].interval;
  221. }
  222. }
  223. }
  224. if (speed >= 3) {
  225. sf->use_square_partition_only = !frame_is_intra_only(cm);
  226. sf->tx_size_search_method =
  227. frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
  228. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
  229. sf->adaptive_pred_interp_filter = 0;
  230. sf->adaptive_mode_search = 1;
  231. sf->cb_partition_search = !boosted;
  232. sf->cb_pred_filter_search = 1;
  233. sf->alt_ref_search_fp = 1;
  234. sf->recode_loop = ALLOW_RECODE_KFMAXBW;
  235. sf->adaptive_rd_thresh = 3;
  236. sf->mode_skip_start = 6;
  237. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  238. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
  239. sf->adaptive_interp_filter_search = 1;
  240. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  241. for (i = 0; i < MAX_MESH_STEP; ++i) {
  242. int mesh_density_level = 2;
  243. sf->mesh_patterns[i].range =
  244. good_quality_mesh_patterns[mesh_density_level][i].range;
  245. sf->mesh_patterns[i].interval =
  246. good_quality_mesh_patterns[mesh_density_level][i].interval;
  247. }
  248. }
  249. }
  250. if (speed >= 4) {
  251. sf->use_square_partition_only = 1;
  252. sf->tx_size_search_method = USE_LARGESTALL;
  253. sf->mv.search_method = BIGDIA;
  254. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
  255. sf->adaptive_rd_thresh = 4;
  256. if (cm->frame_type != KEY_FRAME)
  257. sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
  258. sf->disable_filter_search_var_thresh = 200;
  259. sf->use_lp32x32fdct = 1;
  260. sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
  261. sf->use_fast_coef_costing = 1;
  262. sf->motion_field_mode_search = !boosted;
  263. }
  264. if (speed >= 5) {
  265. int i;
  266. sf->optimize_coefficients = 0;
  267. sf->mv.search_method = HEX;
  268. sf->disable_filter_search_var_thresh = 500;
  269. for (i = 0; i < TX_SIZES; ++i) {
  270. sf->intra_y_mode_mask[i] = INTRA_DC;
  271. sf->intra_uv_mode_mask[i] = INTRA_DC;
  272. }
  273. sf->mv.reduce_first_step_size = 1;
  274. sf->simple_model_rd_from_var = 1;
  275. }
  276. }
  277. static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
  278. SPEED_FEATURES *sf,
  279. int speed) {
  280. VP9_COMMON *const cm = &cpi->common;
  281. if (speed >= 1) {
  282. if (VPXMIN(cm->width, cm->height) >= 720) {
  283. sf->disable_split_mask =
  284. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  285. } else {
  286. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  287. }
  288. }
  289. if (speed >= 2) {
  290. if (VPXMIN(cm->width, cm->height) >= 720) {
  291. sf->disable_split_mask =
  292. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  293. } else {
  294. sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
  295. }
  296. }
  297. if (speed >= 5) {
  298. sf->partition_search_breakout_thr.rate = 200;
  299. if (VPXMIN(cm->width, cm->height) >= 720) {
  300. sf->partition_search_breakout_thr.dist = (1 << 25);
  301. } else {
  302. sf->partition_search_breakout_thr.dist = (1 << 23);
  303. }
  304. }
  305. if (speed >= 7) {
  306. sf->encode_breakout_thresh =
  307. (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
  308. }
  309. }
  310. static void set_rt_speed_feature_framesize_independent(
  311. VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
  312. VP9_COMMON *const cm = &cpi->common;
  313. const int is_keyframe = cm->frame_type == KEY_FRAME;
  314. const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
  315. sf->static_segmentation = 0;
  316. sf->adaptive_rd_thresh = 1;
  317. sf->adaptive_rd_thresh_row_mt = 0;
  318. sf->use_fast_coef_costing = 1;
  319. sf->exhaustive_searches_thresh = INT_MAX;
  320. sf->allow_acl = 0;
  321. sf->copy_partition_flag = 0;
  322. sf->use_source_sad = 0;
  323. sf->use_simple_block_yrd = 0;
  324. sf->adapt_partition_source_sad = 0;
  325. sf->use_altref_onepass = 0;
  326. if (speed >= 1) {
  327. sf->allow_txfm_domain_distortion = 1;
  328. sf->tx_domain_thresh = 0.0;
  329. sf->allow_quant_coeff_opt = 0;
  330. sf->quant_opt_thresh = 0.0;
  331. sf->use_square_partition_only = !frame_is_intra_only(cm);
  332. sf->less_rectangular_check = 1;
  333. sf->tx_size_search_method =
  334. frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
  335. sf->use_rd_breakout = 1;
  336. sf->adaptive_motion_search = 1;
  337. sf->adaptive_pred_interp_filter = 1;
  338. sf->mv.auto_mv_step_size = 1;
  339. sf->adaptive_rd_thresh = 2;
  340. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
  341. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
  342. sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  343. }
  344. if (speed >= 2) {
  345. sf->mode_search_skip_flags =
  346. (cm->frame_type == KEY_FRAME)
  347. ? 0
  348. : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
  349. FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
  350. sf->adaptive_pred_interp_filter = 2;
  351. // Reference masking only enabled for 1 spatial layer, and if none of the
  352. // references have been scaled. The latter condition needs to be checked
  353. // for external or internal dynamic resize.
  354. sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
  355. if (sf->reference_masking == 1 &&
  356. (cpi->external_resize == 1 ||
  357. cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
  358. MV_REFERENCE_FRAME ref_frame;
  359. static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
  360. VP9_ALT_FLAG };
  361. for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
  362. const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
  363. if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
  364. const struct scale_factors *const scale_fac =
  365. &cm->frame_refs[ref_frame - 1].sf;
  366. if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
  367. }
  368. }
  369. }
  370. sf->disable_filter_search_var_thresh = 50;
  371. sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
  372. sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
  373. sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
  374. sf->adjust_partitioning_from_last_frame = 1;
  375. sf->last_partitioning_redo_frequency = 3;
  376. sf->use_lp32x32fdct = 1;
  377. sf->mode_skip_start = 11;
  378. sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
  379. }
  380. if (speed >= 3) {
  381. sf->use_square_partition_only = 1;
  382. sf->disable_filter_search_var_thresh = 100;
  383. sf->use_uv_intra_rd_estimate = 1;
  384. sf->skip_encode_sb = 1;
  385. sf->mv.subpel_iters_per_step = 1;
  386. sf->adaptive_rd_thresh = 4;
  387. sf->mode_skip_start = 6;
  388. sf->allow_skip_recode = 0;
  389. sf->optimize_coefficients = 0;
  390. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  391. sf->lpf_pick = LPF_PICK_FROM_Q;
  392. }
  393. if (speed >= 4) {
  394. int i;
  395. sf->last_partitioning_redo_frequency = 4;
  396. sf->adaptive_rd_thresh = 5;
  397. sf->use_fast_coef_costing = 0;
  398. sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
  399. sf->adjust_partitioning_from_last_frame =
  400. cm->last_frame_type != cm->frame_type ||
  401. (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
  402. sf->mv.subpel_force_stop = 1;
  403. for (i = 0; i < TX_SIZES; i++) {
  404. sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
  405. sf->intra_uv_mode_mask[i] = INTRA_DC;
  406. }
  407. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  408. sf->frame_parameter_update = 0;
  409. sf->mv.search_method = FAST_HEX;
  410. sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
  411. sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
  412. sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
  413. sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
  414. sf->max_intra_bsize = BLOCK_32X32;
  415. sf->allow_skip_recode = 1;
  416. }
  417. if (speed >= 5) {
  418. sf->use_quant_fp = !is_keyframe;
  419. sf->auto_min_max_partition_size =
  420. is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
  421. sf->default_max_partition_size = BLOCK_32X32;
  422. sf->default_min_partition_size = BLOCK_8X8;
  423. sf->force_frame_boost =
  424. is_keyframe ||
  425. (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
  426. sf->max_delta_qindex = is_keyframe ? 20 : 15;
  427. sf->partition_search_type = REFERENCE_PARTITION;
  428. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
  429. cpi->rc.is_src_frame_alt_ref) {
  430. sf->partition_search_type = VAR_BASED_PARTITION;
  431. }
  432. sf->use_nonrd_pick_mode = 1;
  433. sf->allow_skip_recode = 0;
  434. sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
  435. sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
  436. sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
  437. sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
  438. sf->adaptive_rd_thresh = 2;
  439. // This feature is only enabled when partition search is disabled.
  440. sf->reuse_inter_pred_sby = 1;
  441. sf->coeff_prob_appx_step = 4;
  442. sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
  443. sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
  444. sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
  445. sf->simple_model_rd_from_var = 1;
  446. if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
  447. if (!is_keyframe) {
  448. int i;
  449. if (content == VP9E_CONTENT_SCREEN) {
  450. for (i = 0; i < BLOCK_SIZES; ++i)
  451. sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
  452. } else {
  453. for (i = 0; i < BLOCK_SIZES; ++i)
  454. if (i > BLOCK_16X16)
  455. sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
  456. else
  457. // Use H and V intra mode for block sizes <= 16X16.
  458. sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
  459. }
  460. }
  461. if (content == VP9E_CONTENT_SCREEN) {
  462. sf->short_circuit_flat_blocks = 1;
  463. }
  464. if (cpi->oxcf.rc_mode == VPX_CBR &&
  465. cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
  466. sf->limit_newmv_early_exit = 1;
  467. if (!cpi->use_svc) sf->bias_golden = 1;
  468. }
  469. }
  470. if (speed >= 6) {
  471. sf->partition_search_type = VAR_BASED_PARTITION;
  472. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
  473. cpi->rc.is_src_frame_alt_ref && !is_keyframe) {
  474. sf->partition_search_type = FIXED_PARTITION;
  475. sf->always_this_block_size = BLOCK_64X64;
  476. }
  477. // Turn on this to use non-RD key frame coding mode.
  478. sf->use_nonrd_pick_mode = 1;
  479. sf->mv.search_method = NSTEP;
  480. sf->mv.reduce_first_step_size = 1;
  481. sf->skip_encode_sb = 0;
  482. if (!cpi->external_resize) sf->use_source_sad = 1;
  483. if (sf->use_source_sad) {
  484. sf->adapt_partition_source_sad = 1;
  485. sf->adapt_partition_thresh =
  486. (cm->width * cm->height <= 640 * 360) ? 40000 : 80000;
  487. if (cpi->content_state_sb_fd == NULL &&
  488. (!cpi->use_svc ||
  489. cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
  490. cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
  491. (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
  492. }
  493. }
  494. if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
  495. // Enable short circuit for low temporal variance.
  496. sf->short_circuit_low_temp_var = 1;
  497. }
  498. if (cpi->svc.temporal_layer_id > 0) {
  499. sf->adaptive_rd_thresh = 4;
  500. sf->limit_newmv_early_exit = 0;
  501. sf->base_mv_aggressive = 1;
  502. }
  503. }
  504. if (speed >= 7) {
  505. sf->adapt_partition_source_sad = 0;
  506. sf->adaptive_rd_thresh = 3;
  507. sf->mv.search_method = FAST_DIAMOND;
  508. sf->mv.fullpel_search_step_param = 10;
  509. // For SVC: use better mv search on base temporal layer, and only
  510. // on base spatial layer if highest resolution is above 640x360.
  511. if (cpi->svc.number_temporal_layers > 2 &&
  512. cpi->svc.temporal_layer_id == 0 &&
  513. (cpi->svc.spatial_layer_id == 0 ||
  514. cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
  515. sf->mv.search_method = NSTEP;
  516. sf->mv.fullpel_search_step_param = 6;
  517. }
  518. if (cpi->svc.temporal_layer_id > 0 || cpi->svc.spatial_layer_id > 1) {
  519. sf->use_simple_block_yrd = 1;
  520. if (cpi->svc.non_reference_frame)
  521. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
  522. }
  523. // Enable partition copy. For SVC only enabled for top spatial resolution
  524. // layer.
  525. cpi->max_copied_frame = 0;
  526. if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
  527. !cpi->external_resize &&
  528. (!cpi->use_svc ||
  529. cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
  530. sf->copy_partition_flag = 1;
  531. cpi->max_copied_frame = 2;
  532. // The top temporal enhancement layer (for number of temporal layers > 1)
  533. // are non-reference frames, so use large/max value for max_copied_frame.
  534. if (cpi->svc.number_temporal_layers > 1 &&
  535. cpi->svc.temporal_layer_id == cpi->svc.number_temporal_layers - 1)
  536. cpi->max_copied_frame = 255;
  537. }
  538. }
  539. if (speed >= 8) {
  540. sf->adaptive_rd_thresh = 4;
  541. sf->skip_encode_sb = 1;
  542. if (!cpi->use_svc) cpi->max_copied_frame = 4;
  543. if (cpi->row_mt && cpi->oxcf.max_threads > 1)
  544. sf->adaptive_rd_thresh_row_mt = 1;
  545. if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = 3;
  546. if (content == VP9E_CONTENT_SCREEN) sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
  547. // Only keep INTRA_DC mode for speed 8.
  548. if (!is_keyframe) {
  549. int i = 0;
  550. for (i = 0; i < BLOCK_SIZES; ++i)
  551. sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
  552. }
  553. if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
  554. content != VP9E_CONTENT_SCREEN) {
  555. // More aggressive short circuit for speed 8.
  556. sf->short_circuit_low_temp_var = 3;
  557. // Use level 2 for noisey cases as there is a regression in some
  558. // noisy clips with level 3.
  559. if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
  560. cm->height >= 720) {
  561. NOISE_LEVEL noise_level =
  562. vp9_noise_estimate_extract_level(&cpi->noise_estimate);
  563. if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
  564. }
  565. // Since the short_circuit_low_temp_var is used, reduce the
  566. // adaptive_rd_thresh level.
  567. if (cm->width * cm->height > 352 * 288)
  568. sf->adaptive_rd_thresh = 1;
  569. else
  570. sf->adaptive_rd_thresh = 2;
  571. }
  572. sf->limit_newmv_early_exit = 0;
  573. sf->use_simple_block_yrd = 1;
  574. }
  575. }
  576. void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
  577. SPEED_FEATURES *const sf = &cpi->sf;
  578. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  579. RD_OPT *const rd = &cpi->rd;
  580. int i;
  581. // best quality defaults
  582. // Some speed-up features even for best quality as minimal impact on quality.
  583. sf->partition_search_breakout_thr.dist = (1 << 19);
  584. sf->partition_search_breakout_thr.rate = 80;
  585. sf->ml_partition_search_early_termination = 0;
  586. if (oxcf->mode == REALTIME) {
  587. set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
  588. } else if (oxcf->mode == GOOD) {
  589. set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
  590. }
  591. if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
  592. sf->adaptive_pred_interp_filter = 0;
  593. }
  594. if (cpi->encode_breakout && oxcf->mode == REALTIME &&
  595. sf->encode_breakout_thresh > cpi->encode_breakout) {
  596. cpi->encode_breakout = sf->encode_breakout_thresh;
  597. }
  598. // Check for masked out split cases.
  599. for (i = 0; i < MAX_REFS; ++i) {
  600. if (sf->disable_split_mask & (1 << i)) {
  601. rd->thresh_mult_sub8x8[i] = INT_MAX;
  602. }
  603. }
  604. // With row based multi-threading, the following speed features
  605. // have to be disabled to guarantee that bitstreams encoded with single thread
  606. // and multiple threads match.
  607. // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
  608. // adaptive_rd_thresh is defined per-row for non-rd pickmode.
  609. if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
  610. oxcf->max_threads > 1)
  611. sf->adaptive_rd_thresh = 0;
  612. // This is only used in motion vector unit test.
  613. if (cpi->oxcf.motion_vector_unit_test == 1)
  614. cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
  615. else if (cpi->oxcf.motion_vector_unit_test == 2)
  616. cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
  617. }
  618. void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
  619. SPEED_FEATURES *const sf = &cpi->sf;
  620. VP9_COMMON *const cm = &cpi->common;
  621. MACROBLOCK *const x = &cpi->td.mb;
  622. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  623. int i;
  624. // best quality defaults
  625. sf->frame_parameter_update = 1;
  626. sf->mv.search_method = NSTEP;
  627. sf->recode_loop = ALLOW_RECODE_FIRST;
  628. sf->mv.subpel_search_method = SUBPEL_TREE;
  629. sf->mv.subpel_iters_per_step = 2;
  630. sf->mv.subpel_force_stop = 0;
  631. sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
  632. sf->mv.reduce_first_step_size = 0;
  633. sf->coeff_prob_appx_step = 1;
  634. sf->mv.auto_mv_step_size = 0;
  635. sf->mv.fullpel_search_step_param = 6;
  636. sf->comp_inter_joint_search_thresh = BLOCK_4X4;
  637. sf->tx_size_search_method = USE_FULL_RD;
  638. sf->use_lp32x32fdct = 0;
  639. sf->adaptive_motion_search = 0;
  640. sf->adaptive_pred_interp_filter = 0;
  641. sf->adaptive_mode_search = 0;
  642. sf->cb_pred_filter_search = 0;
  643. sf->cb_partition_search = 0;
  644. sf->motion_field_mode_search = 0;
  645. sf->alt_ref_search_fp = 0;
  646. sf->use_quant_fp = 0;
  647. sf->reference_masking = 0;
  648. sf->partition_search_type = SEARCH_PARTITION;
  649. sf->less_rectangular_check = 0;
  650. sf->use_square_partition_only = 0;
  651. sf->use_square_only_threshold = BLOCK_SIZES;
  652. sf->auto_min_max_partition_size = NOT_IN_USE;
  653. sf->rd_auto_partition_min_limit = BLOCK_4X4;
  654. sf->default_max_partition_size = BLOCK_64X64;
  655. sf->default_min_partition_size = BLOCK_4X4;
  656. sf->adjust_partitioning_from_last_frame = 0;
  657. sf->last_partitioning_redo_frequency = 4;
  658. sf->disable_split_mask = 0;
  659. sf->mode_search_skip_flags = 0;
  660. sf->force_frame_boost = 0;
  661. sf->max_delta_qindex = 0;
  662. sf->disable_filter_search_var_thresh = 0;
  663. sf->adaptive_interp_filter_search = 0;
  664. sf->allow_partition_search_skip = 0;
  665. sf->allow_txfm_domain_distortion = 0;
  666. sf->tx_domain_thresh = 99.0;
  667. sf->allow_quant_coeff_opt = sf->optimize_coefficients;
  668. sf->quant_opt_thresh = 99.0;
  669. sf->allow_acl = 1;
  670. for (i = 0; i < TX_SIZES; i++) {
  671. sf->intra_y_mode_mask[i] = INTRA_ALL;
  672. sf->intra_uv_mode_mask[i] = INTRA_ALL;
  673. }
  674. sf->use_rd_breakout = 0;
  675. sf->skip_encode_sb = 0;
  676. sf->use_uv_intra_rd_estimate = 0;
  677. sf->allow_skip_recode = 0;
  678. sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
  679. sf->use_fast_coef_updates = TWO_LOOP;
  680. sf->use_fast_coef_costing = 0;
  681. sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
  682. sf->schedule_mode_search = 0;
  683. sf->use_nonrd_pick_mode = 0;
  684. for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
  685. sf->max_intra_bsize = BLOCK_64X64;
  686. sf->reuse_inter_pred_sby = 0;
  687. // This setting only takes effect when partition_search_type is set
  688. // to FIXED_PARTITION.
  689. sf->always_this_block_size = BLOCK_16X16;
  690. sf->search_type_check_frequency = 50;
  691. sf->encode_breakout_thresh = 0;
  692. // Recode loop tolerance %.
  693. sf->recode_tolerance_low = 12;
  694. sf->recode_tolerance_high = 25;
  695. sf->default_interp_filter = SWITCHABLE;
  696. sf->simple_model_rd_from_var = 0;
  697. sf->short_circuit_flat_blocks = 0;
  698. sf->short_circuit_low_temp_var = 0;
  699. sf->limit_newmv_early_exit = 0;
  700. sf->bias_golden = 0;
  701. sf->base_mv_aggressive = 0;
  702. // Some speed-up features even for best quality as minimal impact on quality.
  703. sf->adaptive_rd_thresh = 1;
  704. sf->tx_size_search_breakout = 1;
  705. sf->exhaustive_searches_thresh =
  706. (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
  707. : INT_MAX;
  708. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  709. for (i = 0; i < MAX_MESH_STEP; ++i) {
  710. sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
  711. sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
  712. }
  713. }
  714. if (oxcf->mode == REALTIME)
  715. set_rt_speed_feature_framesize_independent(cpi, sf, oxcf->speed,
  716. oxcf->content);
  717. else if (oxcf->mode == GOOD)
  718. set_good_speed_feature_framesize_independent(cpi, cm, sf, oxcf->speed);
  719. cpi->diamond_search_sad = vp9_diamond_search_sad;
  720. // Slow quant, dct and trellis not worthwhile for first pass
  721. // so make sure they are always turned off.
  722. if (oxcf->pass == 1) sf->optimize_coefficients = 0;
  723. // No recode for 1 pass.
  724. if (oxcf->pass == 0) {
  725. sf->recode_loop = DISALLOW_RECODE;
  726. sf->optimize_coefficients = 0;
  727. }
  728. if (sf->mv.subpel_force_stop == 3) {
  729. // Whole pel only
  730. cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
  731. } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
  732. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
  733. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
  734. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
  735. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
  736. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
  737. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
  738. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
  739. }
  740. x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
  741. x->min_partition_size = sf->default_min_partition_size;
  742. x->max_partition_size = sf->default_max_partition_size;
  743. if (!cpi->oxcf.frame_periodic_boost) {
  744. sf->max_delta_qindex = 0;
  745. }
  746. // With row based multi-threading, the following speed features
  747. // have to be disabled to guarantee that bitstreams encoded with single thread
  748. // and multiple threads match.
  749. // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
  750. // adaptive_rd_thresh is defined per-row for non-rd pickmode.
  751. if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
  752. oxcf->max_threads > 1)
  753. sf->adaptive_rd_thresh = 0;
  754. // This is only used in motion vector unit test.
  755. if (cpi->oxcf.motion_vector_unit_test == 1)
  756. cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
  757. else if (cpi->oxcf.motion_vector_unit_test == 2)
  758. cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
  759. }