Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_ratectrl.c

Issue 1217053002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ratectrl.h ('k') | source/libvpx/vp9/encoder/vp9_rd.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 // should be done here, before the frame qp is selected. 1589 // should be done here, before the frame qp is selected.
1590 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) 1590 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
1591 vp9_cyclic_refresh_update_parameters(cpi); 1591 vp9_cyclic_refresh_update_parameters(cpi);
1592 1592
1593 if (cm->frame_type == KEY_FRAME) 1593 if (cm->frame_type == KEY_FRAME)
1594 target = calc_iframe_target_size_one_pass_cbr(cpi); 1594 target = calc_iframe_target_size_one_pass_cbr(cpi);
1595 else 1595 else
1596 target = calc_pframe_target_size_one_pass_cbr(cpi); 1596 target = calc_pframe_target_size_one_pass_cbr(cpi);
1597 1597
1598 vp9_rc_set_frame_target(cpi, target); 1598 vp9_rc_set_frame_target(cpi, target);
1599 if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC)
1600 cpi->resize_state = vp9_resize_one_pass_cbr(cpi);
1601 else
1602 cpi->resize_state = 0;
1599 } 1603 }
1600 1604
1601 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget, 1605 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget,
1602 vpx_bit_depth_t bit_depth) { 1606 vpx_bit_depth_t bit_depth) {
1603 int start_index = rc->worst_quality; 1607 int start_index = rc->worst_quality;
1604 int target_index = rc->worst_quality; 1608 int target_index = rc->worst_quality;
1605 int i; 1609 int i;
1606 1610
1607 // Convert the average q value to an index. 1611 // Convert the average q value to an index.
1608 for (i = rc->best_quality; i < rc->worst_quality; ++i) { 1612 for (i = rc->best_quality; i < rc->worst_quality; ++i) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1753
1750 void vp9_set_target_rate(VP9_COMP *cpi) { 1754 void vp9_set_target_rate(VP9_COMP *cpi) {
1751 RATE_CONTROL *const rc = &cpi->rc; 1755 RATE_CONTROL *const rc = &cpi->rc;
1752 int target_rate = rc->base_frame_target; 1756 int target_rate = rc->base_frame_target;
1753 1757
1754 // Correction to rate target based on prior over or under shoot. 1758 // Correction to rate target based on prior over or under shoot.
1755 if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ) 1759 if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ)
1756 vbr_rate_correction(cpi, &target_rate); 1760 vbr_rate_correction(cpi, &target_rate);
1757 vp9_rc_set_frame_target(cpi, target_rate); 1761 vp9_rc_set_frame_target(cpi, target_rate);
1758 } 1762 }
1763
1764 // Check if we should resize, based on average QP from past x frames.
1765 // Only allow for resize at most one scale down for now, scaling factor is 2.
1766 int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
1767 const VP9_COMMON *const cm = &cpi->common;
1768 RATE_CONTROL *const rc = &cpi->rc;
1769 int resize_now = 0;
1770 cpi->resize_scale_num = 1;
1771 cpi->resize_scale_den = 1;
1772 // Don't resize on key frame; reset the counters on key frame.
1773 if (cm->frame_type == KEY_FRAME) {
1774 cpi->resize_avg_qp = 0;
1775 cpi->resize_count = 0;
1776 return 0;
1777 }
1778 // Resize based on average QP over some window.
1779 // Ignore samples close to key frame, since QP is usually high after key.
1780 if (cpi->rc.frames_since_key > 2 * cpi->framerate) {
1781 const int window = (int)(5 * cpi->framerate);
1782 cpi->resize_avg_qp += cm->base_qindex;
1783 if (cpi->rc.buffer_level < 0)
1784 ++cpi->resize_buffer_underflow;
1785 ++cpi->resize_count;
1786 // Check for resize action every "window" frames.
1787 if (cpi->resize_count >= window) {
1788 int avg_qp = cpi->resize_avg_qp / cpi->resize_count;
1789 // Resize down if buffer level has underflowed sufficent amount in past
1790 // window, and we are at original resolution.
1791 // Resize back up if average QP is low, and we are currently in a resized
1792 // down state.
1793 if (cpi->resize_state == 0 &&
1794 cpi->resize_buffer_underflow > (cpi->resize_count >> 3)) {
1795 resize_now = 1;
1796 } else if (cpi->resize_state == 1 &&
1797 avg_qp < 40 * cpi->rc.worst_quality / 100) {
1798 resize_now = -1;
1799 }
1800 // Reset for next window measurement.
1801 cpi->resize_avg_qp = 0;
1802 cpi->resize_count = 0;
1803 cpi->resize_buffer_underflow = 0;
1804 }
1805 }
1806 // If decision is to resize, reset some quantities, and check is we should
1807 // reduce rate correction factor,
1808 if (resize_now != 0) {
1809 int target_bits_per_frame;
1810 int active_worst_quality;
1811 int qindex;
1812 int tot_scale_change;
1813 // For now, resize is by 1/2 x 1/2.
1814 cpi->resize_scale_num = 1;
1815 cpi->resize_scale_den = 2;
1816 tot_scale_change = (cpi->resize_scale_den * cpi->resize_scale_den) /
1817 (cpi->resize_scale_num * cpi->resize_scale_num);
1818 // Reset buffer level to optimal, update target size.
1819 rc->buffer_level = rc->optimal_buffer_level;
1820 rc->bits_off_target = rc->optimal_buffer_level;
1821 rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi);
1822 // Reset cyclic refresh parameters.
1823 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled)
1824 vp9_cyclic_refresh_reset_resize(cpi);
1825 // Get the projected qindex, based on the scaled target frame size (scaled
1826 // so target_bits_per_mb in vp9_rc_regulate_q will be correct target).
1827 target_bits_per_frame = (resize_now == 1) ?
1828 rc->this_frame_target * tot_scale_change :
1829 rc->this_frame_target / tot_scale_change;
1830 active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
1831 qindex = vp9_rc_regulate_q(cpi,
1832 target_bits_per_frame,
1833 rc->best_quality,
1834 active_worst_quality);
1835 // If resize is down, check if projected q index is close to worst_quality,
1836 // and if so, reduce the rate correction factor (since likely can afford
1837 // lower q for resized frame).
1838 if (resize_now == 1 &&
1839 qindex > 90 * cpi->rc.worst_quality / 100) {
1840 rc->rate_correction_factors[INTER_NORMAL] *= 0.85;
1841 }
1842 // If resize is back up, check if projected q index is too much above the
1843 // current base_qindex, and if so, reduce the rate correction factor
1844 // (since prefer to keep q for resized frame at least close to previous q).
1845 if (resize_now == -1 &&
1846 qindex > 130 * cm->base_qindex / 100) {
1847 rc->rate_correction_factors[INTER_NORMAL] *= 0.9;
1848 }
1849 }
1850 return resize_now;
1851 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ratectrl.h ('k') | source/libvpx/vp9/encoder/vp9_rd.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698