diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2015-06-03 02:22:25 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-06-04 06:37:32 +0300 |
commit | cc17b43d8dd324fbae98407124618e746a390a76 (patch) | |
tree | d13f812cc871e1a338819af23ac4dc20e33ea7ea /libswresample/resample.c | |
parent | da7c8fd91761dff3f9202e813bb5a5963a2d657c (diff) |
swresample: Add swr_get_out_samples()
Previous version reviewed-by: Pavel Koshevoy <pkoshevoy@gmail.com>
Previous version reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libswresample/resample.c')
-rw-r--r-- | libswresample/resample.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libswresample/resample.c b/libswresample/resample.c index d4c7d06794..f2624b5dc7 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -345,6 +345,25 @@ static int64_t get_delay(struct SwrContext *s, int64_t base){ return av_rescale(num, base, s->in_sample_rate*(int64_t)c->src_incr << c->phase_shift); } +static int64_t get_out_samples(struct SwrContext *s, int in_samples) { + ResampleContext *c = s->resample; + // The + 2 are added to allow implementations to be slightly inaccuarte, they should not be needed currently + // They also make it easier to proof that changes and optimizations do not + // break the upper bound + int64_t num = s->in_buffer_count + 2LL + in_samples; + num *= 1 << c->phase_shift; + num -= c->index; + num = av_rescale_rnd(num, s->out_sample_rate, ((int64_t)s->in_sample_rate) << c->phase_shift, AV_ROUND_UP) + 2; + + if (c->compensation_distance) { + if (num > INT_MAX) + return AVERROR(EINVAL); + + num = FFMAX(num, (num * c->ideal_dst_incr - 1) / c->dst_incr + 1); + } + return num; +} + static int resample_flush(struct SwrContext *s) { AudioData *a= &s->in_buffer; int i, j, ret; @@ -414,4 +433,5 @@ struct Resampler const swri_resampler={ set_compensation, get_delay, invert_initial_buffer, + get_out_samples, }; |