From 3c5a79300c02e85085cb53d71746b3a47810edd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 21 Jun 2024 18:24:30 +0200 Subject: [PATCH] various: remove av channel layout check --- audio/aframe.c | 32 ++------------------------------ audio/chmap_avchannel.h | 4 ---- audio/decode/ad_lavc.c | 5 ----- audio/filter/af_lavcac3enc.c | 24 +----------------------- audio/out/ao_lavc.c | 6 ------ common/av_common.c | 6 ------ demux/demux_lavf.c | 8 -------- filters/f_lavfi.c | 8 -------- filters/f_swresample.c | 17 ----------------- meson.build | 8 +------- test/chmap.c | 14 ++++---------- test/meson.build | 6 ++---- 12 files changed, 10 insertions(+), 128 deletions(-) diff --git a/audio/aframe.c b/audio/aframe.c index 03e8ab8ae8..e22a98edac 100644 --- a/audio/aframe.c +++ b/audio/aframe.c @@ -123,7 +123,6 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame) if (!av_frame || av_frame->width > 0 || av_frame->height > 0) return NULL; -#if HAVE_AV_CHANNEL_LAYOUT if (!av_channel_layout_check(&av_frame->ch_layout)) return NULL; @@ -131,7 +130,6 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame) if (!mp_chmap_from_av_layout(&converted_map, &av_frame->ch_layout)) { return NULL; } -#endif int format = af_from_avformat(av_frame->format); if (!format && av_frame->format != AV_SAMPLE_FMT_NONE) @@ -144,15 +142,7 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame) abort(); frame->format = format; -#if !HAVE_AV_CHANNEL_LAYOUT - mp_chmap_from_lavc(&frame->chmap, frame->av_frame->channel_layout); - - // FFmpeg being a stupid POS again - if (frame->chmap.num != frame->av_frame->channels) - mp_chmap_from_channels(&frame->chmap, av_frame->channels); -#else frame->chmap = converted_map; -#endif if (av_frame->opaque_ref) { struct avframe_opaque *op = (void *)av_frame->opaque_ref->data; @@ -221,15 +211,8 @@ void mp_aframe_config_copy(struct mp_aframe *dst, struct mp_aframe *src) dst->av_frame->sample_rate = src->av_frame->sample_rate; dst->av_frame->format = src->av_frame->format; -#if !HAVE_AV_CHANNEL_LAYOUT - dst->av_frame->channel_layout = src->av_frame->channel_layout; - // FFmpeg being a stupid POS again - dst->av_frame->channels = src->av_frame->channels; -#else - if (av_channel_layout_copy(&dst->av_frame->ch_layout, - &src->av_frame->ch_layout) < 0) + if (av_channel_layout_copy(&dst->av_frame->ch_layout, &src->av_frame->ch_layout) < 0) abort(); -#endif } // Copy "soft" attributes from src to dst, excluding things which affect @@ -339,20 +322,9 @@ bool mp_aframe_set_chmap(struct mp_aframe *frame, struct mp_chmap *in) if (mp_aframe_is_allocated(frame) && in->num != frame->chmap.num) return false; -#if !HAVE_AV_CHANNEL_LAYOUT - uint64_t lavc_layout = mp_chmap_to_lavc_unchecked(in); - if (!lavc_layout && in->num) - return false; -#endif frame->chmap = *in; - -#if !HAVE_AV_CHANNEL_LAYOUT - frame->av_frame->channel_layout = lavc_layout; - // FFmpeg being a stupid POS again - frame->av_frame->channels = frame->chmap.num; -#else mp_chmap_to_av_layout(&frame->av_frame->ch_layout, in); -#endif + return true; } diff --git a/audio/chmap_avchannel.h b/audio/chmap_avchannel.h index e136ccc7ce..84062c49d0 100644 --- a/audio/chmap_avchannel.h +++ b/audio/chmap_avchannel.h @@ -23,10 +23,6 @@ #include "chmap.h" -#if HAVE_AV_CHANNEL_LAYOUT - bool mp_chmap_from_av_layout(struct mp_chmap *dst, const AVChannelLayout *src); void mp_chmap_to_av_layout(AVChannelLayout *dst, const struct mp_chmap *src); - -#endif diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 39cd74cd2a..8bab80901b 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -113,10 +113,6 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec, if (opts->downmix && mpopts->audio_output_channels.num_chmaps == 1) { const struct mp_chmap *requested_layout = &mpopts->audio_output_channels.chmaps[0]; -#if !HAVE_AV_CHANNEL_LAYOUT - lavc_context->request_channel_layout = - mp_chmap_to_lavc(requested_layout); -#else AVChannelLayout av_layout = { 0 }; mp_chmap_to_av_layout(&av_layout, requested_layout); @@ -126,7 +122,6 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec, AV_OPT_SEARCH_CHILDREN); av_channel_layout_uninit(&av_layout); -#endif } // Always try to set - option only exists for AC3 at the moment diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c index def9700d18..a83d24cf18 100644 --- a/audio/filter/af_lavcac3enc.c +++ b/audio/filter/af_lavcac3enc.c @@ -116,12 +116,7 @@ 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; @@ -290,15 +285,6 @@ 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}; - mp_chmap_from_lavc(&chmap, lch[n]); - 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}; @@ -315,7 +301,6 @@ static void add_chmaps_to_autoconv(struct mp_filter *f, if (mp_chmap_is_valid(&chmap)) mp_autoconvert_add_chmap(conv, &chmap); } -#endif } static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent, @@ -357,14 +342,7 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent, // For this one, we require the decoder to export lists of all supported // parameters. (Not all decoders do that, but the ones we're interested // in do.) - if (!s->lavc_acodec->sample_fmts || -#if !HAVE_AV_CHANNEL_LAYOUT - !s->lavc_acodec->channel_layouts -#else - !s->lavc_acodec->ch_layouts -#endif - ) - { + if (!s->lavc_acodec->sample_fmts || !s->lavc_acodec->ch_layouts) { MP_ERR(f, "Audio encoder doesn't list supported parameters.\n"); goto error; } diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 4bae4389e8..83f52e590f 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -126,13 +126,7 @@ static int init(struct ao *ao) if (!ao_chmap_sel_adjust2(ao, &sel, &ao->channels, false)) goto fail; mp_chmap_reorder_to_lavc(&ao->channels); - -#if !HAVE_AV_CHANNEL_LAYOUT - encoder->channels = ao->channels.num; - encoder->channel_layout = mp_chmap_to_lavc(&ao->channels); -#else mp_chmap_to_av_layout(&encoder->ch_layout, &ao->channels); -#endif encoder->sample_fmt = AV_SAMPLE_FMT_NONE; diff --git a/common/av_common.c b/common/av_common.c index a4fa5981ff..8bf65c848c 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -96,13 +96,7 @@ AVCodecParameters *mp_codec_params_to_av(const struct mp_codec_params *c) avp->bit_rate = c->bitrate; avp->block_align = c->block_align; -#if !HAVE_AV_CHANNEL_LAYOUT - avp->channels = c->channels.num; - if (!mp_chmap_is_unknown(&c->channels)) - avp->channel_layout = mp_chmap_to_lavc(&c->channels); -#else mp_chmap_to_av_layout(&avp->ch_layout, &c->channels); -#endif return avp; error: diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 3ac915cdfb..b1b65f53d6 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -714,13 +714,6 @@ static void handle_new_stream(demuxer_t *demuxer, int i) switch (codec->codec_type) { case AVMEDIA_TYPE_AUDIO: { sh = demux_alloc_sh_stream(STREAM_AUDIO); - -#if !HAVE_AV_CHANNEL_LAYOUT - // probably unneeded - mp_chmap_set_unknown(&sh->codec->channels, codec->channels); - if (codec->channel_layout) - mp_chmap_from_lavc(&sh->codec->channels, codec->channel_layout); -#else if (!mp_chmap_from_av_layout(&sh->codec->channels, &codec->ch_layout)) { char layout[128] = {0}; MP_WARN(demuxer, @@ -729,7 +722,6 @@ static void handle_new_stream(demuxer_t *demuxer, int i) layout, 128) < 0 ? "undefined" : layout); } -#endif sh->codec->samplerate = codec->sample_rate; sh->codec->bitrate = codec->bit_rate; diff --git a/filters/f_lavfi.c b/filters/f_lavfi.c index 3e447d16cf..e28e2367ed 100644 --- a/filters/f_lavfi.c +++ b/filters/f_lavfi.c @@ -477,11 +477,7 @@ static bool init_pads(struct lavfi *c) params->sample_rate = mp_aframe_get_rate(fmt); struct mp_chmap chmap = {0}; mp_aframe_get_chmap(fmt, &chmap); -#if !HAVE_AV_CHANNEL_LAYOUT - params->channel_layout = mp_chmap_to_lavc(&chmap); -#else mp_chmap_to_av_layout(¶ms->ch_layout, &chmap); -#endif pad->timebase = (AVRational){1, mp_aframe_get_rate(fmt)}; filter_name = "abuffer"; } else if (pad->type == MP_FRAME_VIDEO) { @@ -1036,11 +1032,7 @@ static const char *get_avopt_type_name(enum AVOptionType type) case AV_OPT_TYPE_VIDEO_RATE: return "fps"; case AV_OPT_TYPE_DURATION: return "duration"; case AV_OPT_TYPE_COLOR: return "color"; -#if LIBAVUTIL_VERSION_MAJOR < 59 - case AV_OPT_TYPE_CHANNEL_LAYOUT: return "ch_layout"; -#else case AV_OPT_TYPE_CHLAYOUT: return "ch_layout"; -#endif case AV_OPT_TYPE_BOOL: return "bool"; case AV_OPT_TYPE_CONST: // fallthrough default: diff --git a/filters/f_swresample.c b/filters/f_swresample.c index 0d88a07af1..ee0835b896 100644 --- a/filters/f_swresample.c +++ b/filters/f_swresample.c @@ -270,38 +270,21 @@ static bool configure_lavrr(struct priv *p, bool verbose) out_ch_layout = fudge_layout_conversion(p, in_ch_layout, out_ch_layout); -#if HAVE_AV_CHANNEL_LAYOUT // Real conversion; output is input to avrctx_out. AVChannelLayout in_layout, out_layout; mp_chmap_to_av_layout(&in_layout, &in_lavc); mp_chmap_to_av_layout(&out_layout, &out_lavc); av_opt_set_chlayout(p->avrctx, "in_chlayout", &in_layout, 0); av_opt_set_chlayout(p->avrctx, "out_chlayout", &out_layout, 0); -#else - av_opt_set_int(p->avrctx, "in_channel_layout", in_ch_layout, 0); - av_opt_set_int(p->avrctx, "out_channel_layout", out_ch_layout, 0); -#endif av_opt_set_int(p->avrctx, "in_sample_rate", p->in_rate, 0); av_opt_set_int(p->avrctx, "out_sample_rate", p->out_rate, 0); av_opt_set_int(p->avrctx, "in_sample_fmt", in_samplefmt, 0); av_opt_set_int(p->avrctx, "out_sample_fmt", out_samplefmtp, 0); -#if HAVE_AV_CHANNEL_LAYOUT AVChannelLayout fake_layout; av_channel_layout_default(&fake_layout, map_out.num); av_opt_set_chlayout(p->avrctx_out, "in_chlayout", &fake_layout, 0); av_opt_set_chlayout(p->avrctx_out, "out_chlayout", &fake_layout, 0); -#else - // Just needs the correct number of channels for deplanarization. - struct mp_chmap fake_chmap; - mp_chmap_set_unknown(&fake_chmap, map_out.num); - uint64_t fake_out_ch_layout = mp_chmap_to_lavc_unchecked(&fake_chmap); - if (!fake_out_ch_layout) - goto error; - av_opt_set_int(p->avrctx_out, "in_channel_layout", fake_out_ch_layout, 0); - av_opt_set_int(p->avrctx_out, "out_channel_layout", fake_out_ch_layout, 0); -#endif - av_opt_set_int(p->avrctx_out, "in_sample_fmt", out_samplefmtp, 0); av_opt_set_int(p->avrctx_out, "out_sample_fmt", out_samplefmt, 0); av_opt_set_int(p->avrctx_out, "in_sample_rate", p->out_rate, 0); diff --git a/meson.build b/meson.build index 1d146423b3..86cd4d22c7 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,7 @@ sources = files( ## Audio 'audio/aframe.c', 'audio/chmap.c', + 'audio/chmap_avchannel.c', 'audio/chmap_sel.c', 'audio/decode/ad_lavc.c', 'audio/decode/ad_spdif.c', @@ -599,13 +600,6 @@ if darwin subdir(join_paths('TOOLS', 'osxbundle')) endif - -# misc dependencies -features += {'av-channel-layout': libavutil.version().version_compare('>= 57.24.100')} -if features['av-channel-layout'] - sources += files('audio/chmap_avchannel.c') -endif - cdda_opt = get_option('cdda').require( get_option('gpl'), error_message: 'the build is not GPL!', diff --git a/test/chmap.c b/test/chmap.c index 48af822e72..d6b69d233f 100644 --- a/test/chmap.c +++ b/test/chmap.c @@ -1,11 +1,9 @@ -#include "audio/chmap.h" -#include "audio/chmap_sel.h" #include "config.h" -#include "test_utils.h" -#if HAVE_AV_CHANNEL_LAYOUT +#include "audio/chmap.h" #include "audio/chmap_avchannel.h" -#endif +#include "audio/chmap_sel.h" +#include "test_utils.h" #define LAYOUTS(...) (char*[]){__VA_ARGS__, NULL} @@ -34,7 +32,6 @@ static void test_sel(const char *input, const char *expected_selection, mp_chmap_to_str(&expected_map)); } -#if HAVE_AV_CHANNEL_LAYOUT static bool layout_matches(const AVChannelLayout *av_layout, const struct mp_chmap *mp_layout, bool require_default_unspec) @@ -151,8 +148,6 @@ static void test_av_channel_layout_to_mp_chmap(void) assert_false(anything_failed); } -#endif - int main(void) { @@ -210,9 +205,8 @@ int main(void) assert_int_equal(mp_chmap_diffn(&a, &b), 0); assert_int_equal(mp_chmap_diffn(&b, &a), 3); -#if HAVE_AV_CHANNEL_LAYOUT test_av_channel_layout_to_mp_chmap(); test_mp_chmap_to_av_channel_layout(); -#endif + return 0; } diff --git a/test/meson.build b/test/meson.build index d7a5839747..2d27169422 100644 --- a/test/meson.build +++ b/test/meson.build @@ -76,11 +76,9 @@ img_utils = static_library('img-utils', 'img_utils.c', include_directories: incd # The actual tests. chmap_files = [ - 'audio/chmap_sel.c' + 'audio/chmap_avchannel.c', + 'audio/chmap_sel.c', ] -if features['av-channel-layout'] - chmap_files += 'audio/chmap_avchannel.c' -endif chmap_objects = libmpv.extract_objects(chmap_files) chmap = executable('chmap', 'chmap.c', include_directories: incdir, dependencies: [libavutil], objects: chmap_objects,