diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/filter/af.c | 27 | ||||
-rw-r--r-- | audio/filter/af.h | 17 |
2 files changed, 16 insertions, 28 deletions
diff --git a/audio/filter/af.c b/audio/filter/af.c index f425cb40e3..4c7d2e9bf5 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -704,16 +704,6 @@ struct mp_audio *af_play(struct af_stream *s, struct mp_audio *data) return data; } -/* Calculate the minimum output buffer size for given input data d - * when using the RESIZE_LOCAL_BUFFER macro. The +t+1 part ensures the - * value is >= len*mul rounded upwards to whole samples even if the - * double 'mul' is inexact. */ -int af_lencalc(double mul, struct mp_audio *d) -{ - int t = d->bps * d->nch; - return d->len * mul + t + 1; -} - // Calculate average ratio of filter output size to input size double af_calc_filter_multiplier(struct af_stream *s) { @@ -742,10 +732,23 @@ double af_calc_delay(struct af_stream *s) return delay; } -/* Helper function called by the macro with the same name this - function should not be called directly */ +/* Calculate the minimum output buffer size for given input data d + * when using the af_resize_local_buffer function. The +t+1 part ensures the + * value is >= len*mul rounded upwards to whole samples even if the + * double 'mul' is inexact. */ +static int af_lencalc(double mul, struct mp_audio *d) +{ + int t = d->bps * d->nch; + return d->len * mul + t + 1; +} + +/* I a local buffer is used (i.e. if the filter doesn't operate on the incoming + * buffer), this macro must be called to ensure the buffer is big enough. */ int af_resize_local_buffer(struct af_instance *af, struct mp_audio *data) { + if (af->data->len >= af_lencalc(af->mul, data)) + return AF_OK; + // Calculate new length register int len = af_lencalc(af->mul, data); mp_msg(MSGT_AFILTER, MSGL_V, "[libaf] Reallocating memory in module %s, " diff --git a/audio/filter/af.h b/audio/filter/af.h index dc776460aa..3cfdee85dd 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -182,14 +182,9 @@ double af_calc_delay(struct af_stream *s); * \{ */ -/* Helper function called by the macro with the same name only to be - called from inside filters */ int af_resize_local_buffer(struct af_instance *af, struct mp_audio *data); -/* Helper function used to calculate the exact buffer length needed - when buffers are resized. The returned length is >= than what is - needed */ -int af_lencalc(double mul, struct mp_audio *data); +#define RESIZE_LOCAL_BUFFER af_resize_local_buffer /** * \brief convert dB to gain value @@ -253,14 +248,4 @@ int af_test_output(struct af_instance *af, struct mp_audio *out); */ float af_softclip(float a); -/** \} */ // end of af_filter group, but more functions of this group below - -/** Memory reallocation macro: if a local buffer is used (i.e. if the - filter doesn't operate on the incoming buffer this macro must be - called to ensure the buffer is big enough. - * \ingroup af_filter - */ -#define RESIZE_LOCAL_BUFFER(a, d) \ - ((a->data->len < af_lencalc(a->mul, d)) ? af_resize_local_buffer(a, d) : AF_OK) - #endif /* MPLAYER_AF_H */ |