Fix some broken clamping in rate control.
commite97c8a9dac60fa2a91e48836252d1a9289b9dcd5
authortterribe <tterribe@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Sun, 11 Oct 2015 04:35:13 +0000 (11 04:35 +0000)
committertterribe <tterribe@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Sun, 11 Oct 2015 04:35:13 +0000 (11 04:35 +0000)
tree093d56a564cf937184feafdae5a030c8cbc80c3b
parent540afe6d5b31d96fa9ad128b23a1b5b2a004183d
Fix some broken clamping in rate control.

If we have some dupe frames right near the end of the buffer, our
 metric window can be slightly larger than the buffer.
However, the clamping we use to determine how many frames' worth of
 metrics to add to the buffer had a mix of signed and unsigned
 types, so if that number when negative, instead of clamping
 against zero, it would ask for all remaining frames in the file.
That would cause an infinite loop when we tried to find the last
 keyframe in the circular buffer in oc_enc_select_qi() (which was
 not big enough to actually hold that many frames).

This patch changes the clamp to a form that works with all unsigned
 values.

Thanks to Brion Vibber for the report.

Fixes #2229

git-svn-id: https://svn.xiph.org/trunk@19507 0101bb08-14d6-0310-b084-bc0e0c8e3800
theora/lib/rate.c