From dcfde2934dd7b5401b29d6a604fa3eca1b867d5c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 24 Jul 2016 19:31:47 +0200 Subject: audio: use idiotic FFmpeg ABI rules for public-except-not-public fields The FFmpeg API is incredibly weird and inconsistent about this. This is also a FFmpeg-only issue and nothing like this is in Libav - which doesn't really show FFmpeg in a very positive light. (To make it even worse: this is a full-blown Libav API incompatibility, even though this crap was added for Libav ABI-compatibility. It's absurd.) Quoting the FFmpeg header for the AVFrame.channels field: /** * number of audio channels, only used for audio. * Code outside libavutil should access this field using: * av_frame_get_channels(frame) * - encoding: unused * - decoding: Read by user. */ int channels; It says "should" not must, and it doesn't even mention av_frame_set_channels(). It's also in the section for public fields (not below a marker that indicates private fields in a public struct, like it's done e.g. in AVCodecContext). But not using the accessor will cause silent failures on ABI changes. The failure that happened due to this code didn't even make it apparent what was wrong. So just use the idiotic accessor. Also harmonize the FFmpeg-cursing in the code. (It's fully justified.) Fixes #3295. Note that mpv will still check the exact library version numbers, and reject mismatches - to protect itself from such issues in the future. --- audio/audio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'audio') diff --git a/audio/audio.c b/audio/audio.c index 710cc03193..4c67a9aa5a 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -347,9 +347,9 @@ struct mp_audio *mp_audio_from_avframe(struct AVFrame *avframe) mp_chmap_from_lavc(&lavc_chmap, avframe->channel_layout); #if LIBAVUTIL_VERSION_MICRO >= 100 - // FFmpeg being special again - if (lavc_chmap.num != avframe->channels) - mp_chmap_from_channels(&lavc_chmap, avframe->channels); + // FFmpeg being stupid POS again + if (lavc_chmap.num != av_frame_get_channels(avframe)) + mp_chmap_from_channels(&lavc_chmap, av_frame_get_channels(avframe)); #endif new->rate = avframe->sample_rate; @@ -407,8 +407,8 @@ int mp_audio_to_avframe(struct mp_audio *frame, struct AVFrame *avframe) if (!avframe->channel_layout) goto fail; #if LIBAVUTIL_VERSION_MICRO >= 100 - // FFmpeg being a stupid POS (but I respect it) - avframe->channels = frame->channels.num; + // FFmpeg being a stupid POS again + av_frame_set_channels(avframe, frame->channels.num); #endif avframe->sample_rate = frame->rate; -- cgit v1.2.3