resampler: Add support for resamplers that consume less data than asked.
libsamplerate_resample() assumed that src_process() would
always consume the whole input buffer. That was an invalid
assumption leading to crashes.
This patch adds a leftover memchunk for storing any
non-consumed input. When pa_resampler_run() is called next
time, the leftover is prepended to the new input.
Changes in v3:
- Make the calculations in pa_resampler_result() and
pa_resampler_max_block_size() more readable and more
correct.
- Rework the leftover storing: instead of using a dedicated
buffer for it, store it in the beginning of remap_buf.
This can avoid some memory copying. (The idea was
suggested by Wang Xingchao.)
- Use a generic save_leftover() function instead of doing
the leftover copying in the resampler implementation.
- Use the leftover logic also with the speex and ffmpeg
resamplers.
[ed: dropped the speex bit since the API guarantees that
it will consume everything -- Arun]
Changes in v2:
- If add_leftover() is called with zero-length input while
the leftover length is non-zero, we don't try to acquire
the input memblock.
- Instead of taking a reference to the original input in
libsamplerate_resample(), we copy the leftover data to a
new memblock. This is done, because otherwise, if the
input is one of the internal buffers, the data can get
overwritten before reading it in add_leftover().
- Store add_leftover_buf size in bytes instead of samples
(more convenient, but less consistent with other code).
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=47156