From 354c1fc06d5c2381dc59a39f02aa61a3c252b283 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 29 Jan 2016 22:43:00 +0100 Subject: audio: move mp_audio->AVFrame conversion to a function This also makes it refcounted, i.e. the new AVFrame will reference the mp_audio buffers, instead of potentially forcing the consumer of the AVFrame to copy the data. All the extra code is for handling the >8 channels case, which requires very messy dealing with the extended_ fields (not our fault). --- audio/filter/af_lavfi.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'audio/filter') diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c index 1e05e734a1..bc4a687487 100644 --- a/audio/filter/af_lavfi.c +++ b/audio/filter/af_lavfi.c @@ -266,32 +266,15 @@ static int filter_frame(struct af_instance *af, struct mp_audio *data) if (!p->graph) goto error; - AVFilterLink *l_in = p->in->outputs[0]; - if (data) { - frame = av_frame_alloc(); + frame = mp_audio_to_avframe_and_unref(data); + data = NULL; if (!frame) goto error; - frame->nb_samples = data->samples; - frame->format = l_in->format; - // Timebase is 1/sample_rate frame->pts = p->samples_in; - - frame->channel_layout = l_in->channel_layout; - frame->sample_rate = l_in->sample_rate; -#if LIBAVFILTER_VERSION_MICRO >= 100 - // FFmpeg being a stupid POS - frame->channels = l_in->channels; -#endif - - frame->extended_data = frame->data; - for (int n = 0; n < data->num_planes; n++) - frame->data[n] = data->planes[n]; - frame->linesize[0] = frame->nb_samples * data->sstride; - - p->samples_in += data->samples; + p->samples_in += frame->nb_samples; } if (av_buffersrc_add_frame(p->in, frame) < 0) -- cgit v1.2.3