diff options
author | wm4 <wm4@nowhere> | 2017-09-21 11:07:02 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-09-21 12:42:09 +0200 |
commit | 3a2d5e68acb2ac0f8b09b896907a692b1c48c6b3 (patch) | |
tree | 13a7e321ce6accceca720fb654cdf7ea8eee0afc /audio/audio.c | |
parent | caaa1189ba75a7df9a4d02f7747d6c0bf3b05012 (diff) | |
download | mpv-3a2d5e68acb2ac0f8b09b896907a692b1c48c6b3.tar.bz2 mpv-3a2d5e68acb2ac0f8b09b896907a692b1c48c6b3.tar.xz |
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.
Diffstat (limited to 'audio/audio.c')
-rw-r--r-- | audio/audio.c | 31 |
1 files changed, 31 insertions, 0 deletions
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); |