Fix buffer pruning
Created by: bbert
The goal of this PR is:
- to fix next segment request determination after buffer has been pruned, due to QuotaExceededError or automatic pruning process (bug existing since v3.0)
- to update buffer lengths according to critical buffer size
- to prune buffer only beyond new buffer limits (instead of clearing all buffer) when a QuotaExceededError happended
BTW, I wonder about use of bufferAheadToKeep parameter. If one sets bufferAheadToKeep lower than bufferTimeAtTopQuality(LongForm) then the buffer will always be pruned before reaching buffer length. Also, since bufferTimeAtTopQuality(LongForm) is used as a limit to append new segments, I don't get the need for bufferAheadToKeep parameter.