2
0

vp9_speed_features.c 25 KB

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