summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_lavcac3enc.c
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/filter/af_lavcac3enc.c
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/filter/af_lavcac3enc.c')
-rw-r--r--audio/filter/af_lavcac3enc.c18
1 files changed, 2 insertions, 16 deletions
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");