summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorJan Ekström <jeebjp@gmail.com>2022-06-14 22:36:54 +0300
committerJan Ekström <jeebjp@gmail.com>2022-06-14 22:41:20 +0300
commite7483ced5de71359223292c07bd177e3c5cb8d20 (patch)
tree1244e361d5dca1bd2f71e99d81b048835e820516 /audio
parent42b58c5698d109d33166c3fbdbe2b38eedd642bd (diff)
downloadmpv-e7483ced5de71359223292c07bd177e3c5cb8d20.tar.bz2
mpv-e7483ced5de71359223292c07bd177e3c5cb8d20.tar.xz
af_lavcac3enc: switch to AVChannelLayout when available
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af_lavcac3enc.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index ac2ba0463c..86c34a1278 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -31,7 +31,10 @@
#include <libavutil/bswap.h>
#include <libavutil/mem.h>
+#include "config.h"
+
#include "audio/aframe.h"
+#include "audio/chmap_avchannel.h"
#include "audio/chmap_sel.h"
#include "audio/fmt-conversion.h"
#include "audio/format.h"
@@ -104,8 +107,13 @@ static bool reinit(struct mp_filter *f)
// Put sample parameters
s->lavc_actx->sample_fmt = af_to_avformat(format);
+
+#if !HAVE_AV_CHANNEL_LAYOUT
s->lavc_actx->channels = chmap.num;
s->lavc_actx->channel_layout = mp_chmap_to_lavc(&chmap);
+#else
+ mp_chmap_to_av_layout(&s->lavc_actx->ch_layout, &chmap);
+#endif
s->lavc_actx->sample_rate = rate;
s->lavc_actx->bit_rate = bit_rate;
@@ -270,9 +278,11 @@ static const struct mp_filter_info af_lavcac3enc_filter = {
.destroy = destroy,
};
-static void add_chmaps_to_autoconv(struct mp_autoconvert *conv,
+static void add_chmaps_to_autoconv(struct mp_filter *f,
+ struct mp_autoconvert *conv,
const struct AVCodec *codec)
{
+#if !HAVE_AV_CHANNEL_LAYOUT
const uint64_t *lch = codec->channel_layouts;
for (int n = 0; lch && lch[n]; n++) {
struct mp_chmap chmap = {0};
@@ -280,6 +290,24 @@ static void add_chmaps_to_autoconv(struct mp_autoconvert *conv,
if (mp_chmap_is_valid(&chmap))
mp_autoconvert_add_chmap(conv, &chmap);
}
+#else
+ const AVChannelLayout *lch = codec->ch_layouts;
+ for (int n = 0; lch && lch[n].nb_channels; n++) {
+ struct mp_chmap chmap = {0};
+
+ if (!mp_chmap_from_av_layout(&chmap, &lch[n])) {
+ char layout[128] = {0};
+ MP_VERBOSE(f, "Skipping unsupported channel layout: %s\n",
+ av_channel_layout_describe(&lch[n],
+ layout, 128) < 0 ?
+ "undefined" : layout);
+ continue;
+ }
+
+ if (mp_chmap_is_valid(&chmap))
+ mp_autoconvert_add_chmap(conv, &chmap);
+ }
+#endif
}
static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
@@ -322,7 +350,12 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
// parameters. (Not all decoders do that, but the ones we're interested
// in do.)
if (!s->lavc_acodec->sample_fmts ||
- !s->lavc_acodec->channel_layouts)
+#if !HAVE_AV_CHANNEL_LAYOUT
+ !s->lavc_acodec->channel_layouts
+#else
+ !s->lavc_acodec->ch_layouts
+#endif
+ )
{
MP_ERR(f, "Audio encoder doesn't list supported parameters.\n");
goto error;
@@ -354,7 +387,7 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
mp_autoconvert_add_afmt(conv, mpfmt);
}
- add_chmaps_to_autoconv(conv, s->lavc_acodec);
+ add_chmaps_to_autoconv(f, conv, s->lavc_acodec);
// At least currently, the AC3 encoder doesn't export sample rates.
mp_autoconvert_add_srate(conv, 48000);