summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-10 23:20:06 +0100
committerwm4 <wm4@nowhere>2013-11-12 23:27:03 +0100
commitd115fb3b0eed9145817a20bc0070590f7428bddd (patch)
tree00aab1420c5ab64f77b777214b92ba51793ea589 /audio
parente763d528e2b9370521b1e28450f48e65af33ca7f (diff)
downloadmpv-d115fb3b0eed9145817a20bc0070590f7428bddd.tar.bz2
mpv-d115fb3b0eed9145817a20bc0070590f7428bddd.tar.xz
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af.c37
-rw-r--r--audio/filter/af.h6
-rw-r--r--audio/filter/af_bs2b.c4
-rw-r--r--audio/filter/af_center.c4
-rw-r--r--audio/filter/af_channels.c9
-rw-r--r--audio/filter/af_convert24.c11
-rw-r--r--audio/filter/af_convertsignendian.c1
-rw-r--r--audio/filter/af_delay.c4
-rw-r--r--audio/filter/af_drc.c4
-rw-r--r--audio/filter/af_dummy.c10
-rw-r--r--audio/filter/af_equalizer.c4
-rw-r--r--audio/filter/af_export.c6
-rw-r--r--audio/filter/af_extrastereo.c4
-rw-r--r--audio/filter/af_format.c16
-rw-r--r--audio/filter/af_hrtf.c9
-rw-r--r--audio/filter/af_karaoke.c12
-rw-r--r--audio/filter/af_ladspa.c7
-rw-r--r--audio/filter/af_lavcac3enc.c18
-rw-r--r--audio/filter/af_lavfi.c9
-rw-r--r--audio/filter/af_lavrresample.c3
-rw-r--r--audio/filter/af_pan.c9
-rw-r--r--audio/filter/af_scaletempo.c40
-rw-r--r--audio/filter/af_sinesuppress.c4
-rw-r--r--audio/filter/af_sub.c4
-rw-r--r--audio/filter/af_surround.c9
-rw-r--r--audio/filter/af_sweep.c2
-rw-r--r--audio/filter/af_volume.c1
27 files changed, 36 insertions, 211 deletions
diff --git a/audio/filter/af.c b/audio/filter/af.c
index 95d0e43673..182ed27d03 100644
--- a/audio/filter/af.c
+++ b/audio/filter/af.c
@@ -201,6 +201,7 @@ static struct af_instance *af_create(struct af_stream *s, char *name,
*af = (struct af_instance) {
.info = info,
.mul = 1,
+ .data = talloc_zero(af, struct mp_audio),
};
struct m_config *config = m_config_from_obj_desc(af, &desc);
if (m_config_initialize_obj(config, &desc, &af->priv, &args) < 0)
@@ -730,42 +731,6 @@ double af_calc_delay(struct af_stream *s)
return delay;
}
-/* 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)
-{
- 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;
-
- mp_msg(MSGT_AFILTER, MSGL_V, "[libaf] Reallocating memory in module %s, "
- "old len = %i, new len = %i\n", af->info->name, oldlen, newlen);
- // If there is a buffer free it
- free(af->data->planes[0]);
- // Create new buffer and check that it is OK
- 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->samples = newlen / af->data->sstride;
- return AF_OK;
-}
-
// documentation in af.h
struct af_instance *af_control_any_rev(struct af_stream *s, int cmd, void *arg)
{
diff --git a/audio/filter/af.h b/audio/filter/af.h
index 3cfdee85dd..36c2cf33fd 100644
--- a/audio/filter/af.h
+++ b/audio/filter/af.h
@@ -61,7 +61,7 @@ struct af_instance {
struct mp_audio * (*play)(struct af_instance *af, struct mp_audio *data);
void *setup; // old field for priv structs
void *priv;
- struct mp_audio *data; // configuration for outgoing data stream
+ struct mp_audio *data; // configuration and buffer for outgoing data stream
struct af_instance *next;
struct af_instance *prev;
double delay; /* Delay caused by the filter, in units of bytes read without
@@ -182,10 +182,6 @@ double af_calc_delay(struct af_stream *s);
* \{
*/
-int af_resize_local_buffer(struct af_instance *af, struct mp_audio *data);
-
-#define RESIZE_LOCAL_BUFFER af_resize_local_buffer
-
/**
* \brief convert dB to gain value
* \param n number of values to convert
diff --git a/audio/filter/af_bs2b.c b/audio/filter/af_bs2b.c
index 5e0caf28af..73388ed5ba 100644
--- a/audio/filter/af_bs2b.c
+++ b/audio/filter/af_bs2b.c
@@ -161,7 +161,6 @@ static int control(struct af_instance *af, int cmd, void *arg)
static void uninit(struct af_instance *af)
{
struct af_bs2b *s = af->priv;
- free(af->data);
if (s->filter)
bs2b_close(s->filter);
}
@@ -173,12 +172,9 @@ static int af_open(struct af_instance *af)
af->control = control;
af->uninit = uninit;
af->mul = 1;
- if (!(af->data = calloc(1, sizeof(struct mp_audio))))
- return AF_ERROR;
// NULL means failed initialization
if (!(s->filter = bs2b_open())) {
- free(af->data);
return AF_ERROR;
}
diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c
index c64c551f1c..018fb756e6 100644
--- a/audio/filter/af_center.c
+++ b/audio/filter/af_center.c
@@ -78,7 +78,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -109,9 +108,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=s=calloc(1,sizeof(af_center_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
// Set default values
s->ch = 1; // Channel nr 2
diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c
index fd3b8262f5..7e05a9e234 100644
--- a/audio/filter/af_channels.c
+++ b/audio/filter/af_channels.c
@@ -222,9 +222,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
static void uninit(struct af_instance* af)
{
free(af->setup);
- if (af->data)
- free(af->data->planes[0]);
- free(af->data);
}
// Filter data through filter
@@ -235,8 +232,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
af_channels_t* s = af->setup;
int i;
- if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
- return NULL;
+ mp_audio_realloc_min(af->data, data->samples);
// Reset unused channels
memset(l->planes[0],0,mp_audio_psize(c) / c->nch * l->nch);
@@ -260,9 +256,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_channels_t));
- if((af->data == NULL) || (af->setup == NULL))
+ if(af->setup == NULL)
return AF_ERROR;
return AF_OK;
}
diff --git a/audio/filter/af_convert24.c b/audio/filter/af_convert24.c
index 96924de344..19904cc8e7 100644
--- a/audio/filter/af_convert24.c
+++ b/audio/filter/af_convert24.c
@@ -74,8 +74,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
{
- if (RESIZE_LOCAL_BUFFER(af, data) != AF_OK)
- return NULL;
+ mp_audio_realloc_min(af->data, data->samples);
struct mp_audio *out = af->data;
size_t len = mp_audio_psize(data) / data->bps;
@@ -104,18 +103,10 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
return data;
}
-static void uninit(struct af_instance* af)
-{
- if (af->data)
- free(af->data->planes[0]);
-}
-
static int af_open(struct af_instance *af)
{
af->control = control;
af->play = play;
- af->uninit = uninit;
- af->data = talloc_zero(af, struct mp_audio);
return AF_OK;
}
diff --git a/audio/filter/af_convertsignendian.c b/audio/filter/af_convertsignendian.c
index 5565438aad..18e04be21a 100644
--- a/audio/filter/af_convertsignendian.c
+++ b/audio/filter/af_convertsignendian.c
@@ -121,7 +121,6 @@ static int af_open(struct af_instance *af)
af->control = control;
af->play = play;
af->mul = 1;
- af->data = talloc_zero(af, struct mp_audio);
return AF_OK;
}
diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c
index c979060fe3..27b1ca2a4a 100644
--- a/audio/filter/af_delay.c
+++ b/audio/filter/af_delay.c
@@ -112,7 +112,6 @@ static void uninit(struct af_instance* af)
{
int i;
- free(af->data);
for(i=0;i<AF_NCH;i++)
free(((af_delay_t*)(af->setup))->q[i]);
free(af->setup);
@@ -183,9 +182,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_delay_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
return AF_OK;
}
diff --git a/audio/filter/af_drc.c b/audio/filter/af_drc.c
index 589844d89b..c1e043ac75 100644
--- a/audio/filter/af_drc.c
+++ b/audio/filter/af_drc.c
@@ -113,7 +113,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -321,9 +320,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_drc_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
((af_drc_t*)af->setup)->mul = MUL_INIT;
diff --git a/audio/filter/af_dummy.c b/audio/filter/af_dummy.c
index ab601ba9bb..87b75fd1b0 100644
--- a/audio/filter/af_dummy.c
+++ b/audio/filter/af_dummy.c
@@ -40,12 +40,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
return AF_UNKNOWN;
}
-// Deallocate memory
-static void uninit(struct af_instance* af)
-{
- free(af->data);
-}
-
// Filter data through filter
static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
{
@@ -58,12 +52,8 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
// Allocate memory and set function pointers
static int af_open(struct af_instance* af){
af->control=control;
- af->uninit=uninit;
af->play=play;
af->mul=1;
- af->data=malloc(sizeof(struct mp_audio));
- if(af->data == NULL)
- return AF_ERROR;
return AF_OK;
}
diff --git a/audio/filter/af_equalizer.c b/audio/filter/af_equalizer.c
index 718445c001..5fcfa18b35 100644
--- a/audio/filter/af_equalizer.c
+++ b/audio/filter/af_equalizer.c
@@ -156,7 +156,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -205,9 +204,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_equalizer_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
return AF_OK;
}
diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c
index a6ebdc322e..0139b17d4f 100644
--- a/audio/filter/af_export.c
+++ b/audio/filter/af_export.c
@@ -183,9 +183,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
*/
static void uninit( struct af_instance* af )
{
- free(af->data);
- af->data = NULL;
-
if(af->setup){
af_export_t* s = af->setup;
if (s->buf)
@@ -260,9 +257,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_export_t));
- if((af->data == NULL) || (af->setup == NULL))
+ if(af->setup == NULL)
return AF_ERROR;
((af_export_t *)af->setup)->filename = mp_find_user_config_file(SHARED_FILE);
diff --git a/audio/filter/af_extrastereo.c b/audio/filter/af_extrastereo.c
index 5b3792763b..68aeadac5e 100644
--- a/audio/filter/af_extrastereo.c
+++ b/audio/filter/af_extrastereo.c
@@ -75,7 +75,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -130,9 +129,8 @@ static int af_open(struct af_instance* af){
af->uninit=uninit;
af->play=play_s16;
af->mul=1;
- af->data=calloc(1,sizeof(struct mp_audio));
af->setup=calloc(1,sizeof(af_extrastereo_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
((af_extrastereo_t*)af->setup)->mul = 2.5;
diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c
index b551ddba42..58f311735e 100644
--- a/audio/filter/af_format.c
+++ b/audio/filter/af_format.c
@@ -35,9 +35,6 @@ struct priv {
struct mp_chmap out_channels;
int fail;
-
- struct mp_audio data;
- struct mp_audio temp;
};
static void force_in_params(struct af_instance *af, struct mp_audio *in)
@@ -101,15 +98,8 @@ static int control(struct af_instance *af, int cmd, void *arg)
static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
{
- struct priv *priv = af->priv;
- struct mp_audio *r = &priv->temp;
-
- *r = *af->data;
- for (int n = 0; n < r->nch; n++)
- r->planes[n] = data->planes[n];
- r->samples = data->samples;
-
- return r;
+ mp_audio_copy_config(data, af->data);
+ return data;
}
static int af_open(struct af_instance *af)
@@ -117,8 +107,6 @@ static int af_open(struct af_instance *af)
af->control = control;
af->play = play;
af->mul = 1;
- struct priv *priv = af->priv;
- af->data = &priv->data;
force_in_params(af, af->data);
force_out_params(af, af->data);
diff --git a/audio/filter/af_hrtf.c b/audio/filter/af_hrtf.c
index 01148dc6a6..a0dbb12675 100644
--- a/audio/filter/af_hrtf.c
+++ b/audio/filter/af_hrtf.c
@@ -366,9 +366,6 @@ static void uninit(struct af_instance *af)
free(s->fwrbuf_rr);
free(af->setup);
}
- if(af->data)
- free(af->data->planes[0]);
- free(af->data);
}
/* Filter data through filter
@@ -391,8 +388,7 @@ static struct mp_audio* play(struct af_instance *af, struct mp_audio *data)
float common, left, right, diff, left_b, right_b;
const int dblen = s->dlbuflen, hlen = s->hrflen, blen = s->basslen;
- if(AF_OK != RESIZE_LOCAL_BUFFER(af, data))
- return NULL;
+ mp_audio_realloc_min(af->data, data->samples);
if(s->print_flag) {
s->print_flag = 0;
@@ -603,9 +599,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_hrtf_t));
- if((af->data == NULL) || (af->setup == NULL))
+ if(af->setup == NULL)
return AF_ERROR;
s = af->setup;
diff --git a/audio/filter/af_karaoke.c b/audio/filter/af_karaoke.c
index d9c62aa85c..0d0ab7b2eb 100644
--- a/audio/filter/af_karaoke.c
+++ b/audio/filter/af_karaoke.c
@@ -41,12 +41,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
return AF_UNKNOWN;
}
-// Deallocate memory
-static void uninit(struct af_instance* af)
-{
- free(af->data);
-}
-
// Filter data through filter
static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
{
@@ -74,14 +68,8 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
// Allocate memory and set function pointers
static int af_open(struct af_instance* af){
af->control = control;
- af->uninit = uninit;
af->play = play;
af->mul = 1;
- af->data = calloc(1,sizeof(struct mp_audio));
-
- if(af->data == NULL)
- return AF_ERROR;
-
return AF_OK;
}
diff --git a/audio/filter/af_ladspa.c b/audio/filter/af_ladspa.c
index 6acdc150d7..3a6c258a89 100644
--- a/audio/filter/af_ladspa.c
+++ b/audio/filter/af_ladspa.c
@@ -646,7 +646,6 @@ static int control(struct af_instance *af, int cmd, void *arg) {
*/
static void uninit(struct af_instance *af) {
- free(af->data);
if (af->setup) {
af_ladspa_t *setup = (af_ladspa_t*) af->setup;
const LADSPA_Descriptor *pdes = setup->plugin_descriptor;
@@ -878,14 +877,8 @@ static int af_open(struct af_instance *af) {
af->play=play;
af->mul=1;
- af->data = calloc(1, sizeof(struct mp_audio));
- if (af->data == NULL)
- return af_ladspa_malloc_failed((char*)af_info_ladspa.name);
-
af->setup = calloc(1, sizeof(af_ladspa_t));
if (af->setup == NULL) {
- free(af->data);
- af->data=NULL;
return af_ladspa_malloc_failed((char*)af_info_ladspa.name);
}
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index d4abf2e942..6ecefa0d8f 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -160,9 +160,6 @@ static void uninit(struct af_instance* af)
{
af_ac3enc_t *s = af->setup;
- if (af->data)
- free(af->data->planes[0]);
- free(af->data);
if (s) {
av_free_packet(&s->pkt);
if(s->lavc_actx) {
@@ -191,18 +188,8 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* audio)
else
max_output_len = AC3_MAX_CODED_FRAME_SIZE * frame_num;
- if (mp_audio_psize(af->data) < max_output_len) {
- mp_msg(MSGT_AFILTER, MSGL_V, "[libaf] Reallocating memory in module %s, "
- "old len = %i, new len = %i\n", af->info->name,
- mp_audio_psize(af->data), max_output_len);
- free(af->data->planes[0]);
- af->data->planes[0] = malloc(max_output_len);
- if (!af->data->planes[0]) {
- mp_msg(MSGT_AFILTER, MSGL_FATAL, "[libaf] Could not allocate memory \n");
- return NULL;
- }
- af->data->samples = max_output_len / af->data->sstride;
- }
+ mp_audio_realloc_min(af->data, max_output_len / af->data->sstride);
+ af->data->samples = max_output_len / af->data->sstride;
l = af->data; // Local data
buf = l->planes[0];
@@ -320,7 +307,6 @@ 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=s;
s->lavc_acodec = avcodec_find_encoder_by_name("ac3");
diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c
index 381e2d0583..e77110c067 100644
--- a/audio/filter/af_lavfi.c
+++ b/audio/filter/af_lavfi.c
@@ -58,11 +58,6 @@ struct priv {
AVFilterContext *in;
AVFilterContext *out;
- // Guarantee that the data stays valid until next filter call
- char *out_buffer;
-
- struct mp_audio temp;
-
int64_t samples_in;
AVRational timebase_out;
@@ -278,8 +273,8 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
af->delay = (in_time - out_time) * r->rate * r->sstride;
}
- p->temp = *r;
- return &p->temp;
+ *data = *r;
+ return data;
}
static void uninit(struct af_instance *af)
diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c
index 8c7a7543fa..02d58122fb 100644
--- a/audio/filter/af_lavrresample.c
+++ b/audio/filter/af_lavrresample.c
@@ -381,9 +381,6 @@ static int af_open(struct af_instance *af)
af->uninit = uninit;
af->play = play;
af->mul = 1;
- af->data = talloc_zero(s, struct mp_audio);
-
- af->data->rate = 0;
if (s->opts.cutoff <= 0.0)
s->opts.cutoff = af_resample_default_cutoff(s->opts.filter_size);
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;
}
diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c
index 33547bc79c..456de89812 100644
--- a/audio/filter/af_scaletempo.c
+++ b/audio/filter/af_scaletempo.c
@@ -47,11 +47,11 @@ typedef struct af_scaletempo_s
// stride
float scale;
float speed;
+ int frames_stride;
float frames_stride_scaled;
float frames_stride_error;
int bytes_per_frame;
int bytes_stride;
- float bytes_stride_scaled;
int bytes_queue;
int bytes_queued;
int bytes_to_slide;
@@ -220,21 +220,8 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
return data;
}
- // RESIZE_LOCAL_BUFFER - can't use macro
- int max_bytes_out = ((int)(mp_audio_psize(data) /
- s->bytes_stride_scaled) + 1) * s->bytes_stride;
- if (max_bytes_out > mp_audio_psize(af->data)) {
- mp_msg(MSGT_AFILTER, MSGL_V, "[libaf] Reallocating memory in module %s, "
- "old len = %i, new len = %i\n", af->info->name,
- mp_audio_psize(af->data), max_bytes_out);
- af->data->planes[0] = realloc(af->data->planes[0], max_bytes_out);
- if (!af->data->planes[0]) {
- mp_msg(MSGT_AFILTER, MSGL_FATAL,
- "[libaf] Could not allocate memory\n");
- return NULL;
- }
- af->data->samples = max_bytes_out / af->data->sstride;
- }
+ mp_audio_realloc_min(af->data,
+ ((int)(data->samples / s->frames_stride_scaled) + 1) * s->frames_stride);
int offset_in = fill_queue(af, data, 0);
int8_t *pout = af->data->planes[0];
@@ -309,15 +296,15 @@ static int control(struct af_instance *af, int cmd, void *arg)
}
int bps = af->data->bps;
- int frames_stride = srate * s->ms_stride;
- s->bytes_stride = frames_stride * bps * nch;
- s->bytes_stride_scaled = s->scale * s->bytes_stride;
- s->frames_stride_scaled = s->scale * frames_stride;
+ s->frames_stride = srate * s->ms_stride;
+ s->bytes_stride = s->frames_stride * bps * nch;
+ s->frames_stride_scaled = s->scale * s->frames_stride;
+ int bytes_stride_scaled = s->scale * s->bytes_stride;
s->frames_stride_error = 0;
- af->mul = (double)s->bytes_stride / s->bytes_stride_scaled;
+ af->mul = (double)s->bytes_stride / bytes_stride_scaled;
af->delay = 0;
- int frames_overlap = frames_stride * s->percent_overlap;
+ int frames_overlap = s->frames_stride * s->percent_overlap;
if (frames_overlap <= 0) {
s->bytes_standing = s->bytes_stride;
s->samples_standing = s->bytes_standing / bps;
@@ -402,8 +389,8 @@ static int control(struct af_instance *af, int cmd, void *arg)
s->bytes_per_frame = bps * nch;
s->num_channels = nch;
- s->bytes_queue
- = (s->frames_search + frames_stride + frames_overlap) * bps * nch;
+ s->bytes_queue = (s->frames_search + s->frames_stride + frames_overlap)
+ * bps * nch;
s->buf_queue = realloc(s->buf_queue, s->bytes_queue + UNROLL_PADDING);
if (!s->buf_queue) {
mp_msg(MSGT_AFILTER, MSGL_FATAL, "[scaletempo] Out of memory\n");
@@ -457,8 +444,6 @@ static int control(struct af_instance *af, int cmd, void *arg)
static void uninit(struct af_instance *af)
{
af_scaletempo_t *s = af->priv;
- free(af->data->planes[0]);
- free(af->data);
free(s->buf_queue);
free(s->buf_overlap);
free(s->buf_pre_corr);
@@ -478,9 +463,6 @@ 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));
- if (af->data == NULL)
- return AF_ERROR;
s->speed_tempo = !!(s->speed_opt & SCALE_TEMPO);
s->speed_pitch = !!(s->speed_opt & SCALE_PITCH);
diff --git a/audio/filter/af_sinesuppress.c b/audio/filter/af_sinesuppress.c
index b733caec93..33486390b9 100644
--- a/audio/filter/af_sinesuppress.c
+++ b/audio/filter/af_sinesuppress.c
@@ -85,7 +85,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -150,9 +149,8 @@ static int af_open(struct af_instance* af){
af->uninit=uninit;
af->play=play_s16;
af->mul=1;
- af->data=calloc(1,sizeof(struct mp_audio));
af->setup=calloc(1,sizeof(af_sinesuppress_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
((af_sinesuppress_t*)af->setup)->freq = 50.0;
diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c
index 92abd2f0ea..561ae94be6 100644
--- a/audio/filter/af_sub.c
+++ b/audio/filter/af_sub.c
@@ -123,7 +123,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -167,9 +166,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=s=calloc(1,sizeof(af_sub_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
// Set default values
s->ch = 5; // Channel nr 6
diff --git a/audio/filter/af_surround.c b/audio/filter/af_surround.c
index 5ee45d126f..9f9d46b788 100644
--- a/audio/filter/af_surround.c
+++ b/audio/filter/af_surround.c
@@ -144,9 +144,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);
}
@@ -172,8 +169,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data){
int ri = s->ri; // Read index for delay queue
int wi = s->wi; // Write index for delay queue
- if (AF_OK != RESIZE_LOCAL_BUFFER(af, data))
- return NULL;
+ mp_audio_realloc_min(af->data, data->samples);
out = af->data->planes[0];
@@ -248,9 +244,8 @@ static int af_open(struct af_instance* af){
af->uninit=uninit;
af->play=play;
af->mul=2;
- af->data=calloc(1,sizeof(struct mp_audio));
af->setup=calloc(1,sizeof(af_surround_t));
- if(af->data == NULL || af->setup == NULL)
+ if(af->setup == NULL)
return AF_ERROR;
((af_surround_t*)af->setup)->d = 20;
return AF_OK;
diff --git a/audio/filter/af_sweep.c b/audio/filter/af_sweep.c
index daa2891219..5b1e9d39c1 100644
--- a/audio/filter/af_sweep.c
+++ b/audio/filter/af_sweep.c
@@ -58,7 +58,6 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Deallocate memory
static void uninit(struct af_instance* af)
{
- free(af->data);
free(af->setup);
}
@@ -86,7 +85,6 @@ 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_sweept));
return AF_OK;
}
diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c
index d4a1ec616b..982b3816c7 100644
--- a/audio/filter/af_volume.c
+++ b/audio/filter/af_volume.c
@@ -105,7 +105,6 @@ static int af_open(struct af_instance *af)
af->control = control;
af->play = play;
af->mul = 1;
- af->data = talloc_zero(af, struct mp_audio);
af_from_dB(1, &s->cfg_volume, &s->level, 20.0, -200.0, 60.0);
return AF_OK;
}