Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] Set native order for wav channel layouts up until 8 channels.
@ 2024-02-23 20:41 Romain Beauxis
  2024-02-23 21:11 ` Marton Balint
  2024-02-25  1:27 ` Michael Niedermayer
  0 siblings, 2 replies; 7+ messages in thread
From: Romain Beauxis @ 2024-02-23 20:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis

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".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-28  2:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 20:41 [FFmpeg-devel] [PATCH] Set native order for wav channel layouts up until 8 channels Romain Beauxis
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

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