vp9_speed_features.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. #if !CONFIG_REALTIME_ONLY
  20. // Define 3 mesh density levels to control the number of searches.
  21. #define MESH_DENSITY_LEVELS 3
  22. static MESH_PATTERN
  23. good_quality_mesh_patterns[MESH_DENSITY_LEVELS][MAX_MESH_STEP] = {
  24. { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
  25. { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
  26. { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
  27. };
  28. // Intra only frames, golden frames (except alt ref overlays) and
  29. // alt ref frames tend to be coded at a higher than ambient quality
  30. static int frame_is_boosted(const VP9_COMP *cpi) {
  31. return frame_is_kf_gf_arf(cpi);
  32. }
  33. // Sets a partition size down to which the auto partition code will always
  34. // search (can go lower), based on the image dimensions. The logic here
  35. // is that the extent to which ringing artefacts are offensive, depends
  36. // partly on the screen area that over which they propogate. Propogation is
  37. // limited by transform block size but the screen area take up by a given block
  38. // size will be larger for a small image format stretched to full screen.
  39. static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
  40. unsigned int screen_area = (cm->width * cm->height);
  41. // Select block size based on image format size.
  42. if (screen_area < 1280 * 720) {
  43. // Formats smaller in area than 720P
  44. return BLOCK_4X4;
  45. } else if (screen_area < 1920 * 1080) {
  46. // Format >= 720P and < 1080P
  47. return BLOCK_8X8;
  48. } else {
  49. // Formats 1080P and up
  50. return BLOCK_16X16;
  51. }
  52. }
  53. static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
  54. SPEED_FEATURES *sf,
  55. int speed) {
  56. VP9_COMMON *const cm = &cpi->common;
  57. const int min_frame_size = VPXMIN(cm->width, cm->height);
  58. const int is_480p_or_larger = min_frame_size >= 480;
  59. const int is_720p_or_larger = min_frame_size >= 720;
  60. const int is_1080p_or_larger = min_frame_size >= 1080;
  61. const int is_2160p_or_larger = min_frame_size >= 2160;
  62. // speed 0 features
  63. sf->partition_search_breakout_thr.dist = (1 << 20);
  64. sf->partition_search_breakout_thr.rate = 80;
  65. sf->use_square_only_thresh_high = BLOCK_SIZES;
  66. sf->use_square_only_thresh_low = BLOCK_4X4;
  67. if (is_480p_or_larger) {
  68. // Currently, the machine-learning based partition search early termination
  69. // is only used while VPXMIN(cm->width, cm->height) >= 480 and speed = 0.
  70. sf->rd_ml_partition.search_early_termination = 1;
  71. } else {
  72. sf->use_square_only_thresh_high = BLOCK_32X32;
  73. }
  74. if (!is_1080p_or_larger) {
  75. sf->rd_ml_partition.search_breakout = 1;
  76. if (is_720p_or_larger) {
  77. sf->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
  78. sf->rd_ml_partition.search_breakout_thresh[1] = 0.0f;
  79. sf->rd_ml_partition.search_breakout_thresh[2] = 0.0f;
  80. } else {
  81. sf->rd_ml_partition.search_breakout_thresh[0] = 2.5f;
  82. sf->rd_ml_partition.search_breakout_thresh[1] = 1.5f;
  83. sf->rd_ml_partition.search_breakout_thresh[2] = 1.5f;
  84. }
  85. }
  86. if (speed >= 1) {
  87. sf->rd_ml_partition.search_early_termination = 0;
  88. sf->rd_ml_partition.search_breakout = 1;
  89. if (is_480p_or_larger)
  90. sf->use_square_only_thresh_high = BLOCK_64X64;
  91. else
  92. sf->use_square_only_thresh_high = BLOCK_32X32;
  93. sf->use_square_only_thresh_low = BLOCK_16X16;
  94. if (is_720p_or_larger) {
  95. sf->disable_split_mask =
  96. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  97. sf->partition_search_breakout_thr.dist = (1 << 22);
  98. sf->rd_ml_partition.search_breakout_thresh[0] = -5.0f;
  99. sf->rd_ml_partition.search_breakout_thresh[1] = -5.0f;
  100. sf->rd_ml_partition.search_breakout_thresh[2] = -9.0f;
  101. } else {
  102. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  103. sf->partition_search_breakout_thr.dist = (1 << 21);
  104. sf->rd_ml_partition.search_breakout_thresh[0] = -1.0f;
  105. sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
  106. sf->rd_ml_partition.search_breakout_thresh[2] = -1.0f;
  107. }
  108. #if CONFIG_VP9_HIGHBITDEPTH
  109. if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH) {
  110. sf->rd_ml_partition.search_breakout_thresh[0] -= 1.0f;
  111. sf->rd_ml_partition.search_breakout_thresh[1] -= 1.0f;
  112. sf->rd_ml_partition.search_breakout_thresh[2] -= 1.0f;
  113. }
  114. #endif // CONFIG_VP9_HIGHBITDEPTH
  115. }
  116. if (speed >= 2) {
  117. sf->use_square_only_thresh_high = BLOCK_4X4;
  118. sf->use_square_only_thresh_low = BLOCK_SIZES;
  119. if (is_720p_or_larger) {
  120. sf->disable_split_mask =
  121. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  122. sf->adaptive_pred_interp_filter = 0;
  123. sf->partition_search_breakout_thr.dist = (1 << 24);
  124. sf->partition_search_breakout_thr.rate = 120;
  125. sf->rd_ml_partition.search_breakout = 0;
  126. } else {
  127. sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
  128. sf->partition_search_breakout_thr.dist = (1 << 22);
  129. sf->partition_search_breakout_thr.rate = 100;
  130. sf->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
  131. sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
  132. sf->rd_ml_partition.search_breakout_thresh[2] = -4.0f;
  133. }
  134. sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
  135. // Use a set of speed features for 4k videos.
  136. if (is_2160p_or_larger) {
  137. sf->use_square_partition_only = 1;
  138. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  139. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
  140. sf->alt_ref_search_fp = 1;
  141. sf->cb_pred_filter_search = 1;
  142. sf->adaptive_interp_filter_search = 1;
  143. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  144. }
  145. }
  146. if (speed >= 3) {
  147. sf->rd_ml_partition.search_breakout = 0;
  148. if (is_720p_or_larger) {
  149. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  150. sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
  151. sf->partition_search_breakout_thr.dist = (1 << 25);
  152. sf->partition_search_breakout_thr.rate = 200;
  153. } else {
  154. sf->max_intra_bsize = BLOCK_32X32;
  155. sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
  156. sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
  157. sf->partition_search_breakout_thr.dist = (1 << 23);
  158. sf->partition_search_breakout_thr.rate = 120;
  159. }
  160. }
  161. // If this is a two pass clip that fits the criteria for animated or
  162. // graphics content then reset disable_split_mask for speeds 1-4.
  163. // Also if the image edge is internal to the coded area.
  164. if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
  165. ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
  166. (vp9_internal_image_edge(cpi)))) {
  167. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  168. }
  169. if (speed >= 4) {
  170. sf->partition_search_breakout_thr.rate = 300;
  171. if (is_720p_or_larger) {
  172. sf->partition_search_breakout_thr.dist = (1 << 26);
  173. } else {
  174. sf->partition_search_breakout_thr.dist = (1 << 24);
  175. }
  176. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  177. }
  178. if (speed >= 5) {
  179. sf->partition_search_breakout_thr.rate = 500;
  180. }
  181. }
  182. static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
  183. static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
  184. static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
  185. VP9_COMMON *cm,
  186. SPEED_FEATURES *sf,
  187. int speed) {
  188. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  189. const int boosted = frame_is_boosted(cpi);
  190. int i;
  191. sf->tx_size_search_breakout = 1;
  192. sf->adaptive_rd_thresh = 1;
  193. sf->adaptive_rd_thresh_row_mt = 0;
  194. sf->allow_skip_recode = 1;
  195. sf->less_rectangular_check = 1;
  196. sf->use_square_partition_only = !boosted;
  197. sf->prune_ref_frame_for_rect_partitions = 1;
  198. sf->rd_ml_partition.var_pruning = 1;
  199. sf->rd_ml_partition.prune_rect_thresh[0] = -1;
  200. sf->rd_ml_partition.prune_rect_thresh[1] = 350;
  201. sf->rd_ml_partition.prune_rect_thresh[2] = 325;
  202. sf->rd_ml_partition.prune_rect_thresh[3] = 250;
  203. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  204. sf->exhaustive_searches_thresh = (1 << 22);
  205. } else {
  206. sf->exhaustive_searches_thresh = INT_MAX;
  207. }
  208. for (i = 0; i < MAX_MESH_STEP; ++i) {
  209. const int mesh_density_level = 0;
  210. sf->mesh_patterns[i].range =
  211. good_quality_mesh_patterns[mesh_density_level][i].range;
  212. sf->mesh_patterns[i].interval =
  213. good_quality_mesh_patterns[mesh_density_level][i].interval;
  214. }
  215. if (speed >= 1) {
  216. sf->temporal_filter_search_method = NSTEP;
  217. sf->rd_ml_partition.var_pruning = !boosted;
  218. sf->rd_ml_partition.prune_rect_thresh[1] = 225;
  219. sf->rd_ml_partition.prune_rect_thresh[2] = 225;
  220. sf->rd_ml_partition.prune_rect_thresh[3] = 225;
  221. if (oxcf->pass == 2) {
  222. TWO_PASS *const twopass = &cpi->twopass;
  223. if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
  224. vp9_internal_image_edge(cpi)) {
  225. sf->use_square_partition_only = !boosted;
  226. } else {
  227. sf->use_square_partition_only = !frame_is_intra_only(cm);
  228. }
  229. } else {
  230. sf->use_square_partition_only = !frame_is_intra_only(cm);
  231. }
  232. sf->allow_txfm_domain_distortion = 1;
  233. sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
  234. sf->allow_quant_coeff_opt = sf->optimize_coefficients;
  235. sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
  236. sf->less_rectangular_check = 1;
  237. sf->use_rd_breakout = 1;
  238. sf->adaptive_motion_search = 1;
  239. sf->mv.auto_mv_step_size = 1;
  240. sf->adaptive_rd_thresh = 2;
  241. sf->mv.subpel_search_level = 1;
  242. if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10;
  243. sf->adaptive_pred_interp_filter = 1;
  244. sf->allow_acl = 0;
  245. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
  246. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
  247. if (cpi->oxcf.content != VP9E_CONTENT_FILM) {
  248. sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
  249. sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  250. }
  251. sf->recode_tolerance_low = 15;
  252. sf->recode_tolerance_high = 30;
  253. sf->exhaustive_searches_thresh =
  254. (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
  255. : INT_MAX;
  256. sf->use_accurate_subpel_search = USE_4_TAPS;
  257. }
  258. if (speed >= 2) {
  259. sf->rd_ml_partition.var_pruning = 0;
  260. if (oxcf->vbr_corpus_complexity)
  261. sf->recode_loop = ALLOW_RECODE_FIRST;
  262. else
  263. sf->recode_loop = ALLOW_RECODE_KFARFGF;
  264. sf->tx_size_search_method =
  265. frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
  266. // Reference masking is not supported in dynamic scaling mode.
  267. sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC ? 1 : 0;
  268. sf->mode_search_skip_flags =
  269. (cm->frame_type == KEY_FRAME)
  270. ? 0
  271. : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
  272. FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
  273. sf->disable_filter_search_var_thresh = 100;
  274. sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
  275. sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
  276. sf->recode_tolerance_low = 15;
  277. sf->recode_tolerance_high = 45;
  278. sf->enhanced_full_pixel_motion_search = 0;
  279. sf->prune_ref_frame_for_rect_partitions = 0;
  280. sf->rd_ml_partition.prune_rect_thresh[1] = -1;
  281. sf->rd_ml_partition.prune_rect_thresh[2] = -1;
  282. sf->rd_ml_partition.prune_rect_thresh[3] = -1;
  283. sf->mv.subpel_search_level = 0;
  284. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  285. for (i = 0; i < MAX_MESH_STEP; ++i) {
  286. int mesh_density_level = 1;
  287. sf->mesh_patterns[i].range =
  288. good_quality_mesh_patterns[mesh_density_level][i].range;
  289. sf->mesh_patterns[i].interval =
  290. good_quality_mesh_patterns[mesh_density_level][i].interval;
  291. }
  292. }
  293. sf->use_accurate_subpel_search = USE_2_TAPS;
  294. }
  295. if (speed >= 3) {
  296. sf->use_square_partition_only = !frame_is_intra_only(cm);
  297. sf->tx_size_search_method =
  298. frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
  299. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
  300. sf->adaptive_pred_interp_filter = 0;
  301. sf->adaptive_mode_search = 1;
  302. sf->cb_partition_search = !boosted;
  303. sf->cb_pred_filter_search = 1;
  304. sf->alt_ref_search_fp = 1;
  305. sf->recode_loop = ALLOW_RECODE_KFMAXBW;
  306. sf->adaptive_rd_thresh = 3;
  307. sf->mode_skip_start = 6;
  308. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  309. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
  310. sf->adaptive_interp_filter_search = 1;
  311. sf->allow_partition_search_skip = 1;
  312. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  313. for (i = 0; i < MAX_MESH_STEP; ++i) {
  314. int mesh_density_level = 2;
  315. sf->mesh_patterns[i].range =
  316. good_quality_mesh_patterns[mesh_density_level][i].range;
  317. sf->mesh_patterns[i].interval =
  318. good_quality_mesh_patterns[mesh_density_level][i].interval;
  319. }
  320. }
  321. }
  322. if (speed >= 4) {
  323. sf->use_square_partition_only = 1;
  324. sf->tx_size_search_method = USE_LARGESTALL;
  325. sf->mv.search_method = BIGDIA;
  326. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
  327. sf->adaptive_rd_thresh = 4;
  328. if (cm->frame_type != KEY_FRAME)
  329. sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
  330. sf->disable_filter_search_var_thresh = 200;
  331. sf->use_lp32x32fdct = 1;
  332. sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
  333. sf->use_fast_coef_costing = 1;
  334. sf->motion_field_mode_search = !boosted;
  335. }
  336. if (speed >= 5) {
  337. int i;
  338. sf->optimize_coefficients = 0;
  339. sf->mv.search_method = HEX;
  340. sf->disable_filter_search_var_thresh = 500;
  341. for (i = 0; i < TX_SIZES; ++i) {
  342. sf->intra_y_mode_mask[i] = INTRA_DC;
  343. sf->intra_uv_mode_mask[i] = INTRA_DC;
  344. }
  345. sf->mv.reduce_first_step_size = 1;
  346. sf->simple_model_rd_from_var = 1;
  347. }
  348. }
  349. #endif // !CONFIG_REALTIME_ONLY
  350. static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
  351. SPEED_FEATURES *sf,
  352. int speed) {
  353. VP9_COMMON *const cm = &cpi->common;
  354. if (speed >= 1) {
  355. if (VPXMIN(cm->width, cm->height) >= 720) {
  356. sf->disable_split_mask =
  357. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  358. } else {
  359. sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
  360. }
  361. }
  362. if (speed >= 2) {
  363. if (VPXMIN(cm->width, cm->height) >= 720) {
  364. sf->disable_split_mask =
  365. cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
  366. } else {
  367. sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
  368. }
  369. }
  370. if (speed >= 5) {
  371. sf->partition_search_breakout_thr.rate = 200;
  372. if (VPXMIN(cm->width, cm->height) >= 720) {
  373. sf->partition_search_breakout_thr.dist = (1 << 25);
  374. } else {
  375. sf->partition_search_breakout_thr.dist = (1 << 23);
  376. }
  377. }
  378. if (speed >= 7) {
  379. sf->encode_breakout_thresh =
  380. (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
  381. }
  382. }
  383. static void set_rt_speed_feature_framesize_independent(
  384. VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
  385. VP9_COMMON *const cm = &cpi->common;
  386. SVC *const svc = &cpi->svc;
  387. const int is_keyframe = cm->frame_type == KEY_FRAME;
  388. const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
  389. sf->static_segmentation = 0;
  390. sf->adaptive_rd_thresh = 1;
  391. sf->adaptive_rd_thresh_row_mt = 0;
  392. sf->use_fast_coef_costing = 1;
  393. sf->exhaustive_searches_thresh = INT_MAX;
  394. sf->allow_acl = 0;
  395. sf->copy_partition_flag = 0;
  396. sf->use_source_sad = 0;
  397. sf->use_simple_block_yrd = 0;
  398. sf->adapt_partition_source_sad = 0;
  399. sf->use_altref_onepass = 0;
  400. sf->use_compound_nonrd_pickmode = 0;
  401. sf->nonrd_keyframe = 0;
  402. sf->svc_use_lowres_part = 0;
  403. sf->overshoot_detection_cbr_rt = NO_DETECTION;
  404. sf->disable_16x16part_nonkey = 0;
  405. sf->disable_golden_ref = 0;
  406. sf->enable_tpl_model = 0;
  407. sf->enhanced_full_pixel_motion_search = 0;
  408. sf->use_accurate_subpel_search = USE_2_TAPS;
  409. sf->nonrd_use_ml_partition = 0;
  410. sf->variance_part_thresh_mult = 1;
  411. sf->cb_pred_filter_search = 0;
  412. sf->force_smooth_interpol = 0;
  413. if (speed >= 1) {
  414. sf->allow_txfm_domain_distortion = 1;
  415. sf->tx_domain_thresh = 0.0;
  416. sf->allow_quant_coeff_opt = 0;
  417. sf->quant_opt_thresh = 0.0;
  418. sf->use_square_partition_only = !frame_is_intra_only(cm);
  419. sf->less_rectangular_check = 1;
  420. sf->tx_size_search_method =
  421. frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
  422. sf->use_rd_breakout = 1;
  423. sf->adaptive_motion_search = 1;
  424. sf->adaptive_pred_interp_filter = 1;
  425. sf->mv.auto_mv_step_size = 1;
  426. sf->adaptive_rd_thresh = 2;
  427. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
  428. sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
  429. sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  430. }
  431. if (speed >= 2) {
  432. sf->mode_search_skip_flags =
  433. (cm->frame_type == KEY_FRAME)
  434. ? 0
  435. : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
  436. FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
  437. sf->adaptive_pred_interp_filter = 2;
  438. // Reference masking only enabled for 1 spatial layer, and if none of the
  439. // references have been scaled. The latter condition needs to be checked
  440. // for external or internal dynamic resize.
  441. sf->reference_masking = (svc->number_spatial_layers == 1);
  442. if (sf->reference_masking == 1 &&
  443. (cpi->external_resize == 1 ||
  444. cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
  445. MV_REFERENCE_FRAME ref_frame;
  446. static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
  447. VP9_ALT_FLAG };
  448. for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
  449. const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
  450. if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
  451. const struct scale_factors *const scale_fac =
  452. &cm->frame_refs[ref_frame - 1].sf;
  453. if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
  454. }
  455. }
  456. }
  457. sf->disable_filter_search_var_thresh = 50;
  458. sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
  459. sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
  460. sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
  461. sf->adjust_partitioning_from_last_frame = 1;
  462. sf->last_partitioning_redo_frequency = 3;
  463. sf->use_lp32x32fdct = 1;
  464. sf->mode_skip_start = 11;
  465. sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
  466. }
  467. if (speed >= 3) {
  468. sf->use_square_partition_only = 1;
  469. sf->disable_filter_search_var_thresh = 100;
  470. sf->use_uv_intra_rd_estimate = 1;
  471. sf->skip_encode_sb = 1;
  472. sf->mv.subpel_search_level = 0;
  473. sf->adaptive_rd_thresh = 4;
  474. sf->mode_skip_start = 6;
  475. sf->allow_skip_recode = 0;
  476. sf->optimize_coefficients = 0;
  477. sf->disable_split_mask = DISABLE_ALL_SPLIT;
  478. sf->lpf_pick = LPF_PICK_FROM_Q;
  479. }
  480. if (speed >= 4) {
  481. int i;
  482. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0)
  483. sf->use_altref_onepass = 1;
  484. sf->last_partitioning_redo_frequency = 4;
  485. sf->adaptive_rd_thresh = 5;
  486. sf->use_fast_coef_costing = 0;
  487. sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
  488. sf->adjust_partitioning_from_last_frame =
  489. cm->last_frame_type != cm->frame_type ||
  490. (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
  491. sf->mv.subpel_force_stop = QUARTER_PEL;
  492. for (i = 0; i < TX_SIZES; i++) {
  493. sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
  494. sf->intra_uv_mode_mask[i] = INTRA_DC;
  495. }
  496. sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
  497. sf->frame_parameter_update = 0;
  498. sf->mv.search_method = FAST_HEX;
  499. sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
  500. sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
  501. sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
  502. sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
  503. sf->max_intra_bsize = BLOCK_32X32;
  504. sf->allow_skip_recode = 1;
  505. }
  506. if (speed >= 5) {
  507. sf->use_altref_onepass = 0;
  508. sf->use_quant_fp = !is_keyframe;
  509. sf->auto_min_max_partition_size =
  510. is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
  511. sf->default_max_partition_size = BLOCK_32X32;
  512. sf->default_min_partition_size = BLOCK_8X8;
  513. sf->force_frame_boost =
  514. is_keyframe ||
  515. (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
  516. sf->max_delta_qindex = is_keyframe ? 20 : 15;
  517. sf->partition_search_type = REFERENCE_PARTITION;
  518. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
  519. cpi->rc.is_src_frame_alt_ref) {
  520. sf->partition_search_type = VAR_BASED_PARTITION;
  521. }
  522. sf->use_nonrd_pick_mode = 1;
  523. sf->allow_skip_recode = 0;
  524. sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
  525. sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
  526. sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
  527. sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
  528. sf->adaptive_rd_thresh = 2;
  529. // This feature is only enabled when partition search is disabled.
  530. sf->reuse_inter_pred_sby = 1;
  531. sf->coeff_prob_appx_step = 4;
  532. sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
  533. sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
  534. sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
  535. sf->simple_model_rd_from_var = 1;
  536. if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
  537. if (!is_keyframe) {
  538. int i;
  539. if (content == VP9E_CONTENT_SCREEN) {
  540. for (i = 0; i < BLOCK_SIZES; ++i)
  541. if (i >= BLOCK_32X32)
  542. sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
  543. else
  544. sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
  545. } else {
  546. for (i = 0; i < BLOCK_SIZES; ++i)
  547. if (i > BLOCK_16X16)
  548. sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
  549. else
  550. // Use H and V intra mode for block sizes <= 16X16.
  551. sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
  552. }
  553. }
  554. if (content == VP9E_CONTENT_SCREEN) {
  555. sf->short_circuit_flat_blocks = 1;
  556. }
  557. if (cpi->oxcf.rc_mode == VPX_CBR &&
  558. cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
  559. sf->limit_newmv_early_exit = 1;
  560. if (!cpi->use_svc) sf->bias_golden = 1;
  561. }
  562. // Keep nonrd_keyframe = 1 for non-base spatial layers to prevent
  563. // increase in encoding time.
  564. if (cpi->use_svc && svc->spatial_layer_id > 0) sf->nonrd_keyframe = 1;
  565. if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
  566. cpi->oxcf.rc_mode == VPX_CBR) {
  567. if (cm->width * cm->height <= 352 * 288 && !cpi->use_svc &&
  568. cpi->oxcf.content != VP9E_CONTENT_SCREEN)
  569. sf->overshoot_detection_cbr_rt = RE_ENCODE_MAXQ;
  570. else
  571. sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
  572. }
  573. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
  574. cm->width <= 1280 && cm->height <= 720) {
  575. sf->use_altref_onepass = 1;
  576. sf->use_compound_nonrd_pickmode = 1;
  577. }
  578. if (cm->width * cm->height > 1280 * 720) sf->cb_pred_filter_search = 1;
  579. }
  580. if (speed >= 6) {
  581. if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) {
  582. sf->use_altref_onepass = 1;
  583. sf->use_compound_nonrd_pickmode = 1;
  584. }
  585. sf->partition_search_type = VAR_BASED_PARTITION;
  586. sf->mv.search_method = NSTEP;
  587. sf->mv.reduce_first_step_size = 1;
  588. sf->skip_encode_sb = 0;
  589. if (!cpi->external_resize) sf->use_source_sad = 1;
  590. if (sf->use_source_sad) {
  591. sf->adapt_partition_source_sad = 1;
  592. sf->adapt_partition_thresh =
  593. (cm->width * cm->height <= 640 * 360) ? 40000 : 60000;
  594. if (cpi->content_state_sb_fd == NULL &&
  595. (!cpi->use_svc ||
  596. svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
  597. cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
  598. (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
  599. }
  600. }
  601. if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
  602. // Enable short circuit for low temporal variance.
  603. sf->short_circuit_low_temp_var = 1;
  604. }
  605. if (svc->temporal_layer_id > 0) {
  606. sf->adaptive_rd_thresh = 4;
  607. sf->limit_newmv_early_exit = 0;
  608. sf->base_mv_aggressive = 1;
  609. }
  610. if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
  611. cpi->oxcf.rc_mode == VPX_CBR)
  612. sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
  613. }
  614. if (speed >= 7) {
  615. sf->adapt_partition_source_sad = 0;
  616. sf->adaptive_rd_thresh = 3;
  617. sf->mv.search_method = FAST_DIAMOND;
  618. sf->mv.fullpel_search_step_param = 10;
  619. // For SVC: use better mv search on base temporal layer, and only
  620. // on base spatial layer if highest resolution is above 640x360.
  621. if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
  622. (svc->spatial_layer_id == 0 ||
  623. cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
  624. sf->mv.search_method = NSTEP;
  625. sf->mv.fullpel_search_step_param = 6;
  626. }
  627. if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
  628. sf->use_simple_block_yrd = 1;
  629. if (svc->non_reference_frame)
  630. sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
  631. }
  632. if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
  633. sf->adaptive_rd_thresh_row_mt = 1;
  634. // Enable partition copy. For SVC only enabled for top spatial resolution
  635. // layer.
  636. cpi->max_copied_frame = 0;
  637. if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
  638. !cpi->external_resize &&
  639. (!cpi->use_svc ||
  640. (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
  641. !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
  642. sf->copy_partition_flag = 1;
  643. cpi->max_copied_frame = 2;
  644. // The top temporal enhancement layer (for number of temporal layers > 1)
  645. // are non-reference frames, so use large/max value for max_copied_frame.
  646. if (svc->number_temporal_layers > 1 &&
  647. svc->temporal_layer_id == svc->number_temporal_layers - 1)
  648. cpi->max_copied_frame = 255;
  649. }
  650. // For SVC: enable use of lower resolution partition for higher resolution,
  651. // only for 3 spatial layers and when config/top resolution is above VGA.
  652. // Enable only for non-base temporal layer frames.
  653. if (cpi->use_svc && svc->use_partition_reuse &&
  654. svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
  655. cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
  656. sf->svc_use_lowres_part = 1;
  657. // For SVC when golden is used as second temporal reference: to avoid
  658. // encode time increase only use this feature on base temporal layer.
  659. // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
  660. if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
  661. svc->temporal_layer_id > 0)
  662. cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
  663. if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 1;
  664. }
  665. if (speed >= 8) {
  666. sf->adaptive_rd_thresh = 4;
  667. sf->skip_encode_sb = 1;
  668. sf->nonrd_keyframe = 1;
  669. if (!cpi->use_svc) cpi->max_copied_frame = 4;
  670. if (cpi->row_mt && cpi->oxcf.max_threads > 1)
  671. sf->adaptive_rd_thresh_row_mt = 1;
  672. // Enable ML based partition for low res.
  673. if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) {
  674. sf->nonrd_use_ml_partition = 1;
  675. }
  676. #if CONFIG_VP9_HIGHBITDEPTH
  677. if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH)
  678. sf->nonrd_use_ml_partition = 0;
  679. #endif
  680. if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
  681. // Only keep INTRA_DC mode for speed 8.
  682. if (!is_keyframe) {
  683. int i = 0;
  684. for (i = 0; i < BLOCK_SIZES; ++i)
  685. sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
  686. }
  687. if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
  688. content != VP9E_CONTENT_SCREEN) {
  689. // More aggressive short circuit for speed 8.
  690. sf->short_circuit_low_temp_var = 3;
  691. // Use level 2 for noisey cases as there is a regression in some
  692. // noisy clips with level 3.
  693. if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
  694. cm->height >= 720) {
  695. NOISE_LEVEL noise_level =
  696. vp9_noise_estimate_extract_level(&cpi->noise_estimate);
  697. if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
  698. }
  699. // Since the short_circuit_low_temp_var is used, reduce the
  700. // adaptive_rd_thresh level.
  701. if (cm->width * cm->height > 352 * 288)
  702. sf->adaptive_rd_thresh = 1;
  703. else
  704. sf->adaptive_rd_thresh = 2;
  705. }
  706. sf->limit_newmv_early_exit = 0;
  707. sf->use_simple_block_yrd = 1;
  708. if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 1;
  709. }
  710. if (speed >= 9) {
  711. sf->cb_pred_filter_search = 1;
  712. sf->mv.enable_adaptive_subpel_force_stop = 1;
  713. sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
  714. sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
  715. sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
  716. // Disable partition blocks below 16x16, except for low-resolutions.
  717. if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
  718. sf->disable_16x16part_nonkey = 1;
  719. // Allow for disabling GOLDEN reference, for CBR mode.
  720. if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
  721. if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
  722. if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
  723. }
  724. if (sf->nonrd_use_ml_partition)
  725. sf->partition_search_type = ML_BASED_PARTITION;
  726. if (sf->use_altref_onepass) {
  727. if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
  728. sf->partition_search_type = FIXED_PARTITION;
  729. sf->always_this_block_size = BLOCK_64X64;
  730. }
  731. if (cpi->count_arf_frame_usage == NULL)
  732. cpi->count_arf_frame_usage =
  733. (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
  734. sizeof(*cpi->count_arf_frame_usage));
  735. if (cpi->count_lastgolden_frame_usage == NULL)
  736. cpi->count_lastgolden_frame_usage =
  737. (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
  738. sizeof(*cpi->count_lastgolden_frame_usage));
  739. }
  740. if (svc->previous_frame_is_intra_only) {
  741. sf->partition_search_type = FIXED_PARTITION;
  742. sf->always_this_block_size = BLOCK_64X64;
  743. }
  744. // Special case for screen content: increase motion search on base spatial
  745. // layer when high motion is detected or previous SL0 frame was dropped.
  746. if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
  747. (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
  748. sf->mv.search_method = NSTEP;
  749. // TODO(marpan/jianj): Tune this setting for screensharing. For now use
  750. // small step_param for all spatial layers.
  751. sf->mv.fullpel_search_step_param = 2;
  752. }
  753. // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
  754. // off for now.
  755. if (speed <= 4 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
  756. cpi->oxcf.aq_mode = 0;
  757. }
  758. void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
  759. SPEED_FEATURES *const sf = &cpi->sf;
  760. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  761. RD_OPT *const rd = &cpi->rd;
  762. int i;
  763. // best quality defaults
  764. // Some speed-up features even for best quality as minimal impact on quality.
  765. sf->partition_search_breakout_thr.dist = (1 << 19);
  766. sf->partition_search_breakout_thr.rate = 80;
  767. sf->rd_ml_partition.search_early_termination = 0;
  768. sf->rd_ml_partition.search_breakout = 0;
  769. if (oxcf->mode == REALTIME)
  770. set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
  771. #if !CONFIG_REALTIME_ONLY
  772. else if (oxcf->mode == GOOD)
  773. set_good_speed_feature_framesize_dependent(cpi, sf, speed);
  774. #endif
  775. if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
  776. sf->adaptive_pred_interp_filter = 0;
  777. }
  778. if (cpi->encode_breakout && oxcf->mode == REALTIME &&
  779. sf->encode_breakout_thresh > cpi->encode_breakout) {
  780. cpi->encode_breakout = sf->encode_breakout_thresh;
  781. }
  782. // Check for masked out split cases.
  783. for (i = 0; i < MAX_REFS; ++i) {
  784. if (sf->disable_split_mask & (1 << i)) {
  785. rd->thresh_mult_sub8x8[i] = INT_MAX;
  786. }
  787. }
  788. // With row based multi-threading, the following speed features
  789. // have to be disabled to guarantee that bitstreams encoded with single thread
  790. // and multiple threads match.
  791. // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
  792. // adaptive_rd_thresh is defined per-row for non-rd pickmode.
  793. if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
  794. oxcf->max_threads > 1)
  795. sf->adaptive_rd_thresh = 0;
  796. }
  797. void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
  798. SPEED_FEATURES *const sf = &cpi->sf;
  799. #if !CONFIG_REALTIME_ONLY
  800. VP9_COMMON *const cm = &cpi->common;
  801. #endif
  802. MACROBLOCK *const x = &cpi->td.mb;
  803. const VP9EncoderConfig *const oxcf = &cpi->oxcf;
  804. int i;
  805. // best quality defaults
  806. sf->frame_parameter_update = 1;
  807. sf->mv.search_method = NSTEP;
  808. sf->recode_loop = ALLOW_RECODE_FIRST;
  809. sf->mv.subpel_search_method = SUBPEL_TREE;
  810. sf->mv.subpel_search_level = 2;
  811. sf->mv.subpel_force_stop = EIGHTH_PEL;
  812. sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
  813. sf->mv.reduce_first_step_size = 0;
  814. sf->coeff_prob_appx_step = 1;
  815. sf->mv.auto_mv_step_size = 0;
  816. sf->mv.fullpel_search_step_param = 6;
  817. sf->comp_inter_joint_search_thresh = BLOCK_4X4;
  818. sf->tx_size_search_method = USE_FULL_RD;
  819. sf->use_lp32x32fdct = 0;
  820. sf->adaptive_motion_search = 0;
  821. sf->enhanced_full_pixel_motion_search = 1;
  822. sf->adaptive_pred_interp_filter = 0;
  823. sf->adaptive_mode_search = 0;
  824. sf->cb_pred_filter_search = 0;
  825. sf->cb_partition_search = 0;
  826. sf->motion_field_mode_search = 0;
  827. sf->alt_ref_search_fp = 0;
  828. sf->use_quant_fp = 0;
  829. sf->reference_masking = 0;
  830. sf->partition_search_type = SEARCH_PARTITION;
  831. sf->less_rectangular_check = 0;
  832. sf->use_square_partition_only = 0;
  833. sf->use_square_only_thresh_high = BLOCK_SIZES;
  834. sf->use_square_only_thresh_low = BLOCK_4X4;
  835. sf->auto_min_max_partition_size = NOT_IN_USE;
  836. sf->rd_auto_partition_min_limit = BLOCK_4X4;
  837. sf->default_max_partition_size = BLOCK_64X64;
  838. sf->default_min_partition_size = BLOCK_4X4;
  839. sf->adjust_partitioning_from_last_frame = 0;
  840. sf->last_partitioning_redo_frequency = 4;
  841. sf->disable_split_mask = 0;
  842. sf->mode_search_skip_flags = 0;
  843. sf->force_frame_boost = 0;
  844. sf->max_delta_qindex = 0;
  845. sf->disable_filter_search_var_thresh = 0;
  846. sf->adaptive_interp_filter_search = 0;
  847. sf->allow_partition_search_skip = 0;
  848. sf->allow_txfm_domain_distortion = 0;
  849. sf->tx_domain_thresh = 99.0;
  850. sf->allow_quant_coeff_opt = sf->optimize_coefficients;
  851. sf->quant_opt_thresh = 99.0;
  852. sf->allow_acl = 1;
  853. sf->enable_tpl_model = oxcf->enable_tpl_model;
  854. sf->prune_ref_frame_for_rect_partitions = 0;
  855. sf->temporal_filter_search_method = MESH;
  856. for (i = 0; i < TX_SIZES; i++) {
  857. sf->intra_y_mode_mask[i] = INTRA_ALL;
  858. sf->intra_uv_mode_mask[i] = INTRA_ALL;
  859. }
  860. sf->use_rd_breakout = 0;
  861. sf->skip_encode_sb = 0;
  862. sf->use_uv_intra_rd_estimate = 0;
  863. sf->allow_skip_recode = 0;
  864. sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
  865. sf->use_fast_coef_updates = TWO_LOOP;
  866. sf->use_fast_coef_costing = 0;
  867. sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
  868. sf->schedule_mode_search = 0;
  869. sf->use_nonrd_pick_mode = 0;
  870. for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
  871. sf->max_intra_bsize = BLOCK_64X64;
  872. sf->reuse_inter_pred_sby = 0;
  873. // This setting only takes effect when partition_search_type is set
  874. // to FIXED_PARTITION.
  875. sf->always_this_block_size = BLOCK_16X16;
  876. sf->search_type_check_frequency = 50;
  877. sf->encode_breakout_thresh = 0;
  878. // Recode loop tolerance %.
  879. sf->recode_tolerance_low = 12;
  880. sf->recode_tolerance_high = 25;
  881. sf->default_interp_filter = SWITCHABLE;
  882. sf->simple_model_rd_from_var = 0;
  883. sf->short_circuit_flat_blocks = 0;
  884. sf->short_circuit_low_temp_var = 0;
  885. sf->limit_newmv_early_exit = 0;
  886. sf->bias_golden = 0;
  887. sf->base_mv_aggressive = 0;
  888. sf->rd_ml_partition.prune_rect_thresh[0] = -1;
  889. sf->rd_ml_partition.prune_rect_thresh[1] = -1;
  890. sf->rd_ml_partition.prune_rect_thresh[2] = -1;
  891. sf->rd_ml_partition.prune_rect_thresh[3] = -1;
  892. sf->rd_ml_partition.var_pruning = 0;
  893. sf->use_accurate_subpel_search = USE_8_TAPS;
  894. // Some speed-up features even for best quality as minimal impact on quality.
  895. sf->adaptive_rd_thresh = 1;
  896. sf->tx_size_search_breakout = 1;
  897. sf->tx_size_search_depth = 2;
  898. sf->exhaustive_searches_thresh =
  899. (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
  900. : INT_MAX;
  901. if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
  902. for (i = 0; i < MAX_MESH_STEP; ++i) {
  903. sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
  904. sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
  905. }
  906. }
  907. if (oxcf->mode == REALTIME)
  908. set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
  909. #if !CONFIG_REALTIME_ONLY
  910. else if (oxcf->mode == GOOD)
  911. set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
  912. #endif
  913. cpi->diamond_search_sad = vp9_diamond_search_sad;
  914. // Slow quant, dct and trellis not worthwhile for first pass
  915. // so make sure they are always turned off.
  916. if (oxcf->pass == 1) sf->optimize_coefficients = 0;
  917. // No recode for 1 pass.
  918. if (oxcf->pass == 0) {
  919. sf->recode_loop = DISALLOW_RECODE;
  920. sf->optimize_coefficients = 0;
  921. }
  922. if (sf->mv.subpel_force_stop == FULL_PEL) {
  923. // Whole pel only
  924. cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
  925. } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
  926. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
  927. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
  928. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
  929. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
  930. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
  931. } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
  932. cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
  933. }
  934. // This is only used in motion vector unit test.
  935. if (cpi->oxcf.motion_vector_unit_test == 1)
  936. cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
  937. else if (cpi->oxcf.motion_vector_unit_test == 2)
  938. cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
  939. x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
  940. x->min_partition_size = sf->default_min_partition_size;
  941. x->max_partition_size = sf->default_max_partition_size;
  942. if (!cpi->oxcf.frame_periodic_boost) {
  943. sf->max_delta_qindex = 0;
  944. }
  945. // With row based multi-threading, the following speed features
  946. // have to be disabled to guarantee that bitstreams encoded with single thread
  947. // and multiple threads match.
  948. // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
  949. // adaptive_rd_thresh is defined per-row for non-rd pickmode.
  950. if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
  951. oxcf->max_threads > 1)
  952. sf->adaptive_rd_thresh = 0;
  953. }