From: Romain Beauxis <toots@rastageeks.org> To: ffmpeg-devel@ffmpeg.org Cc: Romain Beauxis <toots@rastageeks.org> Subject: [FFmpeg-devel] [PATCH] Set native order for wav channel layouts up until 8 channels. Date: Fri, 23 Feb 2024 14:41:06 -0600 Message-ID: <20240223204105.95953-1-toots@rastageeks.org> (raw) The new default channel layout for the various RIFF/WAV decoders is not backward compatible. Historically, most decoders will expect the channel layouts to follow the native layout up-to a reasonable number of channels. Additionally, non-native layouts are causing troubles with filters chaining. This PR changes the default channel layout reported by RIFF/WAV decoders to default to the native layout when the number of channels is up-to 8. The logic for these changes is the same as the logic for the vorbis/opus decoders. Romain --- libavformat/riff.h | 1 + libavformat/riffdec.c | 31 ++++++++++++++++++++++++++++--- libavformat/wavdec.c | 4 +--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavformat/riff.h b/libavformat/riff.h index a93eadfeca..f474efdce9 100644 --- a/libavformat/riff.h +++ b/libavformat/riff.h @@ -67,6 +67,7 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags); enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps); +void ff_get_wav_ch_layout(AVChannelLayout *ch_layout, int channels); int ff_get_wav_header(void *logctx, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian); diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index 0fe4e02b7b..bb7c01c5f5 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -90,6 +90,33 @@ static void parse_waveformatex(void *logctx, AVIOContext *pb, AVCodecParameters } } +const AVChannelLayout ff_wav_demux_ch_layouts[9] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + { + .nb_channels = 7, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER, + }, + AV_CHANNEL_LAYOUT_7POINT1, + { 0 } +}; + +void ff_get_wav_ch_layout(AVChannelLayout *ch_layout, int channels) +{ + av_channel_layout_uninit(ch_layout); + if (channels > 8) { + ch_layout->order = AV_CHANNEL_ORDER_UNSPEC; + ch_layout->nb_channels = channels; + } else { + av_channel_layout_copy(ch_layout, &ff_wav_demux_ch_layouts[channels - 1]); + } +} + /* "big_endian" values are needed for RIFX file format */ int ff_get_wav_header(void *logctx, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian) @@ -195,9 +222,7 @@ int ff_get_wav_header(void *logctx, AVIOContext *pb, /* ignore WAVEFORMATEXTENSIBLE layout if different from channel count */ if (channels != par->ch_layout.nb_channels) { - av_channel_layout_uninit(&par->ch_layout); - par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - par->ch_layout.nb_channels = channels; + ff_get_wav_ch_layout(&par->ch_layout, channels); } return 0; diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 0c6629b157..282e1ae017 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -222,9 +222,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream *st) channels += avio_r8(pb); avio_skip(pb, 3); } - av_channel_layout_uninit(&st->codecpar->ch_layout); - st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - st->codecpar->ch_layout.nb_channels = channels; + ff_get_wav_ch_layout(&st->codecpar->ch_layout, channels); if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; -- 2.39.3 (Apple Git-145) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2024-02-23 20:41 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-23 20:41 Romain Beauxis [this message] 2024-02-23 21:11 ` Marton Balint 2024-02-23 22:32 ` Romain Beauxis 2024-02-23 22:57 ` Marton Balint 2024-02-24 0:01 ` James Almer 2024-02-25 1:27 ` Michael Niedermayer 2024-02-28 2:29 ` Romain Beauxis
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240223204105.95953-1-toots@rastageeks.org \ --to=toots@rastageeks.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git