OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 #define MAX_BPB_FACTOR 50 | 41 #define MAX_BPB_FACTOR 50 |
42 | 42 |
43 #define FRAME_OVERHEAD_BITS 200 | 43 #define FRAME_OVERHEAD_BITS 200 |
44 | 44 |
45 // Tables relating active max Q to active min Q | 45 // Tables relating active max Q to active min Q |
46 static int kf_low_motion_minq[QINDEX_RANGE]; | 46 static int kf_low_motion_minq[QINDEX_RANGE]; |
47 static int kf_high_motion_minq[QINDEX_RANGE]; | 47 static int kf_high_motion_minq[QINDEX_RANGE]; |
48 static int arfgf_low_motion_minq[QINDEX_RANGE]; | 48 static int arfgf_low_motion_minq[QINDEX_RANGE]; |
49 static int arfgf_high_motion_minq[QINDEX_RANGE]; | 49 static int arfgf_high_motion_minq[QINDEX_RANGE]; |
50 static int inter_minq[QINDEX_RANGE]; | 50 static int inter_minq[QINDEX_RANGE]; |
| 51 static int rtc_minq[QINDEX_RANGE]; |
51 static int gf_high = 2000; | 52 static int gf_high = 2000; |
52 static int gf_low = 400; | 53 static int gf_low = 400; |
53 static int kf_high = 5000; | 54 static int kf_high = 5000; |
54 static int kf_low = 400; | 55 static int kf_low = 400; |
55 | 56 |
56 // Functions to compute the active minq lookup table entries based on a | 57 // Functions to compute the active minq lookup table entries based on a |
57 // formulaic approach to facilitate easier adjustment of the Q tables. | 58 // formulaic approach to facilitate easier adjustment of the Q tables. |
58 // The formulae were derived from computing a 3rd order polynomial best | 59 // The formulae were derived from computing a 3rd order polynomial best |
59 // fit to the original data (after plotting real maxq vs minq (not q index)) | 60 // fit to the original data (after plotting real maxq vs minq (not q index)) |
60 static int get_minq_index(double maxq, double x3, double x2, double x1) { | 61 static int get_minq_index(double maxq, double x3, double x2, double x1) { |
(...skipping 16 matching lines...) Expand all Loading... |
77 void vp9_rc_init_minq_luts() { | 78 void vp9_rc_init_minq_luts() { |
78 int i; | 79 int i; |
79 | 80 |
80 for (i = 0; i < QINDEX_RANGE; i++) { | 81 for (i = 0; i < QINDEX_RANGE; i++) { |
81 const double maxq = vp9_convert_qindex_to_q(i); | 82 const double maxq = vp9_convert_qindex_to_q(i); |
82 kf_low_motion_minq[i] = get_minq_index(maxq, 0.000001, -0.0004, 0.125); | 83 kf_low_motion_minq[i] = get_minq_index(maxq, 0.000001, -0.0004, 0.125); |
83 kf_high_motion_minq[i] = get_minq_index(maxq, 0.000002, -0.0012, 0.50); | 84 kf_high_motion_minq[i] = get_minq_index(maxq, 0.000002, -0.0012, 0.50); |
84 arfgf_low_motion_minq[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.30); | 85 arfgf_low_motion_minq[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.30); |
85 arfgf_high_motion_minq[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.50); | 86 arfgf_high_motion_minq[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.50); |
86 inter_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.90); | 87 inter_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.90); |
| 88 rtc_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.70); |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 // These functions use formulaic calculations to make playing with the | 92 // These functions use formulaic calculations to make playing with the |
91 // quantizer tables easier. If necessary they can be replaced by lookup | 93 // quantizer tables easier. If necessary they can be replaced by lookup |
92 // tables if and when things settle down in the experimental bitstream | 94 // tables if and when things settle down in the experimental bitstream |
93 double vp9_convert_qindex_to_q(int qindex) { | 95 double vp9_convert_qindex_to_q(int qindex) { |
94 // Convert the index to a real Q value (scaled down to match old Q values) | 96 // Convert the index to a real Q value (scaled down to match old Q values) |
95 return vp9_ac_quant(qindex, 0) / 4.0; | 97 return vp9_ac_quant(qindex, 0) / 4.0; |
96 } | 98 } |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 } else { | 544 } else { |
543 q = active_worst_quality; | 545 q = active_worst_quality; |
544 } | 546 } |
545 active_best_quality = get_active_quality( | 547 active_best_quality = get_active_quality( |
546 q, rc->gfu_boost, gf_low, gf_high, | 548 q, rc->gfu_boost, gf_low, gf_high, |
547 arfgf_low_motion_minq, arfgf_high_motion_minq); | 549 arfgf_low_motion_minq, arfgf_high_motion_minq); |
548 } else { | 550 } else { |
549 // Use the lower of active_worst_quality and recent/average Q. | 551 // Use the lower of active_worst_quality and recent/average Q. |
550 if (cm->current_video_frame > 1) { | 552 if (cm->current_video_frame > 1) { |
551 if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) | 553 if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) |
552 active_best_quality = inter_minq[rc->avg_frame_qindex[INTER_FRAME]]; | 554 active_best_quality = rtc_minq[rc->avg_frame_qindex[INTER_FRAME]]; |
553 else | 555 else |
554 active_best_quality = inter_minq[active_worst_quality]; | 556 active_best_quality = rtc_minq[active_worst_quality]; |
555 } else { | 557 } else { |
556 if (rc->avg_frame_qindex[KEY_FRAME] < active_worst_quality) | 558 if (rc->avg_frame_qindex[KEY_FRAME] < active_worst_quality) |
557 active_best_quality = inter_minq[rc->avg_frame_qindex[KEY_FRAME]]; | 559 active_best_quality = rtc_minq[rc->avg_frame_qindex[KEY_FRAME]]; |
558 else | 560 else |
559 active_best_quality = inter_minq[active_worst_quality]; | 561 active_best_quality = rtc_minq[active_worst_quality]; |
560 } | 562 } |
561 } | 563 } |
562 | 564 |
563 // Clip the active best and worst quality values to limits | 565 // Clip the active best and worst quality values to limits |
564 active_best_quality = clamp(active_best_quality, | 566 active_best_quality = clamp(active_best_quality, |
565 rc->best_quality, rc->worst_quality); | 567 rc->best_quality, rc->worst_quality); |
566 active_worst_quality = clamp(active_worst_quality, | 568 active_worst_quality = clamp(active_worst_quality, |
567 active_best_quality, rc->worst_quality); | 569 active_best_quality, rc->worst_quality); |
568 | 570 |
569 *top_index = active_worst_quality; | 571 *top_index = active_worst_quality; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 int q; | 967 int q; |
966 if (cpi->pass == 0) { | 968 if (cpi->pass == 0) { |
967 if (cpi->oxcf.rc_mode == RC_MODE_CBR) | 969 if (cpi->oxcf.rc_mode == RC_MODE_CBR) |
968 q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index); | 970 q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index); |
969 else | 971 else |
970 q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index); | 972 q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index); |
971 } else { | 973 } else { |
972 q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index); | 974 q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index); |
973 } | 975 } |
974 | 976 |
975 // Q of 0 is disabled because we force tx size to be | |
976 // 16x16... | |
977 if (cpi->sf.use_nonrd_pick_mode) { | 977 if (cpi->sf.use_nonrd_pick_mode) { |
978 if (q == 0) | |
979 q++; | |
980 if (cpi->sf.force_frame_boost == 1) | 978 if (cpi->sf.force_frame_boost == 1) |
981 q -= cpi->sf.max_delta_qindex; | 979 q -= cpi->sf.max_delta_qindex; |
982 | 980 |
983 if (q < *bottom_index) | 981 if (q < *bottom_index) |
984 *bottom_index = q; | 982 *bottom_index = q; |
985 else if (q > *top_index) | 983 else if (q > *top_index) |
986 *top_index = q; | 984 *top_index = q; |
987 } | 985 } |
988 return q; | 986 return q; |
989 } | 987 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 } | 1140 } |
1143 | 1141 |
1144 void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) { | 1142 void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) { |
1145 // Update buffer level with zero size, update frame counters, and return. | 1143 // Update buffer level with zero size, update frame counters, and return. |
1146 update_buffer_level(cpi, 0); | 1144 update_buffer_level(cpi, 0); |
1147 cpi->common.last_frame_type = cpi->common.frame_type; | 1145 cpi->common.last_frame_type = cpi->common.frame_type; |
1148 cpi->rc.frames_since_key++; | 1146 cpi->rc.frames_since_key++; |
1149 cpi->rc.frames_to_key--; | 1147 cpi->rc.frames_to_key--; |
1150 } | 1148 } |
1151 | 1149 |
1152 static int test_for_kf_one_pass(VP9_COMP *cpi) { | |
1153 // Placeholder function for auto key frame | |
1154 return 0; | |
1155 } | |
1156 // Use this macro to turn on/off use of alt-refs in one-pass mode. | 1150 // Use this macro to turn on/off use of alt-refs in one-pass mode. |
1157 #define USE_ALTREF_FOR_ONE_PASS 1 | 1151 #define USE_ALTREF_FOR_ONE_PASS 1 |
1158 | 1152 |
1159 static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) { | 1153 static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) { |
1160 static const int af_ratio = 10; | 1154 static const int af_ratio = 10; |
1161 const RATE_CONTROL *const rc = &cpi->rc; | 1155 const RATE_CONTROL *const rc = &cpi->rc; |
1162 int target; | 1156 int target; |
1163 #if USE_ALTREF_FOR_ONE_PASS | 1157 #if USE_ALTREF_FOR_ONE_PASS |
1164 target = (!rc->is_src_frame_alt_ref && | 1158 target = (!rc->is_src_frame_alt_ref && |
1165 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) ? | 1159 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) ? |
(...skipping 11 matching lines...) Expand all Loading... |
1177 static const int kf_ratio = 25; | 1171 static const int kf_ratio = 25; |
1178 const RATE_CONTROL *rc = &cpi->rc; | 1172 const RATE_CONTROL *rc = &cpi->rc; |
1179 const int target = rc->avg_frame_bandwidth * kf_ratio; | 1173 const int target = rc->avg_frame_bandwidth * kf_ratio; |
1180 return vp9_rc_clamp_iframe_target_size(cpi, target); | 1174 return vp9_rc_clamp_iframe_target_size(cpi, target); |
1181 } | 1175 } |
1182 | 1176 |
1183 void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) { | 1177 void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) { |
1184 VP9_COMMON *const cm = &cpi->common; | 1178 VP9_COMMON *const cm = &cpi->common; |
1185 RATE_CONTROL *const rc = &cpi->rc; | 1179 RATE_CONTROL *const rc = &cpi->rc; |
1186 int target; | 1180 int target; |
| 1181 // TODO(yaowu): replace the "auto_key && 0" below with proper decision logic. |
1187 if (!cpi->refresh_alt_ref_frame && | 1182 if (!cpi->refresh_alt_ref_frame && |
1188 (cm->current_video_frame == 0 || | 1183 (cm->current_video_frame == 0 || |
1189 (cpi->frame_flags & FRAMEFLAGS_KEY) || | 1184 (cpi->frame_flags & FRAMEFLAGS_KEY) || |
1190 rc->frames_to_key == 0 || | 1185 rc->frames_to_key == 0 || |
1191 (cpi->oxcf.auto_key && test_for_kf_one_pass(cpi)))) { | 1186 (cpi->oxcf.auto_key && 0))) { |
1192 cm->frame_type = KEY_FRAME; | 1187 cm->frame_type = KEY_FRAME; |
1193 rc->this_key_frame_forced = cm->current_video_frame != 0 && | 1188 rc->this_key_frame_forced = cm->current_video_frame != 0 && |
1194 rc->frames_to_key == 0; | 1189 rc->frames_to_key == 0; |
1195 rc->frames_to_key = cpi->oxcf.key_freq; | 1190 rc->frames_to_key = cpi->oxcf.key_freq; |
1196 rc->kf_boost = DEFAULT_KF_BOOST; | 1191 rc->kf_boost = DEFAULT_KF_BOOST; |
1197 rc->source_alt_ref_active = 0; | 1192 rc->source_alt_ref_active = 0; |
1198 } else { | 1193 } else { |
1199 cm->frame_type = INTER_FRAME; | 1194 cm->frame_type = INTER_FRAME; |
1200 } | 1195 } |
1201 if (rc->frames_till_gf_update_due == 0) { | 1196 if (rc->frames_till_gf_update_due == 0) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 } | 1303 } |
1309 vp9_rc_set_frame_target(cpi, target); | 1304 vp9_rc_set_frame_target(cpi, target); |
1310 rc->frames_till_gf_update_due = INT_MAX; | 1305 rc->frames_till_gf_update_due = INT_MAX; |
1311 rc->baseline_gf_interval = INT_MAX; | 1306 rc->baseline_gf_interval = INT_MAX; |
1312 } | 1307 } |
1313 | 1308 |
1314 void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) { | 1309 void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) { |
1315 VP9_COMMON *const cm = &cpi->common; | 1310 VP9_COMMON *const cm = &cpi->common; |
1316 RATE_CONTROL *const rc = &cpi->rc; | 1311 RATE_CONTROL *const rc = &cpi->rc; |
1317 int target; | 1312 int target; |
| 1313 // TODO(yaowu): replace the "auto_key && 0" below with proper decision logic. |
1318 if ((cm->current_video_frame == 0 || | 1314 if ((cm->current_video_frame == 0 || |
1319 (cpi->frame_flags & FRAMEFLAGS_KEY) || | 1315 (cpi->frame_flags & FRAMEFLAGS_KEY) || |
1320 rc->frames_to_key == 0 || | 1316 rc->frames_to_key == 0 || |
1321 (cpi->oxcf.auto_key && test_for_kf_one_pass(cpi)))) { | 1317 (cpi->oxcf.auto_key && 0))) { |
1322 cm->frame_type = KEY_FRAME; | 1318 cm->frame_type = KEY_FRAME; |
1323 rc->this_key_frame_forced = cm->current_video_frame != 0 && | 1319 rc->this_key_frame_forced = cm->current_video_frame != 0 && |
1324 rc->frames_to_key == 0; | 1320 rc->frames_to_key == 0; |
1325 rc->frames_to_key = cpi->oxcf.key_freq; | 1321 rc->frames_to_key = cpi->oxcf.key_freq; |
1326 rc->kf_boost = DEFAULT_KF_BOOST; | 1322 rc->kf_boost = DEFAULT_KF_BOOST; |
1327 rc->source_alt_ref_active = 0; | 1323 rc->source_alt_ref_active = 0; |
1328 target = calc_iframe_target_size_one_pass_cbr(cpi); | 1324 target = calc_iframe_target_size_one_pass_cbr(cpi); |
1329 } else { | 1325 } else { |
1330 cm->frame_type = INTER_FRAME; | 1326 cm->frame_type = INTER_FRAME; |
1331 target = calc_pframe_target_size_one_pass_cbr(cpi); | 1327 target = calc_pframe_target_size_one_pass_cbr(cpi); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 if (rc->max_gf_interval > oxcf->lag_in_frames - 1) | 1410 if (rc->max_gf_interval > oxcf->lag_in_frames - 1) |
1415 rc->max_gf_interval = oxcf->lag_in_frames - 1; | 1411 rc->max_gf_interval = oxcf->lag_in_frames - 1; |
1416 | 1412 |
1417 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) | 1413 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) |
1418 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; | 1414 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; |
1419 } | 1415 } |
1420 | 1416 |
1421 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) | 1417 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) |
1422 rc->max_gf_interval = rc->static_scene_max_gf_interval; | 1418 rc->max_gf_interval = rc->static_scene_max_gf_interval; |
1423 } | 1419 } |
OLD | NEW |