0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

various: remove av channel layout check

This commit is contained in:
Kacper Michajłow 2024-06-21 18:24:30 +02:00
parent b64521ae10
commit 3c5a79300c
12 changed files with 10 additions and 128 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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) {
@ -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:

View File

@ -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);

View File

@ -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!',

View File

@ -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;
}

View File

@ -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,