diff options
author | wm4 <wm4@nowhere> | 2013-11-10 23:11:40 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-11-12 23:16:31 +0100 |
commit | d2e7467eb203d3a34bc1111564c7058b5e9c6b12 (patch) | |
tree | 9285523821c8710a0609f47e3ee923a20d038826 /audio/filter/af.c | |
parent | b2d4b5ee43206f8c4491b3af1c24fedd35dbdc31 (diff) | |
download | mpv-d2e7467eb203d3a34bc1111564c7058b5e9c6b12.tar.bz2 mpv-d2e7467eb203d3a34bc1111564c7058b5e9c6b12.tar.xz |
audio/filter: prepare filter chain for non-interleaved audio
Based on earlier work by Stefano Pigozzi.
There are 2 changes:
1. Instead of mp_audio.audio, mp_audio.planes[0] must be used.
2. mp_audio.len used to contain the size of the audio in bytes. Now
mp_audio.samples must be used. (Where 1 sample is the smallest unit
of audio that covers all channels.)
Also, some filters need changes to reject non-interleaved formats
properly.
Nothing uses the non-interleaved features yet, but this is needed so
that things don't just break when doing so.
Diffstat (limited to 'audio/filter/af.c')
-rw-r--r-- | audio/filter/af.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/audio/filter/af.c b/audio/filter/af.c index edee4bef65..95d0e43673 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -523,8 +523,7 @@ static int af_reinit(struct af_stream *s) // Check if this is the first filter struct mp_audio in = *af->prev->data; // Reset just in case... - in.audio = NULL; - in.len = 0; + mp_audio_set_null_data(&in); int rv = af->control(af, AF_CONTROL_REINIT, &in); if (rv == AF_OK && !mp_audio_config_equals(&in, af->prev->data)) @@ -640,8 +639,8 @@ int af_init(struct af_stream *s) return -1; // Precaution in case caller is misbehaving - s->input.audio = s->output.audio = NULL; - s->input.len = s->output.len = 0; + mp_audio_set_null_data(&s->input); + mp_audio_set_null_data(&s->output); // Check if this is the first call if (s->first->next == s->last) { @@ -731,36 +730,39 @@ double af_calc_delay(struct af_stream *s) return delay; } -/* 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)) + assert(data->format); + + if (!af->data->format && !af->data->planes[0]) { + // Dummy initialization + mp_audio_set_format(af->data, AF_FORMAT_U8); + } + + int oldlen = af->data->samples * af->data->sstride; + + /* Calculate the minimum output buffer size for given input data d + * when using the af_resize_local_buffer function. The +x part ensures + * the value is >= len*mul rounded upwards to whole samples even if the + * double 'mul' is inexact. */ + int newlen = data->samples * data->sstride * af->mul + data->sstride + 1; + + if (oldlen >= newlen) 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, " - "old len = %i, new len = %i\n", af->info->name, af->data->len, len); + "old len = %i, new len = %i\n", af->info->name, oldlen, newlen); // If there is a buffer free it - free(af->data->audio); + free(af->data->planes[0]); // Create new buffer and check that it is OK - af->data->audio = malloc(len); - if (!af->data->audio) { + af->data->planes[0] = malloc(newlen); + if (!af->data->planes[0]) { mp_msg(MSGT_AFILTER, MSGL_FATAL, "[libaf] Could not allocate memory \n"); return AF_ERROR; } - af->data->len = len; + af->data->samples = newlen / af->data->sstride; return AF_OK; } |