Skip to content

Commit

Permalink
various: remove av channel layout check
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 committed Jun 22, 2024
1 parent b64521a commit 3c5a793
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 128 deletions.
32 changes: 2 additions & 30 deletions audio/aframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,13 @@ 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;

struct mp_chmap converted_map = { 0 };
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)
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 0 additions & 4 deletions audio/chmap_avchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions audio/decode/ad_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
24 changes: 1 addition & 23 deletions audio/filter/af_lavcac3enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 0 additions & 6 deletions audio/out/ao_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 0 additions & 6 deletions common/av_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions demux/demux_lavf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions filters/f_lavfi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params->ch_layout, &chmap);
#endif
pad->timebase = (AVRational){1, mp_aframe_get_rate(fmt)};
filter_name = "abuffer";
} else if (pad->type == MP_FRAME_VIDEO) {
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 0 additions & 17 deletions filters/f_swresample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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!',
Expand Down
14 changes: 4 additions & 10 deletions test/chmap.c
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -151,8 +148,6 @@ static void test_av_channel_layout_to_mp_chmap(void)

assert_false(anything_failed);
}
#endif


int main(void)
{
Expand Down Expand Up @@ -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;
}
6 changes: 2 additions & 4 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3c5a793

Please sign in to comment.