From 388cf6dc9666be6c5a66332326180ef669171ad0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 15 Jan 2015 20:10:55 +0100 Subject: audio/filter: switch remaining filters to refcounting All of these filters are very similar in frame management, and copy data to a new frame during filtering. --- audio/filter/af_channels.c | 23 +++++++++++++---------- audio/filter/af_hrtf.c | 27 ++++++++++++++++----------- audio/filter/af_pan.c | 24 +++++++++++++----------- audio/filter/af_surround.c | 28 ++++++++++++++++------------ 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c index 83be68263e..22be38a31d 100644 --- a/audio/filter/af_channels.c +++ b/audio/filter/af_channels.c @@ -181,15 +181,20 @@ static int control(struct af_instance* af, int cmd, void* arg) return AF_UNKNOWN; } -// Filter data through filter -static int filter(struct af_instance* af, struct mp_audio* data, int flags) +static int filter_frame(struct af_instance *af, struct mp_audio *c) { - struct mp_audio* c = data; // Current working data - struct mp_audio* l = af->data; // Local data af_channels_t* s = af->priv; int i; - mp_audio_realloc_min(af->data, data->samples); + if (!c) + return 0; + + struct mp_audio *l = mp_audio_pool_get(af->out_pool, &af->fmt_out, c->samples); + if (!l) { + talloc_free(c); + return -1; + } + mp_audio_copy_attributes(l, c); // Reset unused channels memset(l->planes[0],0,mp_audio_psize(c) / c->nch * l->nch); @@ -199,17 +204,15 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) copy(af, c->planes[0],l->planes[0],c->nch,s->route[i][FR], l->nch,s->route[i][TO],mp_audio_psize(c),c->bps); - // Set output data - c->planes[0] = l->planes[0]; - mp_audio_set_channels(c, &l->channels); - + talloc_free(c); + af_add_output_frame(af, l); return 0; } // Allocate memory and set function pointers static int af_open(struct af_instance* af){ af->control=control; - af->filter=filter; + af->filter_frame = filter_frame; af_channels_t *s = af->priv; // If router scan commandline for routing pairs diff --git a/audio/filter/af_hrtf.c b/audio/filter/af_hrtf.c index 5dc08f2dbf..1496f8b634 100644 --- a/audio/filter/af_hrtf.c +++ b/audio/filter/af_hrtf.c @@ -375,17 +375,26 @@ frequencies). 2. A bass compensation is introduced to ensure that 0-200 Hz are not damped (without any real 3D acoustical image, however). */ -static int filter(struct af_instance *af, struct mp_audio *data, int flags) +static int filter(struct af_instance *af, struct mp_audio *data) { af_hrtf_t *s = af->priv; + + if (!data) + return 0; + struct mp_audio *outframe = + mp_audio_pool_get(af->out_pool, &af->fmt_out, data->samples); + if (!outframe) { + talloc_free(data); + return -1; + } + mp_audio_copy_attributes(outframe, data); + short *in = data->planes[0]; // Input audio data - short *out = NULL; // Output audio data + short *out = outframe->planes[0]; // Output audio data short *end = in + data->samples * data->nch; // Loop end float common, left, right, diff, left_b, right_b; const int dblen = s->dlbuflen, hlen = s->hrflen, blen = s->basslen; - mp_audio_realloc_min(af->data, data->samples); - if(s->print_flag) { s->print_flag = 0; switch (s->decode_mode) { @@ -412,8 +421,6 @@ static int filter(struct af_instance *af, struct mp_audio *data, int flags) "channel\n"); } - out = af->data->planes[0]; - /* MPlayer's 5 channel layout (notation for the variable): * * 0: L (LF), 1: R (RF), 2: Ls (LR), 3: Rs (RR), 4: C (CF), matrix @@ -551,10 +558,8 @@ static int filter(struct af_instance *af, struct mp_audio *data, int flags) s->cyc_pos += dblen; } - /* Set output data */ - data->planes[0] = af->data->planes[0]; - mp_audio_set_num_channels(data, 2); - + talloc_free(data); + af_add_output_frame(af, outframe); return 0; } @@ -588,7 +593,7 @@ static int af_open(struct af_instance* af) af->control = control; af->uninit = uninit; - af->filter = filter; + af->filter_frame = filter; s = af->priv; diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index 65269a86e1..979e4721e1 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -107,11 +107,17 @@ static int control(struct af_instance* af, int cmd, void* arg) return AF_UNKNOWN; } -// Filter data through filter -static int filter(struct af_instance* af, struct mp_audio* data, int flags) +static int filter_frame(struct af_instance *af, struct mp_audio *c) { - struct mp_audio* c = data; // Current working data - struct mp_audio* l = af->data; // Local data + if (!c) + return 0; + struct mp_audio *l = mp_audio_pool_get(af->out_pool, &af->fmt_out, c->samples); + if (!l) { + talloc_free(c); + return -1; + } + mp_audio_copy_attributes(l, c); + af_pan_t* s = af->priv; // Setup for this instance float* in = c->planes[0]; // Input audio data float* out = NULL; // Output audio data @@ -120,8 +126,6 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) int ncho = l->nch; // Number of output channels register int j,k; - mp_audio_realloc_min(af->data, data->samples); - out = l->planes[0]; // Execute panning // FIXME: Too slow @@ -137,17 +141,15 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) in+= nchi; } - // Set output data - c->planes[0] = l->planes[0]; - set_channels(c, l->nch); - + talloc_free(c); + af_add_output_frame(af, l); return 0; } // Allocate memory and set function pointers static int af_open(struct af_instance* af){ af->control=control; - af->filter=filter; + af->filter_frame = filter_frame; af_pan_t *s = af->priv; int n = 0; int j,k; diff --git a/audio/filter/af_surround.c b/audio/filter/af_surround.c index 7e04a79ed8..eabf1474bd 100644 --- a/audio/filter/af_surround.c +++ b/audio/filter/af_surround.c @@ -141,21 +141,27 @@ static const float steering_matrix[][12] = { // Experimental moving average dominance //static int amp_L = 0, amp_R = 0, amp_C = 0, amp_S = 0; -// Filter data through filter -static int filter(struct af_instance* af, struct mp_audio* data, int flags){ +static int filter_frame(struct af_instance *af, struct mp_audio *data) +{ + if (!data) + return 0; + struct mp_audio *outframe = + mp_audio_pool_get(af->out_pool, &af->fmt_out, data->samples); + if (!outframe) { + talloc_free(data); + return -1; + } + mp_audio_copy_attributes(outframe, data); + af_surround_t* s = (af_surround_t*)af->priv; const float* m = steering_matrix[0]; float* in = data->planes[0]; // Input audio data - float* out = NULL; // Output audio data + float* out = outframe->planes[0]; // Output audio data float* end = in + data->samples * data->nch; int i = s->i; // Filter queue index int ri = s->ri; // Read index for delay queue int wi = s->wi; // Write index for delay queue - mp_audio_realloc_min(af->data, data->samples); - - out = af->data->planes[0]; - while(in < end){ /* Dominance: abs(in[0]) abs(in[1]); @@ -215,16 +221,14 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags){ // Save indexes s->i = i; s->ri = ri; s->wi = wi; - // Set output data - data->planes[0] = af->data->planes[0]; - mp_audio_set_channels_old(data, af->data->nch); - + talloc_free(data); + af_add_output_frame(af, outframe); return 0; } static int af_open(struct af_instance* af){ af->control=control; - af->filter=filter; + af->filter_frame = filter_frame; return AF_OK; } -- cgit v1.2.3