From d2e7467eb203d3a34bc1111564c7058b5e9c6b12 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 10 Nov 2013 23:11:40 +0100 Subject: 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. --- audio/filter/af_pan.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'audio/filter/af_pan.c') diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index b3e31dab98..3c15b8f629 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -147,7 +147,7 @@ static int control(struct af_instance* af, int cmd, void* arg) static void uninit(struct af_instance* af) { if(af->data) - free(af->data->audio); + free(af->data->planes[0]); free(af->data); free(af->setup); } @@ -158,9 +158,9 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) struct mp_audio* c = data; // Current working data struct mp_audio* l = af->data; // Local data af_pan_t* s = af->setup; // Setup for this instance - float* in = c->audio; // Input audio data + float* in = c->planes[0]; // Input audio data float* out = NULL; // Output audio data - float* end = in+c->len/4; // End of loop + float* end = in+c->samples*c->nch; // End of loop int nchi = c->nch; // Number of input channels int ncho = l->nch; // Number of output channels register int j,k; @@ -168,7 +168,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) return NULL; - out = l->audio; + out = l->planes[0]; // Execute panning // FIXME: Too slow while(in < end){ @@ -184,8 +184,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) } // Set output data - c->audio = l->audio; - c->len = c->len / c->nch * l->nch; + c->planes[0] = l->planes[0]; set_channels(c, l->nch); return c; -- cgit v1.2.3 From d115fb3b0eed9145817a20bc0070590f7428bddd Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 10 Nov 2013 23:20:06 +0100 Subject: af: don't require filters to allocate af_instance->data, redo buffers Allocate af_instance->data in generic code before filter initialization. Every filter needs af->data (since it contains the output configuration), so there's no reason why every filter should allocate and free it. Remove RESIZE_LOCAL_BUFFER(), and replace it with mp_audio_realloc_min(). Interestingly, most code becomes simpler, because the new function takes the size in samples, and not in bytes. There are larger change in af_scaletempo.c and af_lavcac3enc.c, because these had copied and modified versions of the RESIZE_LOCAL_BUFFER macro/function. --- audio/filter/af_pan.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'audio/filter/af_pan.c') diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index 3c15b8f629..cc6f129542 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -146,9 +146,6 @@ static int control(struct af_instance* af, int cmd, void* arg) // Deallocate memory static void uninit(struct af_instance* af) { - if(af->data) - free(af->data->planes[0]); - free(af->data); free(af->setup); } @@ -165,8 +162,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data) int ncho = l->nch; // Number of output channels register int j,k; - if(AF_OK != RESIZE_LOCAL_BUFFER(af,data)) - return NULL; + mp_audio_realloc_min(af->data, data->samples); out = l->planes[0]; // Execute panning @@ -196,9 +192,8 @@ static int af_open(struct af_instance* af){ af->uninit=uninit; af->play=play; af->mul=1; - af->data=calloc(1,sizeof(struct mp_audio)); af->setup=calloc(1,sizeof(af_pan_t)); - if(af->data == NULL || af->setup == NULL) + if(af->setup == NULL) return AF_ERROR; return AF_OK; } -- cgit v1.2.3 From 824e6550f8ef1f361701eae469ada35d3889ab83 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 10 Nov 2013 23:39:29 +0100 Subject: audio/filter: fix mul/delay scale and values Before this commit, the af_instance->mul/delay values were in bytes. Using bytes is confusing for non-interleaved audio, so switch mul to samples, and delay to seconds. For delay, seconds are more intuitive than bytes or samples, because it's used for the latency calculation. We also might want to replace the delay mechanism with real PTS tracking inside the filter chain some time in the future, and PTS will also require time-adjustments to be done in seconds. For most filters, we just remove the redundant mul=1 initialization. (Setting this used to be required, but not anymore.) --- audio/filter/af_pan.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'audio/filter/af_pan.c') diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index cc6f129542..3d8c6045d0 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -57,7 +57,6 @@ static int control(struct af_instance* af, int cmd, void* arg) af->data->rate = ((struct mp_audio*)arg)->rate; mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE); set_channels(af->data, s->nch ? s->nch: ((struct mp_audio*)arg)->nch); - af->mul = (double)af->data->nch / ((struct mp_audio*)arg)->nch; if((af->data->format != ((struct mp_audio*)arg)->format) || (af->data->bps != ((struct mp_audio*)arg)->bps)){ @@ -191,7 +190,6 @@ static int af_open(struct af_instance* af){ af->control=control; af->uninit=uninit; af->play=play; - af->mul=1; af->setup=calloc(1,sizeof(af_pan_t)); if(af->setup == NULL) return AF_ERROR; -- cgit v1.2.3