From 3a2d5e68acb2ac0f8b09b896907a692b1c48c6b3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 21 Sep 2017 11:07:02 +0200 Subject: audio: move libswresample wrapper out of audio filter code Move it from af_lavrresample.c to a new aconverter.c file, which is independent from the filter chain code. It also doesn't use mp_audio, and thus has no GPL dependencies. Preparation for later commits. Not particularly well tested, so have fun. --- audio/audio.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'audio/audio.c') diff --git a/audio/audio.c b/audio/audio.c index 008aa1883b..b636c66620 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -406,6 +406,9 @@ fail: struct mp_audio *mp_audio_from_aframe(struct mp_aframe *aframe) { + if (!aframe) + return NULL; + struct AVFrame *av = mp_aframe_get_raw_avframe(aframe); struct mp_audio *res = mp_audio_from_avframe(av); if (!res) @@ -428,6 +431,34 @@ void mp_audio_config_from_aframe(struct mp_audio *dst, struct mp_aframe *src) dst->rate = mp_aframe_get_rate(src); } +struct mp_aframe *mp_audio_to_aframe(struct mp_audio *mpa) +{ + if (!mpa) + return NULL; + + struct mp_aframe *aframe = mp_aframe_create(); + struct AVFrame *av = mp_aframe_get_raw_avframe(aframe); + mp_aframe_set_format(aframe, mpa->format); + mp_aframe_set_chmap(aframe, &mpa->channels); + mp_aframe_set_rate(aframe, mpa->rate); + + // bullshit it into ffmpeg-compatible parameters + struct mp_audio mpb = *mpa; + struct mp_chmap chmap; + mp_chmap_set_unknown(&chmap, mpb.channels.num); + mp_audio_set_channels(&mpb, &chmap); + if (af_fmt_is_spdif(mpb.format)) + mp_audio_set_format(&mpb, AF_FORMAT_S16); + + // put the reference into av, which magically puts it into aframe + // aframe keeps its parameters, so the bullshit doesn't matter + if (mp_audio_to_avframe(&mpb, av) < 0) { + talloc_free(aframe); + return NULL; + } + return aframe; +} + int mp_audio_to_avframe(struct mp_audio *frame, struct AVFrame *avframe) { av_frame_unref(avframe); -- cgit v1.2.3