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 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 else | 1208 else |
1209 cpi->rate_correction_factor = rate_correction_factor; | 1209 cpi->rate_correction_factor = rate_correction_factor; |
1210 } | 1210 } |
1211 } | 1211 } |
1212 | 1212 |
1213 | 1213 |
1214 int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) | 1214 int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) |
1215 { | 1215 { |
1216 int Q = cpi->active_worst_quality; | 1216 int Q = cpi->active_worst_quality; |
1217 | 1217 |
| 1218 if (cpi->force_maxqp == 1) { |
| 1219 cpi->active_worst_quality = cpi->worst_quality; |
| 1220 return cpi->worst_quality; |
| 1221 } |
| 1222 |
1218 /* Reset Zbin OQ value */ | 1223 /* Reset Zbin OQ value */ |
1219 cpi->mb.zbin_over_quant = 0; | 1224 cpi->mb.zbin_over_quant = 0; |
1220 | 1225 |
1221 if (cpi->oxcf.fixed_q >= 0) | 1226 if (cpi->oxcf.fixed_q >= 0) |
1222 { | 1227 { |
1223 Q = cpi->oxcf.fixed_q; | 1228 Q = cpi->oxcf.fixed_q; |
1224 | 1229 |
1225 if (cpi->common.frame_type == KEY_FRAME) | 1230 if (cpi->common.frame_type == KEY_FRAME) |
1226 { | 1231 { |
1227 Q = cpi->oxcf.key_q; | 1232 Q = cpi->oxcf.key_q; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 | 1557 |
1553 /* Check if we're dropping the frame: */ | 1558 /* Check if we're dropping the frame: */ |
1554 if (cpi->drop_frame) | 1559 if (cpi->drop_frame) |
1555 { | 1560 { |
1556 cpi->drop_frame = 0; | 1561 cpi->drop_frame = 0; |
1557 return 0; | 1562 return 0; |
1558 } | 1563 } |
1559 } | 1564 } |
1560 return 1; | 1565 return 1; |
1561 } | 1566 } |
| 1567 // If this just encoded frame (mcomp/transform/quant, but before loopfilter and |
| 1568 // pack_bitstream) has large overshoot, and was not being encoded close to the |
| 1569 // max QP, then drop this frame and force next frame to be encoded at max QP. |
| 1570 // Condition this on 1 pass CBR with screen content mode and frame dropper off. |
| 1571 // TODO(marpan): Should do this exit condition during the encode_frame |
| 1572 // (i.e., halfway during the encoding of the frame) to save cycles. |
| 1573 int vp8_drop_encodedframe_overshoot(VP8_COMP *cpi, int Q) { |
| 1574 if (cpi->pass == 0 && |
| 1575 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER && |
| 1576 cpi->drop_frames_allowed == 0 && |
| 1577 cpi->common.frame_type != KEY_FRAME) { |
| 1578 // Note: the "projected_frame_size" from encode_frame() only gives estimate |
| 1579 // of mode/motion vector rate (in non-rd mode): so below we only require |
| 1580 // that projected_frame_size is somewhat greater than per-frame-bandwidth, |
| 1581 // but add additional condition with high threshold on prediction residual. |
| 1582 |
| 1583 // QP threshold: only allow dropping if we are not close to qp_max. |
| 1584 int thresh_qp = 3 * cpi->worst_quality >> 2; |
| 1585 // Rate threshold, in bytes. |
| 1586 int thresh_rate = 2 * (cpi->av_per_frame_bandwidth >> 3); |
| 1587 // Threshold for the average (over all macroblocks) of the pixel-sum |
| 1588 // residual error over 16x16 block. Should add QP dependence on threshold? |
| 1589 int thresh_pred_err_mb = (256 << 4); |
| 1590 int pred_err_mb = cpi->mb.prediction_error / cpi->common.MBs; |
| 1591 if (Q < thresh_qp && |
| 1592 cpi->projected_frame_size > thresh_rate && |
| 1593 pred_err_mb > thresh_pred_err_mb) { |
| 1594 // Drop this frame: advance frame counters, and set force_maxqp flag. |
| 1595 cpi->common.current_video_frame++; |
| 1596 cpi->frames_since_key++; |
| 1597 // Flag to indicate we will force next frame to be encoded at max QP. |
| 1598 cpi->force_maxqp = 1; |
| 1599 return 1; |
| 1600 } else { |
| 1601 cpi->force_maxqp = 0; |
| 1602 return 0; |
| 1603 } |
| 1604 return 0; |
| 1605 } |
| 1606 return 0; |
| 1607 } |
OLD | NEW |