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 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 for (i = rc->best_quality; i < rc->worst_quality; ++i) { | 1602 for (i = rc->best_quality; i < rc->worst_quality; ++i) { |
1603 if (vp9_rc_bits_per_mb(frame_type, i, 1.0, bit_depth) <= | 1603 if (vp9_rc_bits_per_mb(frame_type, i, 1.0, bit_depth) <= |
1604 target_bits_per_mb) { | 1604 target_bits_per_mb) { |
1605 target_index = i; | 1605 target_index = i; |
1606 break; | 1606 break; |
1607 } | 1607 } |
1608 } | 1608 } |
1609 return target_index - qindex; | 1609 return target_index - qindex; |
1610 } | 1610 } |
1611 | 1611 |
1612 void vp9_rc_set_gf_max_interval(const VP9_COMP *const cpi, | 1612 #define MIN_GF_INTERVAL 4 |
1613 RATE_CONTROL *const rc) { | 1613 #define MAX_GF_INTERVAL 16 |
| 1614 void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi, |
| 1615 RATE_CONTROL *const rc) { |
1614 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 1616 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
1615 // Set Maximum gf/arf interval | 1617 |
1616 rc->max_gf_interval = 16; | 1618 // Set a minimum interval. |
| 1619 rc->min_gf_interval = |
| 1620 MIN(MAX_GF_INTERVAL, MAX(MIN_GF_INTERVAL, (int)(cpi->framerate * 0.125))); |
| 1621 |
| 1622 // Set Maximum gf/arf interval. |
| 1623 rc->max_gf_interval = |
| 1624 MIN(MAX_GF_INTERVAL, (int)(cpi->framerate * 0.75)); |
| 1625 // Round up to next even number if odd. |
| 1626 rc->max_gf_interval += (rc->max_gf_interval & 0x01); |
1617 | 1627 |
1618 // Extended interval for genuinely static scenes | 1628 // Extended interval for genuinely static scenes |
1619 rc->static_scene_max_gf_interval = MAX_LAG_BUFFERS * 2; | 1629 rc->static_scene_max_gf_interval = MAX_LAG_BUFFERS * 2; |
1620 | 1630 |
1621 if (is_altref_enabled(cpi)) { | 1631 if (is_altref_enabled(cpi)) { |
1622 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) | 1632 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) |
1623 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; | 1633 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; |
1624 } | 1634 } |
1625 | 1635 |
1626 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) | 1636 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) |
1627 rc->max_gf_interval = rc->static_scene_max_gf_interval; | 1637 rc->max_gf_interval = rc->static_scene_max_gf_interval; |
| 1638 |
| 1639 // Clamp min to max |
| 1640 rc->min_gf_interval = MIN(rc->min_gf_interval, rc->max_gf_interval); |
1628 } | 1641 } |
1629 | 1642 |
1630 void vp9_rc_update_framerate(VP9_COMP *cpi) { | 1643 void vp9_rc_update_framerate(VP9_COMP *cpi) { |
1631 const VP9_COMMON *const cm = &cpi->common; | 1644 const VP9_COMMON *const cm = &cpi->common; |
1632 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 1645 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
1633 RATE_CONTROL *const rc = &cpi->rc; | 1646 RATE_CONTROL *const rc = &cpi->rc; |
1634 int vbr_max_bits; | 1647 int vbr_max_bits; |
1635 | 1648 |
1636 rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate); | 1649 rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate); |
1637 rc->min_frame_bandwidth = (int)(rc->avg_frame_bandwidth * | 1650 rc->min_frame_bandwidth = (int)(rc->avg_frame_bandwidth * |
1638 oxcf->two_pass_vbrmin_section / 100); | 1651 oxcf->two_pass_vbrmin_section / 100); |
1639 | 1652 |
1640 rc->min_frame_bandwidth = MAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS); | 1653 rc->min_frame_bandwidth = MAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS); |
1641 | 1654 |
1642 // A maximum bitrate for a frame is defined. | 1655 // A maximum bitrate for a frame is defined. |
1643 // The baseline for this aligns with HW implementations that | 1656 // The baseline for this aligns with HW implementations that |
1644 // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits | 1657 // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits |
1645 // per 16x16 MB (averaged over a frame). However this limit is extended if | 1658 // per 16x16 MB (averaged over a frame). However this limit is extended if |
1646 // a very high rate is given on the command line or the the rate cannnot | 1659 // a very high rate is given on the command line or the the rate cannnot |
1647 // be acheived because of a user specificed max q (e.g. when the user | 1660 // be acheived because of a user specificed max q (e.g. when the user |
1648 // specifies lossless encode. | 1661 // specifies lossless encode. |
1649 vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth * | 1662 vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth * |
1650 oxcf->two_pass_vbrmax_section) / 100); | 1663 oxcf->two_pass_vbrmax_section) / 100); |
1651 rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), | 1664 rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), |
1652 vbr_max_bits); | 1665 vbr_max_bits); |
1653 | 1666 |
1654 vp9_rc_set_gf_max_interval(cpi, rc); | 1667 vp9_rc_set_gf_interval_range(cpi, rc); |
1655 } | 1668 } |
1656 | 1669 |
1657 #define VBR_PCT_ADJUSTMENT_LIMIT 50 | 1670 #define VBR_PCT_ADJUSTMENT_LIMIT 50 |
1658 // For VBR...adjustment to the frame target based on error from previous frames | 1671 // For VBR...adjustment to the frame target based on error from previous frames |
1659 static void vbr_rate_correction(VP9_COMP *cpi, | 1672 static void vbr_rate_correction(VP9_COMP *cpi, |
1660 int *this_frame_target, | 1673 int *this_frame_target, |
1661 int64_t vbr_bits_off_target) { | 1674 int64_t vbr_bits_off_target) { |
1662 int max_delta; | 1675 int max_delta; |
1663 double position_factor = 1.0; | 1676 double position_factor = 1.0; |
1664 | 1677 |
(...skipping 21 matching lines...) Expand all Loading... |
1686 | 1699 |
1687 void vp9_set_target_rate(VP9_COMP *cpi) { | 1700 void vp9_set_target_rate(VP9_COMP *cpi) { |
1688 RATE_CONTROL *const rc = &cpi->rc; | 1701 RATE_CONTROL *const rc = &cpi->rc; |
1689 int target_rate = rc->base_frame_target; | 1702 int target_rate = rc->base_frame_target; |
1690 | 1703 |
1691 // Correction to rate target based on prior over or under shoot. | 1704 // Correction to rate target based on prior over or under shoot. |
1692 if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ) | 1705 if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ) |
1693 vbr_rate_correction(cpi, &target_rate, rc->vbr_bits_off_target); | 1706 vbr_rate_correction(cpi, &target_rate, rc->vbr_bits_off_target); |
1694 vp9_rc_set_frame_target(cpi, target_rate); | 1707 vp9_rc_set_frame_target(cpi, target_rate); |
1695 } | 1708 } |
OLD | NEW |