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_lavfi.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'audio/filter/af_lavfi.c') diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c index 3c6d981f1d..f08e7ff85c 100644 --- a/audio/filter/af_lavfi.c +++ b/audio/filter/af_lavfi.c @@ -181,6 +181,7 @@ static int control(struct af_instance *af, int cmd, void *arg) if (af_to_avformat(in->format) == AV_SAMPLE_FMT_NONE) mp_audio_set_format(in, AF_FORMAT_FLOAT_NE); + mp_audio_force_interleaved_format(in); if (!mp_chmap_is_lavc(&in->channels)) mp_chmap_reorder_to_lavc(&in->channels); // will always work @@ -193,6 +194,7 @@ static int control(struct af_instance *af, int cmd, void *arg) out->rate = l_out->sample_rate; mp_audio_set_format(out, af_from_avformat(l_out->format)); + mp_audio_force_interleaved_format(out); struct mp_chmap out_cm; mp_chmap_from_lavc(&out_cm, l_out->channel_layout); @@ -228,7 +230,7 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) int out_frame_size = r->bps * r->channels.num; AVFrame *frame = av_frame_alloc(); - frame->nb_samples = data->len / in_frame_size; + frame->nb_samples = data->samples; frame->format = l_in->format; // Timebase is 1/sample_rate @@ -238,7 +240,7 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) av_frame_set_channel_layout(frame, l_in->channel_layout); av_frame_set_sample_rate(frame, l_in->sample_rate); - frame->data[0] = data->audio; + frame->data[0] = data->planes[0]; frame->extended_data = frame->data; if (av_buffersrc_add_frame(p->in, frame) < 0) { @@ -268,11 +270,11 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) av_frame_free(&frame); } - r->audio = p->out_buffer; - r->len = out_len; + r->planes[0] = p->out_buffer; + r->samples = out_len / r->sstride; - p->bytes_in += data->len; - p->bytes_out += r->len; + p->bytes_in += data->samples * data->sstride; + p->bytes_out += r->samples * r->sstride; if (out_pts != AV_NOPTS_VALUE) { int64_t num_in_frames = p->bytes_in / in_frame_size; @@ -280,8 +282,7 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data) double out_time = out_pts * av_q2d(p->timebase_out); // Need pts past the last output sample. - int out_frames = r->len / out_frame_size; - out_time += out_frames / (double)r->rate; + out_time += r->samples / (double)r->rate; af->delay = (in_time - out_time) * r->rate * out_frame_size; } -- cgit v1.2.3